
$(document).ready(function(){
	initSliders();
	setupSortTable() ;

	// : anything not tidied up in here
	miscSetup() ;

	initAjax();
	setupSearchHandler();
	updateRangeSearch();
	setupCustomise();
	setupModelPopup();
	
	setupEmailSubscribe();
}) ;


// ----------------------------- functions --------------------------------- //

function initAjax() {
	// set up makes...
	$('.quick-search .searchbar-make').each(function(){
		$(this).change(function(){
							var make_id = $(this).parent().children('.searchbar-make').val() ;
							_searchbarquick = $(this).parent() ;
							// alert("/ajaxGateway/vehicle.ajax.php?action=ranges&make_id="+make_id) ;
							$.getJSON("/ajaxGateway/vehicle.ajax.php?action=ranges&make_id="+make_id, {},
							  function(data){
							    var options = '';
							    options += '<option value="false">All Vehicle Models</option>';
							    for (row in data.vehiclefinder['ranges']) {
							      vehicle = data.vehiclefinder['ranges'][row] ;
						          options += '<option value="' + vehicle.range_id + '">' + vehicle.range + '</option>';
						        }
							    _searchbarquick.children('.searchbar-range').html(options) ;
							    _searchbarquick.children('.searchbar-variant').html("<option value='false'>Please Select a Vehicle Model</option>") ;
							  });
						})
	}) ;

	// set up models...
	$('.quick-search .searchbar-range').each(function(){
		$(this).change(function(){
							var model_id = $(this).parent().children('.searchbar-range').val() ;
							_searchbarquick = $(this).parent() ;
							$.getJSON("/ajaxGateway/vehicle.ajax.php?action=variants&range_id="+model_id, {},
							  function(data){
							    var options = '';
							    for (row in data.vehiclefinder['variants']) {
							      vehicle = data.vehiclefinder['variants'][row] ;
						          options += '<option value="' + vehicle.id + '">' + vehicle.model + ' ' + vehicle.variant + '</option>';
						        }
							    _searchbarquick.children('.searchbar-variant').html(options) ;
							  });
						})
		
	}) ;

	return ;
}

function setupSearchHandler() {

	// : ajax forms : //
	var options = {		target:        	'#content-2col-left',   // target element(s) to be updated with server response 
						beforeSubmit:  	preSearch,  // pre-submit callback 
						success:       	showResults,  // post-submit callback
						error:			errorSearch, // something's gone wrong
						type:      		"post"
					};

	// : bind form using 'ajaxForm' : //
	var searchform = $('#searchform') ;

	// : hide the search button : //
	$('.hidden-search-submit').hide() ;

	// : set up the checkboxes on the search filter : //
	$('.check-list li').each(function(){
		$(this).click(function(){
			$('#searchform').submit() ;
		}) ;

		$(this).find("a").click(function(){
						var input = $(this).parent().parent().find("input") ;
						if(input.attr("checked") == true) {
							input.attr("checked", false) ;
						} else {
							input.attr("checked", true) ;
						}

						$('#searchform').submit() ;
						return false ;
		}) ;

	}) ;

	$('.check-list select').change(function(){
		$('#searchform').submit() ;
	}) ;

	searchform.attr("action", "/ajaxGateway/search.ajax.php") ;
	searchform.ajaxForm(options) ;

	// check and update form if no makes are selected
	$(".make-cb").click(function() {
		if($('.make-cb:checked').size() == 0 ) {
			// show the 'no makes selected' message
			$('.any-make').attr("checked", "true") ;
			$('.range-select-holder').hide() ;
		} else {
			$('.any-make').attr("checked", "") ;
			$('.range-select-holder').show() ;
		}
	}) ;
	if($('.make-cb:checked').size() == 0 ) {
		// show the 'no makes selected' message
		$('.range-select-holder').hide() ;
	} else {
		$('.range-select-holder').show() ;
	}
	$(".any-make").click(function() {
		$(".make-cb").attr("checked", "") ;
	}) ;

	// copy the checked values in the pop up into hidden fields in the actual form
	$(".range-cb").click(function() {
		$("#"+$(this).attr("id")+"-hidden").attr("checked", $(this).attr("checked")) ;
		// alert($(this).attr("checked")) ;
	}) ;

	// submit the form
	$(".rangeSelect-cls-btn").click(function() {
		// $('#searchform').submit() ;
	}) ;
	
	// submit the form
	$("a.rangeSelect").click(function() {
		$('#searchform').submit() ;
	}) ;

	// cancel the range select (reset 

	// set up the handlers for the range 'any' checkboxes
	$('.range-any').click(function(){
		if($(this).attr("checked") == true) {
			$('.'+$(this).attr("id")).attr("checked", "") ;
		}

		$('.'+$(this).attr("id")).attr("checked", "") ;
		// $('.'+$(this).attr("id")).attr("checked", !($(this).attr("checked"))) ;
	}) ;
	// if an individual checkbox is checked - update 'any' cb for this group
	$('.range-cb').click(function(){
		// alert($(this).attr("id")) ;
		var str = $(this).attr("id") ;
		var t = str.split("-") ;

		// alert('#range-cb-'+t[2]) ;
		// build a string for the section id
		$('#range-cb-'+t[2]).attr("checked", false) ;
	}) ;
}

