// preload flash
$.flashExpressInstaller = '/assets/swf/expressInstall.swf';

frontBanner = $.flash({   
     swf: '/assets/swf/slideshow.swf',   
     height: 313,   
     width: 931,
     params: {
         scale: "noscale",
         menu: "false",
         flashvars: {   
             xmlSrc: "/assets/xml/slideshow.xml",
             delay: "7200",
             fontSize: "32"  
         }
     }   
});

$(document).ready(function(){
    // flash insertion
    $('#flashWrap').html(frontBanner);
    
    //other
    
	$('.bottomLink').css("cursor", "pointer").hover(function(){
	    $(this).children().children('p').css("text-decoration", "underline");
	 }, function() {
	    $(this).children().children('p').css("text-decoration", "none");
 	    
	}).click(function(){
	    window.location = $(this).children().children().children('a').attr('href');
	});

// special offers
    function offer(image, imageInfo) {
        $(imageInfo).hide();
         $(image).css("cursor", "pointer").toggle(function() {
             $(this).next(imageInfo).slideDown('fast');
         }, function() {
             $(this).next(imageInfo).slideUp('fast');
         });
    }
    
    offer(".terms", ".termsText");
    offer("#newCustomers", "#newCustomersText");
    
//services widget 

if($('#serviceBox').length > 0) {
    fullHeight = $('#serviceBox').height();
    
    $('#serviceBox').css({height: "200px", overflow: "hidden"});
    $('#moreServices a').toggle(function() {
        $('#serviceBox').animate({ height: fullHeight+"px"}, 1000 );
        $(this).html('less...');
    }, function() {
        $('#serviceBox').animate({ height: "200px"}, 1000 );
        $(this).html('more...');
        
    }); 
}
    
//contact
    email = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,9}\b/;
    phoneTest = /.[\d\s]{6,}/;
    valid = false;
    $('#contactSubmit').after('<div id="sendStatus" class="loader"><p>sending...</p></div>');
    $('#sendStatus').hide();
    startVal = $('#contactBox').html();
    $('#contactBox').click(function() {
        if($(this).val() == startVal) {
            $(this).css({fontSize: "14px"}).val('');
        } 
    
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).css({fontSize: "24px"}).val(startVal);
        } 
    });

	function ajaxFunction(button) {
	    $.ajax({
			type:"POST",
			url:"/assets/aspx/process.aspx",
			data:"query="+mess,
			success: function(msg){
				$('#sendStatus p').html("Success! We'll contact you shortly.").parent().removeClass('loader');
				$('#contactBox').fadeTo(50, 0.2);
				$(button).html('Submit')
				setTimeout(function(){
					$('#sendStatus').hide().children().html("loading...");
					$('#contactBox').fadeTo(50, 1).css({fontSize: "24px"}).val(startVal);
				}, 4000);
			},
			error: function(){
				alert('Unfortunately there is an error processing your message. Please use the contact details above the form .');
			}
		});
	}
	$('#contactSubmit').click(function(){
		mess = $('#contactBox').val();
		if($(this).html() == "Submit") {
			if(email.test(mess) == true || phoneTest.test(mess) == true) {
				$('#sendStatus').fadeIn('fast');
    			ajaxFunction($(this));

				return false;
			} else {
				$('#sendStatus p').html("Are you sure you've included a correct email address or telephone number? If not, please include one and then click proceed.").parent().removeClass('loader').show();
				$('#contactSubmit').html("Proceed");
				return false;
			}
		} else if($(this).html() == "Proceed") {
			$('#sendStatus p').html("loading...").parent().addClass('loader');
			ajaxFunction($(this));

			return false;
		}
	});
	
// professional contact form:
    if($('#profForm').length > 0) {
		$('#profForm').sitVal();
    }

});