

// ********************************************************
//
// Project		:	Menu / ImageSwapper
// Date			:	Donnerstag, 23. November 2000
// Last Update	:	-
//
// Author		:	Silvan Minghetti
// Email		:	plazma@bluewin.ch
//					plazma@gamesweb.com
//
//
// Copyright (c) 2000 by plazma. All rights reserved.
//
// You may not use, distribute or modify this code without
// explicit permission of the author.
//
// ********************************************************


// ********************************
// Begin: Menu
//
var isNav4=false;
var isNav6=false;
var isIe=false;
var coll="";
var styleObj="";


if(navigator.appName == "Netscape")
{
	if(parseInt(navigator.appVersion) >= 5)
		isNav6 = true;
	else if(parseInt(navigator.appVersion) >= 4)
		isNav4 = true;
}
else if(navigator.appName == "Microsoft Internet Explorer")
{
	if(parseInt(navigator.appVersion) >= 4)
	{
		isIe=true;
		coll ="all.";
		styleObj=".style";
	}
}


function getObject(obj)
{
	var newObj;

	if(isNav4 == true)
	{
		if(typeof obj == "string")
			newObj = eval("document." + "layers." + obj);
		else
			newObj = obj;
	}
	else if(isNav6 == true)
	{
		if(typeof obj == "string")
			newObj = document.getElementById(obj).style;
		else
			newObj = obj;
	}
	else if(isIe == true)
	{
		if(typeof obj == "string")
			newObj = eval("document." + coll + obj + styleObj);
		else
			newObj = obj;
	}

	return newObj;
}

function hideObject(obj)
{
	var theObject=getObject(obj);

	theObject.visibility = "hidden";
}

var bLetTimerClose = false;
var strOpenMenuId = null;

function ClickMenu(strId)
{
	bLetTimerClose = false;

	// close any opened menu's
	if((strOpenMenuId != null) && (strOpenMenuId != strId))
	{
		hideObject(strOpenMenuId);

//		var SwapObj = eval("Menu_" + strOpenMenuId);
//		SwapObj.Enable();
//		SwapObj.SwapTo(0);
	}

	// hide | open menu
	objMenu = getObject(strId);
	if(objMenu.visibility == "hidden" || objMenu.visibility == "hide")
	{
		strOpenMenuId = strId;
		objMenu.visibility = "visible";

//		var SwapObj = eval("Menu_" + strId);
//		SwapObj.Disable();
//		SwapObj.ForceSwapTo(2);
	}
	else
	{
		objMenu.visibility = "hidden";

//		var SwapObj = eval("Menu_" + strId);
//		SwapObj.ForceSwapTo(1);
//		SwapObj.Enable();

		strOpenMenuId = null;
	}
}


function OverMenu(strId)
{
//	var SwapObj = eval("Menu_" + strId);
//	SwapObj.Swap();

	if(strOpenMenuId != null && strId != strOpenMenuId)
	{
		// change opened menu

		// close currently opened
		objMenu = getObject(strOpenMenuId);
		objMenu.visibility = "hidden";

//		var SwapObj = eval("Menu_" + strOpenMenuId);
//		SwapObj.ForceSwapTo(0);
//		SwapObj.Enable();
		
		// open new menu
		objMenu = getObject(strId);
		objMenu.visibility = "visible";

//		var SwapObj = eval("Menu_" + strId);
//		SwapObj.Disable();
//		SwapObj.ForceSwapTo(2);


		// set new menu to opened
		strOpenMenuId = strId;
	}
}

function OutMenu(strId)
{
//	var SwapObj = eval("Menu_" + strId);
//	SwapObj.Swap();
}


function ActivateCloseTimer()
{
	bLetTimerClose = true;
	setTimeout("CloseByTimer();", 20);
}

function CloseByTimer()
{
	if(bLetTimerClose == true && strOpenMenuId != null)
	{
		hideObject(strOpenMenuId);

//		var SwapObj = eval("Menu_" + strOpenMenuId);
//		SwapObj.Enable();
//		SwapObj.SwapTo(0);

		strOpenMenuId = null;
	}
}
document.onclick = ActivateCloseTimer;

//
// End: Menu
// ********************************



// ****************************
// Begin: ImageSwapper
// Author: plazma
//

