/* 
 * main.js 
 * JavaScript for Oklahoma Agritourism Growing Adventure.
 
 * Applies to all pages.
 */


window.addEvent('domready', function(){
	/*if (document.forms.hdrSearchForm){
		document.forms.hdrSearchForm.addEvent('submit', function(event){
			//event.stop();
			//var srchUrl = '/?id=19&u=http://agritourism.travelok.com/?id=4%26action=doSearch%26keywords=' + escape(document.forms.hdrSearchForm.hdrSearchInput.value);
			var srchUrl = 'http://agritourism.travelok.com/?id=4&action=doSearch&keywords=' + escape(document.forms.hdrSearchForm.hdrSearchInput.value);
			//window.location = srchUrl;
			openPartnerSite(srchUrl);
			return false;
		});
	}*/
	
	$('hdrSearchBtn').addEvent('click', function(){
		submitSearchForm();
	});
	
	if ($('agriLogoDiv')){
		$('agriLogoDiv').addEvent('click', function(){ window.location = '/'; });
	}
	
	$$('#mainnavLinks ul li').each(function(obj){
		if (obj.getElement('ul')) obj.getElement('ul').fade('hide');
		obj.addEvent('mouseover', function(){
			if (this.getElement('ul')) this.getElement('ul').fade('in');
				//this.getElement('ul').setStyle('display', 'block');
		});
		obj.addEvent('mouseleave', function(){
			if (this.getElement('ul')) this.getElement('ul').fade('out');
				//this.getElement('ul').setStyle('display', 'none');
		});
	});
});



function submitSearchForm(){
	var srchUrl = 'http://agritourism.travelok.com/?id=4&action=doSearch&keywords=' + escape(document.forms.hdrSearchForm.hdrSearchInput.value);
	openPartnerSite(srchUrl);
	return false;
}




function openPartnerSite(u){
	if (confirm("You are about to be redirected to our consumer site. You can use your browser's back button to return.\n\nPress OK to continue.")){
		window.location = u;
	}
}



// Includes the Google Map API
function includeGoogleMapAPI(){
	// dev
	key = 'ABQIAAAAlUR188h4rgkW3-IO0kz5iBQl6Wf5VOkJ0Nfi0rAUjuJ3wCGMXBR76JG8Mwlz02E3w2JrbxyzLL_clw';
	
	// live
	//key = 'ABQIAAAAlUR188h4rgkW3-IO0kz5iBSTjj81faSk4WITiiPj--DXOwecphRC8wg1TBrwU58QgmRUbw6qS9nlNw';
	
	document.writeln('<scr' + 'ipt type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;sensor=false&amp;key=' + key + '"></scr' + 'ipt>');
}