// JavaScript Document

var timeoutID = new Array();
var nextExit = "";
var browse = "";
var pause = false;
var current = "";

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

function getBrowse(){
	return browse;
}

function init(){
	browse = whichBrs();
	for(var i = 1; i <7; i++){
		var theDiv = ".slice"+i+"over";
		if(browse == "Firefox"){
		//do nothing
		}
		else{
			$(theDiv).mouseleave(function() {
			  outFade(event);
			  });
		 }
	}

}

function enterFirst(){
if(current == 1){}
else{
	pause = true;
	current = 1;
	clearIntervals();
	resetToOriginal();
    $('.slide_container').show();	
    $('.slice1').animate({opacity:'+=1',	marginTop: '+=368px'}, 500);
	$('.slice2').animate({opacity:'+=1', marginTop: '+=560px'}, 700);
	$('.slice3').animate({opacity:'+=1', marginTop: '-=664px'}, 1200, 
	function() {
		timeout = window.setTimeout(exitFirst, 4500);
		timeoutID.push(timeout);
		nextExit = "exitFirst()";
		resetToPlacement();
		pause = false;
	});
}
}

function exitFirst(){
	pause = true;
	$('.slice1').animate({opacity:'-=1', marginTop: '-=368px'}, 500);
	$('.slice2').animate({opacity:'-=1', marginTop: '-=560px'}, 1200);
	$('.slice3').animate({opacity:'-=1', marginTop: '+=664px'}, 700, function() {
		// Animation complete.
		$('.slide_container').hide();
		pause = false;
		enterSecond();
	});  
}

function enterSecond(){
if(current == 2){}
else{
	current = 2;
	pause = true;
	clearIntervals();
	resetToOriginal();
	$('.slide_container2').show();
	$('.slice4').animate({opacity:'+=1', marginTop: '-=368px'}, 1000);
	$('.slice5').animate({opacity:'+=1', marginTop: '-=368px'}, 1450);
	$('.slice6').animate({opacity:'+=1', marginTop: '-=368px'}, 1700, function() {
			// Animation complete.
			timeout = window.setTimeout(exitSecond, 4500);
			timeoutID.push(timeout);
			nextExit = "exitSecond()";
			resetToPlacement();
			pause = false;
		}); 
}		
}

function exitSecond(){
	pause = true;
	$('.slide_container2').fadeOut('slow', function(){
		resetToOriginal();
		pause = false;
		enterThird();
	});	
}

function enterThird(){
	current = 3;
	pause = true;
	clearIntervals();
	$('.slide_container3').show();
  	$('.slice7').fadeIn(1200, function(){
		timeout = window.setTimeout(exitThird, 4500);
		timeoutID.push(timeout);
		nextExit = "exitThird()";
		pause = false;
	});
}

function exitThird(){
	pause = true;
	$('.slice7').fadeOut('slow', function(){
		$('.slide_container3').hide();									  	
		pause = false;
		slideshow();
	});
}

function slideshow(){
	clearIntervals();
	enterFirst();
}

function inFade(e){
if(pause){}
else{
	clearIntervals();
	var evt = e || window.event;
    box = evt.target || evt.srcElement;
	boxB = "";
	boxC = "";
	switch(box.className){
		case 'slice1':
			boxB= '.slice2over';
			boxC = '.slice3over';
			break;
		case 'slice2':
			boxB= '.slice1over';
			boxC = '.slice3over';
			break;
		case 'slice3':
			boxB= '.slice2over';
			boxC = '.slice1over';
			break;
		case 'slice4':
			boxB= '.slice5over';
			boxC = '.slice6over';
			break;
		case 'slice5':
			boxB= '.slice6over';
			boxC = '.slice4over';
			break;
		case 'slice6':
			boxB= '.slice4over';
			boxC = '.slice5over';
			break;
	}
	if(boxB != ""){
		$(boxB).fadeOut(100);
		$(boxC).fadeOut(100);
	}
	box = "."+box.className + "over";
	if ($.browser.msie){
		$(box).show();
	}
	else{
		$(box).fadeIn(100);
	}
}
}

function outFade(e){
if(pause){}
else{
	resume();
	var evt = e || window.event;
    which1 = evt.target || evt.srcElement;
	which1 = "."+which1.className;
	if ($.browser.msie){
		$(which1).hide();
	}
	else{
		$(which1).fadeOut(100);
	}
}	
}

function resume(){
timeout = window.setTimeout(nextExit, 2000);
timeoutID.push(timeout);
}

function clearIntervals() {
      for (var i= 0;i < timeoutID.length; i++) {
        clearTimeout(timeoutID[i]);
      }
      timeoutID = new Array();
    }
	
function resetToOriginal(){
	$('.slice1').css('margin-top', '-368px');
	$('.slice2').css('margin-top', '-560px');
	$('.slice3').css('margin-top', '666px');
	$('.slice4').css('margin-top', '368px');
	$('.slice5').css('margin-top', '368px');
	$('.slice6').css('margin-top', '368px');
}

function resetToPlacement(){
	$('.slice1').css('margin-top', '0px');
	$('.slice2').css('margin-top', '0px');
	$('.slice3').css('margin-top', '2px');
	$('.slice4').css('margin-top', '0px');
	$('.slice5').css('margin-top', '0px');
	$('.slice6').css('margin-top', '0px');
}

function FFCheck1(e){
	var evt = e || window.event;
    parent = evt.target || evt.srcElement;
	//var parent = event.relatedtarget;
	while ( parent && parent != divElement ) {
	parent = parent.parentNode;
	}
	if (parent != divElement) { // relatedtarget is outside of the div
	// execute function
	outFade(e);
}

}

function FFCheck(e){
var evt = e || window.event;
parent = evt.target || evt.srcElement;
p
if (parent.getAttribute('name') == "slice") {
outFade(e);
} else {
//nevermind, don't do anything
}
}

