var Promos = {current: 1, num:4, shown:0};
var Globals = {shortTime: 10000, longTime: 10000};

function switchContent(el){
	$clear(timer);
	if(Promos.current != el){
		//Promos.current = el;
		changeContent(el);
		startTimer(Globals.longTime);
	}
}

function changeContent(el){
	//setup tween
	newEl = $("content"+el.toString());

	currentEl = $("content"+Promos.current);
	newEl.set('tween',{duration: 1000});
	newEl.fade(0.999);

	if(newEl != currentEl){
		currentEl.fade(0);
	}

	Promos.current = el;
}

function page(dir){
	$clear(timer);
	next = (Promos.current + dir)%Promos.num;

	if(next == 0)
		next = Promos.num;

	changeContent(next);

	startTimer(Globals.shortTime);
}

var addCount = function(){this.shown++; $clear(timer); changeContent((this.current%this.num)+1); startTimer(Globals.shortTime);};

function selectRandom(){
	//var j = Math.floor(((Math.random()*10)%Promos.num)+1);
	var j = $random(1, 100);
	var randomPromo = 0;

	/*switch(true){
		case ((0 < j) && (j<41)):
			randomPromo = 1;
			break;
		case ((40 < j) && (j<81)):
			randomPromo = 2;
			break;
		case ((80 < j) && (j<91)):
			randomPromo = 3;
			break;
		case ((90 < j) && (j<101)):
			randomPromo = 4;
			break;
	}*/

	randomPromo = 1;

	changeContent(randomPromo);
	$('loader').fade(0);
}

function startTimer(time){
	if(Promos.shown < Promos.num)
		timer = addCount.periodical(time, Promos); //Will add the number of seconds at the Site.
		
	else
		$clear(timer);
}

function initFade(){
	for(i=1;i<=Promos.num;i++){
		newEl = $("content"+i);
		newEl.fade(0);
	}
}

function showStyles(obj){
	alert($(obj).getStyle('margin'));
}

function initControls(){
	var controlDivs = $('container_wrapper').getElements('div.controlLinks');

	for (var i in controlDivs)
	{
		controlDivs[i].innerHTML = $('controls').innerHTML;
	}

}

function showSpecsCallout(){
	$('specsCallout').fade(1);
}

function hideSpecsCallout(){
	$('specsCallout').fade(0);
}

var compareBox_state = 'closed';
function openCompareBox(){

	if(compareBox_state == 'closed'){
		$('compareBox').set('tween',{duration: 1500,transition: Fx.Transitions.linear.easeOut});
		$('compareBox').tween('height', 200);

		compareBox_state = 'open';
	}
	else{
		$('compareBox').set('tween',{duration: 1500,transition: Fx.Transitions.linear.easeOut});
		$('compareBox').tween('height', 0);
		compareBox_state = 'closed';
	}

}

function initCompareBox(){
	//IF - Check for 'navtop_desc' object
	if($('compareBox')){
		$(document.body).getElements('a.compareButton').addEvent('click', function(){
				openCompareBox();
		});
		$(document.body).getElements('a.compareButton').setProperties({
			href: '#compare'
		});
	}
}

function initSpecsEvent(){
	$(document.body).getElements('a.specs').addEvents({
		'mouseenter': function(){
			showSpecsCallout();
		},
		'mouseleave': function(){
			hideSpecsCallout();
		}
	});
}

function stop(){
	$clear(timer);
}

window.addEvent('domready', function(){
	initNavTopDesc();

	//initControls();
	//initCompareBox();
	//initFade();
	//initSpecsEvent()

	//setTimeout(selectRandom, 200);

	//startTimer(Globals.shortTime);
});