var curDiv = "home_content_block";
/********************************* 
//
	function updateDIV(_divVal)
	Script to handle page content
//
********************************* */

function updateDIV(_divVal){
	_divVal = _divVal+'_block';
	if($(curDiv).hasClass('div_on')){
		$(curDiv).addClass('div_off');
		$(curDiv).removeClass('div_on');
	}
	$(_divVal).addClass('div_on');
	$(_divVal).removeClass('div_off');
	if(_divVal == "gallery_content_block"){
		var tempID = $E('a','thumb_container').getProperty('id');
		programGalleryThumbs();
		updateMain(tempID);
	}
	curDiv = $(_divVal);
	fUpdateMenu(_divVal);
}

/*Tell menu to light up*/
function fUpdateMenu(mid){

	if(getFlashMovie('flash_container_flash') != undefined){
	//alert('flash name : '+getFlashMovie('flash_container_flash'));
		getFlashMovie('flash_container_flash').updateNavigation(mid);
	}

}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
//  alert('movieName :'+movieName);
  return (isIE) ? window[movieName] : document[movieName];
}

/********************************* 
//
	function updateMain(imgVal)
	Script to handle main gallery image
//
********************************* */
function updateMain(imgVal){

	var isVid = $('vid_div').hasClass('div_on');
	var isGetFlash = $('get_flash_button').hasClass('div_on');
	
	if(isVid || isGetFlash){
		
		$('vid_div').addClass('div_off');
		$('vid_div').removeClass('div_on');
		$('main_img').addClass('div_on');
		$('main_img').removeClass('div_off');
		if(isGetFlash){
			$('get_flash_button').addClass('div_off');
			$('get_flash_button').removeClass('div_on');
		}
	}
	
	var tempImg = '/images/gallery/'+imgVal+'.jpg';
	$('main_img').setStyles('border: 1px solid #000; background-image: url('+tempImg+')');
	
	updateCaption(imgVal);
	
}
function growWrapper(){
	var wrapperHeightChange = new Fx.Style('wrapper', 'height', {duration:500, transition:Fx.Transitions.Sine.easeIn, fps:30, onComplete:showFlashDiv});
	wrapperHeightChange.start(600); 
	/*var heightChange = new Fx.Style('main_content', 'height', {duration:600, transition:Fx.Transitions.Sine.easeIn, fps:30});
	heightChange.start(600); 
	*/
}

function showFlashDiv(){
	//$('flash_container').addClass('div_on');
//	$('flash_container').removeClass('div_off');
}

function buildYTPlayer(vidVal){
	var tempVideo = videos[vidVal];
	var tempDiv = '';
	var isImg = $('main_img').hasClass('div_on');
	if(userData.bandwidth != 'low'){
		$('vid_div').addClass('div_on');
		$('vid_div').removeClass('div_off');
		$('main_img').addClass('div_off');
		if(isImg){
			$('main_img').removeClass('div_on');
		}
		tempDiv += '<object width="425" height="344">';
		tempDiv += '<param name="movie" value="'+tempVideo+'"></param>';
		tempDiv += '<param name="allowFullScreen" value="true"></param>';
		tempDiv += '<param name="allowscriptaccess" value="always"></param>';
		tempDiv += '<embed src="'+tempVideo+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>';
		tempDiv += '</object>';
		$('vid_div').setHTML(tempDiv);
	}else{
		$('main_img').addClass('div_off');
		if(isImg){
			$('main_img').removeClass('div_on');
		}
		$('get_flash_button').setHTML("<a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW' title='Get Flash' class='borderLR'>Get the latest Flash player to view this video.</a>");
		$('get_flash_button').removeClass('div_off');
		$('get_flash_button').addClass('div_on');
	}
	updateCaption(vidVal);
	
}

function updateCaption(cVal){
	
	var tempCaption = caption[cVal];
	//	alert('tempCaption '+tempCaption);
	if(tempCaption != undefined){
		$('caption_text').getFirst().setText(tempCaption);
		$('caption_text').addClass('borderLR');
	}else{
		$('caption_text').removeClass('borderLR');
		$('caption_text').getFirst().setText('');
	}
}
function programGalleryThumbs(){
	var thumbArray = $ES('a','thumb_container');
	for(var i=0; i<thumbArray.length; i++){
		var tempThID = thumbArray[i].getProperty('id');
		$(tempThID).addEvent('click', function(){
			var tempThClass = this.hasClass('video');		
			(tempThClass)?buildYTPlayer(this.id):updateMain(this.id);
		});
		$(tempThID).setStyle('cursor','pointer');
	}

}

function programStaticNav(){
	$('static_nav').removeClass('div_off');
	var navArray = $ES('a','static_nav');
	//var navArray = $('link_list').getElements('a');
	//alert(navArray.length);
	for(var i=0; i<navArray.length; i++){
		var tempID = navArray[i].getProperty('id');
		$(tempID).addEvent('click', function(){ 
			updateDIV(this.id)
		});
		$(tempID).setStyle('cursor','pointer');
	}
	updateDIV(navArray[0].id);
}
