String.prototype.trim=function(){return this.replace(/^\s*|\s*$/g,'');};String.prototype.ltrim=function(){return this.replace(/^\s*/g,'');};String.prototype.rtrim=function(){return this.replace(/\s*$/g,'');};

YAHOO.widget.Effect = function(el) {
	this.objEl = YAHOO.util.Dom.get(el);
	this.height = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	this.width = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'width'));
};
YAHOO.widget.Effect.prototype.BlindUp = function(iTimer,hide) {
	var $D = YAHOO.util.Dom;
	var timer = iTimer || 1;
	this.objEl.style.overflow = 'hidden';
	var blind = new YAHOO.util.Anim(this.objEl, { height: { to:0} }, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	if ( hide ) {
		blind.onComplete.subscribe(
			function() {
				$D.addClass(hide,'hide');
			}
		);
	}
	blind.animate();
};
YAHOO.widget.Effect.prototype.BlindDown = function(iTimer,onComplete) {
	var timer = iTimer || 1;
	this.objEl.style.visibility = 'hidden';
	this.objEl.style.overflow = 'hidden';
	this.objEl.style.display = '';
	this.objEl.style.position = 'absolute';
	this.objEl.style.height = '';
	var height = parseInt(this.objEl.offsetHeight);
	this.objEl.style.height = height;
	if (!height)  var height = 405;
	this.objEl.style.height = '0';
	this.objEl.style.visibility = 'visible';
	this.objEl.style.position = '';
	var blind = new YAHOO.util.Anim(this.objEl, { height: { to:height, from:0} }, timer, YAHOO.util.Easing.easeIn);
	var that = this;
	blind.onComplete.subscribe( function () {
			height2 = document.getElementById('content').offsetHeight
			height3 = document.getElementById('sidebar').offsetHeight
			if (height2<height3) height2=height3;
			var blind2 = new YAHOO.util.Anim(that.objEl, { height: { to:height2, from:height} }, timer, YAHOO.util.Easing.easeOut);
			blind2.animate();
		}
	);
	
	blind.animate();
};
YAHOO.widget.Effect.prototype.yoyo = function(iTimer,onComplete) {
	var $D = YAHOO.util.Dom;
	this.objEl.style.overflow = 'hidden';
	var height = parseInt(YAHOO.util.Dom.getStyle(this.objEl,'height'));
	if (!height) var height = this.objEl.offsetHeight;
	var timer = iTimer || 1;
	var yoyo = new YAHOO.util.Anim(this.objEl, { height: { to:0} }, timer, YAHOO.util.Easing.easeOut);
	var that = this;
	yoyo.onComplete.subscribe(
		function() {
			
			if ( onComplete ) {
				onComplete();
			}
			that.objEl.style.visibility = 'hidden';
			that.objEl.style.overflow = 'hidden';
			that.objEl.style.position = 'absolute';
			that.objEl.style.height = '';
			var height = parseInt(YAHOO.util.Dom.getStyle(that.objEl,'height'));
			if (!height) var height = that.objEl.offsetHeight;
			that.objEl.style.height = '0';
			that.objEl.style.position = '';
			that.objEl.style.visibility = 'visible';
			
			var blind = new YAHOO.util.Anim(that.objEl, { height: { to:height, from:0} }, timer, YAHOO.util.Easing.easeIn);
			blind.animate();
			blind.onComplete.subscribe(
				function() {
					that.objEl.style.height = '';
				}
			);
		}
	);
	yoyo.animate();
};

YAHOO.smartfinds = function() {
	var $D = YAHOO.util.Dom;
	var $E = YAHOO.util.Event;
	var $M = YAHOO.util.Motion;
	var $A = YAHOO.util.Anim;
	var $ = $D.get;
	var $path = '/store/';
	var $url = '';

	return {
		init : function() {
						
			// hide content
			$E.onAvailable('contentw',this.hideContent);
			$E.on('quick_contact','submit',this.doForm);
			$E.onAvailable('content',this.externalLinks);
		},
		externalLinks : function () {
			var anchors = document.getElementsByTagName("A");
			for (i=0; i<anchors.length; i++) {
				var a = anchors[i];
				if (a.getAttribute("href") && a.getAttribute("rel") == "external") {
					a.target = "_blank";
				}
			}
		},
		hideContent : function() {
			if ($D.hasClass($('contentw'),'init')) {
				$('contentw').style.display = 'none';
				$D.removeClass($('contentw'),'init');
			}
		},
		getPage : function(url) {
			$C = $('contentw');
			var a = new YAHOO.widget.Effect($C);
			if (($url == url) && $D.hasClass($C,'under')) {
				a.BlindUp(0.5);
				$D.removeClass($C,'under');
			}else{
				postBody = 'p='+url;
					var callback = {
						success: function(o) {
							if ($D.hasClass($C,'under')) {
								a.BlindUp(0.5,function () { $('content').innerHTML = o.responseText; YAHOO.smartfinds.externalLinks(); });
								$D.removeClass($C,'under');
							}else{
								$('content').innerHTML = o.responseText;
								YAHOO.smartfinds.externalLinks();
								a.BlindDown(0.5);
								$D.addClass($C,'under');
								$url = url;
							}
						},
						failure: function(o) { alert('failure');},
						timeout: 5000
					};
				var transaction = YAHOO.util.Connect.asyncRequest('POST','includes/pages.php',callback,postBody);
			}
		},
		swapPage : function (url) {
			$C = $('contentw');
			var a = new YAHOO.widget.Effect($C);
			if ($D.hasClass($C,'under')) {
				postBody = 'p='+url;
					var callback = {
						success: function(o) {
							a.yoyo(0.5,function () { $('content').innerHTML = o.responseText; });
						},
						failure: function(o) { alert('failure');},
						timeout: 5000
					};
				var transaction = YAHOO.util.Connect.asyncRequest('POST','includes/pages.php',callback,postBody);
				
			}
		},
		doForm : function(e) {
			$E.stopEvent(e);
			btn = $('quick_submit');
			var valid = true;
			var error = ''
			emailF = $('slas8fkfmasdfktasdfg');
			nameF = $('ld0dasdf90u8sdfj823534a');
			email = YAHOO.smartfinds.checkField('email',emailF)
			name =	YAHOO.smartfinds.checkField('string',nameF)
			if (!name) {
				nameF.className = 'failed';
				error = "Please enter your name.";
				valid = false;
			}
			if (!email) {
				emailF.className = 'failed';
				if (error.length > 0) error = error+"\n";
				error = error+"Please enter a valid e-mail address.";
				valid = false;
			}
				
			if ((!name) || (!email)) {
				alert(error);
				return false;
			}
			btn.src = 'images/sending.gif';
			btn.id = 'quick_sending';
			form = $('quick_contact');
			YAHOO.util.Connect.setForm(form);
				var callback = {
					success: function(o) {
						$('contact_ct').innerHTML = o.responseText;
						qc = $('quick_contact');
						if (qc) $E.on(qc,'submit',YAHOO.smartfinds.doForm);
					},
					failure: function(o) { alert('failure');},
					timeout: 5000
				};
			var cObj = YAHOO.util.Connect.asyncRequest('POST', 'includes/contact.php', callback); 
		},
		checkField : function(c,e) {
			var valid = true;
			var t = e.value.trim();
			
			//search for required
			if (c == 'string' && t.length == 0) {
				//required found, and not filled in
				valid = false;
			}
			if (c == 'email' && !t.match(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/)) {
				//email bad
				valid = false;
			}
			
			return valid;
		},
		cancel: function() {
			if(typeof this.timeoutID == "number") {
				window.clearTimeout(this.timeoutID);
				this.timeoutID=null;
			}
		}
	};
}();

function getPage(url) {
	YAHOO.smartfinds.getPage(url);
}

function swapPage(url) {
	YAHOO.smartfinds.swapPage(url);	
}

YAHOO.util.Event.onAvailable('content', YAHOO.smartfinds.init, YAHOO.smartfinds, true);