Palet.Search=Palet.extend({
	loadContent:function()
	{
	this.loadGeocoder();
	},
	loadGeocoder:function(options){
		var me=this;
		var search=me.createSearchbox({
			tip:"Find Location::enter the address you want to find on the map",
			columns:"28"
		}); //object containing elements: container-div, textarea-element, TextAreaMessage, and GeoCoder
		me.attachFind(search);
		me.attachZoomIn(search);
		me.attachZoomOut(search);

	},
	createSearchbox:function(options){
		var me=this;

		//me.menu.content.appendChild(menuControl.space()); 
		//adds a spacer between stage and the following menus
		//menuControl.space is a static method attached to the menuControl object

		var container=new Element('div',{'class':"geoCodercontainer",title:options.tip});
		new mediaTips(container);
		var entry=new Element('textarea',{'class':"geoCoderInput"});
		/*
		 * TextAreaMessage is a class (HTMLObjects.js) that places a custom message 
		 * inside of a text area 
		 */
		var entryMessage=new TextAreaMessage(entry,{message:"enter address here"});
		container.appendChild(entry);
		/*
		 * NOTE: buttons float over the spacer (below)
		 * as defined in the css file (this may change) but it looks cool 
		 * so i left it
		 */
		me.menu.content.appendChild(container);

		me.menu.content.appendChild(menuControl.space()); 
		//adds a spacer between stage and any following menus
		//menuControl.space is a static method attached to the menuControl object
		var geoCoder=new GClientGeocoder();
		geoCoder.setBaseCountryCode('.ca');

		return {cntnr:container,el:entry,msg:entryMessage,geo:geoCoder};
	},
	attachFind:function(search){
		var me=this;
		var find=new Element('button',{'class':"paletButton"});
		find.innerHTML="find";
		me.initPanButton(find, search, function(latlng){});
		search.cntnr.appendChild(find);
	},
	attachZoomIn:function(search){
		var me=this;
		var zoomin=new Element('button',{'class':"paletButton"});
		zoomin.innerHTML="in";
		me.initPanButton(zoomin, search, function(latlng){me.mediaMap.mainMap.zoomIn(latlng,true,true);});
		search.cntnr.appendChild(zoomin);
	},
	attachZoomOut:function(search){
		var me=this;
		var zoomout=new Element('button',{'class':"paletButton"});
		zoomout.innerHTML="out";
		me.initPanButton(zoomout, search, function(latlng){me.mediaMap.mainMap.zoomOut(latlng,true,true);});
		search.cntnr.appendChild(zoomout);
	},
	initPanButton:function(button, search, afterPanFn){
		var me=this;

		/*
		 * pre-compute effects on initialize as well as variables.
		 * the start left and right variables depend on location and 
		 * therefore change and must be computed on each event. (below)
		 */
		var one="#FFFFFF";//white
		var two="#FFA0A0";//light red
		var three="#A0FFA0";//light green

		var fade=new Fx.Style(search.msg.el, 'backgroundColor', 
				{
			duration:200
				});

		var slideRight = new Fx.Style(me.menu.container,'left', 
				{
			transition: Fx.Transitions.Sine.easeOut, 
			duration:100
				});

		var myTransition = new Fx.Transition(Fx.Transitions.Elastic,7);
		var bounceLeft=new Fx.Style(me.menu.container,'left', 
				{
			transition: myTransition.easeOut, 
			duration:300
				});

		button.addEvent('click',function(){
			search.geo.getLatLng(search.el.value, function(latlng){

				var left=me.menu.container.getStyle('left');
				var right=left.toInt()+30;

				if(latlng&&search.msg.verify()){
					/**
					 * Fade in and out green background on successful entry.
					 */
					fade.start(one, three).chain(function(){fade.start(three, one);});
					MapFactory.PanTo(me.mediaMap.mainMap, latlng, function(){
						if(afterPanFn)
							afterPanFn(latlng);
					});
				}
				else{
					me.menu.reset();
					//TODO: Explorer Bug: convert string with 'px' to int, currently disabled for explorer. (left='NaNpx') 
					/**
					 * 	MAC OS Like shake on invalid entry.	
					 */
					if(BrowserDetect.browser!='Explorer')
						slideRight.start(start, right).chain(function(){
							bounceLeft.start(right, left).chain(function(){
								me.menu.checkBounds();
							});
						});
					/**
					 *  Fade in and out a red background on invalid entry.
					 */
					fade.start(one, two).chain(function(){
						fade.start(two, one);
					});	
				}
			});
		});
	}
});
//Palet.Shake=function(p){return 1 - Math.sin((1 - p) * Math.PI / 2);};

//convenience variable
var SearchPalet=Palet.Search;
