$(document).ready(function(){

	// Put your headers that need to be converted to Cufon here
	 Cufon.replace('h1,.redBt,#breadcrumbs,.blueDotted,.whiteBorder,.redDotted, #leftContact h3, #leftContact p:not(.terms),.cars-box h3,.cars-box h4,#cars-search-actions li a, #pricelist strong, h2', { fontFamily: 'Nobel-Book', hover: true });
	 Cufon.replace('#cars-actions li a,#modCalls,#leftCalls li a,.redSubmit,#anav li a,#quicklinks h3', { fontFamily: 'SF New Republic SC', hover: true });
	 
	 $("#enquiryform").attr("action","http://www.phase.com.au/forms/afp_spam.asp?formid="+$("#enquiryform").attr("alt"));
	 
	 
	$(".cNext").click(function(){
		$(this).parent().parent().animate({left: '-=320'})
	}) 
	$(".cPrev").click(function(){
		$(this).parent().parent().animate({left: '+=320'})
	}) 
	
	/******************************/
	// Forms
	/******************************/
	
	// Remove empty class from items that need to be corrected by user on focus
	$(".ajForm input.empty").live('focus',function(){$(this).removeClass('empty')})
	
	// Update form action list
	$(".pFormCheck").live('click',function(){
		var checked = $(this).attr('checked')
		if(!checked) vis("#"+$(this).val(),true)
		else vis("#"+$(this).val())
	})
	
	// Launch the form processing action via ajax
	$(".pFormSubmit").live('click',function(event){					   
		var me = $(this).prev('.ajForm')
		$.ajax({
		  type: 'POST',
		  url: 'form-processor.php',
		  data: me.serialize(),
		  success: function(data){me.after(data);},
		  dataType: 'text'
		})
	})
	
	$("#fClose").live('click',function(){
		$("#formContainer").html('')
	})
	
	// Jquery UI date picker
	$(".jCal").live('focus', function() {
        $(this).datepicker()
    })
	
})


function vis(element,hide) {
	if(!hide) var hide = false
	var change = hide ? 'none' : 'block'
	$(element).css('display',change)
}

function showHideSub(trigger,element) {
	if(!$(element).hasClass('active')) {
		$(element).css('z-index',150);
		var both = trigger+','+element
		$(both).hover(function(){
			$(trigger).stopTime()
			$(trigger).addClass("hover")
			$(element).css('display','block')
		},function(){
			$(trigger)
				.oneTime(250,function(){$(element).fadeOut(250,function(){$(trigger).removeClass("hover")})})
		})
	}
	else $(element).css('z-index',140);
}

function genForm(args) {
	if(!$("#formContainer").length) $("#content").prepend('<div id="formContainer"></div>')
	$("#formContainer").load("form-generator.php?"+args,function(){
			Cufon.replace('#multiform h2, #multiform h3, #multiform h4,.fSend', { fontFamily: 'Nobel-book', hover: true });
		})
}
