/*

 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php

 *

 * Uses the built In easIng capabilities added In jQuery 1.1

 * to offer multiple easIng options

 *

 * Copyright (c) 2007 George Smith

 * Licensed under the MIT License:

 *   http://www.opensource.org/licenses/mit-license.php

 */



// t: current time, b: begInnIng value, c: change In value, d: duration





pic1 = new Image(379,91); 

pic1.src = "http://www.kkzadar.net/img/layout/search-bg2.png";



jQuery.extend( jQuery.easing,

{

	easeInQuad: function (x, t, b, c, d) {

		return c*(t/=d)*t + b;

	},

	easeOutQuad: function (x, t, b, c, d) {

		return -c *(t/=d)*(t-2) + b;

	},

	easeInOutQuad: function (x, t, b, c, d) {

		if ((t/=d/2) < 1) return c/2*t*t + b;

		return -c/2 * ((--t)*(t-2) - 1) + b;

	},

	easeInCubic: function (x, t, b, c, d) {

		return c*(t/=d)*t*t + b;

	},

	easeOutCubic: function (x, t, b, c, d) {

		return c*((t=t/d-1)*t*t + 1) + b;

	},

	easeInOutCubic: function (x, t, b, c, d) {

		if ((t/=d/2) < 1) return c/2*t*t*t + b;

		return c/2*((t-=2)*t*t + 2) + b;

	},

	easeInQuart: function (x, t, b, c, d) {

		return c*(t/=d)*t*t*t + b;

	},

	easeOutQuart: function (x, t, b, c, d) {

		return -c * ((t=t/d-1)*t*t*t - 1) + b;

	},

	easeInOutQuart: function (x, t, b, c, d) {

		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;

		return -c/2 * ((t-=2)*t*t*t - 2) + b;

	},

	easeInQuint: function (x, t, b, c, d) {

		return c*(t/=d)*t*t*t*t + b;

	},

	easeOutQuint: function (x, t, b, c, d) {

		return c*((t=t/d-1)*t*t*t*t + 1) + b;

	},

	easeInOutQuint: function (x, t, b, c, d) {

		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;

		return c/2*((t-=2)*t*t*t*t + 2) + b;

	},

	easeInSine: function (x, t, b, c, d) {

		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;

	},

	easeOutSine: function (x, t, b, c, d) {

		return c * Math.sin(t/d * (Math.PI/2)) + b;

	},

	easeInOutSine: function (x, t, b, c, d) {

		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;

	},

	easeInExpo: function (x, t, b, c, d) {

		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;

	},

	easeOutExpo: function (x, t, b, c, d) {

		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;

	},

	easeInOutExpo: function (x, t, b, c, d) {

		if (t==0) return b;

		if (t==d) return b+c;

		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;

		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;

	},

	easeInCirc: function (x, t, b, c, d) {

		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;

	},

	easeOutCirc: function (x, t, b, c, d) {

		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;

	},

	easeInOutCirc: function (x, t, b, c, d) {

		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;

		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;

	},

	easeInElastic: function (x, t, b, c, d) {

		var s=1.70158;var p=0;var a=c;

		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;

		if (a < Math.abs(c)) { a=c; var s=p/4; }

		else var s = p/(2*Math.PI) * Math.asin (c/a);

		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;

	},

	easeOutElastic: function (x, t, b, c, d) {

		var s=1.70158;var p=0;var a=c;

		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;

		if (a < Math.abs(c)) { a=c; var s=p/4; }

		else var s = p/(2*Math.PI) * Math.asin (c/a);

		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;

	},

	easeInOutElastic: function (x, t, b, c, d) {

		var s=1.70158;var p=0;var a=c;

		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);

		if (a < Math.abs(c)) { a=c; var s=p/4; }

		else var s = p/(2*Math.PI) * Math.asin (c/a);

		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;

		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;

	},

	easeInBack: function (x, t, b, c, d, s) {

		if (s == undefined) s = 1.70158;

		return c*(t/=d)*t*((s+1)*t - s) + b;

	},

	easeOutBack: function (x, t, b, c, d, s) {

		if (s == undefined) s = 1.70158;

		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;

	},

	easeInOutBack: function (x, t, b, c, d, s) {

		if (s == undefined) s = 1.70158; 

		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;

		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;

	},

	easeInBounce: function (x, t, b, c, d) {

		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;

	},

	easeOutBounce: function (x, t, b, c, d) {

		if ((t/=d) < (1/2.75)) {

			return c*(7.5625*t*t) + b;

		} else if (t < (2/2.75)) {

			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;

		} else if (t < (2.5/2.75)) {

			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;

		} else {

			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;

		}

	},

	easeInOutBounce: function (x, t, b, c, d) {

		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;

		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;

	}

});





