/* javascript - Kavoo v5 */

/*********************************/
// 00 - Popup
// 05 - Write Flash
// 10 - rescueFrame
// 15 - Home switcher
// 99 - onLoad
/*********************************/

/***** 15 - Home switcher *****/
var lastSwitched = '';
var switchTimer;
var currentSwitch = 0;
var switchLength;
function switchTo(id){
	clearInterval(fadeTimer);
	if(lastSwitched != ''){
		$bS('del',$b(lastSwitched),'on');
		$b(lastSwitched).onmouseover = function(){ switchTo(this.id); };
	}
	$bS('add',$b(id),'on');
	$b(id).onmouseover = null;
	fadeTimer = setInterval('fadeOff(\''+id+'\');', 15);
	lastSwitched = id;
	currentSwitch = id.substr(8);
}

var opacityLVL = 20;
var fadeTimer;
function fadeOff(id){
	if(opacityLVL > 0){
		opacityLVL = opacityLVL-10;
		$b('switcherView').style.opacity  = opacityLVL/100;
		$b('switcherView').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+opacityLVL+')';
	} else {
		clearInterval(fadeTimer);
		$b('switcherView').innerHTML = $b(id+'Content').innerHTML;
		fadeTimer = setInterval('fadeOn()', 15);
	}
}
function fadeOn(){
	if(opacityLVL < 100){
		opacityLVL = opacityLVL+10;
		$b('switcherView').style.opacity  = opacityLVL/100;
		$b('switcherView').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+opacityLVL+')';
	} else {
		clearInterval(fadeTimer);
	}
}

function autoSwitcher(){
	if(currentSwitch < switchLength){
		currentSwitch++;
	} else {
		currentSwitch = 0;
	}
	switchTo('switcher'+currentSwitch);
}

/***** 99 - onLoad *****/
window.onload = function(){
	
	// 15 - Home switcher
	var switcherTab = $b$b('div','switcher');
	if(switcherTab.length > 0){
		switcherTab[0].id = 'switcher';
		var switcherElement = $b('switcher','li',-1);
			switchLength = switcherElement.length-1;
		for(i=0; i<switcherElement.length; i++){
			switcherElement[i].id = 'switcher'+i;
			switcherElement[i].onmouseover = function(){ clearInterval(switchTimer); switchTo(this.id); }
		}
		var switcherContent = $b('switcher','p',-1);
		for(i=0; i<switcherContent.length; i++){
			switcherContent[i].id = 'switcher'+i+'Content';
		}
		$b('switcher','div',0).id = 'switcherView';
		switchTo('switcher0');
		switchTimer = setInterval('autoSwitcher();', 3000);
		$b('switcher').onmouseover = function(){ clearInterval(switchTimer); }
		$b('switcher').onmouseout = function(){ clearInterval(switchTimer); switchTimer = setInterval('autoSwitcher();', 3000); }
	}
	
}
