/******************************************************************************
 *
 * Copyright (c) Enigma Interactive 2004
 * 7-15 pink lane / newcastle / ne1 5dw / england
 * t: +44 (0)191 261 2991 www.enigma-interactive.co.uk f: +44 (0)191 261 2378
 *
 * Filename: 	utility.js
 * Description:	A set of fuction sused by PLAY to manipulte the HTML page
 *
 *
 * History
 * ver	date		who					comment
 * ----------------------------------------------------------------------------
 * 1.0	07-Apr-2004	Graeme Wilkinson	Created
 *****************************************************************************/
 
 
 /*******************************************************************************
 * Description:	Expands or colapses the cd tracks display
 * Parameters:	p_strObjectId	- the id of the object that contains the track 
 *								listing (usually a div element)
 *				p_strId			- the id of the image to change
 *				p_objImage		- the image to change
 *									
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 *	    19-Aug-2004 Chris Gair			Checks if the image is defined - if not then
 *										it tries to get the element using it's id
 * 1.3	04-Jun-2004	Graeme Wilkinson	Now replaces image
 * 1.0	07-Apr-2004	Graeme Wilkinson	Created
 ******************************************************************************/
 function viewCDTracks(p_strObjectId, p_objImage) {
 
 	objElement = document.getElementById(p_strObjectId);
	
	strCurrentClass = objElement.className;
	strCurrentImage = p_objImage.src;

	if ((strCurrentImage == 'undefined') || ( strCurrentImage == null)){
		p_objImage = document.getElementById(p_objImage);
		strCurrentImage = p_objImage.src;
	}
	
	if (strCurrentClass.indexOf("hidden") != -1 ) {
		strCurrentClass = strCurrentClass.replace("hidden", "visible");
		strCurrentImage = strCurrentImage.replace("_e", "_c");
	}
	else if ( strCurrentClass.indexOf("visible") != -1 ) {
		strCurrentClass = strCurrentClass.replace("visible", "hidden");
		strCurrentImage = strCurrentImage.replace("_c", "_e");
	}
	
	setClass( p_strObjectId, strCurrentClass );
	p_objImage.src = strCurrentImage;
 
 } // end of function setClass
 
  /*******************************************************************************
 * Description:	Expands or colapses the folder
 * Parameters:	p_strObjectId	- the id of the object that contains the folder 
 *								listing (usually a div element)
 *									
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1.0	17-May-2004	Chris Gair			Created
 ******************************************************************************/
 function viewFolder(p_strObjectId) {
 
 	objElement = document.getElementById(p_strObjectId);

	strCurrentClass = objElement.className;
	
	if (strCurrentClass.indexOf("hidden") != -1 ) {
		strCurrentClass = strCurrentClass.replace("hidden", "visible");
		test = objElement.id + "_Symbol";
		img_id = document.getElementById(test);
		img_id_src = img_id.src;
		img_id_src = img_id_src.replace("plus","minus");
		img_id.src = img_id_src;
		
		test = objElement.id + "_Folder";
		img_id = document.getElementById(test);
		img_id_src = img_id.src;
		img_id_src = img_id_src.replace("closefolder","openfolder");
		img_id.src = img_id_src;
	}
	else if ( strCurrentClass.indexOf("visible") != -1 ) {
		strCurrentClass = strCurrentClass.replace("visible", "hidden");
		
		test = objElement.id + "_Symbol";
		img_id = document.getElementById(test);
		img_id_src = img_id.src;
		img_id_src = img_id_src.replace("minus","plus");
		img_id.src = img_id_src;
		
		test = objElement.id + "_Folder";
		img_id = document.getElementById(test);
		img_id_src = img_id.src;
		img_id_src = img_id_src.replace("openfolder","closefolder");
		img_id.src = img_id_src;
	}
	
	setClass( p_strObjectId, strCurrentClass );
 } 
 
 var oldElementClassName="";
 var oldElementId=0;
 
 function highlightTrack(p_strElementId){
	objElement = document.getElementById(p_strElementId);
	
	oldClassName = oldElementClassName;
	oldId = oldElementId;
	
	strCurrentClass = objElement.className+"High";
	elementClassName = objElement.className;
	setClass( p_strElementId, strCurrentClass );
	
	if (oldClassName == "") {
		oldElementClassName = elementClassName;
		oldElementId = p_strElementId;
	}
	else{
		setClass( oldId, oldClassName );
	}
 }
 
 /*
 * Description: Sets the height of an element to take up
 *				the remaining space in its parent. Note:
 *				all other elements must be a fixed height
 * Paremeters:	param1 - the element that should be resized
 *				param2 - the containing element
 *				paramn - all fixed height elements
 *						in the containing element
 */
function setSizeableHeight() {

	objSizeable = xGetElementById( arguments[0] );
	objContent = xGetElementById( arguments[1] );
	intHeight = xHeight(objContent);

	for(var i=2; i<arguments.length; i++) {
		 objFixed = xGetElementById( arguments[i] )	 
		 intHeight = intHeight - xHeight(objFixed);
	}

	xHeight(objSizeable, intHeight);
}

/*
 * Description: Sets the content panel height 
 */
function setContentSize() {

	objContent = xGetElementById("mainBody");
	objTop = xGetElementById("topBar");
	objBottom = xGetElementById("bottomBar");
	intHeight = xClientHeight() - xHeight(objTop) - xHeight(objBottom);
	xHeight(objContent, intHeight);

}

/**
 * sets the state of teh specified icon 
 * (highlight/lowlight state)
 **/
function setIconState(p_strId, p_bolState) {
	
	objIcon = xGetElementById( p_strId );

	if ( objIcon ) {
		strImageSrc = objIcon.src;
		
		if( p_bolState ) {
			strImageSrc = strImageSrc.replace("_off", "_hi_0");
		}
		else {
			strImageSrc = strImageSrc.replace("_hi_0", "_off");
		}
		
		objIcon.src = strImageSrc;
	}
	
	return true;
	
} // end of function setShareIcon
