function topNavOV(div){
	alert("here");
}

function topNavOUT(div){
	alert("there");
}

function switchImg(){
	var zero = setInterval("getNum()", 4000);
	var one = setInterval("switchLoop('ani_1', '0')", 1000);
	var three = setInterval("switchLoop('ani_2', '0')", 9000);
	var five = setInterval("switchLoop('ani_3', '0')", 4000);
	var seven = setInterval("switchLoop('ani_4', '0')", 2000);
	var nine = setInterval("switchLoop('ani_5', '0')", 5000);
	var eleven = setInterval("switchLoop('ani_6', '0')", 8000);
	var thirteen = setInterval("switchLoop('ani_7', '0')", 7000);
	var fifteen = setInterval("switchLoop('ani_8', '0')", 3000);
	var seventeen = setInterval("switchLoop('ani_9', '0')", 6000);
}

function switchLoop(div,act){
	var num = $("#animate").val();
	if(num == 0){
		var one = $("#"+div).html('<img src="2010/'+div+'.jpg" width="70" height="94" border="0">');
		var two = $("#"+div).animate({ opacity: 1 }, 1000 );
	}else{
		//$("#"+div).html('<img src="2010/0spacer.gif" width="70" height="94" border="0">');
		$("#"+div).animate({ opacity: 0 }, 1000 );
	}
}

function getNum(){
	var num = $("#animate").val();
	if(num == 0){
		$("#animate").val(1);
	}else{
		$("#animate").val(0);
	}
}

function startMain(){
	setInterval("mainImg()", 5000);
}

