var myVerticalSlide;
var myOptionsSlide;
window.addEvent('domready', function() {
	
	var status = {
		'true': 'open',
		'false': 'close'
	};
	if ($chk($('vertical_slide'))) {
	myVerticalSlide = new Fx.Slide('vertical_slide', {

		transition: 'sine:in:out'
		
		});
	}
	
	if ($chk($('more_options_box'))) {
	$('more_options_box').slide('hide');
	$('more_options_box').setStyle('display','block');
	}

});

function encode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}

function searchFor(search_for,search_txt,search_class)
	{
		$('search').value=search_for;
		$('search_for_txt').set('html','Search for ' + search_txt );
		$('search_for_txt').removeClass('hc');
		$('search_for_txt').removeClass('bb');
		$('search_for_txt').removeClass('cc');
		$('search_for_txt').removeClass('hh');
		$('search_for_txt').addClass(search_class);
		
		myVerticalSlide.slideOut().chain(function(){

		$('location').focus();
		});
}

function resetSearch()
{
	myVerticalSlide.slideIn();
	
}

function pushSearch()
{
	search_url = "";
	search_url = "/" + $('search').value;
	 
	if ($('county').value=="" && $('location').value!="" ) search_url = search_url + "/" + encode($('location').value);
	if ($('county').value!="") search_url = search_url + "/" + encode($('county').value);
	
	var searchOptions = $$('#more_options_box input.search_option');
	var options_url = "";
	//alert(searchOptions.length);
	for (var x=0;x<searchOptions.length;x++)
		{
			if (searchOptions[x].checked) {
			
			if (options_url.length!=0) options_url = options_url + ",";
			if (options_url.length==0) options_url = "/options=";
			options_url = options_url + searchOptions[x].name	
				
			}
			
		}
	//alert (options_url);
	document.location=search_url + options_url;
	
	
}

function showExtendedSearch()
{

	if ($chk($('featured_box_holder'))) {
	$('featured_box_holder').setStyle('display','none');
	}
	
	if ($chk($('county_box_holder'))) {
	$('county_box_holder').setStyle('display','none');
	}

	$('search_box_outer').morph({
		width: 965,
		onComplete: function(){
			$('more_options_box').slide('in');
		}
	});
	$('more_options').setStyle('display','none');
	$('less_options').setStyle('display','inline-block');	

}

function showExtendedSearchNow()
{

	if ($chk($('featured_box_holder'))) {
	$('featured_box_holder').setStyle('display','none');
	}
	
	if ($chk($('county_box_holder'))) {
	$('county_box_holder').setStyle('display','none');
	}

	$('search_box_outer').setStyle('width','965');
	$('more_options_box').slide('in');

	$('more_options').setStyle('display','none');
	$('less_options').setStyle('display','inline-block');	

}


function hideExtendedSearch()
{

	$('more_options_box').slide('out');
	$('search_box_outer').morph({ width: 380});
	$('less_options').setStyle('display','none');
	$('more_options').setStyle('display','inline-block');
	if ($chk($('featured_box_holder'))) {
	$('featured_box_holder').setStyle('display','block');
	
	}
	if ($chk($('county_box_holder'))) {
	$('county_box_holder').setStyle('display','block');
	}
	
}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode; //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
$('location').blur;
pushSearch();
return false 
}
else{
return true 
}

}



var last_day=0;
var last_month=0;
function hoverDate(z,d)
{
	
	
	if (last_month!=0) $('month_'+last_month).removeClass('month_hover');
	if (last_day!=0) $('day_title_'+last_day).removeClass('day_hover');
	
	/* for (x = 1; x < 13; x++) {
		$('month_' + x).removeClass('month_hover');
	}
	for (x=1;x<36;x++)
	{
		$('day_title_'+x).removeClass('day_hover');
	}
	*/
	last_month=z;
	last_day=d;
	$('month_'+z).addClass('month_hover');
	$('day_title_'+d).addClass('day_hover');
	
}

function changeYear(id,county)
{
	document.location='/' + county + '/'+ id + '/' + $('this_year').value;
	
	
}
