var leadFormOptions = {
    beforeSubmit:  leadFormSubmitBefore,
    success:       leadFormSubmitResponse
}

$(document).ready(function(){
	
	$('div.thumbnail').click(function(){
		$('#main_flash').hide();
		$('#mango_flash').hide();
		var id = $(this).attr('id');
		xmlUrl = Registry.URL_SLIDESHOW_XML + id;
		//alert(xmlUrl);
		var slideShowSample = $('#slideshowSample').html();
		var slideShow = slideShowSample.replace(/slideshow\.swf"/, "slideshow.swf?xml_url_var="+xmlUrl+"\"");
		var slideShow = slideShow.replace(/slideshow\.swf"/, "slideshow.swf?xml_url_var="+xmlUrl+"\"");
		$('#slideshow').html(slideShow).show();
		$('#slideshowContainer').show();
	});
	
    $('html').keypress(function(event) {    	
        if(event.keyCode == 27) { // ESC   
        
        }
    });
    
    $("#leadFormSend").click(function(){
    	$('#leadForm').ajaxSubmit(leadFormOptions);  
    	
    }); 
});

function closeSlideshow()
{
	$('#slideshow').html('').hide();
    
    //$('#main_flash').show();
}

function leadFormSubmitBefore()
{   
	if(trim($("#firstname").val()).length == 0 ||
	   trim($("#lastname").val()).length == 0 ||
	   trim($("#email").val()).length == 0 ||
	   trim($("#phone").val()).length == 0) {
		new MessageBox("Please fill all fields");
		return false;
	}
	$("#firstname").attr("disabled","disabled");
    $("#lastname").attr("disabled","disabled");
    $("#email").attr("disabled","disabled");
    $("#phone").attr("disabled","disabled");
	$(".send").html("wait&hellip;");
	return true;
}

function leadFormSubmitResponse(response)
{
	new MessageBox("Thank you for your request. Our representative will contact you shortly");
	$('#leadForm').resetForm();
	$("#firstname").removeAttr("disabled");
    $("#lastname").removeAttr("disabled");
    $("#email").removeAttr("disabled");
    $("#phone").removeAttr("disabled");
	$(".send").text("SEND");	
}
