/**
 * WUP
 * skrypty ogólne
 * 
 * @project wawro_wup
 * @requires JQuery 1.4.2+
 * @lastmodified 
 */


/**
* 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);


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}}; 
 
 
/**
* Marquee plugin
* author Remy Sharp
* url http://remysharp.com/tag/marquee
*/
(function(a){a.fn.marquee=function(b){var e=[],d=this.length;function c(m,k,l){var j=l.behavior,h=l.width,g=l.dir;var i=0;if(j=="alternate"){i=m==1?k[l.widthAxis]-(h*2):h}else{if(j=="slide"){if(m==-1){i=g==-1?k[l.widthAxis]:h}else{i=g==-1?k[l.widthAxis]-(h*2):0}}else{i=m==-1?k[l.widthAxis]:0}}return i}function f(){var h=e.length,j=null,m=null,l={},k=[],g=false;while(h--){j=e[h];m=a(j);l=m.data("marqueeState");if(m.data("paused")!==true){j[l.axis]+=(l.scrollamount*l.dir);g=l.dir==-1?j[l.axis]<=c(l.dir*-1,j,l):j[l.axis]>=c(l.dir*-1,j,l);if((l.behavior=="scroll"&&l.last==j[l.axis])||(l.behavior=="alternate"&&g&&l.last!=-1)||(l.behavior=="slide"&&g&&l.last!=-1)){if(l.behavior=="alternate"){l.dir*=-1}l.last=-1;m.trigger("stop");l.loops--;if(l.loops===0){if(l.behavior!="slide"){j[l.axis]=c(l.dir,j,l)}else{j[l.axis]=c(l.dir*-1,j,l)}m.trigger("end")}else{k.push(j);m.trigger("start");j[l.axis]=c(l.dir,j,l)}}else{k.push(j)}l.last=j[l.axis];m.data("marqueeState",l)}else{k.push(j)}}e=k;if(e.length){setTimeout(f,25)}}this.each(function(j){var n=a(this),g=n.attr("width")||n.width(),o=n.attr("height")||n.height(),p=n.after("<div "+(b?'class="'+b+'" ':"")+'style="display: block-inline; width: '+g+"px; height: "+o+'px; overflow: hidden;"><div style="float: left; white-space: nowrap;">'+n.html()+"</div></div>").next(),m=p.get(0),k=0,l=(n.attr("direction")||"left").toLowerCase(),h={dir:/down|right/.test(l)?-1:1,axis:/left|right/.test(l)?"scrollLeft":"scrollTop",widthAxis:/left|right/.test(l)?"scrollWidth":"scrollHeight",last:-1,loops:n.attr("loop")||-1,scrollamount:n.attr("scrollamount")||this.scrollAmount||2,behavior:(n.attr("behavior")||"scroll").toLowerCase(),width:/left|right/.test(l)?g:o};if(n.attr("loop")==-1&&h.behavior=="slide"){h.loops=1}n.remove();if(/left|right/.test(l)){p.find("> div").css("padding","0 "+g+"px")}else{p.find("> div").css("padding",o+"px 0")}p.bind("stop",function(){p.data("paused",true)}).bind("pause",function(){p.data("paused",true)}).bind("start",function(){p.data("paused",false)}).bind("unpause",function(){p.data("paused",false)}).data("marqueeState",h);e.push(m);m[h.axis]=c(h.dir,m,h);p.trigger("start");if(j+1==d){f()}});return a(e)}}(jQuery));
 

/**
 * in-field label
 *
 * @revision 2
 */
(function($){
	$.fn.inFieldLabel = function() {
		this.each(function() {
			var $this = $(this);
			if($this.val() === '') {
				$this.val($this.attr('title'));
			}
			$this.focus(function() {
				$this.removeClass('default');
				if($this.val() === $this.attr('title')) {
					$this.val('');
				}
			});
			$this.blur(function() {
				if($this.val() === '') {
					$this.val($this.attr('title')).addClass('default');
				}
			});
		});
		return $(this);
	}
})(jQuery);	  


