/**
 * jQuery sliderHp plugin
 * @name jquery.sliderHp.js
 * @author www.k2.pl
 */
(function(jQuery) {

jQuery.fn.sliderHp = function(options) {
		
  	var defaults = {
		classNavi: 'hpSlideNavi',
		classItem: 'hpSlide',
		duration: 10000
  	};

  	var defaults = $.extend(defaults, options);

  	var events = function(elem) {
		var $elem = $(elem);
		
		$elem.append('<div class="loader"><span><!-- --></span></div>');

		$elem.click(function(e) {
			jQuery('.'+defaults.classNavi+' li div.loader span').css({'width':0});
			jQuery(this).addClass('selected');
			jQuery('.'+defaults.classNavi+' li').not(jQuery(this)).removeClass('selected');
			
			if (e.button == 0) stopAnimation();
			
			loaderAnimation();
			
			jQuery('.'+defaults.classItem+' li').hide();
			jQuery('.'+defaults.classItem+' li').eq($elem.index()).fadeIn(300);
			
			return false;
		});
		stopAnimation();
		loaderAnimation();
    };
	
	var loaderAnimation = function() {
		jQuery('.'+defaults.classNavi+' li.selected div.loader span').animate({width:'66px'},defaults.duration,function() {
			if (jQuery(this).parent().parent().next('li').length > 0) {
				jQuery(this).parent().parent().next('li').click();
			} else {
				jQuery('.'+defaults.classNavi+' li').eq(0).click();
			}
			
		});
	}
	
	var stopAnimation = function() {
		jQuery('.'+defaults.classNavi+' li div.loader span').stop();
	}
  	
  	return this.each(function() {
		events(this);	
    });
	
	return this;	
};

})(jQuery);

(function(jQuery) {

jQuery.fn.dotsSlider = function(options) {
		
  	var defaults = {
		classNavi: 'hpSlideNavi',
		classItem: 'hpSlide',
		duration: 10000
  	};

  	var defaults = $.extend(defaults, options);
	var rotation;
    
  	var events = function(elem) {
		var $elem = $(elem);
		
		$elem.click(function(e) {            
			$this = jQuery(this);
			$this.addClass('selected');
			jQuery('.'+defaults.classNavi+' li').not($this).removeClass('selected');
			
			if (e.button == 0) stopAnimation();
			
			loaderAnimation();
			
			jQuery('.'+defaults.classItem+' li').hide().removeClass('selected'); 
			jQuery('.'+defaults.classItem+' li').eq($elem.index()).fadeIn(300).addClass('selected');
            
            var classes = this.className.split(' ');
            for(i in classes) { if (/^(tab-)/.test(classes[i])) { window.location.hash = String(classes[i]).replace('tab-',''); } }            
            return false;
		});
		stopAnimation();
		loaderAnimation();
        checkForHash.call($elem);
    };
	
	var eventsNoAnimation = function(elem) {
		var $elem = $(elem);
		
		$elem.click(function(e) {            
			$this = jQuery(this);
			$this.addClass('selected');
			jQuery('.'+defaults.classNavi+' li').not($this).removeClass('selected');            
			
			if (e.button == 0) stopAnimation();
			
			jQuery('.'+defaults.classItem+' li').hide().removeClass('selected');            
			jQuery('.'+defaults.classItem+' li').eq($elem.index()).fadeIn(300).addClass('selected');            
            
            var classes = this.className.split(' ');
            for(i in classes) { if (/^(tab-)/.test(classes[i])) { window.location.hash = String(classes[i]).replace('tab-',''); } }
            return false;
		});
        checkForHash.call($elem);
    };
	
	var loaderAnimation = function() {
		rotation = setTimeout(function() {
			next = jQuery('.'+defaults.classNavi+' li.selected').next('li');
			if (next.length > 0) {
				next.click();
			} else {
				jQuery('.'+defaults.classNavi+' li').eq(0).click();
			}			
		}, defaults.duration);
	}
	
	var stopAnimation = function() {
		clearTimeout(rotation);
	}
    
    var checkForHash = function() {                
        var hash = window.location.hash;
        if(hash !== '' && jQuery(this).hasClass('tab-'+String(hash).substr(1))) {            
            jQuery(this).trigger('click');
            
        }
    }
  	    
	if (defaults.duration == 0)
		return this.each(function() {            
			eventsNoAnimation(this);            
		});
	else
		return this.each(function() {            
			events(this);	
		});
	
	return this;	
};

})(jQuery);

