var xmlHttp
var pxmlHttp
var status=0;
var curPhotoID=0;
var fromFile=0;
var productID=0;
var max_height = 360;
var max_width = 500;


function hideDivGallery(){
	document.getElementById("gallerycontent").style.display = "none";	
	document.getElementById("gallery").style.display = "none";
	document.getElementById("gallery").innerHTML="";
	document.getElementById("fonfix").style.display = "none";
	document.getElementById("conteiner").style.display = "none";	

	var obj=document.getElementById("gallerycontent");	
	obj.style.display = "none";
	obj.style.width = 100+"px";
	obj.style.height = 100+"px";
	
	showSelectBoxes();
}


function showGallery(photoID,ind,heightPic,file,prodID){

	hideSelectBoxes();	
	
	//show overlay div		
	var fondiv=document.getElementById("fonfix");	
	fondiv.style.display = "block";

	var bwidth=GetWidth();
	fondiv.style.width=bwidth+"px";
		
	var bheight=GetHeight();			
	fondiv.style.height = bheight+"px";			

	
	if(status!=ind) status=ind;
	if(curPhotoID!=photoID) curPhotoID=photoID;
	if(fromFile!=file) fromFile=file;
	if(productID!=prodID) productID=prodID;

	document.getElementById("conteiner").style.display = "block";	
	document.getElementById("gallerycontent").style.display = "block";		
	document.getElementById("gallery").style.display = "block";
	document.getElementById("content").style.display = "none";	
	
	if(ind!=1) HeightDivDown(30);
	OpGalleryDown(photoID,100,heightPic);
}

function SlideDive(photoID,heightPic){
	
	document.getElementById("gallery").innerHTML="";
	
	if(status==1){
		slideHeight(100,photoID);
	}
	else{
			
		if(heightPic> max_height){
			slideHeightUp(heightPic,max_height,photoID);
		}
		else{
			slideHeightDown(heightPic,max_height,photoID);
		}
		
	}

	if(max_height!=heightPic) max_height=heightPic;	
		
}

