function e(id)
{
	return document.getElementById(id)?document.getElementById(id):false;
} 
 
function onRollOver(img_obj){
	img_obj.src = img_obj.src.split("-off").join("-on");
}

function onRollOut(img_obj){
	img_obj.src = img_obj.src.split("-on").join("-off");	
}  

function setAlpha(obj_ref, percentage) {
	if (obj_ref.filters && obj_ref.filters[0]) {
		if (typeof obj_ref.filters[0].opacity == "number") { //if IE6+
			obj_ref.filters[0].opacity = percentage;
		} else { //else if IE5.5-
			obj_ref.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+percentage+")";
		}
	} else if (obj_ref.style.MozOpacity) {
		obj_ref.style.MozOpacity = percentage / 101;
	} else if (obj_ref.style.KhtmlOpacity) {
		obj_ref.style.KhtmlOpacity = percentage / 100;
	}
}
		
function onSubNavOver(td_obj){
	td_obj.className="subnavcell-on";
}	

function onSubNavOff(td_obj){
	td_obj.className="subnavcell-off";
}

function onSubSubNavOver(td_obj){
	td_obj.className="subsubnavcell-on";
}	

function onSubSubNavOff(td_obj){
	td_obj.className="subsubnavcell-off";
}

var credit_timeout=-1;
var timeout_in_seconds = 2;	

function onCreditsOver(){
	clearTimeout(credit_timeout);
	if(e("credit_links")){
		e("credit_links").className="show";
	}
}

function onCreditsOut(){	
	credit_timeout = setTimeout("onCreditsOutHide()", timeout_in_seconds * 1000);	
}

function onCreditsOutHide(){
	if(e("credit_links")){			
		e("credit_links").className="hide";		
	}	
}

/*------------ Javascript fader --------------------------*/

var FADE_FRAME_DURATION=5;
var FADE_ALPHA_STEP=2;
var WAIT_BETWEEN_FADES = 350;


function setTransparency(obj_ref, percentage) {
	if (obj_ref.filters && obj_ref.filters[0]) {
		if (typeof obj_ref.filters[0].opacity == "number") { //if IE6+
			obj_ref.filters[0].opacity = percentage;
		} else { //else if IE5.5-
			obj_ref.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+percentage+")";
		}
	} else if (obj_ref.style.MozOpacity) {
		obj_ref.style.MozOpacity = percentage / 101;
	} else if (obj_ref.style.KhtmlOpacity) {
		obj_ref.style.KhtmlOpacity = percentage / 100;
	}
}


window.onload = function(){		
	clearTimeout(int_fade_anim_id);				
	int_fade_anim_id = setTimeout("goLoadNextHomeImage()", WAIT_BETWEEN_FADES);
}

var int_current_set = -1;
var str_current_img_id = "";
var int_fade_anim_id = -1;
function goLoadNextHomeImage(){

	if (typeof arr_fade_ele !== 'undefined' && arr_fade_ele.length > 0) {
		// (1) Pick a random set - make sure it's not the same as last time
		var old_set = int_current_set
		int_current_set = Math.floor(Math.random() * arr_fade_images.length);
		if (arr_fade_images.length > 1 ){
			while (int_current_set==old_set){
				int_current_set = Math.floor(Math.random() * arr_fade_images.length);
			}
		}
					
		// For this list - get the next item
		
		arr_fade_ele[int_current_set]++;
		
		
		if (arr_fade_ele[int_current_set] == arr_fade_images[int_current_set].length){
			arr_fade_ele[int_current_set] = 0;
		}
		
		str_current_img_id = arr_fade_images[int_current_set][arr_fade_ele[int_current_set]];
		
		// Bring to front
		arr_fade_z_index[int_current_set]++;
		e(str_current_img_id).style.zIndex = arr_fade_z_index[int_current_set];
		
		// Set alpha to zero
		arr_fade_alpha[int_current_set] = 0;			
		setTransparency(e(str_current_img_id), arr_fade_alpha[int_current_set]);
		
		// Show it
		e(str_current_img_id).className = "show";
		
		// Fade it in	
		
		//alert("START" + str_current_img_id + ":" + e(str_current_img_id).className + ":"  +e(str_current_img_id).style.zIndex );
		goAnimateFade()
	}
	
}


function goAnimateFade(){
	
	arr_fade_alpha[int_current_set]+= FADE_ALPHA_STEP
	setTransparency(e(str_current_img_id), arr_fade_alpha[int_current_set])
	
	if (arr_fade_alpha[int_current_set] >= 100){
		
		setTransparency(e(str_current_img_id), 100)
		arr_fade_alpha[int_current_set] = 100;
		
		// Now hide the image that just got faded over...
		
		var int_last_ele = arr_fade_ele[int_current_set] - 1;
		
		if (int_last_ele < 0 ){
			int_last_ele = arr_fade_images[int_current_set].length - 1;
		}
		
		var old_image_id = arr_fade_images[int_current_set][int_last_ele];
		
		if(e(old_image_id)){
			e(old_image_id).className="hide";
		}
		
		clearTimeout(int_fade_anim_id);				
		int_fade_anim_id = setTimeout("goLoadNextHomeImage()", WAIT_BETWEEN_FADES);
		
	} else {
	
		clearTimeout(int_fade_anim_id);
		int_fade_anim_id = setTimeout("goAnimateFade()", FADE_FRAME_DURATION);	
	}
	
}


arr_fade_images = new Array();	
arr_fade_ele = new Array();
arr_fade_z_index = new Array();
arr_fade_alpha = new Array();

		