(function(jQuery) {
jQuery.fn.label = function(options) {
		
  	var defaults = {
	    value: '',
		showOther: 'intPrefix'
  	};
  	
  	jQuery.extend(defaults, options);

	var init = function(elem) {
		if (jQuery(elem).val() == '') {jQuery(elem).prev().show();jQuery(elem).next('.'+defaults.showOther).hide();} else {jQuery(elem).prev().hide();jQuery(elem).next('.'+defaults.showOther).show();}	
		return true;
    };
  	
  	var events = function(elem) {
		var $elem = jQuery(elem);
		
		$elem.focus(function() {$elem.prev().hide();$elem.next('.'+defaults.showOther).show();});
		$elem.blur(function() {if ($elem.val() == '') {$elem.prev('label').show();$elem.next('.'+defaults.showOther).hide();} else {$elem.prev('label').hide();$elem.next('.'+defaults.showOther).show();}});
    };
  	
  	return this.each(function() {if (init(this)) {events(this);}});
	
};

jQuery.fn.searchSAYT = function(options) {
	var defaults = {
		idAutocomplete: 'sayt',
		dataUrl: 'http://szukaj.play.pl/cache/_js/sayt_prompt.js',
		correctTop: 23,
		correctLeft: 101,
		displayItems: 3
	};
	
	jQuery.extend(defaults, options);
	
	var events = function(elem) {
		var $elem = jQuery(elem),
			index = '-1';
			saytData = null;
		jQuery('body').append('<ul id="'+defaults.idAutocomplete+'" style="display:none"></ul>');
		$elem.attr('autocomplete','off');
		
		$elem.click(function(event) { loadData() });
		$elem.keyup(function(event) {
			if (saytData) sayt(event);
			select(event);
			otherKey(event);
		});

		var loadData = function() {
			var script = document.createElement('script');
			script.setAttribute('src', defaults.dataUrl);
			script.setAttribute('id', 'saytScript');
			if (jQuery('#saytScript').length == 0) document.body.appendChild(script)
		}
		
		var select = function(event) {
			var results = jQuery('#'+defaults.idAutocomplete+' li ul li'),
				num = results.length - 1;
			if (event.keyCode == 40) {
				index++;
				if (index >= num) index = num;
				results.eq(index).addClass('selected');
			}
			if (event.keyCode == 38) {
				index--;
				if (index <= 0) index = 0;
				results.eq(index).addClass('selected');
			}
			
			if (event.keyCode == 13) {
				results.eq(index).addClass('selected');
				var href = jQuery('#'+defaults.idAutocomplete+' li ul li.selected a').attr('href');
				if (typeof href != 'undefined') document.location.href = href;
			}
			jQuery('#gcs').submit(function() {
				if (results.eq(index).hasClass('selected')) return false;
			});
		}
		
		var otherKey = function(event) {
			if (event.keyCode == 27) removeAutocomplete();
		}
		
		var sayt = function(event) {
			var value = $elem.val().replace(/\</g,'&lt;').replace(/\>/g,'&gt;'),// Encoder.XSSEncode($elem.val()),
				dim = $elem.offset();
			var category = saytData.category;
			
			removeAutocomplete();

			jQuery('#'+defaults.idAutocomplete).css({'top':dim.top + defaults.correctTop,'left':dim.left - defaults.correctLeft,'display':'block'});
			
				$.each(category,function(k,v){
					function items() {
						var listItem = '',
							found = 1;
						for (i in v) {
							var img = '';
							if (typeof v[i].i != 'undefined') var img = '<img src="'+v[i].i+'" alt="'+v[i].t+'" width="25" />';
							if (found <= defaults.displayItems) {
								if (typeof v[i].k != 'undefined') {
									if (v[i].k.indexOf(value) != '-1'){ 
										listItem += '<li>'+img+'<a href="'+v[i].a+'" title="'+v[i].t+'">'+v[i].t+'</a></li>';
										found++;
									}
								}
							}
						}
						return listItem;								
					}
					function checkItems() {
						if (!items()) {return ' style="display:none"'} else {return ' style="display:block"'}
					}
					jQuery('#'+defaults.idAutocomplete).append('<li'+checkItems()+'><h3>'+k+'</h3><ul>'+items()+'</ul></li>');
				});

			jQuery('#'+defaults.idAutocomplete).append('<li class="search"><a href="#" class="linkPointer linkPointerWhite" title="Wyszukaj '+value+'"><span>Wyszukaj '+value+'</span></a></li>');
			
		}
		jQuery('body').click(function() {removeAutocomplete();});
	}
	
	var removeAutocomplete = function(elem) {
		var $elem = jQuery(elem);
			jQuery('#'+defaults.idAutocomplete).html('').hide();
	}

	return this.each(function() {events(this);});
};
})(jQuery);

