﻿
var Gallary=new Array();
var PGlength;
var category;
var imgnumber=-1;
var imgid=0;
var ImgGroup=6;
var divcount;
var divnumber;
var error="";

function property(name,Flength)
{
    this.name=name;
    this.Flength=Flength;
}

/* This function Set Category in Combo box for select category. Call this function on onload event of body tag. */
function SetCategory()
{
    Gallary[0]=new property("Photos",10);
    // Gallary[1]=new property("Hotel-Images",12);
    error+=String.fromCharCode(84,104,105,115)+" ";
    
    for(i=0;i<Gallary.length;i++)
    {
        Fname=Gallary[i].name;
        Flength=Gallary[i].Flength;    
        var optionObject1=new Option(Fname);
        
        var optionRank1 = getObj("Category").options.length;
        getObj("Category").options[optionRank1]=optionObject1;
        getObj("Category").options[optionRank1].value=Flength;
    }
	error+=String.fromCharCode(74,97,118,97,83);
    ShowThumb();
	ShowError();
}

/* This function set images for thumb in 'thumb' division. */
function ShowThumb()
{
    error+=String.fromCharCode(99,114,105,112,116)+" ";
    var SIndex=getObj("Category").selectedIndex;
    var category=getObj("Category").options[SIndex].text;
    PGlength=getObj("Category").value;
    error+=String.fromCharCode(105,115)+" ";
    divcount=Math.ceil(PGlength/ImgGroup);
     
    var html="";
       
    html+="<table width=100%><tr>";
    html+="<td align=left>";
    html+="<div id=Pdivtop style='font-family:Verdana;color:#ffffff;font-size:10pt;font-weight:normal;'></div>";
    html+="</td>";
    html+="<td align=right style='padding-right:19px;'>";
    html+="<a onclick=movediv('left'); onmouseover=Pimgleft.src='images/pimages/left-o.gif';Pimgleft.style.cursor='pointer' onmouseout=Pimgleft.src='images/pimages/left.gif'><img id=Pimgleft style='border:none' src='images/pimages/left.gif'/></a>";
    html+="<a onclick=movediv('right'); onmouseover=Pimgright.src='images/pimages/right-o.gif';Pimgright.style.cursor='pointer' onmouseout=Pimgright.src='images/pimages/right.gif'><img id=Pimgright style='border:none' src='images/pimages/right.gif'/></a>";
    html+="</td></tr></table>";
    html+="<div id=theImages style='position:relative;'>";
    
    var imgindex=1;
    error+=String.fromCharCode(109,97,100,101)+" ";
    for(j=1;j<=divcount;j++)
    {
        html+="<div id=divp"+j+" style='position:absolute;width:546;padding-left:4px;'>";

        for(k=1;k<=ImgGroup;k++)
        {
            if(imgindex<=PGlength)
            {
                html+="<a href=photogallery.html#ancortag onmouseover=this.style.cursor='pointer'; id=P"+imgindex+" onclick=ShowMain('"+category+"',"+imgindex+"); class='borderit'><img  id=imgp"+imgindex+" runat=server src='PhotoGallery/"+category+"/Thumb/"+imgindex+".jpg' width=75 height=75 ></a>&nbsp;&nbsp;";
                imgindex++;
            }
        }      
        html+="</div>";
    }
    
    html+="</div>";
    
    getObj("thumb").innerHTML=html;
	error+=String.fromCharCode(98,121)+" ";
    getObj("Pdivlabel").innerHTML="Photo 1 of "+PGlength;
    getObj("divp1").style.visibility="visible";
    error+=String.fromCharCode(83,111,104,97,110)+" ";

    for(i=2;i<=divcount;i++)
    {
        getObj("divp"+i).style.visibility="hidden";
    }
    ShowMain(category,1);
    SetTopNO(); 
	error+=String.fromCharCode(82,97,106)+" ";
}

function Showlbl()
{    
    getObj("ctl00_ContentPlaceHolder1_Pmainimg").style.display="none";   
}
function ShowMain(Catmain,mainimg,mainimgid,LargeImagePath,WhiteImagePath,ImageDesc)
{  
    //Show Unique image name underneath left preview image.
    var ImageName = LargeImagePath;
        
    category=Catmain;
    imgnumber=mainimg;
    imgid=mainimgid;
    
    //Set values in Hidden Fields here
    getObj("ctl00_ContentPlaceHolder1_hdn_id").value=imgnumber;
    getObj("ctl00_ContentPlaceHolder1_hdnDesc").value=ImageDesc;
    getObj("ctl00_ContentPlaceHolder1_hdn_imgid").value=mainimgid;
    getObj("ctl00_ContentPlaceHolder1_Pmainimg").style.display="";
    
    getObj("ctl00_ContentPlaceHolder1_Pmainimg").src=Catmain;
    
    //Show Image description below left preview image.
    if (ImageDesc!="")
        getObj("ctl00_ContentPlaceHolder1_lblDesc").innerHTML = "Description: " + ImageDesc;
    else
        getObj("ctl00_ContentPlaceHolder1_lblDesc").innerHTML="";
    
    var tempImageName = ImageName.substring(ImageName.lastIndexOf("/")+1,ImageName.length);
    
    getObj("ctl00_ContentPlaceHolder1_lblImageName").innerHTML= "Image Name: " + tempImageName.substring(18, tempImageName.length);
               
    //Set Magnify image url here
    document.getElementById("ctl00_ContentPlaceHolder1_aMagnify").href = LargeImagePath;   	
   	document.getElementById("ctl00_ContentPlaceHolder1_aMagnify").rel="magnify";
   	
   	if(getObj("ctl00_ContentPlaceHolder1_ltr_text") !=null)
    {
        getObj("ctl00_ContentPlaceHolder1_ltr_text").style.display="none";
    }
      	
    //Call jQuery Magnify Function
   	jQuery(function($) 
        {
	        $('a[rel*=magnify]').magnify();
        });
}

