/* usemedia.com . joes koppers . 2006-2007 */
/* thnx for reading this code */


//general js utilities


function IdArray(collection)
{
	//id-based object 'array'
	this.collection = collection;
	this[collection] = new Object();
	this.length = 0;
}
IdArray.prototype.push = function(obj)
{
	this[this.collection][obj.id] = obj;
	this.length++;
}
IdArray.prototype.del = function(id)
{
	this[this.collection][id].dispose();
	delete this[this.collection][id];
	this.length--;
}

function BrowserCheck()
{
	//simple browser identification, use after body load (var browser = new BrowserCheck();)
	var agent = navigator.userAgent;
	this.agent = agent
	this.cssfilter = (typeof(document.body.style.filter)=='string')? true:false; //means IE
	this.ie_pre7 = (this.cssfilter && parseInt(agent.substr(agent.indexOf("MSIE")+5,1))<7)? true:false;
	this.safari = (agent.indexOf("Safari")!=-1)? true:false;
	this.safari_pre3 = (this.safari && parseInt(agent.substr(agent.indexOf("Version/")+8,1))>=3)? false:true;
}

function pngBgImage(media)
{
	//png transparency workaround for MSIE
	if (browser.cssfilter) return 'FILTER:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'media/'+media+'.png\');';
	else return 'background-image:url(\'media/'+media+'.png\');';
}

function noSpamMail(user,domain) 
{
	//antispam mailto
	self.location = 'mailto:'+user+'@'+domain;
}

function cancelEvents(e,complete)
{
	//cross browser event cancellation
	if (!e) e = event;
	
	if (typeof(e.stopPropagation)=='function') e.stopPropagation();
	e.cancelBubble = true;
	if (complete)
	{
		if (typeof(e.preventDefault)=='function') e.preventDefault();
		e.returnValue = false;
	}
}

function iframeDocument(id)
{
	var iframe = document.getElementById(id);
	
	if (iframe.contentDocument)	return iframe.contentDocument.documentElement;
	else if (iframe.contentWindow) return iframe.contentWindow.document.body;
	else if (iframe.document) return iframe.document;
	else 
	{
		//failed
		return iframe;
		//alert('sorry,\nunsupported browser. please upgrade');
	}
}

function readCookie(name) //from www.quirksmode.org
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0; i<ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}

function encrypt(str,decrypt)
{
	//no security, just that (login)info is not shown as cleartext in cookie
	var result = '';
	if (decrypt)
	{
		for (i=0; i<str.length; i+=2)
		{
			var n = parseInt(str.substr(i,[2])) + 23;
			n = unescape('%' + n.toString(16));
			result+= n;
		}
		result = unescape(result);
	}
	else
	{
		for (i=0; i<str.length; i++) result+= str.charCodeAt(i) - 23;
	}
	return result;
}