/**
 * we have multiple scripts that use window.onload, but it can only be called once per page, 
 * so to get everything inited use this instead.
 */ 
if(window.addToLoadQueue == undefined || window.addToLoadQueue == null)
{
	window.addToLoadQueue = function(loadFunction)
	{
		this.getLoadArray().push(loadFunction);
	}
}


if(window.createRoundCorners == undefined || window.createRoundCorners == null)
{
	/**
	 * creates a settings object and stores this along with the name of the div
	 * to be rounded in an array. 
	 * @param name the string name of the div
	 * @param preset the array that should be like [0,0,1,1] or the like meaning [topleft, topright, bottomleft, bottomright]
	 */
	window.createRoundCorners = function(name, preset)
	{
		// set defaults if preset and size arent passed
		var aCorners = (preset != null && preset.length == 4) ? preset : null;
		//var nSize = (size != undefined || size != null) ? size : 8;
		// create empty settings object
		var settings;
		
		// if the a corners array exists and is the right size
		if(aCorners != null && aCorners.length == 4)
		{
			var aCornerNames = ['tl', 'tr', 'bl', 'br'];
			settings = { antiAlias: true,autoPad: true,validTags: ["div"] };
			for(var z = 0 ; z < aCorners.length; z++)
			{
				if(aCorners[z] > 0 )
				{
					settings[ aCornerNames[z] ] = {radius: aCorners[z]};
				}
				else
				{
					settings[ aCornerNames[z] ] = {radius: 1};
				}	
			}
		}
		
		this.getCornerArray().push({ name: name, settings: settings});
	}
}

/**
 * gets a single array for this window. prevents it being overwritten
 * @param {Object} arg_name
 */
window.getSingletonArray = function(arg_name){
	if(typeof this[arg_name] == 'undefined' )
		this[arg_name]=new Array(); 

	return this[arg_name];	
}

window.getCornerArray = function(){	return this.getSingletonArray('cornerArray');	}
window.getLoadArray = function(){	return this.getSingletonArray('onLoadArray');	}




window.makeLastInQueue = function( endFunction )
{
	if(this.lastItem == null || this.lastItem == undefined)
		this.lastItem = endFunction;
}


			
window.onload = function()
{
	if(this.getLoadArray().length)
	{
		for(var x = 0 ; x < this.getLoadArray().length; x++)
		{
			if(typeof(this.getLoadArray()[x]) == "function")
				this.getLoadArray()[x]();
			else
				alert(".."+ this.getLoadArray()[x] + "  / " + typeof(this.getLoadArray()[x]))
		}
	}
	if(this.lastItem)
		this.lastItem();
		
	// render round corners
	for(var z = 0 ; z< this.getCornerArray().length ; z++)
	{
		if( curvyCorners == null || curvyCorners == undefined )
			return;
			
		var rc = new curvyCorners( this.getCornerArray()[z].name, this.getCornerArray()[z].settings);
		rc.applyCornersToAll();
	}
}

