$(function(){
	
	// Pomeranje pozadinske slike u hederu
	$('header li a').hover(
		function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:400})
		},
		function(){
			$(this).stop().animate({backgroundPosition:"(0px -146px)"}, {duration:400})
		}
	);
	
	// Fancybox za slike
	
	jQuery.fn.getTitle = function() {
		var arr = jQuery("a.fancybox");
		jQuery.each(arr, function() {
			var title = jQuery(this).children("img").attr("title");
			jQuery(this).attr('title',title);
		})
	}
	
	var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

	$(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();
	
	$("a.fancybox").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBounce',
		'easingOut'			: 'easeOutBounce',
		'overlayOpacity'	: 0.4,
		'opacity'			: true,
		'centerOnScroll'	: true,
		'overlayColor'		: '#85BAD1',
		'titleShow'			: false,
		'speedIn'			: 1000,
		'speedOut'			: 1000,
		'changeSpeed'		: 600
	});
	
	// JavaScript dateinput
	$.tools.dateinput.localize("sr", {
		months		: 'Januar,Februar,Mart,April,Maj,Jun,Jul,Avgust,Septembar,Oktobar,Novembar,Decembar',
		shortMonths : 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
		days		: 'Nedelja,Ponedeljak,Utorak,Sreda,Četvrtak,Petak,Subota',
		shortDays	: 'Ned,Pon,Uto,Sre,Čet,Pet,Sub'
	});
	
	$(".no_history:date").dateinput({
		lang		: 'sr',
		format		: 'dd.mm.yyyy',
		selectors	: true,
		firstDay	: 1,
		min			: 0
	});
	
	$(".with_history:date").dateinput({
		lang		: 'sr',
		format		: 'dd.mm.yyyy',
		selectors	: true,
		firstDay	: 1,
		max			: 0,
		yearRange	: [-70, -18],
		value		: '1990-01-01'
	});
	
	// JavaScript validacija
	$.tools.validator.localize("sr", {
		'*'				: 'Molimo vas popunite ovo polje',
		':email'  		: 'Unesite validnu email adresu',
		'[required]'	: 'Obavezno polje'
	});
	
	// $("form").validator({
		// lang		: 'sr',
	// }).submit(function(e){
		// var form = $(this);
		
		// var dataString = form.serialize();
		
		// if(!e.isDefaultPrevented()){
				
			// var ajax_btn = $('#send_button').after("<span class='ajax_load' style='padding:0 20px;'>Podaci se šalju...</span><img class='ajax_load' src='http://www.cuvanjedece.rs/wp-content/themes/cuvanjedece.rs/style-images/ajax-loader.gif' alt='ajax loading' />")
			
			// $.ajax({
				// type: "POST",
				// data: dataString,
				// success: function(){
					// $('.ajax_load').remove();
					// $('#error').html('<h2>Podaci koje ste uneli su strogo poverljivi. Zahvaljujemo se na popunjenom upitniku i nadamo se uspešnoj saradnji.</h2>').fadeIn(3000);
					// setTimeout('$("#error").fadeOut("slow")',10000);
				// }
			// });
			
			// e.preventDefault();
		// }
	// }).bind("onFail", function(e, els)  {
		// $('#error').html("<h2>Molimo Vas popunite sva polja!</h2>").fadeIn(2000);
		// setTimeout('$("#error").fadeOut("slow")',5000);
	// });
});