function galleryContent(photoID){
	
	
	var loadDiv=document.getElementById("load");
	loadDiv.style.display = "block";
	loadDiv.style.height=max_height+"px";
	
	
	var GalleryDiv=document.getElementById("gallery");
	GalleryDiv.style.display = "none";

	pxmlHttp=GetXmlHttpObject()
	if (pxmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	var url="gallerycontent.php"
	url=url+"?phID="+photoID
	url=url+"&productID="+productID	
	url=url+"&fromFile="+fromFile

	url=url+"&sid="+Math.random()
	pxmlHttp.onreadystatechange=stateChangedPic 
	pxmlHttp.open("GET",url,true)
	pxmlHttp.send(null)	
		
}

function stateChangedPic() 
{ 
	if (pxmlHttp.readyState==4 || pxmlHttp.readyState=="complete")
	{		
		document.getElementById("gallery").innerHTML=pxmlHttp.responseText 	
		ShowPic();	
	}
}
function ShowPic(){
	document.getElementById("load").style.display = "none";
	
	var GalleryDiv=document.getElementById("gallery");
	GalleryDiv.style.display = "block";	
	
	OpGalleryUp(0);
}

function TextGallery(){	

	pxmlHttp=GetXmlHttpObject()
	if (pxmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	

	var url="textcontent.php"
	url=url+"?photoID="+curPhotoID	
	url=url+"&productID="+productID
	url=url+"&fromFile="+fromFile
	
	url=url+"&sid="+Math.random()
	pxmlHttp.onreadystatechange=stateChangedClient 
	pxmlHttp.open("GET",url,true)
	pxmlHttp.send(null)		
}

function stateChangedClient() 
{ 
	if (pxmlHttp.readyState==4 || pxmlHttp.readyState=="complete")
	{
		var contentObj=document.getElementById("content");
		document.getElementById("idphoto").innerHTML="";
		document.getElementById("idclose").innerHTML="";
		
		contentObj.style.height = 0+"px";
		contentObj.style.display="block"
		
		obj = document.getElementById("gallerycontent");
		var newHeight=max_height+10;
		obj.style.height = newHeight +"px";
		
		HeightDivUp(0);
	}
}

function showContentText(){
		setOpacity('textgall',100);
		setOpacity('idclose',100);	
		document.getElementById("idphoto").innerHTML=pxmlHttp.responseText 
		document.getElementById("idclose").innerHTML="<span onclick='hideDivGallery();' style='cursor:pointer;'><img src='images/closelabel.gif'></span>";
		
}

	
function HeightDivUp (heightDiv){

	if (heightDiv <30) {	
		obj = document.getElementById("gallerycontent");
		var newHeight=max_height+heightDiv+10;		
		obj.style.height = newHeight +"px";
		
		heightDiv =(1*heightDiv) + 10;		
		obj = document.getElementById("content");
		obj.style.height = heightDiv +"px";
			
		window.setTimeout("HeightDivUp("+heightDiv+")", 20);
	}
	else{
		showContentText();	
	}
}


function HeightDivDown (heightDiv){
	if (heightDiv > 0) {			
		heightDiv =(1*heightDiv) - 10;	
		obj = document.getElementById("content");
		obj.style.height = heightDiv +"px";	

		obj = document.getElementById("gallerycontent");
		var newHeight=max_height+heightDiv;	
		obj.style.height = newHeight +"px";
				
		window.setTimeout("HeightDivDown("+heightDiv+")", 20);
	}
	else{
		obj = document.getElementById("gallerycontent");
		obj.style.height = max_height +"px";	
		document.getElementById("content").style.display="none";	
		
	}
}
//-----------------------------------------------------
function OpGalleryDown(photoID,opacity,heightPic) {
	if (opacity > 0) {
		opacity =(1*opacity) - 10;
		
		setOpacity('tdgallery',opacity);
		window.setTimeout("OpGalleryDown("+photoID+","+opacity+","+heightPic+")", 20);
	}
	else{	
		SlideDive(photoID,heightPic);
	}
}
function OpGalleryUp(opacity){
	if (opacity < 100) {
		opacity =(1*opacity) + 10;
		setOpacity('tdgallery',opacity);
		window.setTimeout("OpGalleryUp("+opacity+")", 20);
	}
	else{
	
		TextGallery();
	}
}
function setOpacity(id,opacity){
		obj = document.getElementById(id);
		// IE/Win
		obj.style.filter = "alpha(opacity:"+opacity+")";
		// Safari<1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
		// Safari 1.2, newer Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;		
}

// ---------------------------------------------------

function slideHeightUp(height,max_height,photoID){
	if (height > max_height) {
		max_height =(1*max_height) + 10;			
		obj = document.getElementById("gallerycontent");
		obj.style.height = max_height+"px";
		window.setTimeout("slideHeightUp("+height+","+max_height+","+photoID+")", 10);
	}	
	else{	
	
		galleryContent(photoID);
	}
}

function slideHeightDown(height,max_height,photoID){
	if (height < max_height) {		
		mh=(1*max_height) - 10;	

		if(height > mh) {
			max_height=height;
		}else{
			max_height =(1*max_height) - 10;					
		}
		obj = document.getElementById("gallerycontent");
		obj.style.height = max_height+"px";
		window.setTimeout("slideHeightDown("+height+","+max_height+","+photoID+")", 10);
	}	
	else{	
		galleryContent(photoID);
	}
}

function slideHeight(height,photoID){
	if (height < max_height) {
		height =(1*height) + 10;			
		obj = document.getElementById("gallerycontent");
		obj.style.height = height+"px";
		window.setTimeout("slideHeight("+height+","+photoID+")", 10);
	}
	else{		
		slide(100,photoID);
	}
}

function slide(width,photoID){
	if (width < max_width) {
		width =(1*width) + 10;
		obj = document.getElementById("gallerycontent");
		obj.style.width = width +"px";
		window.setTimeout("slide("+width+","+photoID+")", 5);
	}
	else{
		galleryContent(photoID);
	}
}
// ---------------------------------------------------

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

//----------------------------------------------------------
function divOverPrev(prev){
	if(prev>0){		
		document.getElementById("prevlebl").style.display = "block";	
	}	
}

function divOutPrev(){
	document.getElementById("prevlebl").style.display = "none";	
}

function divOverNext(next){
	if(next>0){		
		document.getElementById("nextlebl").style.display = "block";
	}
}
function divOutNext(){
	document.getElementById("nextlebl").style.display = "none";	
}


//---------------------------------------------
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function GetWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}

function GetHeight()
{
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}