/**
 * pictureViewer
 * jQuery Plugin
 * 
 * @revision 2
 * @requires jquery.colorbox-min.js
 * @author Mateusz Janik
 *
 */
(function($){
$.fn.pictureViewer = function() {
	
	return this.each( function() {

		var 
		$this = $(this),
		$picture = $('.pv-picture', $this),
		$thumbs = $('.pv-thumbs', $this)
		;
		
		// init "lightbox"
		$thumbs.find('.big')
		//.attr('rel','gallery')
		.colorbox(config.colorbox);
		
		$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);
/**/
 

/* ************************************************

   Document ready 

*/
$(function(){

	
	/**
	 * Opóźnienie rozwijania menu
	 */
	$('#nav > ul > li:has(ul)').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() { 
			$t = $(this);
			$t.parents('#nav').find('> ul ul').hide().parent('li').removeClass('h');
			$t.addClass('h');
			$(' > ul', this).show().css('z-index','1999'); 
		}, 
		out: function() {
			$t = $(this);
			$(' > ul', this).slideUp(100, function () {
				$(this).css('z-index','');
				$t.removeClass('h');
			} ); 
		}
	} );
	/**/
	
	
	/**
	 * 
	 */
	$("#searchbar-text, #newsletter :text").inFieldLabel();
	
	
	/**
	 * Zakładki na stronie głównej
	 * @requires JQuery Tools
	 */
	$("#home-slides .nav").tabs("#home-slides .panes > div", {
		rotate: true,
		tabs: 'a'
	})
	.slideshow({
		autoplay: true,
		interval: 4000,
		clickable: false
	});
	
	$("#home-empemp .tabs").tabs("#home-empemp .panes > div", {
		rotate: true,
		tabs: 'li'
	});
	$("#home-news .tabs").tabs("#home-news .panes > div", {
		rotate: true,
		tabs: 'li'
	});


	/**
	 * Zmiana rozmiaru tekstu i trybu tekstowego
	 */
	$('#readability .size > a').click( function () {
		var cl = 'font'+$(this).attr('class');
		$('body').removeClass('fontsize-1 fontsize-2').toggleClass(cl)
		$.cookie('readability_size', cl);
		return false;
	} );
	$('#readability .contrast > a').click( function () { 
		// kontrast:
		$('body').toggleClass('contrast');
		$.cookie('readability_contrast', $('body').hasClass('contrast') ? 'contrast' : '');
		return false;
	} );
	// Włączenie trybu na start strony wedle zapisanych ciastek:
	$('body').addClass($.cookie('readability_size'));
	$('body').addClass($.cookie('readability_contrast'));	
	

	/**
	 * Otwieranie warstwy z newsletterem
	 */
	var $newsletter_popup = $('#newsletter');
	$('#header-tools .mail').click(function () {
		$newsletter_popup.slideToggle();
		return false
	});
	$newsletter_popup.find('.close').click(function () {
		$newsletter_popup.slideToggle();
		return false
	});
		

	/**
	 * Inicjalizacja przeglądarki zdjęć
	 */	
	$('.picviewer').pictureViewer();	
	
	
	/**
	 * Marquee
	 */
	var $sms_list = $('#sms-list');
	$sms_list.find('.marquee ul').marquee('marquee').mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	}).mousemove(function (event) {
		if ($(this).data('drag') == true) {
			this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
		}
	}).mousedown(function (event) {
		$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
		$(this).data('drag', false);
	});	
		

	
	
	
}) // Document ready
/* ************************************************ */


var config = config || {};

config.colorbox = {
	opacity: .64,
	transition: 'none',
	current: "Zdjęcie <b>{current}</b> z {total}",
	title: function(){
		var url = $(this).attr('href');
		return '<a href="'+url+'" target="_blank">Otwórz w nowym oknie</a>';
	},
	maxWidth: '90%',
	maxHeight: '90%'
}
