/**
 *
 * Latex opony
 * skrypty ogólne
 * 
 * @lastmodified 00:44 2010-04-13
 * @requires jQuery 1.4.2
 *
 */

 
/**
 * tabz
 * jQuery plugin
 *
 * @revision 2 
 */
(function($){
$.fn.tabz = function(options) {
	var settings = $.extend({
			clActive: 'active'
		}, options);	
	
	return this.each( function() {
		var $root = $(this);
		var activeID = $root.find('.'+settings.clActive+' a').attr('href');
		
		$root.find('a').click(function () {
			( $(activeID).length ) ? $(activeID).hide() : ''; 
			
			$(this).parents('li').addClass(settings.clActive).siblings().removeClass(settings.clActive);
			activeID = $(this).attr('href');
			
			( $(activeID).length ) ? $(activeID).show() : '';
			
			return false
		}) // click
		
	});	// each
}
})(jQuery); 
/**/
 

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
/**/


/**
 * pictureViewer
 * jQuery Plugin
 * 
 * @requires //ceebox// colorbox
 * @revision 1
 *
 */
(function($){
$.fn.pictureViewer = function() {
	
	return this.each( function() {
		var $this = $(this);
		$this.find('.big').colorbox();
		
		var $picture = $('.pv-picture', $this)
		var $thumbs = $('.pv-thumbs', $this)
		
		$picture.find('a').click( function () {
			$thumbs.find('li.active > .big').click();
			return false
		} );
		
		$thumbs.find('a.thumb').click(function () {
			var $self = $(this); 
			var $item = $(this).parent('li');
			
			$picture
			.find('img').attr('src', $self.siblings('.medium').attr('href'))
			.end()
			.find('a').attr('href', $self.siblings('.big').attr('href'))
			.end();
			
			$item.addClass('active').siblings().removeClass() 
			
			return false
 
		}) // click
	});	// each
}
})(jQuery);
/**/

/* Rounds decimals just like PHP round */
function roundVal(val, dec){	
	if (dec == null){
		dec = 2;
	}
	var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
};

/* Delay of action module pattern */
var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();


/* ************************************************

   Document ready 

*/
$(function(){

	
	/**
	 * Opóźnienie rozwijania menu z kategoriami
	 */
	$('#nav > ul > li:not(".current")').hoverIntent( {
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 50, // number = milliseconds for onMouseOver polling interval
		timeout: 250, // number = milliseconds delay before onMouseOut
		over: function() { $(' ul', this).show().css('z-index','999'); }, 
		out: function() {
			$t = $(this);
			$(' ul', this).fadeOut('fast', function () {
				$(this).css('z-index','');
				$t.parent().find('li.current > ul').show();
			} ); 
		}
	} );
	
	/* 	
	@todo
	$('#nav > ul > li:not(".current") > a').hover( function () {
		$(this).parent().parent().find('li.current > ul').hide()
	},
	function () {
		$(this).parent().parent().find('li.current > ul').show()
	}
	); */
	
	
	/**
	 * Produkt: zakładki
	 */
//	$('#product-contents .tabs').tabz({clActive: 'current'});
	$('#product-contents').tabs({});
	 
	/**
	 * Produkt: galeria
	 */	
	$('#product-pics').pictureViewer();
	
	
}) // Document ready
/* ************************************************ */
