$(document).ready(function(){
	
	//navigacija		
//	$(".main-navi ul ul").css({display: "none"}); // Opera Fix
//	$(".main-navi ul ul").css({position: "absolute"}); // Opera Fix
//	$(".main-navi  ul li").hover(function(){
//			//$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(268);
//			var element = $(this).find('ul:first');
//			element.fadeIn("fast");
//		},function(){
//			var element = $(this);
//			element.find('ul:first').fadeOut("slow");
//	});	
	
	
	//aktivnemu elementu navigacije skrijem ločilne elemente
	elem = $("ul#dropmenu>li .active")
	
	id = elem.parent().attr("rel");
	idL = parseInt(id)-1;
	idR = parseInt(id)+1;
	
	//levi sosed
	selector = "[rel="+idL+"]";
	$(selector).find("span").css("display", "none");
	//desni sosed
	selector = "[rel="+idR+"]";
	$(selector).find("span").css("display", "none");
	
	
	
	
	LToggle = true;
	RToggle = true;
	
	var myTimer1 = {};
	var myTimer2 = {};
	
	$("ul#dropmenu>li").hover(function(){
		elem = $(this);
		
		$.clearTimer(myTimer2);
		
//		myTimer1 = $.timer(100, function(){
//			elem.find('ul:first').fadeIn("fast");
//		});
		
			elem.find('ul:first').show();
			
			LToggle = true;
			RToggle = true;
			
			elem.addClass("hover");
			id = elem.attr("rel");
			idL = parseInt(id)-1;
			idR = parseInt(id)+1;
			
			//levi sosed
			selector = "[rel="+idL+"]";
			if($(selector).find("span").css("display") == "none")
				LToggle = false;
			$(selector).find("span").css("display", "none");
			//desni sosed
			selector = "[rel="+idR+"]";
			if($(selector).find("span").css("display") == "none")
				RToggle = false;
			$(selector).find("span").css("display", "none");
		
		
	}, function(){
		elem = $(this);

		$.clearTimer(myTimer1);
		
//		myTimer2 = $.timer(100, function(){
//			elem.find('ul:first').fadeOut("slow");
//		})	
		elem.find('ul:first').hide();
			elem.removeClass("hover");
			id = elem.attr("rel");
			idL = parseInt(id)-1;
			idR = parseInt(id)+1;
			
			//levi sosed
			selector = "[rel="+idL+"]";
			if(LToggle)
				$(selector).find("span").css("display", "block");
			//desni sosed
			selector = "[rel="+idR+"]";
			if(RToggle)
				$(selector).find("span").css("display", "block");
		
	})
	
	var tooltipElems = $(".img-navi li a");
	bigTooltip = false;
	
	for(i=0; i<tooltipElems.length; i++)
	{
		if($(tooltipElems[i]).attr("title").length > 13)
		{
			bigTooltip = true;
		}
	}
	if(bigTooltip)
	{
		$(".img-navi li a").tooltip(
		{ 
			predelay: 200,
			effect	: 'slide',
			tipClass: 'tooltip2'
		});
	}
	else
	{
		$(".img-navi li a").tooltip(
		{ 
			predelay: 200,
			effect	: 'slide'
		});
	}
	
	$(".player-content").scrollable();
	var api = $(".player-content").data('scrollable');
	$(".player .left").click(function(){
		api.prev();
	})
	
	$(".player .right").click(function(){
		if(api.getIndex() < api.getSize()-3)
		api.next();
	})
		
	$(".pop").colorbox();
	$(".highslide").colorbox();
	$("a[href*=uploads/podobe]").attr("rel", "gallery").colorbox();
	
//	$(".player-content img").click(function() {
//		// see if same thumb is being clicked
//		if ($(this).hasClass("active")) { return; }
//		var image = $(this);
//
//		if(image.attr('rel') == api.getIndex())
//			api.prev();
//		if(image.attr('rel') == api.getIndex()+2 && api.getIndex() < api.getSize()-3)
//			api.next();
//
//		// calclulate large image's URL based on the thumbnail URL (flickr specific)
//		var url = $(this).attr("src").replace("crop3", "crop");
//
//		// get handle to element that wraps the image and make it semi-transparent
//		var wrap = $(".display");
////		$(wrap).find('img').fadeOut("fast", function()
////		{
//			// the large image from www.flickr.com
//			var img = new Image();
//	
//	
//			// call this function after it's loaded
//			img.onload = function() {
//	
//				// make wrapper fully visible
////				wrap.find('img').fadeTo("fast", 1);
//	
//				// change the image
//				wrap.find("img").attr("src", url);
//				$(".pop").each(function(){
//					$(this).attr("href", url.replace("/crop", ""));
//				})
//			};
//	
//			// begin loading the image from www.flickr.com
//			img.src = url;
//	
//			// activate item
//			$(".player-content img").removeClass("active");
//			$(image).addClass("active");
////		});
//	// when page loads simulate a "click" on the first image
//	});
})


jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};


function printDiv()
{
	
	
//	$('#areaToPrint input').each(function(){
//	    elem = $(this);
//	    elem.val(elem.val())
//	})
	var divToPrint = $('#areaToPrint').html();
	newWin= window.open("");
	newWin.document.write(divToPrint);
	newWin.document.close();
//	newWin.print();
//	newWin.close();
}