//-----------------------------
// Image gallery JS functions
//-----------------------------
function winSize() {
  var winWidth = 0, winHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    winWidth = document.documentElement.clientWidth;
    winHeight = document.documentElement.clientHeight;
  }
	document.getElementById('largeImgDiv').style.marginLeft = Math.max(0, (winWidth-422)/2)+'px';
}

window.onresize=winSize; 

function divSize(){
	var headTopDivHeight = document.getElementById('pageHeaderTop').clientHeight;
	var headMidHeight    = document.getElementById('pgHeadMid').clientHeight;
	var mainDivHeight    = document.getElementById('mainDiv').clientHeight;
	var footerDivHeight    = document.getElementById('footer').clientHeight;
	
	document.getElementById('leftPane').style.height = mainDivHeight+'px';
	document.getElementById('transDiv').style.height = headTopDivHeight + headMidHeight + mainDivHeight + footerDivHeight + 'px';

}

var curserOverImg = false;
var curserOverTxtBox = false;

function overImg(event){
	if(!curserOverImg && !curserOverTxtBox){
		x=event.clientX
		y=event.clientY
		var textBoxWidth = document.getElementById('imgDescriptionDiv').clientWidth;
		document.getElementById('imgDescriptionDiv').style.display = '';
		document.getElementById('imgDescriptionDiv').style.marginLeft = Math.max(0, (x-textBoxWidth-60))+'px';
		document.getElementById('imgDescriptionDiv').style.marginTop = Math.max(0, (y-14))+'px';
		curserOverImg = true;
		
		document.getElementById('imgTxtBoxTxt').innerHTML = "X coords: " + x + ", Y coords: " + y;
	}
}
function outImg(){
	if(!curserOverTxtBox){
		document.getElementById('imgDescriptionDiv').style.display = 'none';
		curserOverImg = false;
	}
}
function overTextBox(){
	curserOverTxtBox = true;
	curserOverImg = true;
	document.getElementById('imgDescriptionDiv').style.display = '';
}
function outTextBox(){
	if(curserOverImg){
		curserOverImg = false;
	}
		curserOverTxtBox = false;
		document.getElementById('imgDescriptionDiv').style.display = 'none';
}

function show_coords(event){
	x=event.clientX
	y=event.clientY
	
//	var textBoxWidth = document.getElementById('imgDescriptionDiv').clientWidth;
//	document.getElementById('imgDescriptionDiv').style.display = '';
	document.getElementById('imgDescriptionDiv').style.marginLeft = Math.max(0, (x-200))+'px';
	document.getElementById('imgDescriptionDiv').style.marginTop = Math.max(0, (y))+'px';
	document.getElementById('imgDescriptionDiv').style.display = '';
	
//	document.getElementById('imgTxtBoxTxt').innerHTML = "X coords: " + x + ", Y coords: " + y;
	
	//alert("X coords: " + x + ", Y coords: " + y); imgDescriptionDiv
}

function show_coords_img_gal(event, label, desc, large_image_path){
	x=event.clientX
	y=event.clientY

	// Set the label and description for the spscific image
	document.getElementById('imgTexBoxHead').innerHTML = label;
	document.getElementById('imgTxtBoxTxt').innerHTML = desc;
	document.getElementById('largeImagePath').innerHTML = large_image_path;
	document.getElementById('imgDescriptionDiv').style.marginLeft = Math.max(0, (x-200))+'px';
	document.getElementById('imgDescriptionDiv').style.marginTop = Math.max(0, (y))+'px';
	document.getElementById('imgDescriptionDiv').style.display = '';
}

function endsWith(doesItEnd, withThis){
 return (doesItEnd.match(withThis+"$")==withThis);
}


function showLargeImg(){

	// Get the title and description and large image path from the small popup and set the div values
	document.getElementById('title').innerHTML = document.getElementById('imgTexBoxHead').innerHTML;
	document.getElementById('text').innerHTML = document.getElementById('imgTxtBoxTxt').innerHTML;

	var mediapath = document.getElementById('largeImagePath').innerHTML;
	var mediaHTML = '';
	if(endsWith(mediapath, '.swf'))
	{
		mediaHTML = "<embed type=\"application/x-shockwave-flash\"\n"+ 
  	         "src=\""+mediapath+"\" \n" +
  	         "id=\"swfPromo_0\" name=\"swfPromo_0\" bgcolor=\"#ffffff\" "+
  	         "quality=\"best\"  style=\"height:100%; width:100%;\" scale=\"exactfit\""+
  	         "wmode=\"transparent\">\n";
	}
	else if(endsWith(mediapath, '.mpg') || endsWith(mediapath, '.mpeg') || endsWith(mediapath, '.avi') || endsWith(mediapath, '.mov') || endsWith(mediapath, '.wmv'))
	{
		mediaHTML = "<EMBED SRC=\"" + mediapath + "\" WIDTH='400' HEIGHT='300'>";
	}
	else
	{
		mediaHTML = '<img name="largeImage" src="' + mediapath + '" alt="" width="400" height="300" />'
	}
	document.getElementById('downloadLink').href="/Download.bsci?method="+mediapath;
	document.getElementById('mediaPath').innerHTML = mediaHTML;

	// Show the divs
	document.getElementById('largeImgDiv').style.display = '';
	document.getElementById('transDiv').style.display = '';
	

}

function close_popup() {
 document.getElementById('imgDescriptionDiv').style.display = 'none';
}


function showTextBox(){
    winWidth = document.documentElement.clientWidth;
	document.getElementById('imgDescriptionDiv').style.marginLeft = (winWidth/2)+90+'px';
	document.getElementById('imgDescriptionDiv').style.marginTop = 195+'px';
	document.getElementById('imgDescriptionDiv').style.display = '';
}

// JB - Show and Hide multiple elements.
function showHideElms(s){
	args=showHideElms.arguments;
	for (i=1; i<args.length; i++){
		document.getElementById(args[i]).style.display = (s=='on'?'':'none');
	}
}

function imgGalleryToggleShow(showtype)
{
  if(showtype == 'all')
  {
	  // Hide the show all link and display the show fewer link
	  document.getElementById("showAllLink").style.display = 'none';
	  document.getElementById("showFewLink").style.display = '';
	  
	  // Display the second ImgHolder_2 div which contains the remaining images
	  document.getElementById("imgHolder_2").style.display = '';
  }
  else
  {
  	  // Hide the show all link and display the show fewer link
	  document.getElementById("showAllLink").style.display = '';
	  document.getElementById("showFewLink").style.display = 'none';
	  
	  // Display the second ImgHolder_2 div which contains the remaining images
	  document.getElementById("imgHolder_2").style.display = 'none';
  }
}