function mainImg(){
	var N = $("#mainLoop").val();
	N = N * 1;
	switch(N)
	{
		case 0:
			var one = $("#mainSection2").html('<a href="dc.php"><img src="2010/main_2.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 1 }, 1000, function(){$("#mainSection").html('');} );
			$("#mainLoop").val(1);
			break;
		case 1:
			var one = $("#mainSection").html('<a href="darkhorse.php"><img src="2010/main_3.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 0 }, 1000, function(){$("#mainSection2").html('');} );
			$("#mainLoop").val(2);
			break;
		case 2:
			var one = $("#mainSection2").html('<a href="image.php"><img src="2010/main_4.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 1 }, 1000, function(){$("#mainSection").html('');} );
			$("#mainLoop").val(3);
			break;
		case 3:
			var one = $("#mainSection").html('<a href="marvel.php"><img src="2010/main_1.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 0 }, 1000, function(){$("#mainSection2").html('');} );
			$("#mainLoop").val(0);
			break;
	}
	
	/*
		case 0:
	  		num = $("#mainLoop").val(1);
			var one = $("#mainSection2").html('<a href="dc.php"><img src="2010/main_2.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 1 }, 1000 );
			var three = $("#mainSection").html('');
	  	break;
	
		case 1:
	  		num = $("#mainLoop").val(2);
			var one = $("#mainSection").html('<a href="darkhorse.php"><img src="2010/main_3.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 0 }, 1000 );
			var three = $("#mainSection2").html('');
		break;
		case 2:
	  		num = $("#mainLoop").val(3);
			var one = $("#mainSection2").html('<a href="image.php"><img src="2010/main_4.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 1 }, 1000 );
			var three = $("#mainSection").html('');
		break;
		case 3:
	  		num = $("#mainLoop").val(0);
			var one = $("#mainSection").html('<a href="marvel.php"><img src="2010/main_1.jpg" width="500" height="193" border="0"></a>');
			var two = $("#mainSection2").animate({ opacity: 0 }, 1000 );
			var three = $("#mainSection2").html('');
		break;
	}
	*/
}

function openLeft(){
	var state = $("#leftNavState").val();
	
	if(state == "0"){
		$("#leftNavState").val("1");
		showLeftNav();
	}else{
		$("#leftNavState").val("0");
		hideLeftNav();
	}
}

function showLeftNav(){
	$("#navLeft").animate({ left: "0px" }, 1000 );
}

function hideLeftNav(){
	$("#navLeft").animate({ left: "125px" }, 1000 );
}

function openRight(){
	var state = $("#rightNavState").val();
	
	if(state == "0"){
		$("#rightNavState").val("1");
		showRightNav();
	}else{
		$("#rightNavState").val("0");
		hideRightNav();
	}
}

function showRightNav(){
	$("#navRight").animate({ right: "0px" }, 1000, "swing" );
}

function hideRightNav(){
	$("#navRight").animate({ right: "125px" }, 1000 );
}

function startTile(){
	setInterval("animateTile()", 2500);
}

function animateTile(){
	var status = $("#tileState").val();
	status = status * 1;
	switch(status)
	{
		case 1:
			//$("#errorStatus").html("1");
			$("#tileAnimation1").animate({ top: "-64px" }, 1000 );
			$("#tileAnimation2").hide();
			$("#tileAnimation2").animate({ top: "192px" }, 1000 );
			$("#tileState").val(2);
			break;
		case 2:
			//$("#errorStatus").html("2");
			$("#tileAnimation1").animate({ top: "-128px" }, 1000 );
			$("#tileState").val(3);
			break;
		case 3:
			//$("#errorStatus").html("3");
			$("#tileAnimation1").animate({ top: "-192px" }, 1000 );
			$("#tileState").val(4);
			break;
		case 4:
			//$("#errorStatus").html("4");
			$("#tileAnimation2").show();
			$("#tileAnimation1").animate({ top: "-256px" }, 1000 );
			$("#tileAnimation2").animate({ top: "128px" }, 1000 );
			$("#tileState").val(5);
			break;
		case 5:
			//$("#errorStatus").html("5");
			$("#tileAnimation1").animate({ top: "-320px" }, 1000 );
			$("#tileAnimation2").animate({ top: "64px" }, 1000 );
			$("#tileState").val(6);
			break;
		case 6:
			//$("#errorStatus").html("6");
			$("#tileAnimation1").animate({ top: "-384px" }, 1000 );
			$("#tileAnimation2").animate({ top: "0px" }, 1000 );
			$("#tileState").val(7);
			break;
		case 7:
			//$("#errorStatus").html("7");
			$("#tileAnimation1").hide();
			$("#tileAnimation2").animate({ top: "-64px" }, 1000 );
			$("#tileAnimation1").animate({ top: "192px" }, 1000 );
			$("#tileState").val(8);
			break;
		case 8:
			//$("#errorStatus").html("8");
			$("#tileAnimation2").animate({ top: "-128px" }, 1000 );
			$("#tileState").val(9);
			break;
		case 9:
			//$("#errorStatus").html("9");
			$("#tileAnimation2").animate({ top: "-192px" }, 1000 );
			$("#tileState").val(10);
			break;
		case 10:
			//$("#errorStatus").html("10");
			$("#tileAnimation1").show();
			$("#tileAnimation2").animate({ top: "-256px" }, 1000 );
			$("#tileAnimation1").animate({ top: "128px" }, 1000 );
			$("#tileState").val(11);
			break;
		case 11:
			//$("#errorStatus").html("11");
			$("#tileAnimation2").animate({ top: "-320px" }, 1000 );
			$("#tileAnimation1").animate({ top: "64px" }, 1000 );
			$("#tileState").val(12);
			break;
		case 12:
			//$("#errorStatus").html("12");
			$("#tileAnimation2").animate({ top: "-384px" }, 1000 );
			$("#tileAnimation1").animate({ top: "0px" }, 1000 );
			$("#tileState").val(1);
			break;
		default:
			//$("#errorStatus").html("Default");
	}
}

function scroll(direction){
	var query = $("#query").val();
	var status = $("#browseStatus").val();
	var curLimit = $("#browseLimit").val();
	var recLimit = $("#recordLimit").val();
	var DS = disableScroll();
	/*
	$("#errorStatus").show();
	$("#errorStatus").html(status);
	*/
	var zero = $("#browse_"+status).hide();
	var position = positionOffElement(status, direction);
	var limit = getLimit(curLimit, direction, recLimit);
	var populate = populateOff(query,status,limit);
	var animate = setTimeout("animateStage('"+direction+"','"+status+"')", 250);
}

function positionOffElement(status, direction){
	// ***** PUT THE DIV THAT IS OFF THE STAGE INTO POSITION TO ENTER THE STAGE ****
	switch(direction)
	{
		case "left":
			var one = $("#browse_"+status).css("left", "-120px");
			break;
		case "right":
			var one = $("#browse_"+status).css("left", "480px");
			break;
	}
}

function getLimit(curLimit, direction, recLimit){
	// ********* GET THE RESULT LIMIT OF THE NEXT RECORD ***********
	var result = 0;
	var getLim = curLimit.split("*");
	var leftLim = getLim[0];
	var rightLim = getLim[1];
	leftLim = leftLim * 1;
	rightLim = rightLim * 1;
	
	result = rightLim;
	/*
	alert(
		"Current: " + curLimit + "\n"
	);
	*/
	switch(direction)
	{
	
		case "left":
			var diff = parseInt(rightLim) - parseInt(leftLim); 
				if(leftLim == 0){ // original call
					result = (parseInt(recLimit)-1);
					var newRight = 3;
				}else{
					result = parseInt(leftLim) - 1;
					var newRight = parseInt(rightLim) -1;
				}
				
				if(leftLim < 0 ){
					result=(parseInt(recLimit)-1);
				}
				
				if(newRight < 0){
					newRight = parseInt(recLimit);
				}
				
				if(diff > 4){
					newRight = result + 4;
				}

				var newLim = result + "*" + newRight;
				$("#browseLimit").val(newLim);	
				
			break;
		case "right":
				
				result = rightLim + 1;
				var newLeft = leftLim + 1;
				
				if(result >= parseInt(recLimit)){
					result = 0;
				}
				
				if(newLeft >= parseInt(recLimit)){
					newLeft = 0;
				}
				
				//alert(leftLim+"\n"+rightLim+"\n"+result+"\n"+newRight);
				var newLim = newLeft + "*" + result;
				$("#browseLimit").val(newLim);
			break;
	}
	
	return result;
}

function populateOff(query,status,limit){
	var one = $("#browse_"+status).html('<div id="browseName">Loading</div>');
	var two = $.post("ajax/populateOff.php",{
		   query: query,
		   limit: limit,
		   status: status
		 }, function(html) {
				$("#browse_"+status).html(html);
	});
}

function animateStage(direction,status){
	status=status * 1;
	var one = $("#browse_"+status).show();
	switch(direction)
	{
	
		case "left":
			switch(status){
				case 5: // Five is off of the screen so we move it on
					var tw = $("#browse_1").animate({ left: "120px" }, 1000 ); 
					var th = $("#browse_2").animate({ left: "240px" }, 1000 );
					var fo = $("#browse_3").animate({ left: "360px" }, 1000 );
					var fi = $("#browse_4").animate({ left: "480px" }, 1000 );// is moved off
					var si = $("#browse_5").animate({ left: "0px" }, 1000 );
					var se = $("#browseStatus").val(4);
					break;
				case 4: // four is off of the screen so we move it on
					var tw = $("#browse_5").animate({ left: "120px" }, 1000 ); 
					var th = $("#browse_1").animate({ left: "240px" }, 1000 );
					var fo = $("#browse_2").animate({ left: "360px" }, 1000 );
					var fi = $("#browse_3").animate({ left: "480px" }, 1000 ); // is moved off
					var si = $("#browse_4").animate({ left: "0px" }, 1000 );
					var se = $("#browseStatus").val(3);
					break;
				case 3: // three is off of the screen so we move it on
					var tw = $("#browse_4").animate({ left: "120px" }, 1000 ); 
					var th = $("#browse_5").animate({ left: "240px" }, 1000 );
					var fo = $("#browse_1").animate({ left: "360px" }, 1000 );
					var fi = $("#browse_2").animate({ left: "480px" }, 1000 );// is moved off
					var si = $("#browse_3").animate({ left: "0px" }, 1000 );
					var se = $("#browseStatus").val(2);
					break;
				case 2: // two is off of the screen so we move it on
					var tw = $("#browse_3").animate({ left: "120px" }, 1000 ); 
					var th = $("#browse_4").animate({ left: "240px" }, 1000 );
					var fo = $("#browse_5").animate({ left: "360px" }, 1000 );
					var fi = $("#browse_1").animate({ left: "480px" }, 1000 );// is moved off
					var si = $("#browse_2").animate({ left: "0px" }, 1000 );
					var se = $("#browseStatus").val(1);
					break;
				case 1: // one is off of the screen so we move it on
					var tw = $("#browse_2").animate({ left: "120px" }, 1000 ); 
					var th = $("#browse_3").animate({ left: "240px" }, 1000 );
					var fo = $("#browse_4").animate({ left: "360px" }, 1000 );
					var fi = $("#browse_5").animate({ left: "480px" }, 1000 ); // is moved off
					var si = $("#browse_1").animate({ left: "0px" }, 1000 );
					var se = $("#browseStatus").val(5);
					break;
				case 0:
					break;
			}
			break;
			
		case "right":
			switch(status){
				case 5: // Five is off of the screen so we move it on
					var tw = $("#browse_1").animate({ left: "-120px" }, 1000 ) // is moved off
					var th = $("#browse_2").animate({ left: "0px" }, 1000 )
					var fo = $("#browse_3").animate({ left: "120px" }, 1000 )
					var fi = $("#browse_4").animate({ left: "240px" }, 1000 )
					var si = $("#browse_5").animate({ left: "360px" }, 1000 )
					var se = $("#browseStatus").val(1);
					break;
				case 4: // four is off of the screen so we move it on
					var tw = $("#browse_5").animate({ left: "-120px" }, 1000 ) // is moved off
					var th = $("#browse_1").animate({ left: "0px" }, 1000 )
					var fo = $("#browse_2").animate({ left: "120px" }, 1000 )
					var fi = $("#browse_3").animate({ left: "240px" }, 1000 )
					var si = $("#browse_4").animate({ left: "360px" }, 1000 )
					var se = $("#browseStatus").val(5);
					break;
				case 3: // three is off of the screen so we move it on
					var tw = $("#browse_4").animate({ left: "-120px" }, 1000 ) // is moved off
					var th = $("#browse_5").animate({ left: "0px" }, 1000 )
					var fo = $("#browse_1").animate({ left: "120px" }, 1000 )
					var fi = $("#browse_2").animate({ left: "240px" }, 1000 )
					var si = $("#browse_3").animate({ left: "360px" }, 1000 )
					var se = $("#browseStatus").val(4);
					break;
				case 2: // two is off of the screen so we move it on
					var tw = $("#browse_3").animate({ left: "-120px" }, 1000 ) // is moved off
					var th = $("#browse_4").animate({ left: "0px" }, 1000 )
					var fo = $("#browse_5").animate({ left: "120px" }, 1000 )
					var fi = $("#browse_1").animate({ left: "240px" }, 1000 )
					var si = $("#browse_2").animate({ left: "360px" }, 1000 )
					var se = $("#browseStatus").val(3);
					break;
				case 1: // one is off of the screen so we move it on
					var tw = $("#browse_2").animate({ left: "-120px" }, 1000 ) // is moved off
					var th = $("#browse_3").animate({ left: "0px" }, 1000 )
					var fo = $("#browse_4").animate({ left: "120px" }, 1000 )
					var fi = $("#browse_5").animate({ left: "240px" }, 1000 )
					var si = $("#browse_1").animate({ left: "360px" }, 1000 )
					var se = $("#browseStatus").val(2);
					break;
				case 0:
					break;
			}
			break;
	}
	setTimeout("enableScroll()", 1000);

}

function enableScroll(){
	var eight = $("#browseArrowLeft").show();
	var nine = $("#browseArrowRight").show();
}

function disableScroll(){
	var eight = $("#browseArrowLeft").hide();
	var nine = $("#browseArrowRight").hide();
}

function clearField(){
	$(".topSearchField").val("");
}