var cache = [];

// Arguments are image paths relative to the current page.

$.preLoadImages = function() {

	var args_len = arguments.length;

	for (var i = args_len; i--;) {

	  var cacheImage = document.createElement('img');

	  cacheImage.src = arguments[i];

	  cache.push(cacheImage);

	}

}





/*

 * jQuery mail validator 1.0

 * by Juraj Hilje - Futuro I.S.

 */

 

function isValid(emailAddress) {

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

return pattern.test(emailAddress);

} 



$.validate = function(selector) {

	var error = 0;

	var n = $(selector+" .required").size();

	var n_mail = $(selector+" .mail").size();

	$(selector).submit(function() {

		error = 0;					   

		for(i=0; i<n; i++) {					   

			if ($.trim($(selector+" .required:eq("+i+")").val()) == '')	{

				$(selector+" .required:eq("+i+")").addClass("error");

				error = 1;

			} else {

				$(selector+" .required:eq("+i+")").removeClass("error");

			}

		}

		for(i=0; i<n_mail; i++) {					   

			if ( !isValid($.trim($(".mail:eq("+i+")").val())) )	{

				$(selector+" .mail:eq("+i+")").addClass("error");

				error = 1;

			} else {

				$(selector+" .mail:eq("+i+")").removeClass("error");

			}

		}

		if(error) { return false; }

	});

	

	$(selector+" .required").keypress(function() {

		$(this).removeClass("error");							   

	});

}







// pozivanje

