/**author Anubhav Chopra
 * 
 * Instructions on how to add new Featured Fish:
 * 			1.	NOTE: The most latest fish goes on top (index = 0 and first fish to be displayed)
 * 			2.  Add the Image in ImageSrc[0], increment the other index i.e. Now the ImageSrc[0] will be ImageSrc[1] since you added element in ImageSrc[0]
 * 			3.  Repeat 2. for URL, this is the link to the Featured Fish Page
 * 			4.	Repeat 2. for Title, that is the title of the featured fish, ex: Whale Shark
 * 			5.	Repeat 2. for DukText, that is the Did you know text.
 * 			6.	NOTE: Do not Touch anyother functionality, unless needed to be changed or fixed.
 * **/

var which_box_loaded =0;
var TOTAL_BOX=4;	//when adding new box, change the value to the total number of elements
var ImageSrc = new Array();	//add the new Image source when adding a new box
var DukText = new Array();	//add the new Did you Know text when adding a new box
var URL = new Array(); //add the new link to the page
var Title = new Array();
var flagStart = 0;
var firstPlay = 0;
var myTime;
var pause =0;

ImageSrc[0] = "images/whaleshark.jpg";
ImageSrc[1] = "images/smoothhammerhead.jpg";
ImageSrc[2] = "images/greatwhite.jpg";
ImageSrc[3] = "images/fangtooth.jpg";


URL[0] = "whale_shark/";
URL[1] = "smooth_hammerhead/";
URL[2] = "great_white/";
URL[3] = "fangtooth/";

Title[0] = "Whale Shark";
Title[1] = "Smooth Hammerhead Shark";
Title[2] = "Great White Shark";
Title[3] = "Fangtooth";

DukText[0] ="The whale shark employs suction filter feeding mechanisms, as opposed to relying on forward motion to opportunistically capture prey. It can also use continuous ram filter feeding and vertical suspension feeding. For instance, it will hang at a 45-degree angle in the water column and suck prey into its mouth.";
DukText[1] ="The hammer-shape cephalofoil (head) may enhance anterior binocular vision which can provide for an increase in the sampling area for the lateral line canals and may aid in prey handling capabilities.";
DukText[2] = "The great white is a highly versatile predator that feeds on a wide range of prey, including teleost (or bony) fishes, squid, marine mammals, and other chondrichthyans. It has a highly foliated cerebellum, which may be linked to the 3-dimensional oceanic environment in which it lives and its predation on highly active, agile prey.";
DukText[3] = "The common name for the family comes from the numerous elongate fanglike teeth projecting out of the mouths of adults. Their enormous heads are about 1/3 of their body length. Their heads are punctuated by equivalently enormous jaws of equal length.";

/*DO NOT TOUCH*/

/*TOP BOX*/
document.write('<div id="box' +which_box_loaded+ '">');
document.write('<h3 class = "title_ff" id = "title"><a href ='+ URL[0] +' style="text-decoration:none; color:#3976BD;">'+Title[0]+'</a></h3>');
document.write('<div class = "rightbox_ff">');
document.write('<h3 class ="duk_ff">Did You Know?</h3>');
document.write('<div class="text_ff" id="duktext">'+DukText[0]+'  '+'<a href = '+URL[0]+' target = "_blank">View Full Article </a></div></div><div id="imageLink"><a href = '+URL[0]+'><img class = "image_ff" name = "box_image" src="images/whaleshark.jpg"/></a></div></div>');
document.write('<div class= "direction"><div name = "where" id = where_ff>'+(which_box_loaded+1)+' of '+TOTAL_BOX+'</div>');
document.write('<img id = "leftarrow_ff" name="leftArrow" onMouseOut="javascript: MouseOffArrow(-1);" onMouseOver="javascript: MouseOnArrow(-1);" onClick="javascript: changeBox(-1);"  src="images/leftarrow.png"/>');
document.write('<img id = "pause_ff" name="pause" onMouseOut="javascript: MouseOffArrow(0);" onMouseOver="javascript: MouseOnArrow(0);" onClick="javascript: PauseIt();" src="images/pause.png"/>');
document.write('<img id = "rightarrow_ff" name="rightArrow" onMouseOut="javascript: MouseOffArrow(1);" onMouseOver="javascript: MouseOnArrow(1);" onClick="javascript: changeBox(1);" src="images/rightarrow.png"/></div>');
//window.onload = start(); 

