/*
		+-----------------------------------------------------------------------+
		| Penlyte Web Application Framework                                     |
		+-----------------------------------------------------------------------+
		| Copyright (c) 2008 David Turner                                       |
		+-----------------------------------------------------------------------+
		| Authors: David Turner <dave@turneris.com>                             |
		+-----------------------------------------------------------------------+
		| Subversion Version Control Info:                                      |
		| $Id:: penlyte.js 178 2009-10-17 07:57:53Z dturner                   $ |
		+-----------------------------------------------------------------------+
*/
/* AJAX Request Objects */
var xmlreqs = new Array();
function createRequestObject() {
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		var n = xmlreqs.push( new ActiveXObject("Microsoft.XMLHTTP") );
	} else {
		var n = xmlreqs.push( new XMLHttpRequest() );
	}
	return xmlreqs[n - 1];
}
/* Shoping Cart Block */
function updateCartBlock() {
	o = createRequestObject(); //global because the handler uses setTimeout
	o.open("GET",'/cart_block/ajax/1',true);
	o.onreadystatechange = function() { handleUpdateCartBlock(o); }
	o.send(null);
}
function handleUpdateCartBlock(o) {
	if (o.readyState == 4) {
		var b = document.getElementById('cart_block');
		if(b == null) return false; // bail if no block to update
		// only fade out if already in
		if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5) {
			if(b.style.opacity > 0) {
				fadeOut('cart_block',10,25);
			}
		} else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
			if(b.filters.alpha.opacity > 0) {
				fadeOut('cart_block',10,25);
			}
		}
		setTimeout('document.getElementById("cart_block").innerHTML = o.responseText',300);
		setTimeout('fadeIn("cart_block",10,80);',300);
	}
}
/* Fade In, Out */
function fadeOut(el, step, msecs) {
	//alert('fading out...');
	var to = 0;
	e = document.getElementById(el);
	if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5) {
		step = step/100;
		step = parseInt(step * 100)/100;
		for(i = 1; i > 0; i = parseInt((i - step)*100)/100) {
			to = to + msecs;
			self.setTimeout('e.style.opacity = ' + i + ';',to);
		}
		to = to + msecs;
		self.setTimeout('e.style.opacity = 0;',to);
	} else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
		for(i = 100; i > 0; i = parseInt((i - step)*100)/100) {
			to = to + msecs;
			setTimeout('e.filters.alpha.opacity = ' + i + ';',to);
		}
		to = to + msecs;
		setTimeout('e.filters.alpha.opacity = ' + i + ';',to);
		self.setTimeout('e.filters.alpha.opacity = 0;',to);
	}
	to = to + msecs;
	self.setTimeout('e.style.display = "none";',to);
}
function fadeIn(el, step, msecs) {
	var to = 0;
	e = document.getElementById(el);
	if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5) {
		e.style.MozOpacity = 0;
		e.style.display = "block";
		step = step/100;
		step = parseInt(step * 100)/100;
		for(i = 0; i < 1; i = parseInt((i + step)*100)/100) {
			to = to + msecs;
			self.setTimeout('e.style.opacity = ' + i + ';',to);
		}
		to = to + msecs;
		self.setTimeout('e.style.display = "block";',to);
		self.setTimeout('e.style.opacity = 1;',to);
	} else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
		e.filters.alpha.opacity = 0;
		e.style.display = "block";
		for(i = 0; i < 100; i = parseInt((i + step)*100)/100) {
			to = to + msecs;
			setTimeout('e.filters.alpha.opacity = ' + i + ';',to);
		}
		to = to + msecs;
		self.setTimeout('e.filters.alpha.opacity = 100;',to);
		to = to + msecs;
		self.setTimeout('e.style.display = "block";',to);
	}
	to = to + msecs;
	self.setTimeout('e.style.display = "block";',to);
}

