/*
***********************
* Created by:         *
* Varbo.cz.com        *
***********************
*/
$(document).ready(function(){
	var videoTitle="";
	$("#mPlayer").hide();
	loadBackgrounrd();
	checkURL(window.location.hash);
	$.preLoadImages("images/background_link_hover.png","images/play2.png","images/pause2.png","images/stop2.png");
	transBox("#load_sidebar","#616954");
	transBox("#af1","#616954");
	transBox("#af2","#616954");
	transBox("#af3","#616954");
	transBox("#af4","#616954");
	transBox("#af5","#616954");
	transBox("#af6","#616954");
	$('a.sidebarlink').click(function (e){
	   $("#content").css({"z-index":"-1"});
		if($("#content_holder"))
			$("#content_holder").fadeOut('slow').remove();
		$("#background").css('opacity', 1);
		$("a.accordimage").removeClass("active");
		$(this).addClass("active");
		if( window.location.hash!='')
			fadeOut(fade_out);
		var new_url=$(this).attr('href').replace("#","");
		loadPage(new_url,"#sidebar_content");
		fadeIn(fade_in);
	});
	$('#contact a').click(function (e){
		if(!$("#content_holder"))
			$("#content").html('<div id="content_holder"></div>');
		$("#background").css('opacity', 1);
		$("a.accordimage").removeClass("active");
		if( window.location.hash!='')
			fadeOut(fade_out);
		var new_url=$(this).attr('href').replace("#","");
		loadPage(new_url,"#content_holder");
		fadeIn(fade_in);
	});
	var last_box=$("#af2");
	$("a.accordimage").hover(function(){
		$(".accordimage").stop();
		$(this).addClass("active");
	},
	 function(){
		 $(".accordimage").stop();
		 $(this).removeClass("active");
		 $(".accordimage").stop();
	});
});
(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);
function fadeOut(option){
	$('#load_sidebar').stop();
	switch(option){
		case "fadeOutRight":
			$('#load_sidebar').animate({opacity:"hide",width:'hide'}, fade_speed);
		break;
		case "fadeOutUp":
			$('#load_sidebar').animate({opacity:"hide",height:'hide'}, fade_speed);
		break;
		case "default":
			$('#load_sidebar').animate({opacity:"hide"},fade_speed);
		break;
	}
}
function fadeIn(option){
	$('#load_sidebar').stop();
	switch(option){
		case "fadeInLeft":
			$('#load_sidebar').animate({opacity:"show",width:'show'}, fade_speed);
		break;
		case "fadeInDown":
			$('#load_sidebar').animate({opacity:"show", height:'show'}, fade_speed);
		break;
		case "default":
			$('#load_sidebar').animate({opacity:"show"},fade_speed);
		break;
	}
}
var lasturl="";
function checkURL(hash){
	if(hash){
		hash=hash.replace('#','');
		var mass=new Array();
		mass=hash.split('/');
		for(var i=0;i<mass.length;i++){
			if(i!=0){
				loadPage(mass[0]+"_"+mass[i],"#content");
			}else{
				loadPage(mass[i],"#sidebar_content");
			}
		}
	}else{
		 $('#load_sidebar').animate({opacity:"hide"}, 10).hide();
	}
}
function activeA(){
	 $("#sidebar a").click(function(){
		$("#sidebar a").removeClass("sideActive");
		$(this).addClass("sideActive");
	 })
	$("a.a_player").click(function(){
		$("div#navigation").animate({opacity:"hide","heigth":"hide"},fade_speed);
		$("#background").animate({opacity:"hide"},fade_speed);
		$("div#load_sidebar").animate({opacity:"hide","width":"hide"},fade_speed);
		$("div#content_holder").animate({opacity:"hide","width":"hide"},fade_speed);
		setTimeout(function(){
			addPlayer($("a.a_player").attr('rel'));
		}, fade_speed);
	});
	$('a.submenu').click(function(){
		if($("#video").length!=0) $("#video").remove();
	});
	$('a').click(function(){
		var new_location=window.location.hash;
		var url=$(this).attr('href');
		if(url) url=url.replace('#','');
		if(url){
			window.location.hash=$(this).attr('href');
		}
	});
	if( window.location.hash.search("recipes")!=-1){
		if($("div#a_video").length!=0){
			$("#a_close").css({"position":"absolute","right":"0px","bottom":"2px"});
			$("#a_transparent").css({"position":"absolute","left": "247px","bottom":"18px"});
			$("#bottom_panel").css({"height": "35px"});
			$("#a_change").css({"position":"absolute","bottom":"16px","left":"110px"});
			$("#a_video").css({"position":"absolute","bottom":"14px","left":"0px"});
			$("#a_video .separator").css({"padding-left":"0px"});
			$("#content_btn").children("span.separator").remove();
		}
	}
	// new //
	if( window.location.hash.search("gallery")==-1){
		$('div#example_menacc').jScrollPane({showArrows:true, scrollbarWidth:5, dragMaxHeight:26,wheelSpeed:10,scrollbarOnLeft:true});
	}
}
function loadBackgrounrd(media){
	if(media){
		var type=media.match(/\#.*?\[/i);
		media=media.replace(type,'');
		media=media.replace(']','');
		if (type=="#background["){
		   loadBackgroundImage(media);
		}
		if (type=="#video["){
			if($("#content_btn")){
				$("#content_btn").append("<div id=\"a_video\"><span class=\"separator\">|</span><a id=\"a_player\" class=\"a_player\">play video</a></div>");
				$("a.a_player").attr({'rel':hostName+media});
		   }
		}
	}
	/*else{
	   if(window.location.hash=="")
		loadBackgroundImage("images/background.jpg");
	}*/
}
function loadBackgroundImage(media){
  $.ajax({ url: hostName+"php/image.php?fName="+media+"&cW="+screen.width+"&cH="+screen.heigth,
  method:"get",
  success: function(data){
	 var image=hostName+"images/"+data;
	 $.cacheImage(image, {
		load : function (e) {
		   $("#background").animate({opacity:"hide"},fade_speed_background,function(){
			   if($("div#control_hulu").length==0){
			   if($("div#background #backgroundImage")){
				  $("div#background img#backgroundImage").remove();
				  $("div#background").css({"backgroundImage":"none"});
			   }
				if($.browser.msie){
					$("div#background").html("<img src='"+image+"' id='backgroundImage'/>");
				 }else{
					var img = new Image();
					img.src=image;
					img.id="backgroundImage";
					var p=(img.height/$("div#background").height())*100;
					$("div#background").html("<div id=\"subBackground\" style=\"width:100%;height:"+p+"%\"></div>");
					$("div#subBackground").html(img);
				 }
			  setTimeout(function(){
				  $("#background").animate({opacity:"show"},fade_speed_background);
				  $("#backgroundImage").draggable({ revert: true });
				  
			  }, 100);
			  }
		   });
		}
	 });
  }
  })
}
function setTitlePage(title){
   if(title)
	 document.title=hostTitle+" | "+title;
   else document.title=hostTitle;
}
function setVideoDesc(title){
   videoTitle=title;
}
function loadPage(url,div){ 
	if(url){
		url=url.toLowerCase();
		if($.browser.msie){
			if($.browser.version=="7.0"){
				if(url.search("#")!=-1){
					url=url.substr(url.search("#")+1,url.length-url.search("#"));
				}
			}
		}
		hostName=hostName.toLowerCase();
		if(url.search("index.html")!=-1)
			url=url.substr(url.search("index.html")+10,url.length-url.search("index.html"));
		else
			if(url.search(hostName)!=-1 && hostName!="/")
				url=url.substr(url.search(hostName)+hostName.length,url.length-url.search(hostName));
		url=url.replace("#","");
		url=url.replace("/","_");
		if(div=="#sidebar_content")
			$("#load_sidebar").append("<div class='loading'>&nbsp;</div>");
		if(div=="#content"){
		   $("#content").css({"z-index":"97"});
		   $("#content").append("<div class='loading'>&nbsp;</div>");
		}
		if(url)
			$(div).load(hostName+"html/"+url+".html",function(){
				$('.loading').remove();
				resize();
			}).show();
	}else{
		 $('#load_sidebar').animate({opacity:"hide"}, 10).hide();
	}
}
function bottom_btn(div_id){
        var div='<div class="transBox"></div><div id="bottom_panel"><div id="content_btn"><a id="a_close">Close X</a><span class="separator">|</span><div id="a_transparent"><a id="a_50"><div class="div_trans">&nbsp;</div></a><a id="a_75"><div class="div_trans">&nbsp;</div></a><a id="a_def"><div class="div_trans">&nbsp;</div></a></div><a id="a_change">change background</a></div></div>';
	$(div_id).append(div);
	transBox("#bottom_panel","#616954");
	$("#bottom_panel > div.transparent").animate({opacity: 0.8}, 300);
	$("a#a_def .div_trans").fadeTo("slow", 1);
	$("a#a_50 .div_trans").fadeTo("slow", 0.25);
	$("a#a_75 .div_trans").fadeTo("slow", 0.50);
	$('a#a_def').click(function (e){
		$(".transBox").animate({opacity: "0.6"}, 300);
	});
	$('a#a_50').click(function (e){
		$(".transBox").animate({opacity: "0.2"}, 300);
	});
	$('a#a_75').click(function (e){
		$(".transBox").animate({opacity: "0.4"}, 300);
	});
	$('a#a_close').click(function (e){
		$("#content").css({"z-index":"-1"});
		$(div_id).fadeOut('slow').remove();
	});
}
function transBox(div_id,backgroundColor){
	var div='<div class="transparent" style="background-color:'+backgroundColor+'"></div>';
	$(div_id).append(div);
}
function fadeOutSub(option,elem){
	var el=elem;
	var top=elem.position().top;
	el.stop();
	switch(option){
		case "fadeOutRight":
			el.animate({opacity: "hide",width:'hide'},fade_speed);
		break;
		case "fadeOutUp":
			el.animate({opacity: "hide",height:'hide'},fade_speed);
		break;
		case "default":
				el.animate({opacity: "hide"},fade_speed);
		break;
	}
}
function fadeInSub(option,elem){
	var el=elem.next();
	var top=elem.position().top;
	fadeDiv(fade_out_sub);
	el.stop();
	switch(option){
		case "fadeInLeft":
			el.animate({opacity: "show",width:'show'},fade_speed);
		break;
		case "fadeInDown":
			el.animate({opacity: "show",height:'show'},fade_speed);
		break;
		case "default":
			el.animate({opacity: "show"},fade_speed);
		break;
	}
}
function fadeDiv(option){
	switch(option){
		case "fadeOutRight":
			$("div.submenu").animate({opacity: "hide",width:'hide'},fade_speed);
		break;
		case "fadeOutUp":
			$("div.submenu").animate({opacity: "hide" ,height:'hide'},fade_speed);
		break;
		case "default":
			$("div.submenu").animate({opacity: "hide"},fade_speed); 
		break;
	}
}
function  resizeWindow(){
	resize();
	window.onresize = resize;
}
function resize(){
	var box=$("#background").innerWidth()/6;
	if($.browser.mozilla){
		slideMenu.build('sm',box+100,12,12,0);
	}else{
		slideMenu.build('sm',box+100,5,5,0);
	}
	var fP=getH();
	var fL=$("#logo").outerHeight()-$("#footer").outerHeight()+5;
	$("#load_sidebar:visible").css({height: fP-fL-$("#navigation").outerHeight()+"px"});
	$("#load_sidebar:visible div.transparent").css({height: $("#load_sidebar:visible").height()-$("#logo").outerHeight()+"px"});
	// Gallery
	if($("img.gallery").length!=0){
		var fT=$("#load_sidebar .transparent").innerHeight()
		$("div.items").css({height:fT-50+"px"});
		var fI=$("#load_sidebar div.items").innerHeight();
		if($.browser.opera)
			$("a.gallery").css({height:(fI/8)-9.8+"px"});
		else 
		if($.browser.mozilla || $.browser.safari)
			$("a.gallery").css({height:(fI/8)-10+"px"});
		else
			if($.browser.msie)
				$("a.gallery").css({height:(fI/8)-9.8+"px"});
			else
				$("a.gallery").css({height:(fI/10)+1.5+"px"});
		}
	if($("div.box").length!=0){
		var nW=$("#content_holder").height()-$("#bottom_panel").height()-$("#content_holder h1").height()-20;
		$("#content_holder div.box").width("81%");
		$("#content_holder div.jScrollPaneContainer").width("98%");
		$("#content_holder div.box").height(nW+"px");
		$("#content_holder div.jScrollPaneContainer").height(nW+"px");
		$("#content_holder div.box").jScrollPane({showArrows:true, scrollbarWidth:5, dragMaxHeight:26,wheelSpeed:10,animateStep :10});
	}
	if($("#example_menacc").length!=0 && window.location.hash.search("gallery")==-1){
		var nWE=$("#sidebar").height()-$("#logo").height()-20;
		$('div#example_menacc').css({"height":nWE+"px"});
		$("div#sidebar_content div.jScrollPaneContainer").height(nWE+"px");
		$('div#example_menacc').jScrollPane({showArrows:true, scrollbarWidth:5, dragMaxHeight:26,wheelSpeed:10});
		$("div#sidebar_content .jScrollPaneTrack").css({"left":"2px"});
		$("div#sidebar_content .jScrollArrowUp").css({"left":"2px"});
		$("div#sidebar_content .jScrollArrowDown").css({"left":"2px"});
	}
	if(window.location.hash.search("recipes")!=-1){
		$("#content").css({right:$("#load_sidebar").width()+1+"px"},fade_speed,function(){
		});
	}
}
function addPlayer(video){
	var player="";
	if($("a#huluPlayer").length!=0){
	   $("a#huluPlayer").remove();
	}
	if($("a#hulu").length!=0){
	   $("a#hulu").remove();
	}
	player+='<div id="div_huluPlayer"><a href="'+video+'" id="huluPlayer"></a></div>';
	player+='<div id="control_hulu">';
	player+='<span id="title_hulu">'+videoTitle+'</span>';
	player+='<a id="a_close_hulu">close</a>';
	player+='<script>';
	player+='setPlayer();';
	player+='<\/script>';
	player+='</div>';
	setTimeout(function(){
		$("#main").append(player);
		$("div#control_hulu").css({'top':'0px'}).hide();
		if(!$.browser.safari){
			$("div#control_hulu").css({'top':'70px'}).slideDown(fade_speed,function(){
				$("#background").animate({opacity:"hide"},fade_speed);
			});
		}else{
			$("div#control_hulu").css({'top':'13px'}).slideDown(fade_speed,function(){
				$("#background").animate({opacity:"hide"},fade_speed);
			});
		}
	},1000);
}
function setPlayer(){
	var fPath=hostName; 
//        if($.browser.opera)
//            fPath="";
	$f("huluPlayer", {src:fPath+"swf/flowplayer-3.1.5.swf", wmode: 'opaque', width:'100%',height:'100%'},{
		onBeforeLoad:function(){
		},
		logo: {
			fullscreenOnly: true
		},
		clip:{
			accelerated: true,
			autoPlay: false, 
			autoBuffering: false,
			scaling: 'fit',
			fadeInSpeed: 1000
		},
		canvas: {
			backgroundColor: "#000",
			opacity:1
		},
		plugins: {
			tube: {
				url: hostName+"swf/buttons_tube.swf",
				type: "classLibrary"
			},
			controls: {
				url: fPath+'swf/controlbar.swf',
				top:'0px',
				width:"400px",
				height:"30px",
				right:"0px",
				tooltipColor: '#C9C9C9',
				timeBgColor: '#1d1717',
				borderRadius: '0',
				buttonColor: 'white',
				bufferGradient: 'none',
				buttonOverColor: '#81c587',
				sliderColor: '#828282',
				backgroundGradient: 'none',
				durationColor: '#799d74',
				bufferColor: '#434343',
				volumeSliderGradient: 'none',
				tooltipTextColor: '#D00000',
				backgroundColor: '#1d1717',
				sliderGradient: 'none',
				progressGradient: 'none',
				volumeSliderColor: 'white',
				timeColor: '#B1E0FC',
				progressColor: 'white',
				opacity: 1,
				scrubberBarHeightRatio: 0.6,
				volumeBarHeightRatio: 0.6,
				fullscreen:false
			}
		}
	});
	$("div#control_hulu #a_close_hulu").click(function(){
		   $("div#control_hulu").slideUp(fade_speed, function(){
			  $("#huluPlayer").remove();
		   });
		setTimeout(function(){
		   $("div#control_hulu").remove();
		   $("div#navigation").animate({opacity:"show","heigth":"show"},fade_speed);
		   $("#background").animate({opacity:"show"},fade_speed);
		   $("div#load_sidebar").animate({opacity:"show","width":"show"},fade_speed);
		   $("div#content_holder").animate({opacity:"show","width":"show"},fade_speed,function(){
			   resize();
		   });
		}, fade_speed+100);
	})
	
}
function getW(){
  var width=0;
  if(typeof window.innerWidth == 'undefined'){
	 width=document.body.clientWidth;
  }else{
	 width=window.innerWidth;
  }
	 width=$("#main").width();
  return width;
}
function getH(){
  var height=0;
  if(typeof window.innerHeight == 'undefined'){
	 height=document.body.clientHeight;
  }else{
	 height=window.innerHeight;
  }
	 height=$("#main").height();
  return height;
}
function setWH(setw,seth){
  return window.resizeTo(setw,seth);
}
function setAudioPlayer(mp3){
	$("#jquery_jplayer").jPlayer({
		ready:function(){
			$("#jquery_jplayer").change(mp3);
			$("#jquery_jplayer").volume(60);
			$("#jquery_jplayer").play();
			$("#jquery_jplayer").onSoundComplete(function(){
				$("#jquery_jplayer").play();
			})
		}
	});
	$("#jquery_jplayer").jPlayerId("play", "player_play");
	$("#jquery_jplayer").jPlayerId("stop", "player_stop");
	$("a#player_play").click(function(){
		$("a.selected").removeClass("selected");
		$(this).addClass("selected");
	});
	$("a#player_stop").click(function(){
		$("a.selected").removeClass("selected");
		$(this).addClass("selected");
	})
}
function setGalleryTitle(title){
	if($("a.header"))
		$("a.header").html(title);
}

