var s_resultsstatus = 0;
var s_resultshtml = null, closeButHide, searchAjax, s_results;
var sidebar = {
	search: function() {
		if (searchAjax) return false;
		this.className = 'load';
		if (this['side_s'].value.length < 1) {
			searchAjax = 1;
			sidebar.hideList('<ul id="ahah_search"><li id="stitle"><span>Search Results</span></li><li class="full">Your query is too short, please try another search.</li></ul>');
		} else {
			searchAjax = new Ajax(this.action + '?' +Object.toQueryString({s: this['side_s'].value, type: 'xml'}), {method: 'get', onComplete: sidebar.hideList}).request();
		}
		return false;
	},
	hideList: function(response) {
		s_resultshtml = response;
		if (closeButHide) { closeButHide.custom(1,0); closeButHide = null; }
		window.setTimeout("$('sidesearchform').className = '';s_results.toggle();", 300);
	},
	handleResults: function() {
		if (!s_resultsstatus && s_resultshtml != null) {
			$('searchresultsinner').innerHTML = s_resultshtml.replace(/type=xml/, "type=");
			s_resultsstatus = 1;
			window.setTimeout("s_results.toggle();", 300);
		} else if (!s_resultsstatus) {
			$('searchresults').innerHTML = '<div id="searchresultsinner"></div>';
			searchAjax=null;
		} else if (s_resultsstatus == 1) {
			s_resultshtml = null;
			s_resultsstatus = 0;

		var closeBut = document.createElement('a');
		closeBut.id = 'searchclose';
		closeBut.href = 'javascript:sidebar.closeResults();';
		closeBut.className = 'mclose';
		closeBut.title = 'Close results';
		closeButHide = new Fx.Opacity(closeBut, {duration: 300});
		closeButHide.hide();
		$('stitle').insertBefore(closeBut, $('stitle').childNodes[0]);
		window.setTimeout("closeButHide.custom(0,1);", 100);
		window.setTimeout("searchAjax=null;", 400);
		}
	},
	closeResults: function() {
		this.hideList(null);
		$('side_s').focus();
	},

	load: function() {
		if (typeof Gallery != 'undefined') {
			if (window.attachEvent && !document.opera && typeof document.body.style.maxHeight == "undefined")
				$('projectgallery').style.height = '553px';
			else
				$('projectgallery').style.minHeight = '553px';
			Gallery.init();
		}
		if ($('sidesearchform')) {
			$('sidesearchform').onsubmit = this.search;
			var tempElem = document.createElement('a');
			tempElem.className = 'mclose';
			tempElem.title = 'Hide results';
			tempElem.href = "javascript:hideSearch();";
			$('searchresults').insertBefore(tempElem, $('searchresultsinner'));
			var sidestxt = $('side_s');
			sidestxt.onblur = function () { if (this.value == '') this.value = 'Search and press enter...'; if (this.value == 'Search and press enter...') this.className = 'inactive'; };
			sidestxt.onfocus = function () { if (this.value == 'Search and press enter...') this.value = ''; this.className = ''; };
			sidestxt.onblur();
			s_resultsstatus = 0;
			s_results = new Fx.Slide('searchresults', {duration: 500, wait: false, onComplete: sidebar.handleResults});
			s_results.hide();
		}
		//this.pageHandler();
	},

	pageHandler: function() {
		var contLeft = $('content-left');
		var newHref  = window.location.href;
		newHref     += (newHref.indexOf('?') >= 0) ? '&iframe' : '?iframe';
		contLeft.innerHTML = '<iframe id="zenphotoobject" src="'+newHref+'" style="width:100%;overflow:auto"></iframe><!--[if IE 5]><iframe id="zenphotoiframe" src="'+newHref+'" type="text/html" style="width:100%;overflow:visible"></iframe><![endif]-->';
		var siteFrame = $('zenphotoiframe') ? $('zenphotoiframe') : $('zenphotoobject');
		siteFrame.data = window.location.href;
	}
};

sidebar.load();