$(document).ready(function() {

						   

	$.preLoadImages("/img/layout/bg_menu.png","/img/layout/bg_menu2.png");

	

	$("a.lightbox").lightbox();

	/*$("a.lightbox").fancybox();

	$("a.lightbox-video").fancybox({

		'frameWidth': 352,

		'frameHeight': 316,

		'hideOnContentClick': false,

		'overlayShow' : true

	});*/

	

	$(".no-click").click(function() { return false; });

	

	$(".hover img").hover(

		function() {

			$(this).animate( {opacity:"0.7"} , 200);

		},

		function() {

			$(this).animate( {opacity:"1"} , 200);

		}

	);

	

	$.validate(".forma");

	

	//newsletter

	$("input.txt-input").focus(function() {

		$(this).val("");									

	});

	

	 $('body').click(function() {

	 	$("input.txt-input").val("Unesite e-mail adresu");

	 });

	 

	 $("input.txt-input3").focus(function() {

			$(this).val("");									

	 });

		

	 $('body').click(function() {

		$("input.txt-input3").val("Pojam za pretraživanje");

	 });

	

	 $("input.txt-input, input.add-newsletter, input.txt-input2, input.txt-input3").click(function(event){

		 event.stopPropagation();

	 });

	 

	 $("input.txt-input2").focus(function() {

		 if( $(this).val() == '' || $(this).val() == 'Pojam za pretraživanje' )

		 {

			 $(this).val("");

		 }

	});

		

	$('body').click(function() {

		if( $("input.txt-input2").val() == '' )

		{

			$("input.txt-input2").val("Pojam za pretraživanje");

		}

	});

	 

	 //goto URL

	 $("#novost2").click(function() {

		window.location = $(this).find("a").attr("href");

	 });

	 $("#novost1-title").click(function() {

		window.location = $(this).prev("a").attr("href");

	 });

	 $(".thumbs-foto .item .okvir-foto").click(function() {

		window.location = $(this).prev("a").attr("href");

	 });



	//mega menu

	//$("#nav li").find(".sub-main").show();

	$("#nav li").hover(

		function() {

			$(this).find(".sub-main").show("fast");

		},

		function() {

			$(this).find(".sub-main").hide("fast");

		}				  

	);

	

	//MEGA MENU 2

	function megaHoverOver(){

	$(this).find(".sub").stop().fadeTo('fast', 1).show();

	



	

	//Calculate width of all ul's

	 (function($) {

	 jQuery.fn.calcSubWidth = function() {

	 rowWidth = 0;

	 //Calculate row

	 $(this).find("ul").each(function() {

	 rowWidth += $(this).width();

	 });

	 };

	 })(jQuery);

	

	 if ( $(this).find(".row").length > 0 ) { //If row exists...

	 var biggestRow = 0;

	 //Calculate each row

	 $(this).find(".row").each(function() {

	 $(this).calcSubWidth();

	 //Find biggest row

	 if(rowWidth > biggestRow) {

	 biggestRow = rowWidth;

	 }

	 });

	 //Set width

	 $(this).find(".sub").css({'width' :biggestRow});

	 $(this).find(".row:last").css({'margin':'0'});

	

	 } else { //If row does not exist...

	

	 $(this).calcSubWidth();

	 //Set Width

	 $(this).find(".sub").css({'width' : rowWidth});

	

	 }

	 }

	

	 function megaHoverOut(){

	 $(this).find(".sub").stop().fadeTo('fast', 0, function() {

	 $(this).hide();

	 });

	 }

	

	

	 var config = {

	 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)

	 interval: 100, // number = milliseconds for onMouseOver polling interval

	 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)

	 timeout: 100, // number = milliseconds delay before onMouseOut

	 out: megaHoverOut // function = onMouseOut callback (REQUIRED)

	 };

	

	 $("ul#topnav li .sub").css({'opacity':'0'});

	 $("ul#topnav li").hoverIntent(config); 

	 

	 $("ul#topnav li.link2").hover(

		 function() {

			 $(this).find("a.link2").addClass("link2-class");

		 },

		 function() {

			 $(this).find("a.link2").removeClass("link2-class");

		 }

	 );

	 $("ul#topnav li.link3").hover(

		 function() {

			 $(this).find("a.link3").addClass("link3-class");

		 },

		 function() {

			 $(this).find("a.link3").removeClass("link3-class");

		 }

	 );

	 $("ul#topnav li.link4").hover(

		 function() {

			 $(this).find("a.link4").addClass("link4-class");

		 },

		 function() {

			 $(this).find("a.link4").removeClass("link4-class");

		 }

	 );

	 $("ul#topnav li.link5").hover(

		 function() {

			 $(this).find("a.link5").addClass("link5-class");

		 },

		 function() {

			 $(this).find("a.link5").removeClass("link5-class");

		 }

	 );

	 

	 //AJAX rezultati

	 function remove_class1() {

		 $("#rez-nav a").removeClass("current1");

		 $("#rez-nav a").removeClass("current2");

		 $("#rez-nav a").removeClass("current3");

		 $("#rez-nav a").removeClass("current4");

	 }

	 //load doefault

	 $("#rez-top-wrap").load("/ajax/top01.php", { 'liga': 1 });

	 $("#rez-bottom").load("/ajax/bottom01.php", { 'liga': 1 });

	 

	 $("#rez-nav .link1").click(function() {

	 	remove_class1();

		$(this).addClass("current1");

		$("#rez-top-wrap").load("/ajax/top01.php", { 'liga': 1 });

		$("#rez-bottom").load("/ajax/bottom01.php", { 'liga': 1 });

		return false;

	 });

	 $("#rez-nav .link2").click(function() {

	 	remove_class1();

		$(this).addClass("current2");

		$("#rez-top-wrap").load("/ajax/top01.php", { 'liga': 2 });

		$("#rez-bottom").load("/ajax/bottom01.php", { 'liga': 2 });

		return false;

	 });

	 $("#rez-nav .link3").click(function() {

	 	remove_class1();

		$(this).addClass("current3");

		$("#rez-top-wrap").load("/ajax/top01.php", { 'liga': 3 });

		$("#rez-bottom").load("/ajax/bottom01.php", { 'liga': 3 });

		return false;

	 });

	 $("#rez-nav .link4").click(function() {

	 	remove_class1();

		$(this).addClass("current4");

		$("#rez-top-wrap").load("/ajax/top01.php", { 'liga': 4 });

		$("#rez-bottom").load("/ajax/bottom01.php", { 'liga': 4 });

		return false;

	 });

	 

	 $("#content-left p img.slika-clanak").parent("p").css("padding", "0px");

	 $("#content-left p img.slika-clanak").parent("p").next("p").css("padding", "0px");

	 $("#content-left h4.datum").css("padding-bottom", "6px");

	 

	 //PUPUP

	 $("#popup").show();

	 $("#popup").animate({bottom: "+=132px"}, 1500);

	 //$("#popup").fadeIn("slow");

	 $("#popup a.zatvori").click(function() {

		$("#popup").hide();	

		return false;

	 });

	 

	 timer = setTimeout(function() {

		$("#popup").fadeOut("fast");	

	 }, 13800);

	 

	 

	 //home rotator

	var max_panel_br = $(".panel .r-panel").size() - 1;					   

	var br = 0;

	var speed1 = 500;

	var slide_timeout = 7000;

	var play = 1;

	var transitionType = "easeInOutExpo";

	

	$.next = function() {

		if(br < max_panel_br) {					   

		$(".panel").animate({left:"-=470"}, speed1, transitionType);

		++br;

		$.hide_element();

		if(play) {

			$.vrti();

		}

		} else {

			$(".panel").animate({left:"0"}, speed1, transitionType);

			br = 0;

			$.hide_element();

			if(play) {

				$.vrti();

			}

		}

	}

	

	$.prev = function() {

		if(br > 0) {					   

		$(".panel").animate({left:"+=470"}, speed1, transitionType);

		--br;

		$.hide_element();

		}

	}

	

	$.hide_element = function() {

		if(br == 0) {

			$("#prev2").css("visibility","hidden");

			$("#next2").css("visibility","visible");

		}

		if(br > 0) {

			$("#prev2").css("visibility","visible");

		}

		if(br == max_panel_br ) {

			$("#prev2").css("visibility","visible");

			$("#next2").css("visibility","hidden");

		}

		if(br < max_panel_br ) {

			$("#next2").css("visibility","visible");

		}

		if(max_panel_br == 0 ) {

			$("#prev2").css("visibility","hidden");

			$("#next2").css("visibility","hidden");

		}

		

	}

	

	$.vrti = function(thisItem) {

		timer = setTimeout(function() {

			$.next();

		}, slide_timeout);

		play = 1;

	}

	

	$.zaustavi = function() {

		clearTimeout(timer);

		play = 0;

	}

	



	$("#prev2").css("visibility","hidden");

	$.hide_element();

	

	if($(".r-panel").size() <= 1) {

		$("#next2").css("visibility","hidden");	

	}



	$("#next2, a.go-right").click(function() {	

		$.zaustavi();					   

		$.next();

		return false;

	});

	

	$("#prev2").click(function() {

		$.zaustavi();					   

		$.prev();

		return false;

	});
	
	$(document).keydown(
        function(e) {
			if (e.keyCode == 39) {
                $.zaustavi();					   
				$.next();
				return false;
			}
			if (e.keyCode == 37) {
				$.zaustavi();					   
				$.prev();
				return false;							 
			}	
	});

	

	if(play && $(".r-panel").size() > 1)  {

		$.vrti();

	}



	$('input.txt-input2').keyup(function(e) {

		if(e.keyCode == 13) {

			Search(2);

		}

	});



	$('input.txt-input3').keyup(function(e) {

		if(e.keyCode == 13) {

			Search(3);

		}

	});



});







// DIV scrollbar

$(function()

{

	$('#profil-opsirnije').jScrollPane();

});





$(document).ready(function() {

    $('#VrtiSeVrti').jcarousel({

    	scroll: 8

    });

});



function Search(mode)

{

	if( mode == 2 )

	{

		var query = $("input.txt-input2").val();

	}

	else

	{

		var query = $("input.txt-input3").val();

	}	

	window.location = '/pretrazivanje/' + query;

}



var SearchBubble = false;

function SearchBubbleToggle()

{

	if( SearchBubble )

	{

		$("#search-bubble").css('display', 'none');

		$("#search-link").css('background-position', '-225px -190px');

		$("#search-link").hover( function(){

			$("#search-link").css('background-position', '-346px -190px');

		},

		function(){

			$("#search-link").css('background-position', '-225px -190px');

		}	

		);

		SearchBubble = false;

	}

	else

	{

		$("#search-bubble").css('display', 'block');

		$("#search-link").css('background-position', '-346px -190px');

		$("#search-link").removeClass('hover-bg');

		SearchBubble = true;

	}

	return false;

}
