﻿// JavaScript Document
$(function() {$('#imgcarousel').cycle();});
$(document).ready(function(){
	bindfuncs();
	$("#enquire-bttn").click(function(){contactpulse();return false;});
	$("#callback-bttn").click(function(){contactpulse();return false;});
	$("#contactus").click(function(){contactpulse();return false;});
});

function contactpulse(){
	//function to make the page scroll to the contact form and pulse...
	$.scrollTo( '#cform', 400, {offset:{top:-45 },onAfter:function(){ 
		$("#cform").animate( { backgroundColor: 'tsred', borderBottomColor: 'tsred', borderLeftColor: 'tsred', borderRightColor: 'tsred', borderTopColor: 'tsred'}, 250)
				.animate( { backgroundColor: 'white', borderBottomColor: 'tsyellow', borderLeftColor: 'tsyellow', borderRightColor: 'tsyellow', borderTopColor: 'tsyellow' }, 1500);
		$(".pcontact").animate( { backgroundColor: 'tsred' }, 250)
				.animate( { backgroundColor: 'tsyellow' }, 1500);
		}});//specify an easing equation
}


function bindfuncs(){
	
	$('.thimbimg').click(function(){
		var ThisThumbURL=$(this).attr('src');
		var ThisThumbALT=$(this).attr('alt');
		var ThisThumbTITLE=$(this).attr('title');
		//alert(ThisThumbURL);
		ThisThumbURL=ThisThumbURL.replace(/\/100\//gi, "/538/");
		ThisThumbURL=ThisThumbURL.replace(/\/67\//gi, "/359/");
		$('#mainimg').attr('src',ThisThumbURL);
		$('#mainimg').attr('alt',ThisThumbALT);
		$('#mainimg').attr('title',ThisThumbTITLE);
		//alert(ThisThumbURL);
	});
	
	
	
	jQuery('#holder').show();
	jQuery('#test').simple_slider({
		'leftID': 'upNav',
		'rightID': 'downNav',
		'display': 4
	});
	
	$('.allgood').click(function(){

		$("#cbttn").html( "<input type='submit' id='cmysubmit' name='cmysubmit' value='&nbsp;' class='cform-bttn c-bttn-"+lang+"' />" );
		$('#cform-id').clearForm();
		
		return false; 
	});
	
	$("#cform-id").submit(function(event) { 
		// stop form from submitting normally 
		event.preventDefault();  
		//$(".cform-bttn").css("background-image", "url(/sites/2/themes/villalux/images/loading.gif)");
		$("#cbttn").html( "<img name='' src='/images/loading.gif' />" );
		//$("#cloading").html( "<img name='' src='/sites/2/themes/villalux/images/loading.gif' />" );
		// get some values from elements on the page: 
		var $form = $( this ), url = $form.attr( 'action' ); 
		// Send the data using post and put the results in a div 
		var form_data=$( this ).serialize()+'&ajaxcsubmit=submitted';
		//alert(url);
		$.post( url, form_data , 
			function( data ) {
				$( ".cform-container" ).html( data );
				bindfuncs();
			} 
		); 
	});
}

$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = 0;
	});
	
};