rotate(pause);
function loadBox(box_to_load){
	//$('\'#box' +which_box_loaded+'\'').fadeIn('slow',function(box_to_load){
	var image = ImageSrc[box_to_load];
	$('#box0').fadeIn("slow",function(){
	//document.box_image.src = image;//imageThis[box_to_load];
	document.getElementById('title').innerHTML='<a href ='+ URL[box_to_load] +' style="text-decoration:none;color:#3976BD;">'+Title[box_to_load]+'</a>';
	document.getElementById('duktext').innerHTML=DukText[box_to_load]+'  '+'<a href = '+URL[box_to_load]+' target = "_blank">View Full Article </a>';
	document.getElementById('imageLink').innerHTML='<a href = '+URL[box_to_load]+'><img class = "image_ff" name = "box_image" src="'+image+'"/></a></div>';
	document.getElementById('where_ff').innerHTML=(box_to_load+1)+' of '+TOTAL_BOX;
	});
}






function rotate(pause){
	
	if(flagStart != 0){
		if(pause == 0 && firstPlay!=0){
			changeBox(1);
		}
	}
	
	if(pause == 0){
		flagStart = 1;
		firstPlay = 1;
		myTime = setTimeout("rotate(pause)",10000)
	}
}

function PauseIt(){
	if(pause == 0){
		pause=1;
		document.pause.src = "images/play.png";
	}
	else{ 
		pause = 0;
		firstPlay = 0;
		clearTimeout(myTime);
		document.pause.src = "images/pause.png";
		rotate(pause);
	}
}

function MouseOnArrow(whichArrow){
	if(whichArrow ==0){
		if(pause == 0){
			document.pause.src = "images/pauseH.png";		
		}
		else{
			document.pause.src = "images/playH.png";		
		}
	}
	
	else if(whichArrow==-1){
		document.leftArrow.src = "images/leftarrowH.png";
	}
	else{
		document.rightArrow.src = "images/rightarrowH.png";
	}
}

function MouseOffArrow(whichArrow){
	if(whichArrow ==0){
		if(pause == 0){
			document.pause.src = "images/pause.png";		
		}
		else{
			document.pause.src = "images/play.png";		
		}

	}
	else if(whichArrow<1){
		document.leftArrow.src = "images/leftarrow.png";
	}
	else{
		document.rightArrow.src = "images/rightarrow.png";
	}
}

/*change direction of arrow and box visibility*/
function changeBox(direction) {
	//var current_box = 'box'+which_box_loaded;
	//document.getElementById(current_box).style.visibility ="hidden";
	if(direction <1){
		which_box_loaded--;
	}
	else{
		which_box_loaded++;
	}
	
	if(which_box_loaded<0){
		which_box_loaded=3;
	}
	if(which_box_loaded>3){
		which_box_loaded=0;
	}

	firstPlay = 0;
	loadBox(which_box_loaded);
	
	
//	/'<div name = "where" id = where_ff>'+(which_box_loaded+1)+' of 4</div>';
	//style = "text-align = center; float=left; font-style=italic; margin-top=2px; margin-right=5px; margin-left=10px;
	//document.write('<div name = "where" id = where_ff>'+(which_box_loaded+2)+' of 4</div>');
	//document.getElementById('where_ff').style.visibility = "visible";
    
    //var myURL = "http://www.rnmd.net/iphone/microsites/kia/power/trackingPixel.png";
    //myRand = parseInt(Math.random()*99999999);
    //trackingImage.src = myURL + "?rand=" + myRand;
}

//
//function buyButton(){
//    
//    var myURL = "http://www.rnmd.net/iphone/microsites/kia/power/BuyButtontrackingPixel.png";
//    myRand = parseInt(Math.random()*99999999);
//    ButtontrackingImage.src = myURL + "?rand=" + myRand;
//}
