$(document).ready(function(){


	$(".tl_corner").corner("tl 17px");
	
	$(".checkbox").click(function(){
		$(this).toggleClass("active");
		var check=$(this).hasClass("active");
		$(this).find("input[type='checkbox']").attr('checked',check);
	});
	
	$(".radio").click(function(){
		
		var rel=$(this).attr('rel');
		
		$(".radio[rel='"+rel+"']").each(function(){
			$(this).removeClass("active");
			$(this).find("input[type='checkbox']").attr('checked',false);
		})
		
		$(this).toggleClass("active");

		var check=$(this).hasClass("active");
		$(this).find("input[type='checkbox']").attr('checked',check);
	});
	
	$("button.button").click(function(){
		
		$("form input,form textarea").not("[type='submit']").val("");
		$("form .radio,form .checkbox").each(function(){
			$(this).removeClass("active");
			$(this).find("input[type='checkbox']").attr('checked',false);
		});
		
		return false;
	});
	
	$("[type='submit'].button").click(function(){
		
		var err="";
		var err_num=0;
		
		var email=$("input[name='e-naslov']").val();
		
		$.ajax({
			type: "POST",
			url: "/content/ajax/functions.php", 
			data: "action=email_validate&email="+email,
			async: false,
			success: function(msg){
				if(msg=='false'){
					err+=(++err_num)+". Napačen email naslov";
				}
			}
		});	
		
		if(err_num>0){
			alert(err);
			return false;
		}
		
		
		return true;
	});
	
	$(".slide_it").click(function(){
		var h=$(this).attr("href");
		$.scrollTo(h,800);
		
		return false;
	});
	
	
	
/*
	$("ul.big li").click(function(){

		$(this).find("p").slideToggle();
	});
*/
	
	
	
	
});


$(document).ready(function(){

	var img_array;
	
	
	$.ajax({
		type: "POST",
		url: "/content/ajax/functions.php", 
		data: "action=get_top",
		async: false,
		success: function(json){
			img_array=$.parseJSON(json);
		}
	});
	
	var x=0;			// start at first element
	var time=7 * 1000;	// seconds	
	
	$.fn.gallery = function(){
		
		var o=$(this[0]); // selector element
	
		//cleanup
		o.find("#big_pic_hold").html("");
			
		var image=$("<img>").attr({
			'src' : img_array[x].img,
			'class' : 'current'
		});
			
		if($.browser.msie && $.browser.version=='7.0')
			image.addClass("ie7_fix");
		
		
		var napis=$("<img>").attr({
			'src' : img_array[x].napis
		});
		var el=$("<div>").addClass("trans_napis").css('margin-top','-76px').append(napis);
		
		o.find("#big_pic_hold").append(image);
		o.append(el);
		
		// next
		++x;
		
		// preload next
		var img1=new Image();
		img1.src=img_array[x].img;
		var img2=new Image();
		img2.src=img_array[x].napis;
		
		
		setTimeout(change_f,time);
	};
	
	function change_f(){
	
		var o=$("#big_photo");
	
		o.find('.current').addClass('prev').removeClass('current');
		
		var image=$("<img>").attr({
			'src' : img_array[x].img
		}).hide().addClass("current");
		var napis=$("<img>").attr({
			'src' : img_array[x].napis
		});
		
		o.find('.trans_napis').fadeOut(500,function(){
			$(this).find('img').remove();
			$(this).append(napis);
			
			o.prepend(image);
			image.fadeIn(function(){
				o.find('.trans_napis').fadeIn(500,function(){
					
					o.find(".prev").remove();
					
					if(x<img_array.length-1)
						x++;
					else
						x=0;
						
					// preload next
					var img1=new Image();
					img1.src=img_array[x].img;
					var img2=new Image();
					img2.src=img_array[x].napis;	
					
					setTimeout(change_f,time);
					
				});
			});			
		});
	}
});

$(window).load(function(){
	$("#big_photo").gallery();
});









/*
|--------------------------------------------------------------------------
| UItoTop jQuery Plugin 1.1
| http://www.mattvarone.com/web-design/uitotop-jquery-plugin/
|--------------------------------------------------------------------------
*/

(function($){
	$.fn.UItoTop = function(options) {

 		var defaults = {
			text: 'To Top',
			min: 200,
			inDelay:600,
			outDelay:400,
  			containerID: 'toTop',
			containerHoverID: 'toTopHover',
			scrollSpeed: 800,
			easingType: 'linear'
 		};

 		var settings = $.extend(defaults, options);
		var containerIDhash = '#' + settings.containerID;
		var containerHoverIDHash = '#'+settings.containerHoverID;
		
		$('body').append('<a href="#" id="'+settings.containerID+'">'+settings.text+'</a>');
		$(containerIDhash).hide().click(function(){
			$('html, body').animate({scrollTop:0}, settings.scrollSpeed, settings.easingType);
			$('#'+settings.containerHoverID, this).stop().animate({'opacity': 0 }, settings.inDelay, settings.easingType);
			return false;
		})
		.prepend('<span id="'+settings.containerHoverID+'"></span>')
		.hover(function() {
				$(containerHoverIDHash, this).stop().animate({
					'opacity': 1
				}, 300, 'linear');
			}, function() { 
				$(containerHoverIDHash, this).stop().animate({
					'opacity': 0
				}, 300, 'linear');
			});
					
		$(window).scroll(function() {
			var sd = $(window).scrollTop();
			if(typeof document.body.style.maxHeight === "undefined") {
				$(containerIDhash).css({
					'position': 'absolute',
					'top': $(window).scrollTop() + $(window).height() - 50
				});
			}
			if ( sd > settings.min ) 
				$(containerIDhash).fadeIn(settings.inDelay);
			else 
				$(containerIDhash).fadeOut(settings.Outdelay);
		});

};
})(jQuery);