function preSearch() {
	// : change the results pane to a 'loading' image : //
	$('.content-holder-2col-left').fadeTo("fast", 0.50);
	// $("div.result-table table").fadeTo("fast", 0.50);
	$("#searchLoading").show() ;
}

function showResults() {
	// : unchange the results pane from a 'loading' image and bulid the results : //
	$(".content-holder-2col-left").fadeTo("fast", 1);
	// $("div.result-table table").fadeTo("fast", 1);
	$("#searchLoading").hide() ;
}

function errorSearch() {
	// alert("Something has gone wrong - please try again in a moment.") ;
}

function updateRangeSearch() {
	$('.range-update').click(function() {
		// hide all the other makes and make only the selected one's visible
		$('.range-select').hide() ;
		
		$('.range-update').each(function() {
			if($(this).is(':checked')) {
				$(".range-"+$(this).val()).show() ;
			}
		}) ;
	}) ;
}

function setupCustomise() {
	// : attach the function to change the results to the form

	$('.customise_window').openDOMWindow({
		borderSize:0,
		borderColor:'#d9d9da',
		eventType:'click', 
		loader:1, 
		loaderImagePath:'animationProcessing.gif', 
		loaderHeight:16, 
		loaderWidth:17,
		width:780,
		height:600,
		windowPadding:0
	});
	
	$('.customise-btn-submit').click(function() {
		$(this).parent().submit() ;
	}) ;

}

function updateCustomiseTable() {
	form = $("#customiseform") ;

	// find the allowed values for term
	var term_lower = $(".term-slider > .slider-tool > .slider-min").val() ;
	var term_upper = $(".term-slider > .slider-tool > .slider-max").val() ;

	if(term_lower == "Any") {
		term_allowed = new Array("-") ;
	} else {
		term_allowed = new Array(term_lower) ;
		if(term_lower < term_upper) {
			var j = term_allowed.length ;
			term_lower = term_lower * 1 ;
			term_upper = term_upper * 1 ;
			for(i = term_lower ; i <= term_upper ; i = i + 12) {
			 	term_allowed[j++] = i ;
			}
		}
	}

	// find the allowed values for milages
	var mileage_lower = $(".mileage-slider > .slider-tool > .slider-min").val() ;
	var mileage_upper = $(".mileage-slider > .slider-tool > .slider-max").val() ;

	if(mileage_lower == "Any") {
		mileage_allowed = new Array("-") ;
	} else {
		mileage_allowed = new Array(mileage_lower) ;
		if(mileage_lower < mileage_upper) {
			var j = mileage_allowed.length ;
			mileage_lower = mileage_lower * 1 ;
			mileage_upper = mileage_upper * 1 ;
			for(i = mileage_lower ; i <= mileage_upper ; i = i + 5000) {
			 	mileage_allowed[j++] = i ;
			}
		}
	}

	// : now hide everything
	$(".customise_row").hide() ;

	// : and only show allowed values
	for(var i = 0 ; i < term_allowed.length ; i++) {
		for(var j = 0 ; j < mileage_allowed.length ; j++) {
			$(".customise_"+term_allowed[i]+"_"+mileage_allowed[j]).show() ;
			// alert(".customise_"+term_allowed[i]+"_"+mileage_allowed[j]) ;
		}
	}
}

