// Avrio Master JavaScript Document

var theTimeout;
var intSeq;
var intTvPic = 1;
var booSystemOn = false;
var arrOnSeq=new Array(); // regular array
arrOnSeq[0]="#bd"; //rollover
arrOnSeq[1]="#bd-hdmi"; //blue
arrOnSeq[2]="#sky"; //rollover
arrOnSeq[3]="#sky-hdmi"; //blue
arrOnSeq[4]="#ps3"; //rollover
arrOnSeq[5]="#ps3-hdmi"; //blue
arrOnSeq[6]="#tx"; //rollover
arrOnSeq[7]="#tv1-hdmi"; //blue
arrOnSeq[8]="#tv1"; //rollover - class on1
arrOnSeq[9]="#power1"; //red
arrOnSeq[10]="#socket1"; //class on
arrOnSeq[11]="#wall1"; //red
arrOnSeq[12]="#socket2"; //class on
arrOnSeq[13]="#power2"; //red
arrOnSeq[14]="#rx1"; //rollover
arrOnSeq[15]="#tv2-hdmi"; //blue
arrOnSeq[16]="#tv2"; //rollover - class on1
arrOnSeq[17]="#wall2"; //red
arrOnSeq[18]="#socket3"; //class on
arrOnSeq[19]="#power3"; //red
arrOnSeq[20]="#rx2"; //rollover
arrOnSeq[21]="#tv3-hdmi"; //blue
arrOnSeq[22]="#tv3"; //rollover - class on1
arrOnSeq[23]="#hdjuicebox-remote"; //rollover - class
arrOnSeq[24]="#sky-remote"; //rollover - class
arrOnSeq[25]="#bd-remote"; //rollover - class

$(document).ready(function(){
	Cufon.replace('#powerHD #installExample h2', { fontSize: '30px' });
	Cufon.replace('#powerHD h3', { fontSize: '30px' });
	Cufon.replace('#installGFX #key li', { fontSize: '18px' });
	Cufon.replace('#powerHD #installExample #installGFX ol li strong', { fontSize: '18px' });
	
	fncDoSwitch();

});

function fncDoSwitch() {
	intSeq = 0;
	fncActivateSwitch();
}

function fncActivateSwitch() {
	$('span#power').addClass('active');
	$('span#power').bind('click', function() {
		$(this).toggleClass('on');
		$(this).removeClass('active')
		$(this).unbind('click');
		if (booSystemOn == false) {
			booSystemOn = true;
			$(this).attr('title','Turn System Off');
			fncDoOn();
		} else {
			booSystemOn = false;
			$(this).attr('title','Turn System On');
			fncDoOff();
		}
	});
}

function fncDoOn() {
	if (intSeq > (arrOnSeq.length - 1)) {
		//activate rollovers, activate remotes
		fncActivateRollovers();
		$('#hdjuicebox-remote').bind('click', function() {
			//$(this).addClass('on');
			$('#bd').removeClass();
			$('#sky').removeClass();
			$('#ps3').removeClass();
			$('#sky-remote').removeClass();
			$('#bd-remote').removeClass();
			$('#sky-remote').unbind('mouseenter mouseleave click');
			$('#bd-remote').unbind('mouseenter mouseleave click');
			if (intTvPic > 0 && intTvPic <= 3 ) {
				intTvPic = 4;
				$('#sky').addClass('on');
				$('#sky-remote').addClass('on');
				fncSkyRemoteClick();
				fncActivateSkyRemote();
			} else if (intTvPic > 3 && intTvPic <= 5 ) {
				intTvPic = 6;
				$('#ps3').addClass('on');
			} else {
				intTvPic = 1;
				$('#bd').addClass('on');
				$('#bd-remote').addClass('on');
				fncBDRemoteClick();
				fncActivateBDRemote();
			}
			$('#tv1').removeClass().addClass('on'+intTvPic);
			$('#tv2').removeClass().addClass('on'+intTvPic);
			$('#tv3').removeClass().addClass('on'+intTvPic);
		});
		
		fncBDRemoteClick();
		fncActivateSwitch();
		
	} else if (intSeq == 2 || intSeq == 4 || intSeq == 6 || intSeq == 14 || intSeq == 20) {
		//require rollovers
		fncDoNext();
	} else if (intSeq == 8 || intSeq == 16 || intSeq == 22) {
		//require rollovers - class on1
		$(arrOnSeq[intSeq]).addClass('on1');
		fncDoNext();
	} else if (intSeq == 1 || intSeq == 3 || intSeq == 5 || intSeq == 7 || intSeq == 15 || intSeq == 21) {
		//blue
		$(arrOnSeq[intSeq]).animate({backgroundColor: '#000571'}, function() {
			fncDoNext();
		});
	} else if (intSeq == 9 || intSeq == 11 || intSeq == 13 || intSeq == 17 || intSeq == 19) {
		//red
		$(arrOnSeq[intSeq]).animate({backgroundColor: '#FF0000'}, function() {
			fncDoNext();
		});
	} else if (intSeq == 0 || intSeq == 10 || intSeq == 12 || intSeq == 18) {
		//class on
		$(arrOnSeq[intSeq]).addClass('on');
		fncDoNext();
	} else if (intSeq == 23 || intSeq == 25) {
		//require rollovers - class on
		$(arrOnSeq[intSeq]).addClass('on');
		fncDoNext();
	} else {
		fncDoNext();
	} 
}

function fncSkyRemoteClick() {
	$('#sky-remote').bind('click', function() {
		$(this).addClass('on');
		if (intTvPic >= 5 ) {
			intTvPic = 4;
		} else {
			intTvPic++;
		}
		$('#tv1').removeClass().addClass('on'+intTvPic);
		$('#tv2').removeClass().addClass('on'+intTvPic);
		$('#tv3').removeClass().addClass('on'+intTvPic);
	});
}

