function input_focus(id)
{
	$("#l"+id).addClass('lcurrent');
}

function input_blur(id)
{
	$("#l"+id).removeClass('lcurrent');
}

function sendContact()
{
	// check for message
	var msg = $("#name").val();
	if(msg.length == 0)
	{
		$("#name-error").slideDown(500);
		$("#name").focus();
		return false;
	}
	else
		$("#name-error").slideUp(500);
		
	// check for email
	var email = $("#email").val();
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(email))	
	{
		$("#email-error").slideDown(500);
		$("#email").focus();
		return false;
	}
	else
		$("#email-error").slideUp(500);
	
	// check for message
	var msg = $("#message").val();
	if(msg.length == 0)
	{
		$("#message-error").slideDown(500);
		$("#message").focus();
		return false;
	}
	else
		$("#message-error").slideUp(500);
		
	// check for captcha
	var captcha = $("#captcha").val();
	if(captcha != captcha_c)
	{
		$("#captcha-error").slideDown(500);
		$("#captcha").focus();
		return false;
	}
	else
		$("#captcha-error").slideUp(500);	
	
	var data = $("#contact_form > form").serialize();

	$.ajax({
		type: "POST",
		url: "sendContact.php",
		data: data,
		cache: false,
		success: function(msg){
		}
	});
	
	$("#contact_form").fadeOut(1000, function() {
		$("#message_sent").slideDown(500);
	});
	
	
	return false;
}

var captcha_a = Math.ceil(Math.random() * 10);
var captcha_b = Math.ceil(Math.random() * 10);       
var captcha_c = captcha_a + captcha_b;
function generate_captcha(id)
{
	var id = (id) ? id : 'lcaptcha';
	$("#"+id).html(captcha_a + " + " + captcha_b + " = ");
}

var jGalleryTimer = 0;
var jGalleryFirstStart = true;
var jGallery_action = false;
function jGallery(id, visible, timeInterval, transitionInterval)
{
	var visible = (visible) ? visible : 1;
	var timeInterval = (timeInterval) ? timeInterval : 5000;
	var transitionInterval = (transitionInterval) ? transitionInterval : 200;
	var w = (w) ? w : $("."+id+"-gallery-div :first").width();
	var cnt = $("#gallery-"+id+"-holder > div").size();
	
	if(jGalleryTimer)
	{
		clearInterval(jGalleryTimer);
		jGalleryTimer = 0;
	}
	
	if(!jGalleryFirstStart)
	{
		if(!jGallery_move(id, cnt, -1, w, visible, transitionInterval))
			jGallery_restart(id, cnt, transitionInterval);
	}
	
	jGalleryFirstStart = false;
	
	jGalleryTimer = setInterval(function(){ jGallery(id, visible, timeInterval, transitionInterval); }, timeInterval);
}

function jGallery_move(id, cnt, dir, w, visible, transitionInterval)
{
	if(jGallery_action)
		return false;
		
	var curr = document.getElementById("gallery-"+id+"-holder").style.left;
	curr = parseFloat(curr);

	if(isNaN(curr))
		curr = 0;
	if(dir > 0)
	{
		if(curr >= 0)
			return false;
	}
	else
	{
		if(curr + cnt * w - visible * w <= 0)
			return false;
	}

	jGallery_action = true;
	var offset = w;

	if(dir < 0)
		dir = "-";
	else
		dir = "+";
		
	$("#gallery-"+id+"-holder").animate(
		{left : dir+"="+offset+"px"},
		{queue:true, duration:transitionInterval, complete: function() {jGallery_action = false;}}
	);
	
	return true;
}

function jGallery_restart(id, cnt, transitionInterval)
{
	if(jGallery_action)
		return false;
		
	var curr = document.getElementById("gallery-"+id+"-holder").style.left;
	curr = parseFloat(curr);

	if(isNaN(curr))
		curr = 0;
	if(curr >= 0)
		return false;

	jGallery_action = true;
	var offset = curr * (-1);

	var gallerycontainer = $("#gallery-"+id+"-holder");
	gallerycontainer.fadeOut(500);
	window.setTimeout(function(){gallerycontainer.css('left','0px');}, 500)
	gallerycontainer.fadeIn(500);
	jGallery_action = false;

	return true;
}

$(document).ready(function()
{
	$("a[rel^='prettyPhoto']").prettyPhoto();
});
