var galery_offset=0;
var galery_offset_min;
var loadingImg = "data/loading.gif";

var galery_index = -1;
var galery_array = new Array();


function galery_left_over()
{
  document.getElementById("galery_image_left").src="data/arrow-left-red.gif";
  return false;
}


function galery_left_out()
{
  document.getElementById("galery_image_left").src="data/arrow-left.gif";
  return false;
}

function galery_left_click()
{
  if (galery_offset_min<800) return false;
  galery_offset=galery_offset+200;
  if (galery_offset>0) galery_offset=0;
  document.getElementById("galery").style.left=galery_offset;
  return false;
}


function galery_right_over()
{
  document.getElementById("galery_image_right").src="data/arrow-right-red.gif";
  return false;
}



function galery_right_out()
{
  document.getElementById("galery_image_right").src="data/arrow-right.gif";
  return false;
}

function galery_right_click()
{
  if (galery_offset_min<800) return false;
  galery_offset=galery_offset-200;
  if (galery_offset<800-galery_offset_min) galery_offset=800-galery_offset_min;
  document.getElementById("galery").style.left=galery_offset;
  return false;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


// Returns array with page width, height and window width, height
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 
  return arrayPageSize;
}


function showMediaBox(type,objLink,wi,he,comment)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

  if (type==1)
  {
    var objOverlayMed=document.getElementById('overlayMed');
    var objLightBoxMed=document.getElementById('mediaBoxMed');
    var objLightBoxDivMed=document.getElementById('mediaDivMed');
    var objObjectMed = document.createElement("object");
    objObjectMed.setAttribute("id","mediaObjectMed");
    objObjectMed.setAttribute('type','application/x-shockwave-flash');
    objObjectMed.setAttribute('width',wi); 
    objObjectMed.setAttribute('height',he);
    objObjectMed.setAttribute('data','data/player_flv_mini.swf');
    objLightBoxDivMed.appendChild(objObject);
    var objParam1 = document.createElement("param");
    objParam1.setAttribute("name","FlashVars");
    objParam1.setAttribute("id","lightboxObjectParam1");
//    objParam1.setAttribute("value","flv=../"+objLink+"&autoplay=1&width="+wi+"&height="+he);
//    objParam1.setAttribute("value","flv=../Wildlife.flv&autoplay=1&width="+wi+"&height="+he);
    objObjectMed.appendChild(objParam1);
    var objParam2 = document.createElement("param");
    objParam2.setAttribute("name","movie");
    objParam2.setAttribute("value","data/player_flv_mini.swf");
    objObjectMed.appendChild(objParam2);
    var objParam3 = document.createElement("param");
    objParam3.setAttribute("name","wmode");
    objParam3.setAttribute("value","transparent");
    objObjectMed.appendChild(objParam3);
  }
  if (type==0)
  {
    var objOverlayMed=document.getElementById('overlayMed');
    var objLightBoxMed=document.getElementById('mediaBoxMed');
    var objLightBoxDivMed=document.getElementById('mediaDivMed');
    var objObjectMed = document.createElement("img");
    var nextObjLink = parseInt(objLink)+1;
    if (nextObjLink == galery_array.length) nextObjLink=0;
//var nextOnClick="hideMediaBox(); showMediaBox(0,"+nextObjLink+",0,0,''); return false;"; 
//var nextOnClick="hideMediaBox(); return false;";
    objObjectMed.setAttribute("src",loadingImg);
    objObjectMed.setAttribute("id","mediaObjectMed");
    objObjectMed.onclick=function(){
      hideMediaBox();
      showMediaBox(0,nextObjLink,0,0,galery_array[nextObjLink][1]);
      return false;
    };
    objLightBoxDivMed.appendChild(objObjectMed);
    var newImg= new Image();
    newImg.onload=function(){
      objLightBoxMed.style.display='none';
      objLightBoxDivMed.removeChild(objObjectMed);
      objObjectMed.src=galery_array[objLink][0];
      he=newImg.height;
      wi=newImg.width;
    	var lightBoxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - he) / 2);
      var lightBoxLeft = ((arrayPageSize[0] - 20 - wi) / 2);
      objLightBoxDivMed.appendChild(objObjectMed);
    	objLightBoxMed.style.top = (lightBoxTop < 0) ? "0px" : lightBoxTop + "px";
    	objLightBoxMed.style.left = (lightBoxLeft < 0) ? "0px" : lightBoxLeft + "px";
      objLightBoxMed.style.width = (wi+14)+"px";
      objLightBoxMed.style.display='block';
      return false;
    }
    newImg.src=galery_array[objLink][0];
    var loadImg= new Image();
    loadImg.src=loadingImg;
    he=loadImg.height;
    wi=loadImg.width;
  }

  var lightBoxDetailsMed = document.getElementById('mediaDetailMed');
  lightBoxDetailsMed.style.display = 'block';
	lightBoxDetailsMed.innerHTML = comment;

//	var lightBoxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - he) / 2);
//  var lightBoxLeft = ((arrayPageSize[0] - 20 - wi) / 2);
//	objLightBoxMed.style.top = (lightBoxTop < 0) ? "0px" : lightBoxTop + "px";
//	objLightBoxMed.style.left = (lightBoxLeft < 0) ? "0px" : lightBoxLeft + "px";
//  objLightBoxMed.style.width = (wi+14)+"px";

  objOverlayMed.style.display='block';
  objLightBoxMed.style.display='block';
	arrayPageSize = getPageSize();
	objOverlayMed.style.height = (arrayPageSize[1] + 'px');
  return false;
}

function hideMediaBox()
{
  var objLightboxMed=document.getElementById('mediaBoxMed');
  var objLightboxDivMed=document.getElementById('mediaDivMed');
  var objOverlayMed=document.getElementById('overlayMed');
  var objObjectMed=document.getElementById('mediaObjectMed');
  var lightBoxDetailsMed = document.getElementById('mediaDetailMed');
  lightBoxDetailsMed.style.display='none';
  objLightboxDivMed.removeChild(objObjectMed);
  objOverlayMed.style.display='none';
  objLightboxMed.style.display='none';
  return false;
}

function openVideoWindow(objLink,wi,he,comment)
{
  var wid=wi+15;
  var hei=he+60;
  var str='location=no,menubar=no,status=no,toolbar=no,width='+wid+',height='+hei;
  var d=new Date().getTime();
  var VideoWindow=window.open("",d,str,false);
//  VideoWindow.close();
//  VideoWindow=window.open("","_blank",str,false);  

  VideoWindow.document.write('<object data="data/player_flv_mini.swf" type="application/x-shockwave-flash" id="mediaObject" width="480" height="360">');
//  VideoWindow.document.write('<param value="flv=../galery/Wildlife.flv&amp;autoplay=1&amp;width=480&amp;height=360" id="lightboxObjectParam1" name="FlashVars">');
  VideoWindow.document.write('<param value="flv=../'+objLink+'&amp;autoplay=1&amp;width=480&amp;height=360" id="lightboxObjectParam1" name="FlashVars">');
  VideoWindow.document.write('<param value="data/player_flv_mini.swf" name="movie">');
  VideoWindow.document.write('<param value="transparent" name="wmode"></object>');
  VideoWindow.document.write('<br/>');
  VideoWindow.document.write(comment);

  VideoWindow.focus();
  return false;
}


