﻿$(document).ready(function() {
		
		//Fancybox Loading 
		$("a.fancyPopImage").fancybox({
				'overlayOpacity'	: 0.5
		});
		
		$("a.fancyPopIframe").fancybox({
				'width'				: 560,
				'height'			: 500,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'overlayOpacity'	: 0.5
			});
		
		// Add transparency to certian elements
		$('div.foto-moto').transify({
			opacityOrig:.4,
			opacityNew:.85,
			fadeSpeed:400
		});
		
		// Main Menu JS Load
		$('ul.sf-menu').superfish({ 
            delay:       300,                            // one second delay on mouseout 
            animation:   {opacity:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: true                            // disable drop shadows 
        });
		
		// prikazi
		$("div.ui-tabs-panel").css("visibility","visible");
		$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6500, true);
		
		// Mail Protection
		$('a.email').each(function(){
				e = this.rel.replace('/','@').replace('|','.');
				this.href = 'mailto:' + e;
				$(this).text(e);
		});
		
		// Form data change on focuse
		$('#inputIme, #inputMail').focus(function() { //na fokusu se vrednost inputov zbriše
			if($(this).val()=="ime in priimek" || $(this).val()=="vaš email") {
				$(this).val("");
			} 
		});

		$('#inputIme, #inputMail').blur(function() { // ko gremo iz fokusa se vzpostavijo napisi nazaj, vendar le če so prazni
			if($('#inputIme').val()=="") {
				$('#inputIme').val("ime in priimek");
			}
			if($('#inputMail').val()=="") {
				$('#inputMail').val("vaš email");
			}
		});
		
		
		// Needed functions
		function $_GET(q, s) {
			s = s ? s : window.location.search;
			var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
			return (s=s.replace('?','&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
		}
		
		// Needed variable
		var var_site = $_GET('site');
		
		//When page loads...
		$(".tab_content, .tab_content_2, .tab_content_3").hide(); //Hide all content
		
		// show the right kinde of tabs
		if(var_site == '' || var_site == undefined)
		{
			// Show on firstpage
			$("ul.tabs li:first, ul.tabs_2 li:first, ul.tabs_3 li:first").addClass("active").show(); //Activate first tab
			$(".tab_content:first, .tab_content_2:first, .tab_content_3:first").show(); //Show first tab content
		}
		else
		{
			// Show on subpages
			$("ul.tabs li:first, ul.tabs_2 li.tab5_id, ul.tabs_3 li:first").addClass("active").show(); //Activate selected tab
			$(".tab_content:first, #tab5, #tab0").show(); //Show selected tab content
		}

		//alert(var_site);
		
		//On Click Event
		$("ul.tabs li").click(function() {

			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});

		//On Click Event
		$("ul.tabs_2 li").click(function() {

			$("ul.tabs_2 li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content_2").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		//On Click Event
		$("ul.tabs_3 li").click(function() {

			$("ul.tabs_3 li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content_3").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});
		
		// News Rotator
		function rotate(a){ // Rotate News
			if (typeof(a) == 'undefined') {a=1}
			else if(a>(news.length-1)) {a=0}
			$("#newsRotater").fadeOut("slow", function(){
				$('#newsRotater').html(news[a]);
			});
			$("#newsRotater").fadeIn("slow");
			window.st = a+1;
		}
		
		$('#newsRotater').html(news[0]);
		setInterval( function() { rotate(window.st); }, 4500);
		
		//All News Container thingy
		$("#newsContainerAll").css('display','block');
		$("#newsContainerAll").hide();
		
		$("a.cross").click(function () {
      		$("#newsContainerAll").slideToggle('slow');
			$(this).toggleClass('news_minus');
    	});  
		
	});