function setupModelPopup() {
	$('.model_popup').openDOMWindow({
		borderSize:0,
		borderColor:'#d9d9da',
		eventType:'click', 
		loader:1, 
		loaderImagePath:'animationProcessing.gif', 
		loaderHeight:16, 
		loaderWidth:17,
		width:680,
		height:500,
		windowPadding:0
	});

	// setup the actions that will resize the window
	$('.resize-model-popup').click(function() {
		resizeModelPopup() ;
	}) ;
	
	$('.model_popup').click(function() {
		resizeModelPopup() ;
	}) ;
	
}

function resizeModelPopup() {
	var newheight = (($('.make-cb:checked').size()+1) * 75) ;

	if(newheight > 500 ) {
		newheight = 500 ;
	} else if(newheight < 500) {
		newheight = 500 ;
	}

	newheight = 500 ;

	if($('.make-cb:checked').size() == 0 ) {
		// show the 'no makes selected' message
		$('.no_model_selected').show() ;
	} else {
		$('.no_model_selected').hide() ;
	}

	$('#DOMWindow').height(newheight+'px');
}

function initSliders() {
	// : price slider
	// work out the value of the slider
	var maxprice = $("#maxprice").val() ;
	var minprice = $("#minprice").val() ;

	if($("#range-slider").length != 0) {
		var _slider = $("#range-slider");	
		_slider.slider({
			range: true,
			min: 0,
			max: 2000,
			step: 25,
			values: [minprice, maxprice],
			slide: function(event, ui) {
				$("#min").text(ui.values[0]);
				$("#max").text(ui.values[1]);
			},
			change: function(event, ui) {
				$('#slide-value').val(ui.values[0]+'-'+ui.values[1]);
			},
			stop: function(event, ui) {
				// : submit form or something : //
				preSearch() ;
	
				// : set the slider values before submitting... : //
				$("#min").text(_slider.slider("values", 0));
				$("#max").text(_slider.slider("values", 1));
				$('#slide-value').val(_slider.slider("values", 0)+'-'+_slider.slider("values", 1));
				
				$('#searchform').submit() ;
			}
		});
		$("#min").text(_slider.slider("values", 0));
		$("#max").text(_slider.slider("values", 1));
		$('#slide-value').val(_slider.slider("values", 0)+'-'+_slider.slider("values", 1));
	}

	// : term slider
	$(".term-slider > .slider-tool").slider({
		range: true,
		min: 12,
		max: 48,
		step: 12,
		values: [12, 48],
		start: function(event, ui)	{
			$('#variant_deal_results_loading').show() ;
			$('#variant_deal_results').fadeTo("fast", 0.50);
		},
		slide: function(event, ui)	{	updateSlider($(this)) ;		},
		stop: function(event, ui)	{
			updateSlider($(this)) ;
			$('#variant_deal_results_loading').hide() ;
			$('#variant_deal_results').fadeTo("fast", 1, function() {	if($.browser.msie) { this.style.removeAttribute('filter'); }	});
		},
		change: function(event, ui) {
			sliderChange($(this)) ;
			updateCustomiseTable() ;
		}
	});

	// : mileage slider
	$(".mileage-slider > .slider-tool").slider({
		range: true,
		min: 0,
		max: 40000,
		step: 10000,
		values: [10000, 30000],
		start: function(event, ui)	{
			$('#variant_deal_results_loading').show() ;
			$('#variant_deal_results').fadeTo("fast", 0.50);
		},
		slide: function(event, ui)	{	updateSlider($(this)) ;		},
		stop: function(event, ui)	{
			updateSlider($(this)) ;
			$('#variant_deal_results_loading').hide() ;
			$('#variant_deal_results').fadeTo("fast", 1, function() {	if($.browser.msie) { this.style.removeAttribute('filter'); }	});
		},
		change: function(event, ui) {
			sliderChange($(this)) ;
			updateCustomiseTable() ;
		}
	});

	// : initial_payment slider
	$(".initial_payment-slider > .slider-tool").slider({
		min: 0,
		max: 2500,
		step: 50,
		values: [750],
		start: function(event, ui)	{
			$('#variant_deal_results_loading').show() ;
			$('#variant_deal_results').fadeTo("fast", 0.50);
		},
		slide: function(event, ui)	{
			updateSlider($(this)) ;
		},
		stop: function(event, ui)	{
			updateSlider($(this)) ;
			updateInitialPayment($(this)) ;
			$('#variant_deal_results_loading').hide() ;
			$('#variant_deal_results').fadeTo("fast", 1, function() {	if($.browser.msie) { this.style.removeAttribute('filter'); }	});
		},
		change: function(event, ui) {
			// sliderChange($(this)) ;
			//$('#variant_deal_results').fadeTo("fast", 0.50);
			// $('#variant_deal_results_loading').show() ;
			// $('#variant_deal_results').fadeTo("fast", 0.50);
		}
	});
}

