// JavaScript Document


var imgObjectArr = [];
var bgObjectArr = [];
var bioClipArray = [];


//bio navigation
var bioIndex = 0;

//bio detail hero image
var bioDisplayMain = new Image();


function imagePreload() {
	
	for (i = 0; i < mainObjectArray.length; i++) {
        var canvasImage = new Image();
        canvasImage.src = mainObjectArray[i].path;
		
        imgObjectArr.push(canvasImage);
    }

	initialize();
}


function initialize() {
	createClip();
	
	//Assign Click Functions
	$("#bioPrevious").click(function(){
		bioIndex--;
		changeBioInfo();
		return false;	
	});
	$("#bioClose").click(function(){
		enableClipBoards()
		$("#bioContainer").fadeOut();
		$.address.value("/About.aspx");
		return false;	
	});
	$("#bioNext").click(function(){
		bioIndex++;
		changeBioInfo();	
		return false;	
	});
	
	
}

function createClip(){
	for(i=0; i<mainObjectArray.length; i++){
		bioClipArray[bioClipArray.length] = new BioClip(bioClipArray.length);
	}	
}

function BioClip(msg) {
		
	this.bioName = mainObjectArray[msg].name;
	this.bioTitle = mainObjectArray[msg].title;
	this.bioText = mainObjectArray[msg].bio;
	this.bioBag = mainObjectArray[msg].bag;
	this.bioDisclaimer = mainObjectArray[msg].disclaimer;
	
	this.thumb = imgObjectArr[msg];
	
}



function enableClipBoards(){
	$('.hit').click(function(){
		$("#bioContainer").fadeIn();	
		$('.hit').unbind('click');
		bioIndex = this.id;
		changeBioInfo()
	});
}

function changeBioInfo(){
	
	if(bioIndex > bioClipArray.length - 1){
		bioIndex = 0;
	} else if( bioIndex < 0 ){
		bioIndex = bioClipArray.length - 1;
	}
	// Change the bio icon
	//bioDisplayMain.src = imgObjectArr[bioIndex].src;
	//$('#bioIcon').attr('src', imgObjectArr[bioIndex].src);
	//alert(imgObjectArr[bioIndex].src);
	//document.getElementById('bioIcon').src = imgObjectArr[bioIndex].src;
	document.getElementById('bioIcon').src = mainObjectArray[bioIndex].path
	//alert(imgObjectArr[bioIndex].src);
	/*bioDisplayMain.onload = function(){
		drawBioIcon();
	}*/
	
	//$("#bioIcon").html("<img src='" + bioClipArray[bioIndex].thumb.src + "' class='bioPhotoImg' />");
	$("#bioName").text(mainObjectArray[bioIndex].name);
	$("#bioTitle").text(mainObjectArray[bioIndex].title);
	$("#bioText").html(mainObjectArray[bioIndex].bio);
	if(mainObjectArray[bioIndex].bag){
		$("#WhatBag").show();
		$("#bioBag").show();
		$("#bioBag").html(mainObjectArray[bioIndex].bag);
	} else {
		$("#WhatBag").hide();
		$("#bioBag").hide();
	}

	if(mainObjectArray[bioIndex].bioDisclaimer){
		$("#bioDisclaimer").show();
		$("#bioDisclaimer").text(mainObjectArray[bioIndex].bioDisclaimer);
	} else {
		$("#bioDisclaimer").hide();
	}		
}


