$(document).ready(function() {
	
	//facebox
	$('a[rel*=facebox]').facebox();
	
	//h1 rotator
	$('.main-image img').show();
	$('.main-image').cycle({
		fx: 'fade',		// choose your transition type, ex: fade, scrollUp, shuffle, etc...
		cssBefore: { zIndex:1 },
		cssAfter: { zIndex:0 }
	});
	
	
	//scroll over section
	$('.t-thumb').hover(function(){
		var thing = $(this).children('a').attr('href');
		if(thing.indexOf('##') === -1 ){	
			if(thing != 'javascript:void(0);'){
				$(this).append('<div>click for details</div>').find('div').addClass('seemore');
			}
		}else{
			$(this).children('a').attr('href','javascript:void(0);');
		}
	 },function(){
		$(this).find('.seemore').remove();
	 });
	

	//dropdown nav
	$('#topmenu ul li.dropdown').hover(function(){
		$(this).find('ul').fadeIn('fast');
	},function() {
		$('li.dropdown ul').hide();
	});
	
	
	//contact form
	$('#contact_form').validate();
	$('.shop_at_home').change(function(){
		$('.hidden-form').toggle();									   
	});
	
	if( $('#shop_at_home1').is(':checked') ){
		$('.hidden-form').toggle();
	}


	// jquery ui tabs
	$(function() {
		$("#tabs").tabs();
	});
	$(function() {
		$( "#accordion" ).accordion({collapsible: true,active:false,autoHeight:false});
	});
	

	if($('#tabs').length > 0){
		if(document.location.hash === ''){
			document.title = $('#tabs ul li.ui-tabs-selected a').attr('href').replace( /#/gi, "") + " | " + document.title;
			//document.location.hash = $('#tabs ul li.ui-tabs-selected a').attr('href').replace( /#/gi, "");
		}else{
			document.title = document.location.hash.replace( /#/gi, "") + " | " + document.title;
			var orgTitle = document.title;
		}
		
		$('#tabs ul li a').click(function(){
			var theHash = $(this).attr('href').replace( /#/gi, "");			  	
			var theTitle = document.title;		
			var pipePosition = theTitle.indexOf('|');						    	
			theTitle = theTitle.substring(pipePosition+1);
			pipePosition = theTitle.indexOf('|'); 
			document.title = theHash + " | " + $('#pageTitle').html() + " | " + theTitle.substring(pipePosition+1);
		});
	}

});

//setting jquery validate for contact form.
$.validator.setDefaults({
	submitHandler: function() {
		var floor_type = '';
		$('input[name=floor_type]:checked').each(function(){
			floor_type = floor_type + ', ' + $(this).val();
		});
		
		$.post("inc/send_msg.php", {
				name: $("#name").val(),
				email: $("#email").val(),
				phone: $("#phone").val(),
				shop_at_home: $('input[name=shop_at_home]:checked').val(),				
				installation: $('input[name=installation]:checked').val(),
				address: $("#address").val(),
				city: $("#city").val(),
				province: $("#province").val(),
				postal: $("#postal").val(),							
				floor_type: floor_type,
				building_type: $('input[name=building_type]:checked').val(),
				quality: $('input[name=quality]:checked').val(),
				how_did_you_find_us: $('#how_did_you_find_us :selected').text(),
				sqfootage: $("#sqfootage").val(),
				message_body: $("#message_body").val()
		},function(data) {
			$.facebox('<br /><p>' + data + '</p>');
			$("#name").val('');
			$("#email").val('');
			$("#phone").val('');
			$("#address").val('');
			$("#city").val('');
			$("#province").val('');
			$("#postal").val('');				
			$("#sqfootage").val('');
			$("#message_body").val('');
		});
	}
		
});

