// JavaScript Document for Page
$(document).ready(function() {

		/*******************/
		/* vrednosti form */
		/*******************/
		$('#inputIskanje, #inputVemail, #inputPemail, #inputSporocilo').focus(function() { //na fokusu se vrednost inputov zbriše
			if($(this).val()=="iskanje..." || $(this).val()=="vaš email..." || $(this).val()=="prijateljev email..." || $(this).val()=="sporočilo...") {
				$(this).val("");
			}
		});
		$('#inputIskanje, #inputVemail, #inputPemail, #inputSporocilo').blur(function() { // ko gremo iz fokusa se vzpostavijo napisi nazaj, vendar le če so prazni
			if($('#inputIskanje').val()=="") {
				$('#inputIskanje').val("iskanje...");
			}
			if($('#inputVemail').val()=="") {
				$('#inputVemail').val("vaš email...");
			}
			if($('#inputPemail').val()=="") {
				$('#inputPemail').val("prijateljev email...");
			}
			if($('#inputSporocilo').val()=="") {
				$('#inputSporocilo').val("sporočilo...");
			}	
		});
		
		
		/*******************/
		/* Slike na uvodni */
		/*******************/
		$("div.mUnapis_rdec, div.mUnapis_rjav").fadeTo(25, 0.75); // spustimo prosojnost divom na sliki
		
		function whenOver(){ $("div.mUnapis_rdec, div.mUnapis_rjav").fadeTo(400, 1.0); } // funkcija za dvig prosojnosti divov na sliki
		function whenOut(){ $("div.mUnapis_rdec, div.mUnapis_rjav").fadeTo(400, 0.75); } // funkcija za spust prosojnosti divov na sliki
		
		var config = {   // definiramo config variablo za hoverintent
			 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 10, // number = milliseconds for onMouseOver polling interval    
			 over: whenOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 80, // nsumber = milliseconds delay before onMouseOut    
			 out: whenOut // function = onMouseOut callback (REQUIRED)    
		};
		
		$(".mUimage").hoverIntent( config ); // zaženemo hoverintent
		
		var $sections = $('#mainUvodna'); // definiramo slajder
			$sections.serialScroll({
				items:'li', //selector to the items ( relative to the matched elements, '#sections' in this case )
				prev:'',//selector to the 'prev' button (absolute!, meaning it's relative to the document)
				next:'',//selector to the 'next' button (absolute too)
				axis:'x',//the default is 'y'
				event:'showNext',//on which event to react (click is the default, you probably won't need to specify it)
				stop: false,//each click will stop any previous animations of the target. (false by default)
				lock: true, //ignore events if already animating (true by default)
				duration:500,//length of the animation
				start: 0, //on which element (index) to begin ( 0 is the default, redundant in this case )
				force:true, //force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
				cycle: true,//cycle endlessly ( constant velocity, true is the default )
				step: 1, //how many items to scroll each time ( 1 is the default, no need to specify )
				jump: true, //if true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
				lazy:false,//(default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
				easing:'easeInOutCubic' //use this easing equation for a funny effect
			});
			
			$(".mUimage").click(function(){ // preusmeri ob kliku na sliko
				window.location = $(this).attr("title");
				return false;
			});
			
			var myTimer = setInterval(nextPic, 5000 ); // definiramo timer za menjavo slik
			
			function resetTimer(){ clearInterval(myTimer); myTimer = setInterval(nextPic, 4000 ); } // definiramo funkcijo za resetiranje timerja
			function stopTimer(){ clearInterval(myTimer);} // definiramo funkcijo za zaustavitev timerja
			
			function nextPic(){ // definiramo funkcijo za avtomatsko sprožitev naslednje slike
				var alt2 = parseInt($("#mainUvodnaMenu a[class=muchoosen]").attr("name"))+1; // poiščemo trenutno vrednost slike glede na meni
				hoverMenu(alt2); // kličemo funkcijo za dejansko opravilo sprožitve
			}
			
			function hoverMenu(n){
				var nMost = ($("div#mainUvodna li").size())-1;
				if(n>nMost) {var n = 0;}
				$sections.trigger( 'goto', [ n ] );
				$("#mainUvodnaMenu a").removeClass("muchoosen");
				var wE = "#mainUvodnaMenu a[name="+n+"]";
				$(wE).addClass("muchoosen");	
				//$("span#test").text("** "+n+" **"); // trigger the click to start	
			}
			
			function whenOverMenu(){ // definiranje hover funkcije za menu pod veliko sliko
				var alt = $(this).attr("name");
				hoverMenu(alt);
				stopTimer();
			}
			
			var configMenu = {    // definicija config file za hoverintent menuja
				 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
				 interval: 100, // number = milliseconds for onMouseOver polling interval    
				 over: whenOverMenu, // function = onMouseOver callback (REQUIRED)    
				 timeout: 100, // nsumber = milliseconds delay before onMouseOut    
				 out: resetTimer // function = onMouseOut callback (REQUIRED)    
			};
		
			$("#mainUvodnaMenu a").hoverIntent(configMenu); // zaženemo hover menu
			
		
		/**********/
		/* novice */
		/**********/
		$("p#news2").hide(); // skrijemo 2 novici
		$("p#news3").hide();
		
		$(".novine a").click(function () {
			 var altnews = "p#"+$(this).attr("name");
      		$(altnews).toggle();
    	});  
		
		
		/************************/
		/*Menjavnaje poslovalnic*/
		/************************/
		/*
		$("a#pisarna1").click(function () {
			$("a").removeClass("pischoosen");
			$(this).addClass("pischoosen");
      		$("div#pisarnaload").fadeTo("fast",0.01,callback);
				function callback(){
					$("div#pisarnaload").load("poslovalnica_maribor.php");
				}
			$("div#pisarnaload").fadeTo("fast", 1);
    	});  
		
		$("a#pisarna2").click(function () {
			$("a").removeClass("pischoosen");
			$(this).addClass("pischoosen");
      		$("div#pisarnaload").fadeTo("fast",0.01,callback);
				function callback(){
					$("div#pisarnaload").load("poslovalnica_ptuj.php");
				}
			$("div#pisarnaload").fadeTo("fast", 1);
    	});  
		
		$("a#pisarna3").click(function () {
			$("a").removeClass("pischoosen");
			$(this).addClass("pischoosen");
      		$("div#pisarnaload").fadeTo("fast",0.01,callback);
				function callback(){
					$("div#pisarnaload").load("poslovalnica_celje.php");
				}
			$("div#pisarnaload").fadeTo("fast", 1);
    	}); 
		
		$("a#pisarna4").click(function () {
			$("a").removeClass("pischoosen");
			$(this).addClass("pischoosen");
      		$("div#pisarnaload").fadeTo("fast",0.01,callback);
				function callback(){
					$("div#pisarnaload").load("poslovalnica_velenje.php");
				}
			$("div#pisarnaload").fadeTo("fast", 1);
    	}); 
		*/
		
		/*************************/
		/* Nizi na uvodni strani */
		/*************************/
		$(".mainUvodnaNize div").click(
			function(){
				window.location = $(this).attr("title");
				return false;
		});
		
		function mouseOverNiz(){$(this).fadeTo("fast", 0.6);}
		function mouseOutNiz(){$(this).fadeTo("fast", 1);}
		
		var configNiz = {    // definicija config file za hoverintent menuja
				 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
				 interval: 25, // number = milliseconds for onMouseOver polling interval    
				 over: mouseOverNiz, // function = onMouseOver callback (REQUIRED)    
				 timeout: 25, // nsumber = milliseconds delay before onMouseOut    
				 out: mouseOutNiz // function = onMouseOut callback (REQUIRED)    
			};
		
		$(".mainUvodnaNize div").hoverIntent(configNiz);
		
		/**************************/
		/**** Poslji prijatelju ***/
		/**************************/
		$("input#inputPSubmit").click(function () {
			var pemail = $('#inputPemail').val();
			var vemail = $('#inputVemail').val();
			var sporoc = $('#inputSporocilo').val();
			var poveza = $('#inputPovezava').val();
			var ipp = $('#inputIp').val();
			$("div.footleft form span").empty();
			
			if(vemail=="vaš email..." || !vemail){
				 $("#PoslanoSpan").html('Prosim vpišite svoj email!');
			}
			else if(pemail=="prijateljev email..."  || !pemail){
				$("#PoslanoSpan").html('Prosim vpišite prijeteljev email!');
			}
			else if(sporoc=="sporočilo..."  || !sporoc){
				$("#PoslanoSpan").html('Prosim vpišite sporočilo!');	
			}
			else if(!poveza){
				$("#PoslanoSpan").html('Povezava ni določena!');	
			}
			else{ 
				$("#PoslanoSpan").html("Pošiljanje...");
				$.post("posljip.php", { vem: vemail, pem: pemail, spr: sporoc, pov: poveza, ip: ipp}, function(data){
				  $("#PoslanoSpan").html(data);
				});
			}
			return false; 
		});

});


	/*********************/
	/* Menjavnaje napisa */
	/*********************/
		var cPosA = 1;
	
		function rotateNapis(){
			$("#napis").fadeTo("slow", 0.01,callback);
				function callback() {
					if (napis.length==0) return;
						var div = document.getElementById("napis");
							
					if (cPosA == napis.length) cPosA = 0; 
						$("#napis").html(napis[cPosA++]);
					}
				$("#napis").fadeTo("slow", 1);
		}