function ImageSwapper(strSource_1, strSource_2)
{
	this.m_objTarget = null;
	this.m_bEnabled = true;

	this.m_bCurrentState = false;
	this.m_nCurrentIndex = 0;

	this.m_nIndex_1 = 0;
	this.m_nIndex_2 = 1;


	this.m_ImgArray = new Array();

	// preload image 1 and 2
	this.m_ImgArray[0] = new Image();
	this.m_ImgArray[0].src = strSource_1;
	this.m_ImgArray[1] = new Image();
	this.m_ImgArray[1].src = strSource_2;
	this.m_nImages = 2;

	// check for ability to access images object
	if(document.images == null)
		this.m_bEnabled = true;


	// public functions
	this.AddImage = ImageSwapper_AddImage;
	this.Swap = ImageSwapper_Swap;
	this.SwapTo = ImageSwapper_SwapTo;
	this.ForceSwapTo = ImageSwapper_ForceSwapTo
	this.SetTarget = ImageSwapper_SetTarget;
	
	this.SetRotation = ImageSwapper_SetRotation;

	this.GetState = ImageSwapper_GetState;
	this.GetIndex = ImageSwapper_GetIndex;
	
	this.Enable = ImageSwapper_Enable;
	this.Disable = ImageSwapper_Disable;
	this.IsEnabled = ImageSwapper_IsEnabled;
}


function ImageSwapper_AddImage(strSource)
{
	var nIndex = this.m_nImages;
	this.m_ImgArray[nIndex] = new Image();
	this.m_ImgArray[nIndex].src = strSource;
	this.m_nImages++;

	return nIndex;
}


function ImageSwapper_SwapTo(nIndex)
{
	if(this.m_bEnabled == true)
		this.ForceSwapTo(nIndex);
}

function ImageSwapper_ForceSwapTo(nIndex)
{
	if(!this.m_objTarget)
		return;

	if(nIndex >= 0 && nIndex < this.m_nImages)
	{
		this.m_objTarget.src = this.m_ImgArray[nIndex].src;
		this.m_nCurrentIndex = nIndex;

		// set status
		this.m_bCurrentState = false;
		if(nIndex == this.m_nIndex_2)
			this.m_bCurrentState = true;
	}
}


function ImageSwapper_Swap()
{
	if(!this.m_objTarget || this.m_bEnabled != true)
		return;

	if(this.m_bCurrentState == true)
		this.m_nCurrentIndex = this.m_nIndex_1;
	else
		this.m_nCurrentIndex = this.m_nIndex_2;
	
	this.m_objTarget.src = this.m_ImgArray[this.m_nCurrentIndex].src;
	this.m_bCurrentState = !this.m_bCurrentState;
}

function ImageSwapper_SetTarget(objTarget)
{
	this.m_objTarget = objTarget;
}

function ImageSwapper_GetState()
{
	return this.m_bCurrentState;
}

function ImageSwapper_GetIndex()
{
	return this.m_nCurrentIndex;
}

function ImageSwapper_SetRotation(nIndex_1, nIndex_2)
{
	if(nIndex_1 >= 0 && nIndex_2 < this.m_nImages)
		this.m_nIndex_1 = nIndex_1;
	if(nIndex_2 >= 0 && nIndex_2 < this.m_nImages)
		this.m_nIndex_2 = nIndex_2;
}

function ImageSwapper_Enable()
{
	if(document.images == null)
		return;

	this.m_bEnabled = true;
}

function ImageSwapper_Disable()
{
	this.m_bEnabled = false;
}

function ImageSwapper_IsEnabled()
{
	return this.m_bEnabled;
}



// **********************

// End: ImageSwapper
// ********************************



// ********************************
// Begin: Search Animation
// Author: plazma
//
var nTimerId;
var nAnimLoc = 0;
var strOrigSearch = "";
var strSearch = "";
var objSearch = null;

function BeginSearch()
{
	if(objSearch == null)
		return;

	if(objSearch.value.toLowerCase() == strOrigSearch.toLowerCase())
		objSearch.value = "";
}

function EndSearch()
{
	if(objSearch != null)
	{
		if(objSearch.value == "")
		{
			objSearch.value = strOrigSearch;
			strSearch = strOrigSearch;
		}
		else
			strSearch = objSearch.value;
	}
}

//
// End: Search Animation
// ********************************



function InitGWC()
{
	// preload images
	BindImages();

	// start animated search
	objSearch = document.gwc_search_form.form_search;
	strOrigSearch = objSearch.value;
	strSearch = strOrigSearch;
}