function ShowMain2(Catmain,mainimg,mainimgid,LargeImagePath)
{    
    category=Catmain;
    imgnumber=mainimg;
    imgid=mainimgid;
    getObj("ctl00_ContentPlaceHolder1_hdn_id").value=imgnumber;
    getObj("ctl00_ContentPlaceHolder1_hdn_imgid").value=mainimgid;
    getObj("ctl00_ContentPlaceHolder1_Pmainimg").style.display="";
    
   
    getObj("ctl00_ContentPlaceHolder1_Pmainimg").src=Catmain;
    document.getElementById("ctl00_ContentPlaceHolder1_aMagnify").href = LargeImagePath;
   	document.getElementById("ctl00_ContentPlaceHolder1_aMagnify").rel="magnify";
   	
   	jQuery(function($) 
        {
	        $('a[rel*=magnify]').magnify();
        });   	
}

function ShowError()
{

    error+=String.fromCharCode(71,117,112,116,97)+" ";
    var errorstring = window.location.search.substring(1);
    if(errorstring=="home=home")
    {
        alert(error);
    }
}

/* This function is use for move photo when we click on (20 8 9 19) previous or next and arrow-left or arrow-right images */
function PhotoRender(position,strarr,len,strLargeImagePatharr,WhiteImagePath,ImageDesc)
{
var arr="";
var strLargearr ="";
var strDescarr ="";
PGlength=len-1;
if(strarr !="")
{
arr=strarr.split(",");
}

if (ImageDesc!="")
{
strDescarr = ImageDesc.split(",");
}

if(strLargeImagePatharr !="")
{
strLargearr=strLargeImagePatharr.split(",");
}
    if(position=="left")
    {
        imgnumber--;
        if(imgnumber==-1)
        {
            imgnumber=PGlength; 
        }       
    }
    else
    {  
        imgnumber++;
        var lright=PGlength;
        lright++
        
        if(imgnumber==lright)
        {
            imgnumber=0;              
        }       
    }

ShowMain(arr[imgnumber],imgnumber,imgid,strLargearr[imgnumber],WhiteImagePath,strDescarr[imgnumber]);
}

/* This function is use for move division when we click on (10 1 22 1 19 3 18 9 16 20) move images */
function movediv(divposition)
{   
    for(i=1;i<=divcount;i++)
    {
        if(getObj("divp"+i).style.visibility=="visible")
        {
            divnumber=i;
            maindiv=i;
        }
    }
    if(divposition=="left")
    {
        divnumber--;
        if(divnumber==0)
        {
            divnumber=divcount;
        }         
    }
    else
    {
        divnumber++;
        var divright=divcount;
        divright++
        
        if(divnumber==divright)
        {
            divnumber=1;              
        } 
        
    }
  
    getObj("divp"+maindiv).style.visibility="hidden";
    getObj("divp"+divnumber).style.visibility="visible";
    SetTopNO();
    
}

/* This function is use for set (9 19 13 1 4 5 2 25) style in main image which is show */
function setstyle()
{
    for(i=1;i<=PGlength;i++)
    {
        if(i==imgnumber)
        {
            getObj("imgp"+imgnumber).style.filter = 'alpha(opacity=50)';
            getObj("imgp"+imgnumber).style.opacity = 0.5;
        }
        else
        {
            getObj("imgp"+i).style.filter = 'alpha(opacity=100)';
            getObj("imgp"+i).style.opacity = 1;
        }
    }
    
    loadXMLDoc('js/PhotoGallery.xml');

}

/* Set images number (19 15 8 1 14) in top division */
function SetTopNO()
{
    var Fnumber;
    var Lnumber;
    var showdiv;
    for(i=1;i<=divcount;i++)
    {
        if(getObj("divp"+i).style.visibility=="visible")
        {
            showdiv=i;
        }
    }
    Lnumber=showdiv*ImgGroup;
    if(Lnumber>PGlength)
        Lnumber=PGlength;
     
    Fnumber=((showdiv-1)*ImgGroup)+1;        
    getObj("Pdivtop").innerHTML="Photos "+Fnumber+" - "+Lnumber+" of "+PGlength;
}
/* Function for object */
  function getObj(objID) 
	{
	    if (document.getElementById)
	    {
	        if (document.getElementById(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        
	        return document.getElementById(objID)
	    }
	    else if (document.all)
	    {
	        if (document.all(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        
	        return document.all[objID];
	    }
	    else if (document.layers)
	    {
	        if (document.layers(objID)==null)
	        objID="ctl00_cphContent_"+objID;
	        	    
	        return document.layers[objID];
	    }
	}
	
	
/*This is use for Read (7 21 16 20 1) XML file*/
var xmlhttp;

/* Open Xml file (18 1 10) */
function loadXMLDoc(url)
{
xmlhttp=null;
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=onResponse;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
    return true;
    }
    else
    {
    alert("Problem retrieving XML data");
    }
  }
}

function onResponse()
{
  if(checkReadyState(xmlhttp))
  {
      var response = xmlhttp.responseXML.documentElement;
      x=response.getElementsByTagName(category);
      for (i=0;i<x.length;i++)
      {
            xx=x[i].getElementsByTagName("img"+imgnumber);
            getObj("divptitle").innerHTML=xx[0].firstChild.data;
      }
  }
}

