	var wpSearch = {
		init: function(){
			var xy = YAHOO.util.Dom.getXY('s');
	     		YAHOO.util.Dom.setXY('panelShadow', xy);
			YAHOO.util.Dom.setXY('panelOverlay', xy);
			YAHOO.util.Dom.setStyle('panelContent', 'width', '0px');
			YAHOO.util.Dom.setStyle('panelContent', 'height', '0px');
			YAHOO.util.Dom.setStyle('panelContent', 'display', 'block');
			YAHOO.util.Dom.setXY('panelContent', xy);
			YAHOO.util.Dom.setStyle('panelContent', 'display', 'none');
			YAHOO.util.Dom.setStyle('panelContent', 'height', '400px');
			YAHOO.util.Dom.setStyle('panelContent', 'width', '675px');
		},
		
		explodeShadow: function(e){
			YAHOO.util.Event.stopEvent(e);
			var srchTxt = YAHOO.util.Dom.get('s').value;
			if(srchTxt == ''){
				alert('Forget to type something to search for?');
				return false;
			}
			wpSearch.searchSite();
			var attributes = {
				width: {to: 675},
      			height: {to: 400}
			};
			var anim = new YAHOO.util.Anim('panelShadow', attributes, 0.2, YAHOO.util.Easing.easeIn);
			anim.onComplete.subscribe(wpSearch.explodeOverlay);
			anim.animate();
		},

		explodeOverlay: function(e){
			var attributes = {
				width: {to: 675},
      			height: {to: 400}
			};

			var anim = new YAHOO.util.Anim('panelOverlay', attributes, 0.2, YAHOO.util.Easing.easeIn);
			anim.onComplete.subscribe(wpSearch.buildSearchResults);
			anim.animate();
		},

		buildSearchResults: function(){
			YAHOO.util.Dom.setStyle('panelContent','display','block');
		},

		searchSite : function(){    
    			var srchTxt = YAHOO.util.Dom.get('s').value;
	    		var postData = "foo=1";
    			var sUrl = '/samples/xml_search.php?s=' + srchTxt;
    			var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, postData); 
		},

		closeEverything: function(){
			YAHOO.util.Dom.setStyle('panelContent','display','none');
			YAHOO.util.Dom.get('panelResults').innerHTML = '';

			var attributes = {
				width: {to: 0},
      			height: {to: 0}
			};

			var anim1 = new YAHOO.util.Anim('panelOverlay', attributes, 0.2, YAHOO.util.Easing.easeIn);
			anim1.animate();

			var anim2 = new YAHOO.util.Anim('panelShadow', attributes, 0.2, YAHOO.util.Easing.easeIn);
			anim2.animate();
		}
	}

	function handleSuccess(o){ 
		var domXML = o.responseXML;
    		var xmlDoc = domXML.documentElement;

		if(xmlDoc){
			var resultHTML = '';
			var postTags = xmlDoc.getElementsByTagName('post');
			for(x=0; x < postTags.length; x++){
				var postYear = postTags[x].getElementsByTagName('post_year')[0].firstChild.nodeValue;
				var postMonth = postTags[x].getElementsByTagName('post_month')[0].firstChild.nodeValue;
				var postDay = postTags[x].getElementsByTagName('post_day')[0].firstChild.nodeValue;
				var postName = postTags[x].getElementsByTagName('post_name')[0].firstChild.nodeValue;
				var postBrief = postTags[x].getElementsByTagName('post_brief')[0].firstChild.nodeValue;
				var postViews = postTags[x].getElementsByTagName('post_views')[0].firstChild.nodeValue;
				var postTitle = postTags[x].getElementsByTagName('post_title')[0].firstChild.nodeValue;
				var postCommentCount = postTags[x].getElementsByTagName('post_comment_count')[0].firstChild.nodeValue;
				resultHTML += '<p><div style="font-size:12px;"><a href="/w/index.php/' + postYear + '/' + postMonth + '/' + postDay + '/' + postName + '/">' + postTitle + '</a> - (views: ' + postViews + ' :: comments: ' + postCommentCount + ')</div>';
				resultHTML += '<div style="padding-left:20px;padding-right:20px;">' + postBrief + '</div></p>';
			}
			YAHOO.util.Dom.get('panelResults').innerHTML = resultHTML;
    		} else {
			alert(o.responseText);
		}
	}
	
	function handleFailure(o){ 
		alert('failed');
		if(o.responseText !== undefined){ 
			alert(o.responseText);
    		} 
	}

	var callback = { 
		success:handleSuccess, 
		failure: handleFailure
	}

	document.write('<div id="panelShadow" style="background-color:#0066cc;position:absolute;width:0px;height:0px;filter:alpha(opacity=40);-moz-opacity:.40;opacity:.40"></div>');
	document.write('<div id="panelOverlay" style="background-color:#0066cc;position:absolute;width:0px;height:0px;"></div>');
	document.write('<div id="panelContent" style="position:absolute;width:675px;height:400px;background-color:#FFFFFF;display:none;border:solid 3px #000000;"><div id="panelHeader" style="width:75%;height:20px;text-align:left;float:left;background-color:#cccccc;font-weight:bold;">SEARCH RESULTS</div><div id="panelClose" style="width:25%;height:20px;text-align:right;float:left;background-color:#cccccc;font-weight:bold;"><a href="javascript:wpSearch.closeEverything()">[close]&nbsp;<img src="/w/wp-images/publish_x.png" alt="" /></a>&nbsp;&nbsp;&nbsp;</div><div id="panelResults" style="height:370px;clear:left;overflow:auto;padding:5px;text-align:left;"></div></div>');

	YAHOO.util.Event.on('searchform', 'submit', wpSearch.explodeShadow, wpSearch, true);
	YAHOO.util.Event.onAvailable('searchform', wpSearch.init, wpSearch);
