$(document).ready(function(){
	var myTimer1 = {};
	var myTimer2 = {};

	$(".dropdown").hover(function(){
		elem = $(this);
		$.clearTimer(myTimer2);
		myTimer1 = $.timer(600, function(){
			elem.find("ul").fadeIn("fast")
		});
	},function(){
		elem = $(this);
		$.clearTimer(myTimer1);
		myTimer2 = $.timer(400, function(){
			elem.find("ul").fadeOut("fast")
		});
	})
	
	//galerija
	jQuery("a[rel=gallery]").fancybox({
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000000',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over"><script>fade()</script>Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		},
		'onComplete'		: function(){	
			$("#fancybox-overlay").mouseenter(function(){
				$(".fancybox-title-over").slideUp();
			})	
			$("#fancybox-overlay").mouseout(function(){
				$(".fancybox-title-over").slideDown();
			})
//			myTimer = "";	
//			$(document).mousemove(function(){
//				
//				
//				if($("#fancybox-title").css("display") == "none")
//				{
//					$(".fancybox-title-over").slideDown();
//					myTimer = $.timer(3000,function(){
//						$(".fancybox-title-over").slideUp();
//					});
//				}
//				else
//				{
//					$.clearTimer(myTimer);
//					myTimer = $.timer(3000,function(){
//						$(".fancybox-title-over").slideUp();
//					});
//				}
//			})	
//			myTimer = $.timer(1000,function(){
//				$(".fancybox-title-over").slideUp();
//			});
		}
	});

	//funkcija za video..
	jQuery(".video").click(function() {
		jQuery.fancybox({
				'padding'		: 0,
				'autoScale'		: true,
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'overlayOpacity'	: 0.8,
				'overlayColor'		: '#000',
				'centerOnScroll'	: true,
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				   	 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}		
		});

	return false;
	});
	
	//naročilo - zastonj vzorci
	jQuery(".naroci-free").fancybox({
		'width'				: 215,
		'height'			: 500,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'titleShow'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'enableEscapeButton': true,
		'type'				: 'iframe',
		'overlayColor'		: '#000000',
		'overlayOpacity'	: 0.7
	});
	
	//naročilo - zastonj vzorci
	jQuery(".naroci-free2").fancybox({
		'width'				: 420,
		'height'			: 500,
		'autoScale'			: true,
		'autoDimensions'	: true,
		'titleShow'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'enableEscapeButton': true,
		'type'				: 'iframe',
		'overlayColor'		: '#000000',
		'overlayOpacity'	: 0.7
	});
})

function fade()
{
		$("#fancybox-title-over").fadeOut();
}	
	
function checkForm(ref)
{
	napaka = false;
	form = $(ref).parent().parent().parent()
	
	$(form).find(".obvezno").each(function(){
    	if($(this).val() == "")
		{
			napaka = true;
		}
	})
	
	if(napaka)
	{
		$(".response").text("Napaka! Obrazec ste izpolnili pomanjkljivo.");
	}
	else
	{
		$.post("subscribe.php", {
			email: $(form).find("input[name=email]").val(),
			ime:  $(form).find("input[name=ime]").val(),
			tel:  $(form).find("input[name=tel]").val(),
			skupina: $(form).find("input[name=skupina]").val()
		}, function(data){
			if(data.search(/Zahvaljujemo/) != -1)
			{
				$(form).html(data);
				$(form).parent().parent().find(".nagovor").html("");
			}
			else
			{
				$(".response").html(data);
			}
		});
		
	}
}



function resizeIframe()
{
	asd = document.getElementsByTagName("iframe");
	width = asd[0].contentWindow.document.body.offsetWidth;
	height = asd[0].contentWindow.document.body.offsetHeight;

		jQuery('#fancybox-wrap').height(height+20);
		jQuery('#fancybox-inner').height(height);
//		jQuery('#fancybox-wrap').width(width+20);
//		jQuery('#fancybox-inner').width(width);
}

function bookmarksite(title,url)
{
	if (window.sidebar) 
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ 
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
		window.external.AddFavorite(url, title);
}

