jQuery.noConflict();

var selsub = "";

jQuery(document).ready(function(){
  jQuery(".sub").toggle(false);
 	
 	function cropSub(url){
    var up = url.replace("../","");
    up = up.split("/");
    return up[0]; 
  }
 	
 	jQuery("#menu ul li a").each(function(){
   jQuery(this).mouseover(function(){
     var thisHref = cropSub(jQuery(this).attr("href"));
     if(selsub!==thisHref) jQuery(".sub").css("_blank","empty").toggle(false);
     jQuery("#sub_"+thisHref).toggle(true);
     selsub = thisHref; 
    });
   
   jQuery(this).mouseout(function(){
     jQuery("#sub_"+cropSub(jQuery(this).attr("href"))).toggle(false);
   });
   
   jQuery(".sub").each(function(){
    jQuery(this).mouseover(function(){
      jQuery(this).toggle(true);    
    });
   });
  });
  
	// activates the lightbox page, if you are using a dark color scheme use another theme parameter
	my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox']");
	jQuery('#hlavni').kriesi_image_preloader({delay:200});	// activates preloader for non-slideshow images
});

function my_lightbox($elements)
{	
	jQuery('.gallery-item a').attr('rel','lightbox[grouped]');
	
	//volba svetly nebo tmavy theme
	var usedCSS = 3;
	/*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, deeplinking: 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));
						
					});
				},
				
				callback: function()
				{				
					if (variables instanceof Function) { callback = variables; }
					if (callback  instanceof Function) { callback.call(this);  }
					if(options.callback != '') (options.callback)();

				}
			};
			
			methods.checkImage();

		});
	};
})(jQuery);
