jQuery.noConflict();

jQuery(document).ready(function(){
	
	// activates the lightbox page, if you are using a dark color scheme use another theme parameter
	my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox']");
	
	if(!jQuery.browser.msie || jQuery.browser.version >= 9){
		jQuery('#sortiment').kriesi_image_preloader({delay:200});	// activates preloader for non-slideshow images
		jQuery('#hlavni').kriesi_image_preloader({delay:200});	// activates preloader for non-slideshow images
	}
	
		// initialize scrollable
	jQuery(".scrollable").scrollable();
	
	jQuery('#animaceTrans').jqFancyTransitions({
		effect: '', // wave, zipper, curtain
		width: 343, // width of panel
		height: 213, // height of panel
		strips: 20, // number of strips
		delay: 3000, // delay between images in ms
		stripDelay: 50, // delay beetwen strips in ms
		titleOpacity: 0.7, // opacity of title
		titleSpeed: 1000, // speed of title appereance in ms
		position: 'alternate', // top, bottom, alternate, curtain
		direction: 'fountainAlternate', // left, right, alternate, random, fountain, fountainAlternate
		navigation: false, // prev and next navigation buttons
		links: false // show images as links
	});
	
  	
});


function my_lightbox($elements)
{	
	jQuery('.gallery-item a').attr('rel','lightbox[grouped]');
	
	//volba svetly nebo tmavy theme
	var usedCSS = 1;
	/*jQuery('link').each(function()
	{	
		styleURL = jQuery(this).attr('href'); 
		CSSnumber = styleURL.match(/style(\d).css/);
		if(CSSnumber && CSSnumber.length > 0)
		{
			usedCSS = CSSnumber[1];
		}
	});*/
		
	
	var theme_selected = 'light_rounded';
	if (usedCSS == 2 || usedCSS == 4)
	{
		theme_selected = 'dark_rounded';
	}
	
	jQuery($elements).prettyPhoto({
			"theme": theme_selected, social_tools: false, overlay_gallery: false /* light_rounded / dark_rounded / light_square / dark_square */																	});
	
	jQuery($elements).each(function()
	{	
		var $image = jQuery(this).contents("img");
		$newclass = 'lightbox_video';
		
		if(jQuery(this).attr('href').match(/(jpg|gif|jpeg|png|tif)/)) $newclass = 'lightbox_image';
			
		if ($image.length > 0)
		{	
			if(jQuery.browser.msie &&  jQuery.browser.version < 7) jQuery(this).addClass('ie6_lightbox');
			
			var $bg = jQuery("<span class='"+$newclass+" ie6fix'></span>").appendTo(jQuery(this)),
				$padding_x = parseInt($image.css('padding-left')) + parseInt($image.css('padding-right')),
				$padding_y = parseInt($image.css('padding-top')) + parseInt($image.css('padding-bottom')),
				$border_x = 0//parseInt($image.css('border-left-width')) + parseInt($image.css('border-right-width')),
				$border_y = 0//parseInt($image.css('border-top-width')) + parseInt($image.css('border-bottom-width'));
			
			jQuery(this).bind('mouseenter', function()
			{
				$height = parseInt($image.height()) + $padding_x + $border_x;
				$width = parseInt($image.width()) + $padding_y + $border_y;
				$pos =  $image.position();
				$bg.css({height:$height, width:$width, top:$pos.top, left:$pos.left});
			});
		}
	});	
	
	jQuery($elements).contents("img").hover(function()
	{
		jQuery(this).stop().animate({opacity:0.5},400);
	},
	function()
	{
		jQuery(this).stop().animate({opacity:1},400);
	});
}
	
// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------


(function($)
{
	$.fn.kriesi_image_preloader = function(variables, callback) 
	{
		var defaults = 
		{
			fadeInSpeed: 600,
			maxLoops: 10,
			callback: '',
			delay:500
		};
		
		var options = $.extend(defaults, variables);
			
		return this.each(function()
		{
			var container 	= $(this),
				images		= $('img', this).css({opacity:0, visibility:'visible', display:'block'}),
				parent = images.parent(),
				imageCount = images.length,
				interval = '',
				allImages = images ;
				
			
			var methods = 
			{
				checkImage: function()
				{
					images.each(function(i)
					{
						if(this.complete == true) images = images.not(this);
					});
					
					if(images.length && options.maxLoops >= 0)
					{
						options.maxLoops--;
						setTimeout(methods.checkImage, 500);
					}
					else
					{
						methods.showImages();
					}
				},
				
				showImages: function()
				{
					allImages.each(function(i)
					{
						var currentImage = $(this);
						setTimeout(function()
						{	
							currentImage.animate({opacity:1}, options.fadeInSpeed, function()
							{
								if(allImages.length == i+1) methods.callback(i);
							});
						},options.delay*(i+1));
						//if(imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG'){
						
					});
				},
				
				callback: function()
				{				
					if (variables instanceof Function) { callback = variables; }
					if (callback  instanceof Function) { callback.call(this);  }
					if(options.callback != '') (options.callback)();

				}
			};
			
			methods.checkImage();

		});
	};
})(jQuery);
