// JavaScript Document
// colour swapper for the "Colour" page 
function colourSwapper(colour, destinationID, cartype)
{
	var speed = Math.round(5);
	var timer = 0;
	var timeout;
	for(var i = 100; i >= 0; i--)
	{
		timeout = window.setTimeout("changeOpac(" + i + ", '" + destinationID + "', 'fadeout', '"+cartype+"', '"+colour+"')", (timer * speed));
		timer++;
	}
	for(var i = 0; i < 100; i++)
	{
		timeout = window.setTimeout("changeOpac(" + i + ", '" + destinationID + "', 'fadein', '"+cartype+"', '"+colour+"')", (timer * speed));
		timer++;
	}
	var lg_image = document.getElementById(destinationID);
	var colour_name = colour.replace('_', ' ');
	lg_image.setAttribute("alt", colour_name);
	lg_image.setAttribute("title", colour_name);
	clearTimeout(timeout);
}



//change the opacity for different browsers
function changeOpac(opacity, id, dir, carType, carColour) {
	var toggle_image = document.getElementById('swatch_display');
	if(opacity == 0 && dir == 'fadeout') 
	{ 
		toggle_image.src = '/images/'+carType+'/colours/'+carColour+'.jpg'; 
	}
	
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 



function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
	var direction = 'out';
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
		direction = 'out';
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
		direction = 'in';
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
	return direction;
}
