
/*
Page Load Event Handeler
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
function SearchBox_Init() {
	new SearchBox();
}




/*
Creates a new SearchBox Object
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
function SearchBox() {
	// Properties
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	this.opened = false;
	this.searchbox;
	this.advancedLink;
	//this.advancedBox;
	
	
	// Methods
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	this.advancedLinkClick = SearchBox_AdvancedLinkClick;
	
	
	// Tries to create the object based on predetermined page IDs
	try {
		this.searchbox    = document.getElementById("searchbox");
		this.advancedLink = document.getElementById("searchbox-advanced-link");
		
		// Adds the click listener on the advanced search link
		var refObj = this;

		if (this.advancedLink) {
		    if (this.advancedLink.addEventListener)
		        this.advancedLink.addEventListener("click", function() { refObj.advancedLinkClick(); }, false);
		    else if (this.advancedLink.attachEvent)
		        this.advancedLink.attachEvent("onclick", function() { refObj.advancedLinkClick(); });
		}
	} catch (err) {}
}




/*
Advanced Link Click Event Handeler
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
function SearchBox_AdvancedLinkClick() {
	this.opened = !this.opened;
	
	this.searchbox.className = this.opened ? "searchbox-opened" : "";
}




/*
Adds the pageload handeler
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
if ( window.addEventListener )
	window.addEventListener("load", SearchBox_Init, false);
else if ( window.attachEvent )
	window.attachEvent("onload", SearchBox_Init);
