(function($) {
  var cache = [];
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
$(document).ready(function() {

	$('#bannerslider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices: 10,
		animSpeed:500,
		pauseTime:8000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});

	$('.nivo-caption').click(function(){
		$(this).siblings('a.newtarget:visible').each(function(){
			window.open($(this).attr('href'), '_blank').focus();
		});
	});

	$('#cycle5').cycle({
		prev:   '#prev5',
		next:   '#next5',
		timeout: 5000,
		prevNextClick: function(){
			$('#cycle5').cycle('pause');
		}
	});

	$('#cycle6').cycle({
		prev:   '#prev6',
		next:   '#next6',
		timeout: 5000,
		delay: 2500,
		prevNextClick: function(){
			$('#cycle6').cycle('pause');
		}
	});

	$(".newtarget").attr('target','_blank');
	
	if(isNaN($("p.stronnicowanie :first-child").text())){
		$("p.stronnicowanie :first-child").addClass('prev');
	};
	if(isNaN($("p.stronnicowanie :last-child").text())){
		$("p.stronnicowanie :last-child").addClass('next');
	};
	$("#top_container li:last-child").addClass('nobackground');

	$('#top_container ul.level1>li').hover(function(){
		$(this).children('ul.level2').slideDown('slow');
	},function(){
		$(this).children('ul.level2').slideUp('fast');
	});

	$('a.fancy').fancybox({
		margin: 0,
		padding: 0,
		hideOnContentClick: true
	});

	if(!$.cookie('intro_displayed')){
		$('body').append('<div id="introContent"></div>');
		var flashvars = {
		};
		flashvars.verticalGrid = 20;
		flashvars.horizontalGrid = 10;
		flashvars.sparksScale = 1;
		flashvars.staticTime = 5;
		flashvars.randomTime = 3;
		flashvars.disappearTime = 1;
		flashvars.xPoint = 500;
		flashvars.yPoint = 800;
		flashvars.xBlur = 150;
		flashvars.yBlur = 150;
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			bgcolor: "#FFFFFF",
			wmode: "transparent"
		};
		var attributes = {
			id:"introContent"
		};
		swfobject.embedSWF("/gfx/intro.swf", "introContent", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}else{
		jQuery.preLoadImages("/gfx/rh.png", "/gfx/rv.png");
	}
});
function closeIntro(){
	document.getElementById('introContent').style.display = 'none';
	var date = new Date();
	date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); //30 dni
	$.cookie('intro_displayed', '1', {
		path: '/'
//		,		expires: date
	});
	jQuery.preLoadImages("/gfx/rh.png", "/gfx/rv.png");
}
