/*******************************
 *
 *	Misc Class - Handy Stuff
 *
 *  Version: 1.1
 *
 *	Author: 
 *	The Roundhouse
 *
 *  © The Roundhouse 2007 -
 * 	ALL RIGHTS RESERVED
 */
  
if(!TheRoundhouse) 								var TheRoundhouse 							= new Object();
if(!TheRoundhouse.Frameworks) 					TheRoundhouse.Frameworks	 				= new Object();
if(!TheRoundhouse.Frameworks.Misc) 				TheRoundhouse.Frameworks.Misc				= function(){};

TheRoundhouse.Frameworks.__available			= function()
{
	return (typeof $ == "function");
}

TheRoundhouse.Frameworks.__validateOptions  	= function(objOptions, arrExpectedOptions)
{
	for(var i in objOptions)
		for(var j = 0; j < arrExpectedOptions.length; j++)
			if(i == arrExpectedOptions[j])
				arrExpectedOptions.splice(j,1);
				
	if(arrExpectedOptions.length)
		alert("Error: Missing options: "+arrExpectedOptions.join(", "));
	
	return (arrExpectedOptions.length == 0);
}


TheRoundhouse.Frameworks.Misc.prototype 	= {
			
	$get :function(key, url)
	{
		// Function by Jens Anders Bakke, webfreak.no
		// Returns URL query string information
		// NOTE: expect the same results as PHP $get 
		
		if(arguments.length < 2) 					url 		= location.href;
		if(arguments.length > 0 && key != "")
		{
			if(key == "#")							var regex	= new RegExp("[#]([^$]*)");
			else if(key == "?") 					var regex 	= new RegExp("[?]([^#$]*)");
			else 									var regex 	= new RegExp("[?&]"+key+"=([^&#]*)");
			
			var results 							= regex.exec(url);
			return (results == null )? "" : results[1];
		} else 
		{
			url 									= url.split("?");
			var results 							= {};
			if(url.length > 1)
			{
				url 								= url[1].split("#");
				if(url.length > 1) results["hash"] 	= url[1];
				url[0].split("&").each(function(item,index)
				{
				item 								= item.split("=");
				results[item[0]] 					= item[1];
				});
		}
		return results;
		}
	},
	
	showHideElement :function(objCtrl, objMisc)
	{
		var objCollapsible								= objCtrl.objCollapsible;
		var objBtn										= objCtrl.objBtn;
		var bHorizontal									= (objMisc && objMisc.bHorizontal)? objMisc.bHorizontal : false;
		var iSlideDuration								= (objMisc && objMisc.iSlideDuration)? objMisc.iSlideDuration : 450;
		var fSlideType									= (objMisc && objMisc.fSlideType)? objMisc.fSlideType : Fx.Transitions.Quad.easeInOut;
		var bOpenClose									= (Cookie.get('bOpenClose')) ? Number(Cookie.get('bOpenClose')):0;
				
		var cSlide 										= new Fx.Slide(objCollapsible, 
		{
			duration: 		iSlideDuration,
			transition: 	fSlideType
		});
		
		// Set the intial collapsible state the first time through
		if (!bHorizontal && !bOpenClose)				cSlide.hide();
		else if (bHorizontal)							cSlide.hide('horizontal');
		
		objBtn.addEvent('click', function(event)
		{
			event 										= new Event(event).stop();
			// Toggle the Reveal of the collapsible element
			if (!bHorizontal)							cSlide.toggle();
			else 										cSlide.toggle('horizontal');
			
			// Set a cookie to remember what we've done 
			if (!bOpenClose)							Cookie.set('bOpenClose', 1, {duration: 1, domain: document.domain, path:'/'});
			else										Cookie.set('bOpenClose', 0, {duration: 1, domain: document.domain, path:'/'});
		});		
	}

};

