/**
 * LICENSE
 *
 * This source file is subject to the EWS Software License that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license please send us an email
 * so we can send you a copy immediately.
 * Permission to copy and distribute verbatim copies of this source
 * are not granted.
 *
 * @copyright 	Copyright (c) 2008-2009 entrance web studio
 * @license	EWS Software License
 */

/**
 * Javascript library
 *
 * @author christoph lukas lindtner
 * @dependencies prototype, jQuery, global
 */
 
if ( ! ( include instanceof Function ) )
	throw new Error ( "No include function found" );

var Snoooze = 
{
	/* ------------------------------------------------------------------------------------------------------------ *
	 *							 																				     																										*
	 * Class variables																								     																					*
	 *																											     																										*
	 * ------------------------------------------------------------------------------------------------------------ */
	
	/**
	 * All functions included in this stack are called after all document content has been loaded.
	 *
	 * @var Array initFunctions
	 */  
	initFunctions : [],
	
	
	/**
	 * A stack with function which will be called after resizing is completed.
	 *
	 * @var Array resizeFunctions
	 */
	resizeFunctions : [],


	/* ------------------------------------------------------------------------------------------------------------ *
	 *							 																				     																										*
	 * Class methods																								     																						*
	 *																											     																										*
	 * ------------------------------------------------------------------------------------------------------------ */
	  
	/**
	 * @public
	 */
	 
	/**
	 * Navigates to a specific url
 	 *
 	 * @param String url
 	 * @return void
 	 */
 	redirect : function ( url ) {
 		var clean = url.strip().stripTags().stripScripts();
 		
 		document.location.href = clean;
 	},
 	
 	
 	/**
 	 * Opens a new window.
 	 *
 	 * @param String url
 	 * @param String key
 	 * @return void
 	 */
 	open : function ( url , name ) {
 		return window.open ( url , name );
 	} ,
 	
	
	/**
	 * Adds a window onload function.
	 *
	 * @param Function func
	 * @return void
	 */
	construct : function ( func ) {
		if ( typeof ( func ) != "function" )
			return;
		
		this.initFunctions.push ( func );
	},
	
	
	/**
	 * Adds a window resize function which is executed befor the content pane is rendered.
	 *
	 * @param Function func
	 * @return void
	 */
	resize : function ( f ) {
		if ( f instanceof Function )
			this.resizeFunctions.push ( f );
	},
	
	
	/**
	 * This function is called in the onload event. It executes all functions which have been added to the
	 * on-load stack
	 *
	 * Todo: Automate
	 *
	 * @return void
	 */
	initialize : function () {
		var n = this.initFunctions.length;
		
		if ( n <= 0 )
			return;
		
		for ( var i = 0; i < n; i++ ) {
			var f = this.initFunctions [ i ];
			f.call ();
		}
	},
	
	/**
	 * Inits all functions in the resize stack
	 *
	 * @return void
	 */
	resizeAll : function () {
		var n = this.resizeFunctions.length;
		
		if ( n <= 0 )
			return;
		
		for ( var i = 0; i < n; i++ ) {
			var f = this.resizeFunctions [ i ];
			f.call ();
		}
	}
}