function updateSlider(obj) {
	obj.children(".slider-min").val(obj.slider("values", 0)) ;
	obj.parent().find("span.slider-min").text(obj.slider("values", 0)) ;

	obj.children(".slider-max").val(obj.slider("values", 1)) ;
	obj.parent().find("span.slider-max").text(obj.slider("values", 1)) ;

	obj.children(".slider-range").val(obj.slider("values", 0)+"-"+obj.slider("values", 1)) ;
}

function updateInitialPayment(obj) {
	// : update the monthly amounts based on the initial_payment values
	$(".customise_row").each(function(){
		// : calculate the value for this row

		// : basic calculation :
		// totalcost = (term * rental) + initial
		// newrental = (totalcost - initial) / term

		var new_initial_value = $(".initial_payment-slider > .slider-tool > .slider-min").val() ;

		// alert($(this).find('.initial_payment').html() * 1) ;

		// $(this).find('span.initial_payment').html(1000) ;
		// $(this).find('.rental').html(1000) ;
// var rental = $(this).find('.rental') ;

		var term = $(this).find('.term').html() * 1 ;
		var rental = $(this).find('.rental') ;
		var initial_payment = $(this).find('span.initial_payment') ;
		$(this).find('input.initial_payment').val(initial_payment.html()) ;
		

		var totalcost = (((term - 1) * (rental.html() * 1) ) * 1) + (initial_payment.html() * 1) ;
		var left_over_cost = totalcost - (new_initial_value) ;
		
		var new_rental = ( ( left_over_cost ) / (term - 1) * 100 ) / 100 ;
		
		
		rental.html( new_rental.toFixed(2) ) ;

		// initial_payment.html( new_initial_value ) ;

		// : now re-sort table
		// var sorting = [[3,0]]; 
        // sort on the first column 
    	// $(".sortable").trigger("sorton",[sorting]); 

	}) ;

	var new_initial_value = $(".initial_payment-slider > .slider-tool > .slider-min").val() ;
	$(".customise_row span.initial_payment").html(new_initial_value) ;
	$(".customise_row input.initial_payment").val(new_initial_value) ;
}

function sliderChange(obj) {
	// alert("this") ;
	return ;
}

function setupSortTable() {
	// : creates any required sorttables
	$(".sortable").tablesorter();

	// : now sort table
	// var sorting = [[3,0]]; 
    // sort on the first column 
    // $(".sortable").trigger("sorton",[sorting]); 
}


