$(document).ready(function() {
	
	//Cycle the images on frontpage
	$('#images').cycle({ 
		fx:      'scrollLeft', 
		speed:    600, 
		timeout:  5000,
		after: onAfter
	});

	//Change the title to the title of current photo
	function onAfter() {
		var currentTitle = $(this).attr('title');
			
		var title = $('#imgTitle');
		title.html(currentTitle);
	}
	
	//Hide the labels, labels only needed when javascript is disabled
	$('label').css('display', 'none');
	$('.error-message').css('display', 'none');
	
	//Set the error message as title for the field
	$('.error').each(function() {
		var errorMsg = $('.message', $(this));
		
		$(this).children('.field-text').val("");
		$(this).children('.field-text').addClass('errorMsg');
		$(this).children('.field-text').attr('title', errorMsg.html().trim());
	})
	
	//Set the title as text because there's no label    
    $(".field-text, .field-text-multiline, .field-date").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });
	
	//Remove the title on click for userinput
	$(".field-text, .field-text-multiline, .field-date").focus(function(srcc)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("defaultTextActive");
            $(this).removeClass("errorMsg");
            $(this).val("");
        }
    });
    
    $(".field-text, .field-text-multiline, .field-date").blur(); 
	
	//Remove all the titles on submit for serverside validation 
	$('form').submit(function() {
		$(".field-text, .field-text-multiline, .field-date").each(function() {
			if($(this).val() == $(this)[0].title) {
				$(this).val("");
			}
		})
	})

});
