/* Function that toggles hides/unhides stuff */
function Toggle ()
{
	/* Setting option defaults */
	this.defaults =
	{
		linkID:       'login_link',
		containerID:  'login_hidden',
		focusID:      'login_focus',
		forceDisplay: false
	};

	/* Closure for this */
	var thisObject = this;

	this.init = function (options)
	{
		/* Evaluate options */
		this.linkID         = (options !== undefined && options.linkID !== undefined) ? options.linkID : thisObject.defaults.linkID;
		this.containerID    = (options !== undefined && options.containerID !== undefined) ? options.containerID : thisObject.defaults.containerID;
		this.focusID        = (options !== undefined && options.focusID !== undefined) ? options.focusID : thisObject.defaults.focusID;
		this.forceDisplay   = (options !== undefined && options.forceDisplay !== undefined) ? options.forceDisplay : thisObject.defaults.forceDisplay;

		thisObject.setDisplay(thisObject.containerID,'none');
		thisObject.setDisplay(thisObject.linkID,'block');
		thisObject.setOnclick();
		if(thisObject.forceDisplay === true)
		{
			thisObject.setDisplay(thisObject.containerID,'block');
			thisObject.setDisplay(thisObject.linkID,'none');
			document.getElementById(thisObject.focusID).focus();
		}
	};

	this.setDisplay = function (id,style)
	{
		var element = document.getElementById(id);
		if(element) 
		{
			element.style.display = style;
		}
	};

	this.setOnclick = function ()
	{
		var link = document.getElementById(thisObject.linkID);
		if(link)
		{
			link.onclick = function()
			{
				thisObject.setDisplay(thisObject.containerID,'block');
				thisObject.setDisplay(thisObject.linkID,'none');
				document.getElementById(thisObject.focusID).focus();
			};
		}
	};
}

/* domReady comes from imageflow.packed.js */
/*domReady(function()*/
{
	/* Initate toggle behaviour */
	var ToggleLogin = new Toggle();
	ToggleLogin.init();
	
	var ToggleSearch = new Toggle();
	ToggleSearch.init({ linkID:'search_link', containerID:'cse-search-box', focusID:'search_focus' });
}/*)*/;