function miscSetup() {

	var _mainEntry = $('#main div.entry');
	var _btnCancel = $('a.btn-cancel', _mainEntry);
	var _btnMultiple = $('a.btn-multiple', _mainEntry);
	var _expanded = $('div.expanded', _mainEntry);
	var _formItem = $('.search-holder label strong',_mainEntry);
	_btnMultiple.click(function(){
		/*
		 Not used currently /ColB 
		 _expanded.hide().slideDown(700);
		_mainEntry.addClass('opened');
		_formItem.text('Multiple');
		return false;
		*/
	});
	_btnCancel.click(function(){
		_expanded.slideUp(700, function(){
			_formItem.text('Quick');
			_mainEntry.removeClass('opened');
		});
		return false;
	});

	// checkboxs ***************************************************************
	var _vhType = $('div.vh-type, div.vh-make');
	_vhType.each(function(i, _this){
		var _opener = $('a.opener, div.opener-head strong',_this);
		var _slide = $('ul.check-list',_this);
		var _chbMain = $('div.opener-head input',_this);
		var _chbAll = $('ul.check-list input',_this);
		
		if (!$(_opener).hasClass('selected')) {
			_slide.hide();
		} else _opener.addClass('selected');
		
		_opener.click(function(){
			_opener.toggleClass('selected');
			if (_opener.hasClass('selected')) {
				_slide.slideDown(300);
			} else {
				_slide.slideUp(300);
			}
			return false;
		});
		
		if (_chbMain.get(0).checked) _chbAll.attr('checked','checked');
		
		_chbMain.click(function(){
			if (this.checked) {
				_slide.slideDown(300);
				_opener.addClass('selected');
				_chbAll.attr('checked','checked');
			} else if (!_opener.is('.selected')) {
				_slide.slideDown(300);
				$(_opener).addClass('selected');
				_chbAll.removeAttr('checked');
			} else {
				_chbAll.removeAttr('checked');
			}
		});
	});
	var _holder1 = $('.slide-opener');
	_holder1.each(function(_k, _this11){
		var _opener11 = $('a.opener',_this11);
		var _strong11 = $('.slide-head strong',_this11);
		var _sellAll11 = $('.select input',_this11);
		_opener11.click(function(){
			$(this).parents('.frame').find('.search-open').show();
			$(this).parents('.slide-opener').hide();
			initSl();
			return false;
		});
		_strong11.click(function(){
			$(this).parents('.frame').find('.search-open').show();
			$(this).parents('.slide-opener').hide();
			initSl();
			return false;
		});
		_sellAll11.click(function(){
			$(this).parents('.frame').find('.search-open').show();
			$(this).parents('.slide-opener').hide();
			$(this).parents('.frame').find('.search-open').find('.slide-box').eq(2).addClass('open-box');
			$(this).parents('.frame').find('.search-open').find('.slide-box').eq(2).find('.slide-content').show();
			$(this).parents('.frame').find('.search-open').find('.slide-box').eq(2).find('.slide-head .opener').addClass('selected').text('HIDE');
			$(this).parents('.frame').find('.search-open').find('.slide-box').eq(2).find('img.bg-slide-box-open').hide();
			$(this).parents('.frame').find('.search-open').find('.slide-box').eq(2).find('img.bg-slide-box').show();
			initSl();
			return false;
		});
	});
	function initSl(){
		var _hold = $('.slide-box');
		_hold.each(function(i, _this){
			var _opener = $('a.opener',_this);
			var _strong = $('.slide-head strong',_this);
			var _slide = $('.slide-content',_this);
			var _chbMain = $('.select input',_this);
			var _chbAll = $('.option-list input',_this);
			
			_opener.click(function(){
				if($(this).parents('.slide-box').hasClass('open-box')) {
					$(this).removeClass('selected');
					$(this).parents('.slide-box').removeClass('open-box');
					var ___this = $(this);
					_slide.slideUp(300,function(){
						___this.parents('.slide-box').find('img.bg-slide-box-open').show();
						___this.parents('.slide-box').find('img.bg-slide-box').hide();
					});
					$(this).text('SHOW');
				}else{
					_hold.each(function(j, _this1){
						$('a.opener',_this1).each(function(){
							var _slide1 = $('.slide-content',_this1);
							$(this).removeClass('selected');
							$(this).parents('.slide-box').removeClass('open-box');
							var ____this = $(this);
							_slide1.slideUp(300,function(){
								____this.parents('.slide-box').find('img.bg-slide-box-open').show();
								____this.parents('.slide-box').find('img.bg-slide-box').hide();
							});
							$(this).text('SHOW');
						});
					});
					$(this).addClass('selected');
					$(this).parents('.slide-box').addClass('open-box');
					$(this).parents('.slide-box').find('img.bg-slide-box-open').hide();
					$(this).parents('.slide-box').find('img.bg-slide-box').show();
					_slide.slideDown(300);
					$(this).text('HIDE');
				}
				return false;
			});
			
			_strong.click(function(){
				if($(this).parents('.slide-box').hasClass('open-box')) {
					$(this).removeClass('selected');
					$(this).parents('.slide-box').removeClass('open-box');
					var ___this = $(this);
					_slide.slideUp(300,function(){
						___this.parents('.slide-box').find('img.bg-slide-box-open').show();
						___this.parents('.slide-box').find('img.bg-slide-box').hide();
						___this.parents('.slide-box').find('a.opener').removeClass('selected').text('SHOW');
					});
				}else{
					_hold.each(function(j, _this1){
						$('a.opener',_this1).each(function(){
							var _slide1 = $('.slide-content',_this1);
							$(this).removeClass('selected');
							$(this).parents('.slide-box').removeClass('open-box');
							var ____this = $(this);
							_slide1.slideUp(300,function(){
								____this.parents('.slide-box').find('img.bg-slide-box-open').show();
								____this.parents('.slide-box').find('img.bg-slide-box').hide();
								____this.text('SHOW');
							});
						});
					});
					$(this).parents('.slide-box').find('a.opener').addClass('selected');
					$(this).parents('.slide-box').addClass('open-box');
					$(this).parents('.slide-box').find('img.bg-slide-box-open').hide();
					$(this).parents('.slide-box').find('img.bg-slide-box').show();
					_slide.slideDown(300);
					$(this).parents('.slide-box').find('a.opener').text('HIDE');
				}
				return false;
			});
			
			if (_chbMain.get(0).checked) _chbAll.attr('checked','checked');
	
			_chbMain.click(function(){
				if(!$(this).parents('.slide-box').hasClass('.open-box')){
					_hold.each(function(j, _this1){
						$('a.opener',_this1).each(function(){
							var _slide1 = $('.slide-content',_this1);
							$(this).removeClass('selected');
							$(this).parents('.slide-box').removeClass('open-box');
							var ____this = $(this);
							_slide1.slideUp(300,function(){
								____this.parents('.slide-box').find('img.bg-slide-box-open').show();
								____this.parents('.slide-box').find('img.bg-slide-box').hide();
								____this.text('SHOW');
							});
						});
					});
					$(this).parents('.slide-box').find('a.opener').addClass('selected');
					$(this).parents('.slide-box').addClass('open-box');
					$(this).parents('.slide-box').find('img.bg-slide-box-open').hide();
					$(this).parents('.slide-box').find('img.bg-slide-box').show();
					_slide.slideDown(300);
					$(this).parents('.slide-box').find('a.opener').text('HIDE');
				}
				if (this.checked) {
					_chbAll.attr('checked','checked');
				}else{
					_chbAll.removeAttr('checked');
				}
			});
		});
	}
	
	
	// --------------------------------------------------------------------- 
	
	if ($.browser.msie && $.browser.version < 7){
        $(".nav > li").mouseenter(function(){
            $(this).addClass('hover');
            if($(this).children('div.drop').length) $('.entry select').css({visibility:'hidden'});
        }).mouseleave(function(){
            $(this).removeClass('hover');
            if($(this).children('div.drop').length) $('.entry select').css({visibility:'visible'});
        });
    }
	
	// --------------------------------------------------------------------- 
	
	// Slide effect
    var _parentSlide = 'div.slide-wrap';
    var _linkOpen = 'a.link-open';
	var _linkClose = 'a.link-close';
    var _slideBlock = 'div.slide-text';
    var _openClassS = 'active';
    var _durationSlide = 500;
    
    $(_parentSlide).each(function(){
	if (!$(this).is('.'+_openClassS)) {
	    $(this).find(_slideBlock).css('display','none');
	}
    });
	$(_linkOpen,_parentSlide).click(function(){
	    $(this).parents(_parentSlide).addClass(_openClassS);
	    $(this).parents(_parentSlide).find(_slideBlock).slideDown(_durationSlide);
		$(_linkOpen).css('display','none');
	});
    $(_linkClose,_parentSlide).click(function(){
	if ($(this).parents(_parentSlide).is('.'+_openClassS)) {
	    $(this).parents(_parentSlide).removeClass(_openClassS);
	    $(this).parents(_parentSlide).find(_slideBlock).slideUp(_durationSlide);
		$(_linkOpen).css('display','inline');
	}
	return false;
    });
	
}


function setupEmailSubscribe() {
	/*
	$(".emailsubscribe_name").bind("focus blur", function() {
		var txt = "Enter name..." ;
		if($(this).val() == "") {
			$(this).val(txt) ;
		} else if($(this).val() == txt) {
			$(this).val("") ;
		}
	}) ;
	*/

	$(".emailsubscribe_email").bind("focus blur", function() {
		var txt = "Enter email address" ;
		if($(this).val() == "") {
			$(this).val(txt) ;
		} else if($(this).val() == txt) {
			$(this).val("") ;
		}
	}) ;

	// ajax forms //
	var options = {		target:        	'#emailsubscribe',	// target element(s) to be updated with server response 
						beforeSubmit:  	function() {},  	// pre-submit callback 
						success:       	function() {
														setupEmailSubscribe() ;
														$.cookie("emailsubscribed", 'true');
													},  	// post-submit callback
						type:      		"post"
					};

	// bind form using 'ajaxForm' 
	$('form.emailsubscribe').ajaxForm(options) ;

}


