jQuery(function(){
	//Linkable Search Calendar
	var searchURL = '/Default.aspx?CCID=3872&FID=24892&ExcludeBoolFalse=True&ID=/results'
	
	//search function
	function postSearch() {
		jQuery('#content').hide();
		jQuery('#contentWrap .ad').hide();
		jQuery('#contentWrap').prepend('<div class="load">Searching...</div>');
	}
	
	function search(data){
		jQuery('.load').remove();
		jQuery('#content').html(data);
		jQuery(".event-list .text p").truncate(150);
		jQuery('#content').fadeIn('1000');
		jQuery('#contentWrap .ad').show();
		jQuery('#content title, #content link').remove();
	}
	
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	//$.historyInit(pageload);
	
	//Creates today/tomorrow search links
	//var d = new Date();
	//today = d.getDate();
	//tomorrow = d.getDate() + 1;
	//if (today <= 9) {today = "0" + today;}
	//if (tomorrow <= 9) {tomorrow = "0" + tomorrow;}
	//jQuery('a#today').attr('href','#'+today);
	//jQuery('a#tomorrow').attr('href','#'+tomorrow);

	
    //jQuery('a#today, a#tomorrow').click(function(){ //add '.calendar a' when enabling calendar again
	//	var query = jQuery(this).attr('href');
	//	postSearch();
	//	$.post(searchURL,query,search);
    //});
	
	//Next week link
	//jQuery('a#thisweek').click(function() {
	//	postSearch();
	//	var week=new Array()
	//	d = d.getDate();
	//	var query = "";
	//	for (i=0;i<6;i++) {
	//		if (d <= 9) {d = '0' + d;}
	//		week[i] = '&CAT_Custom_66898='+d;
	//		d++;
	//		query=query+week[i];
	//	}
	//	$.post(searchURL,query,search);
	//  return false;
	//});
	
	//advanced search
	jQuery('table.advanceds select option:first-child').attr('value','');
	
	var type = jQuery('select[id="CAT_Category"]');
	var location = jQuery('select[id="CAT_Custom_70934"]');
	var cuisine = jQuery('select[id="CAT_Custom_72500"]');
	var date = jQuery('select[id="CAT_Custom_66898"]');
	var restaurant = jQuery('input[id="CAT_Custom_67203"]');
	var keyword = jQuery('input[id="CAT_txtKeywords"]');
	var vego = jQuery('input[id="CAT_Custom_69494"]');
	var child = jQuery('input[id="CAT_Custom_69495"]');
	var wheelchair = jQuery('input[id="CAT_Custom_69496"]');
	
	jQuery('table.advanceds input[type="submit"]').click(function(){
		postSearch();
		jQuery(window).scrollTop('0');
		if (restaurant.val() == 'Restaurant Name') {restaurant.val('')}
		if (keyword.val() == 'Keyword') {keyword.val('');}
		var options = ''
		if (vego.is(':checked') == true) {options = options + '&CAT_Custom_69494=1'}
		if (child.is(':checked') == true) {options = options + '&CAT_Custom_69495=1'}
		if (wheelchair.is(':checked') == true) {options = options + '&CAT_Custom_69495=1'}
		var query = '&CAT_Category='+type.val()+'&CAT_Custom_70934='+location.val()+'&CAT_Custom_72500='+cuisine.val()+'&CAT_Custom_66898='+date.val()+'&CAT_Custom_67203='+restaurant.val()+'&CAT_txtKeywords='+keyword.val()+options;
		$.post(searchURL,query,search);
		return false;
	});
});