function fncBDRemoteClick() {
	$('#bd-remote').bind('click', function() {
		$(this).addClass('on');
		if (intTvPic >= 3 ) {
			intTvPic = 1;
		} else {
			intTvPic++;
		}
		$('#tv1').removeClass().addClass('on'+intTvPic);
		$('#tv2').removeClass().addClass('on'+intTvPic);
		$('#tv3').removeClass().addClass('on'+intTvPic);
	});
}

function fncActivateRollovers() {
	$('#bd').hover(
		function () {
			$('li.lounge span.bd').css('display','block');
		}, 
		function () {
			$('li.lounge span.bd').css('display','none')
		}
	);
	
	$('#sky').hover(
		function () {
			$('li.lounge span.sky').css('display','block');
		}, 
		function () {
			$('li.lounge span.sky').css('display','none')
		}
	);
	
	$('#ps3').hover(
		function () {
			$('li.lounge span.ps3').css('display','block');
		}, 
		function () {
			$('li.lounge span.ps3').css('display','none')
		}
	);
	
	$('#tx').hover(
		function () {
			$('li.lounge span.tx').css('display','block');
		}, 
		function () {
			$('li.lounge span.tx').css('display','none')
		}
	);
	
	$('#tv1').hover(
		function () {
			$('li.lounge span.tv1').css('display','block');
		}, 
		function () {
			$('li.lounge span.tv1').css('display','none')
		}
	);
	
	$('#hdjuicebox-remote').hover(
		function () {
			$('li.lounge span.remote-juice').css('display','block');
		}, 
		function () {
			$('li.lounge span.remote-juice').css('display','none')
		}
	);
	
	$('#rx1').hover(
		function () {
			$('li.office span.rx').css('display','block');
		}, 
		function () {
			$('li.office span.rx').css('display','none')
		}
	);
	
	$('#tv2').hover(
		function () {
			$('li.office span.tv2').css('display','block');
		}, 
		function () {
			$('li.office span.tv2').css('display','none')
		}
	);
	
	$('#rx2').hover(
		function () {
			$('li.bedroom span.rx').css('display','block');
		}, 
		function () {
			$('li.bedroom span.rx').css('display','none')
		}
	);
	
	$('#tv3').hover(
		function () {
			$('li.bedroom span.tv3').css('display','block');
		}, 
		function () {
			$('li.bedroom span.tv3').css('display','none')
		}
	);
	
	fncActivateBDRemote();
}

function fncActivateSkyRemote() {
	$('#sky-remote').hover(
		function () {
			$('li.office span.remote-sky').css('display','block');
		}, 
		function () {
			$('li.office span.remote-sky').css('display','none')
		}
	);
}

function fncActivateBDRemote() {
	$('#bd-remote').hover(
		function () {
			$('li.bedroom span.remote').css('display','block');
		}, 
		function () {
			$('li.bedroom span.remote').css('display','none')
		}
	);
}

function fncDoNext() {
	intSeq++;
	fncDoOn();
}

function fncDoOff() {
	$('#bd').unbind('mouseenter mouseleave');
	$('#sky').unbind('mouseenter mouseleave');
	$('#ps3').unbind('mouseenter mouseleave');
	$('#tx').unbind('mouseenter mouseleave');
	$('#tv1').unbind('mouseenter mouseleave');
	$('#hdjuicebox-remote').unbind('mouseenter mouseleave');
	$('#rx1').unbind('mouseenter mouseleave');
	$('#tv2').unbind('mouseenter mouseleave');
	$('#rx2').unbind('mouseenter mouseleave');
	$('#tv3').unbind('mouseenter mouseleave');
	$('#sky-remote').unbind('mouseenter mouseleave');
	$('#bd-remote').unbind('mouseenter mouseleave');
	if (intSeq < 0) {
		//do nothing
		fncActivateSwitch();
	} else if (intSeq == 2 || intSeq == 4 || intSeq == 6 || intSeq == 14 || intSeq == 20) {
		//require rollovers
		$(arrOnSeq[intSeq]).removeClass();
		fncDoPrevious();
	} else if (intSeq == 8 || intSeq == 16 || intSeq == 22) {
		//require rollovers - class on1
		$(arrOnSeq[intSeq]).removeClass();
		fncDoPrevious();
	} else if (intSeq == 1 || intSeq == 3 || intSeq == 5 || intSeq == 7 || intSeq == 15 || intSeq == 21) {
		//blue
		/*$(arrOnSeq[intSeq]).animate({backgroundColor: '#CCCCCC'}, function() {
			fncDoPrevious();
		});*/
		$(arrOnSeq[intSeq]).css('backgroundColor','#C3C3C3');
		fncDoPrevious();
	} else if (intSeq == 9 || intSeq == 11 || intSeq == 13 || intSeq == 17 || intSeq == 19) {
		//red
		/*$(arrOnSeq[intSeq]).animate({backgroundColor: '#CCCCCC'}, function() {
			fncDoPrevious();
		});*/
		$(arrOnSeq[intSeq]).css('backgroundColor','#C3C3C3');
		fncDoPrevious();
	} else if (intSeq == 0 || intSeq == 10 || intSeq == 12 || intSeq == 18) {
		//class on
		$(arrOnSeq[intSeq]).removeClass();
		fncDoPrevious();
	} else if (intSeq == 23 || intSeq == 25 || intSeq == 24) {
		//require rollovers - class on
		$(arrOnSeq[intSeq]).removeClass();
		fncDoPrevious();
	} else {
		fncDoPrevious();
	} 
}

function fncDoPrevious() {
	intSeq--;
	fncDoOff();
}

