jQuery(document).ready(function($){

	// fix the size of the website body
	// make it 100% height
	adjustBody();
	
	$(window).resize(function() {
		adjustBody();
	});
	
	$(".bigPhoto li:first").addClass("current").show();
	if ( $(".bigPhoto li").length > 1 )
	{
		setInterval(function(){
			rotateFeatured("",".bigPhoto","","next");
		}, 4500);
	}
	
	// process email form
	//----------------
	$("#inqForm #submit").live("click",function(){
		
		var data = $("#inqForm").serialize();
		//console.log(data);
		
		$.ajax({
			contentType: "application/x-www-form-urlencoded; charset=utf-8",
			type: "POST",
			url: "/process/sendmail.php",
			data: data,
			success: function(msg){
				
				if( msg == "sent" )
				{
					window.location = "http://www.r-tisk.si/povprasevanje-poslano";
					
				}
				
				if( msg == "" || msg == "error_missing_data" )
				{
					$("#errorMessage").css("display","block");
				}
			}
		});
		
		return false;
		
	});
	//----------------
	
	// INPUT PLACEHOLDER
	//---------------------------
	
	$("[placeholder]").each(function(){
		
		var input = $(this);
		var val = $(this).attr("placeholder");
		input.val(val);
		
	});
	
	
	$("[placeholder]").focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr("placeholder")) {
	    input.val("");
	    input.removeClass("placeholder");
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == "" || input.val() == input.attr("placeholder")) {
	    input.addClass("placeholder");
	    input.val(input.attr("placeholder"));
	  }
	}).blur();
	
	$("[placeholder]").parents("form").submit(function() {
	  $(this).find("[placeholder]").each(function() {
	    var input = $(this);
	    if (input.val() == input.attr("placeholder")) {
	      input.val("");
	    }
	  })
	});
	//---------------------------
	
});

function adjustBody()
{
	var bodyHeight = $("body").height();
	if( bodyHeight > 727 )
	{
		$("#wrap").height(bodyHeight - 30);
	}	
}

// ROTATE FEATURED BANNERS
//---------------------------------

function rotateFeatured(target, group, navgroup, dir)
{
	
	//alert( target +" "+ group +" "+ navgroup +" "+ dir );
	
	// get current and next
	var curr = jQuery(group+" li.current");
	
	if( dir == "" || dir == "next" )
	{
		var next = ( target!="" ) ? jQuery(group+" li#"+target) : ( ( curr.next().length ) ? jQuery(group+" li.current").next() : jQuery(group+" li:first") );
	}
	
	if( dir == "" || dir == "prev" )
	{
		var next = ( target!="" ) ? jQuery(group+" li#"+target) : ( ( curr.prev().length ) ? jQuery(group+" li.current").prev() : jQuery(group+" li:last") );
	}
	
	var currIdent = curr.attr("id");
	var nextIdent = next.attr("id");
	
	// switch classes
	curr.removeClass("current");
	next.addClass("current");
	
	// hide current and show next
	curr.fadeOut("slow");
	next.fadeIn("slow");
	
	// update pagination
	if(navgroup!="")
	{
		jQuery("#"+navgroup+" div[rel="+currIdent+"]").removeClass("active");
		jQuery("#"+navgroup+" div[rel="+nextIdent+"]").addClass("active");
	}
	
}
//---------------------------------
