		
var Y = YAHOO.util,
        Lang = YAHOO.lang,
        Get = TWCI.util.Get,
        Event = TWCI.util.Event,
        Connect = YAHOO.util.Connect,
        Dom = TWCI.util.Dom;

		var _recentSearch = (wx.config.user.signature.match(/^0\^noId/)) ? '/pagelet/rs/' : '/pagelet/rs/?i='+wx.config.user.signature,
				_reqType = 'GET',
				_fromString = wx.config.page.fromStr;


		Event.onAvailable("twc-weather-recent-search-results",function(){
			var RSID = 'twc-weather-recent-search-results';
			Event.on("typeaheadBox","focus",function(e, matchedEl, container){
				Connect.asyncRequest(_reqType, _recentSearch, {
					success:function(o) {
						 if(o.status.toString().match("2[0-9][0-9]")!=null) {
							  O = o.responseText;
						      Dom.get(RSID).innerHTML = O;
						      Dom.replaceClass(RSID, "twc-hide", "twc-show");
					    	  Event.delegate(RSID,"mousedown",function(e, matchedEL,container){
					    	    //try{console.log("recentSearch-Mousedown")}catch(e){}
					    	  	window.location.href=matchedEL.getAttribute("url");
					    	  },".twc-clickable");
						  } else {
							  TWCI.firePageletError(wx.config.page.pageId,"recentsearch",o.status);
						  }
						  
						  
					     
					  },
	
					failure:function(o) {
						// Failure handler
						TWCI.firePageletError(wx.config.page.pageId,"recentsearch",o.status);
					}
				});
			});
			
			Event.on("typeaheadBox","blur",function(e, matchedEl, container){
				//try{console.log("typeaheadBox blur")}catch(e){}
				window.rsTimeout = setTimeout(function (){
					Dom.replaceClass(RSID, "twc-show", "twc-hide");
				}, 100);
			});
			
			Event.on(RSID, 'mouseover',function(e) {
				try{
					clearTimeout(window.rsTimeout);
				} catch (e) {
				}
			});
			
			Event.on("typeaheadBox","keydown",function(e, matchedEl, container){
				Dom.replaceClass(RSID, "twc-show", "twc-hide");
			});
		});
		
		(function() {
			Event.on("twc-social-facebook", "click", function(el){
				sc_trackAction(el,'socialhdr_facebook',null);
				PopupCenter('http://www.facebook.com/TheWeatherChannel', 'myPop2',980,550);
			});

			Event.on("twc-social-twitter", "click", function(el){
				sc_trackAction(el,'socialhdr_twitter',null);
				PopupCenter('http://www.twitter.com/weatherchannel/', 'myPop1',550,450);
			});
		})();	