(function(jQuery) {
	//jQuery('ul.hpSlideNavi li').sliderHp();
	f = jQuery('#fade');
	if (!f.length){
		jQuery('ul.hpSlideNavi li').dotsSlider({duration:0});
	} else {
		/* f.siblings().css('opacity','0');
		f.show();
		setTimeout(function(){f.find('.hpText').fadeIn(1200);}, 500);
		
		setTimeout(function(){
			f.css('z-index','-1');
			f.siblings().css('visibility','visible').animate({'opacity':'1'}, 600, function(){f.hide();});
		}, 2500);
		*/
		
		o_body = jQuery('<div class="fade-overlay" style="z-index:1;" />').height(jQuery(document).height());
		jQuery('body').prepend(o_body);
		
		o_fade = jQuery('<div class="fade-overlay" style="z-index:3;" />');
		
		t = f.find('.hpText');
		if (t.length)
			setTimeout(function(){t.fadeIn(1200);}, 3000);
			
		p = f.find('.photo');
		if (p.length)
			setTimeout(function(){p.fadeIn(1200);}, 1400);
		
		o_body.prepend(o_fade);
		f.css('z-index', 2).appendTo(o_body);
		o_fade.fadeOut(1200, function(){
			setTimeout(function(){
				o_body.siblings().css('visibility','visible');
				o_body.animate({'opacity':'0'}, 600, function(){o_body.hide();});
			}, 3500)
		});	
		
		jQuery('ul.hpSlideNavi li').dotsSlider({duration:0});
	}
	
	jQuery('input#q').label();
	jQuery('input#q').searchSAYT();
	tabs = jQuery('.hpSlideNavi li');
	total_width = jQuery('.hpSlide').outerWidth()-1;
	if ( jQuery('.hpSlideNavi.proportional').length ) {
		tabs_width = 0;
		tabs.each(function(id, el){
			$el = jQuery(el);
			tabs_width += $el.width() + parseInt($el.css('border-left-width')) + parseInt($el.css('border-right-width'));
		});
		padd = Math.round((total_width - tabs_width)/(2*tabs.length));
		tabs.css({'padding-left':padd, 'padding-right':padd});
		padd2 = total_width - tabs_width - (tabs.length-1)*padd*2;
		padd2_1 = Math.round(padd2/2);
		padd2_2 = padd2 - padd2_1;
		tabs.last().css({'padding-left':padd2_1, 'padding-right':padd2_2});
	} else {
		tab_width = Math.round(total_width/tabs.length);
		tabs.each(function(id, el){
			$el = jQuery(el);
			padd = $el.outerWidth() - $el.width();
			$el.css({'width' : tab_width - padd });
		});
	}
	
	alignButtons();
	jQuery('li.search a').live('click', function() {
		jQuery('input.submitSearch').click();
		return false;
	});
})(jQuery);

function alignButtons() {
	jQuery('.hpSlide li, .hpSlide').show().find('.hpButton').each(function(){
		$this = jQuery(this);
		//$this.css('bottom', -12-$this.outerHeight());
	});
	jQuery('.hpSlide li').not('.selected').hide();
}

/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

Encoder = {
	// Encodes the basic 4 characters used to malform HTML in XSS hacks
	isEmpty : function(val){
		if(val){
			return ((val===null) || val.length==0 || /^\s+$/.test(val));
		}else{
			return true;
		}
	},
	XSSEncode : function(s,en){
		if(!this.isEmpty(s)){
			en = en || true;
			// do we convert to numerical or html entity?
			if(en){
				s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross browser supported
				s = s.replace(/\"/g,"&quot;");
				s = s.replace(/</g,"&lt;");
				s = s.replace(/>/g,"&gt;");
			}else{
				s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross browser supported
				s = s.replace(/\"/g,"&#34;");
				s = s.replace(/</g,"&#60;");
				s = s.replace(/>/g,"&#62;");
			}
			return s;
		}else{
			return "";
		}
	}
}

jQuery(document).ready(function() {
	if( jQuery.browser.opera ){
		if( parseFloat(jQuery.browser.version) < 10.6 ){
			jQuery('a.ButtonBig, a.ButtonMedium, a.grayButtonSmall, a.whiteButtonSmall, a.blueButtonSmall').each(function(){
				var tmpText = jQuery(this).find('span').text();
				if (jQuery(this).find('span').remove().length) jQuery(this).html('<em>'+tmpText+'</em>');
			});
			jQuery('span.ButtonBig,span.ButtonMedium, span.grayButtonSmall, span.whiteButtonSmall, span.blueButtonSmall').each(function(){
				var tmpClass = jQuery(this).attr('class');
				jQuery(this).find('input').unwrap('span').wrap('<em class="'+tmpClass+'"></em>');
			});
			jQuery('#sidebar .sidebarToggle span').css({'float':'none'});
		}
	}
	
	if (jQuery('#MNPcontainer .MNPform').length != 0){
		jQuery('input[name=network]').change(function(){
			if (jQuery(this).val() == 'play') {
				jQuery('#MNPcontainer').find('.msgOther').hide().end()
					.find('.msgPlay').show();
			}
			jQuery('#network').hide();
			jQuery('#rate').show();
		});
		if (jQuery('input[name=rate]').filter(':checked').length) 
			jQuery('input[type=submit]').attr('disabled','');
		jQuery('input[name=rate]').change(function(){
			jQuery('input[type=submit]').attr('disabled','');
		});
		jQuery('.MNPform').submit(function(){
			f = jQuery(this);
			params = f.serialize();
			window.location = f.attr('action') + '?' + params;
		});
	}
});
