//=============================================================================
// file: js.js
// auth: nick 05/07/05
// desc: the javascript for salisbury cathedral
//=============================================================================

// init vars
var currentDetails = false;
var currentId      = '';

//==========================================================
// func: details(id)
// auth: nick 06/05/05
// desc: turns on and off the given details
// args: id - the id of the details to alter
// retn: none
//==========================================================
function details(id)
{
    // check for no existing details
    if (!currentDetails)
    {
        // show the new details
        showDetails(id);
        
        // set the current details
        currentDetails = id;
    }
    else if (currentDetails != id)
    {
        // hide the current details
        hideDetails(currentDetails);
        
        // show the new details
        showDetails(id);
        
        // set the current details
        currentDetails = id;
    }
    else
    {
        // hide the details
        hideDetails(id);
        
        // set the currentDetails
        currentDetails = false;
    }
}

//==========================================================
// func: showDetails(id)
// auth: nick 06/05/05
// desc: turns on given details
// args: id - the id of the details to alter
// retn: none
//==========================================================
function showDetails(id)
{
    // show the details
    document.getElementById('classDetails' + id).style.display = 'block';
    
    // change the image and text
    document.getElementById('classImage' + id).src   = '/img/buttonMinus.gif';
    document.getElementById('classImage' + id).alt   = 'Click here to hide details';
    document.getElementById('classImage' + id).title = 'Click here to hide details';
}

//==========================================================
// func: hideDetails(id)
// auth: nick 06/05/05
// desc: turns off given details
// args: id - the id of the details to alter
// retn: none
//==========================================================
function hideDetails(id)
{
    // show the details
    document.getElementById('classDetails' + id).style.display = 'none';
    
    // change the image and text
    document.getElementById('classImage' + id).src   = '/img/buttonExpand.gif';
    document.getElementById('classImage' + id).alt   = 'Click here to view more details';
    document.getElementById('classImage' + id).title = 'Click here to view more details';
}

//==========================================================
// func: highlight(id)
// auth: nick 27/07/05
// desc: highlights and un-highlights the close images
// args: id     - the id of the image to alter
// retn: none
//==========================================================
function highlight(id)
{
    // there is no data defined, restore the image
    if (!id && currentId != '')
    {
        // swap the image
        document.getElementById(currentId).className = 'blankState';
        
        // empty the image
        currentId = '';
    }
    // store the image and swap
    else
    {
        // save the image
        currentId = id;
        
        // swap the image
        document.getElementById(id).className = 'hoverState';
    }
}

//==========================================================
// func: updateQuantity(formName, changeValue)
// auth: nick 27/07/05
// desc: updates the quantity for the basket
// args: formName    - the name of the form to change
//       changeValue - the amount to change the value by
// retn: none
//==========================================================
function updateQuantity(formName, id, changeValue)
{
    temp = Number(changeValue);
    
    if (temp > 0) 
        document.getElementById(formName).action = '/shop.basket.php?add=' + id;
    else
        document.getElementById(formName).action = '/shop.basket.php?remove=' + id;
}


function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}