jQuery(document).ready( function() {
 	jQuery.each(jQuery.browser, function(i, val) {
    var ok = true;
	if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){
		ok=false;
	//}else if(i=="mozilla" && jQuery.browser.version.substr(0,1)<3){
	//	ok = false;	
	}
	if(!ok)
       alert("Vaš brskalnik ni podprt. Prosimo da ga posodobite ali uporabite drug brskalnik (Firefox, Opera, Chrome, Safari, Internet Explorer 8)");
 	});
	/********************************************* NAVIGATION **********************************
	*************************************************/
	$("#TopPanel #TopPanelContent ul li").hover(function(){
		var thi = $(this);
		toppanel_sleep = setTimeout(function(){ 
			$(thi).addClass("hover");
			var widthC = $(thi).find("ul").width();
			var widthP = $(thi).width();
			if(widthP>widthC+10){
				 $(thi).find("ul").css("width",widthP-10);	
			}
        	$('ul:first',thi).fadeIn(200);} , 200 ); 
		},function() {
		try{clearTimeout(toppanel_sleep);
		
		}catch(e){}; 
			 $(this).removeClass("hover");
        $('ul:first',this).fadeOut(100);
       
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).fadeOut(100);
    });
	
	 $("#Head #Navigation ul li").hover(function(){
		 var thi = $(this);
		navi_sleep = setTimeout(function(){ 
			$(thi).addClass("hover");
			var widthC = $(thi).find("ul").width();
			var widthP = $(thi).width();
			if(widthP>widthC+10){
				 $(thi).find("ul").css("width",widthP-10);	
			}
        	$('ul:first',thi).fadeIn(200);} , 300 ); 
		},function() {
		try{clearTimeout(navi_sleep);
		
		}catch(e){}; 
			 $(this).removeClass("hover");
        $('ul:first',this).fadeOut(100);
       
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).fadeOut(100);
    
    });
	$("input[name='search']").focusin(function(){
		if($(this).val()=="Iskanje..."){
			$(this).val("");	
		}
	}).focusout(function(){
		if($(this).val()==""){
			$(this).val("Iskanje...");	
		}
	});
	$("input[name='search']").keypress(function(e){
		if($(this).val()!=""){
	var code = (e.keyCode ? e.keyCode : e.which);
		 if(code == 13) { //Enter keycode
  			 window.location = "iskanje/"+$(this).val();
		}
		}
	});
	$("#TopPanel #sGo").click(function(){
		if($("input[name='search']").val()!=""){
  			 window.location = "iskanje/"+$("input[name='search']").val();
		}
	});
	/********************************************* NAVIGATION ***********************************************************************************/
	/********************************************* SLIDER ***********************************************************************************/
	var topContentNewsCount = 0;
	var topContentGalleryCount = 0;
	$("#TopContentNews #NewsImages div").hide();
	$("#TopContentGallery #GalleryImages div").hide();
	$("#TopContentNews #NewsImages div").eq(topContentNewsCount).fadeIn(200);
	$("#TopContentNews #NewsContent div").eq(topContentGalleryCount).fadeIn(200);
	$("#TopContentGallery #GalleryImages div").eq(topContentGalleryCount).fadeIn(200);
	$("#TopContentGallery #GalleryContent div").eq(topContentGalleryCount).fadeIn(200);
	var intervalSliderNews = window.setInterval(function(){moveSlider("R","News",$("#NewsImages div").size());}, 10000);
	var intervalSliderGallery = window.setInterval(function(){moveSlider("R","Gallery",$("#GalleryImages div").size());}, 5000);
	$(".TopContentControlL, .TopContentControlR").click(function(){
		var where = $(this).attr("class").substr(($(this).attr("class").length-1),1);
		var what = $(this).attr("id").substr(19);
		var many = $("#"+what+"Images div").size();
		moveSlider(where,what,many);		
	});
	/*$("#TopContentControl_Gallery span, #TopContentControl_News span").click(function(){
		var what = $(this).closest("div").attr("id").substr(18);
		$("#TopContentControl_"+what+" span").removeClass("active");	
		$(this).addClass("active");	
		var where = $("#TopContentControl_"+what+" span").index($('.active',$("#TopContentControl_"+what+"")));
		moveSlider(where,what,-1);
	});*/
	function moveSlider(where,what,many){
		if(many>1){
		if(what=="News"){
			window.clearInterval(intervalSliderNews);
			var counter = 	topContentNewsCount;
		}else{
			window.clearInterval(intervalSliderGallery);
			var counter = topContentGalleryCount;	
		}
		if(where!=counter){
			//
			$("#TopContent"+what+" #"+what+"Images div").eq(counter).fadeOut(600);
			$("#TopContent"+what+" #"+what+"Content div").eq(counter).fadeOut(100);
			$("#TopContentControl_"+what+" span").eq(counter).removeClass("active");
			if(where=="R"){
				counter++;
			}else if(where=="L"){
				counter--;
			}else{
				counter=where	
			}
			if(many!=-1){
				if(many-1<counter){
						counter=0;
				}
				if(counter<0){
					counter=many-1;
				}
			}
			$("#TopContent"+what+" #"+what+"Images div").eq(counter).fadeIn(500);
			$("#TopContent"+what+" #"+what+"Content div").eq(counter).fadeIn(500);
			$("#TopContentControl_"+what+" span").eq(counter).addClass("active");
			if(what=="News"){
				topContentNewsCount=counter;
				intervalSliderNews = window.setInterval(function(){moveSlider("R","News",many);}, 10000);	
			}else{
				topContentGalleryCount=counter;	
				intervalSliderGallery = window.setInterval(function(){moveSlider("R","Gallery",many);}, 5000);
			}
			//$("#Testing").html("Counter:"+counter+"<br />What:"+where+"<br />many:"+many);
		}
		}
	}
	/********************************************* SLIDER ***********************************************************************************/
	/********************************************* EVENTS ***********************************************************************************/
	$("#Calendar td.event, #Calendar td.past_event").click(function(){
		var html = $(this).find("div").html();
		$("#EventList").html(html);
	});
	$("#EventList li").live("click",function(){
		
		var desc = $(this).find("p");
		if(!desc.is(":visible")){
			$("#EventList li p").slideUp(200);
			desc.slideDown(200);	
		}
	});
	/********************************************* SLIDER ***********************************************************************************/
	/********************************************* ZAPOSLENI ***********************************************************************************/
	/*var SliderZaposleniCount = 0;
	var intervalSliderZaposleni = window.setInterval(function(){
			$("#Zaposleni ul li").eq(SliderZaposleniCount).fadeOut(500);
			SliderZaposleniCount++;
			if((SliderZaposleniCount+1)>$("#Zaposleni ul li").size()){
				SliderZaposleniCount=0;	
			}
			$("#Zaposleni ul li").eq(SliderZaposleniCount).fadeIn(400);
		}, 5000);
	$("#Zaposleni ul").hover(function(){
		window.clearInterval(intervalSliderZaposleni);
	},function(){
		intervalSliderZaposleni = window.setInterval(function(){
			$("#Zaposleni ul li").eq(SliderZaposleniCount).fadeOut(500);
			SliderZaposleniCount++;
			if((SliderZaposleniCount+1)>$("#Zaposleni ul li").size()){
				SliderZaposleniCount=0;	
			}
			$("#Zaposleni ul li").eq(SliderZaposleniCount).fadeIn(400);
		}, 5000);
	});*/
	/********************************************* ZAPOSLENI ***********************************************************************************/
	$(".photogallery_album_photo_link").prettyPhoto();
	$(".iframe").prettyPhoto();
});
