/*
Photo Gallery

Copyright (c) 2008 IVUM
http://www.ivum.co.uk

Copyright (c) 2008 Richard Coulson
http://www.ivum.co.uk

 Not for re-sale or distribution, this gallery is copyright to IVUM and any kind of distribution of this gallery will lead to prosecution!
 You may use this gallery on ONE website, please inform us of the domain name that the gallery is being used on and if you move the gallery to another domain name please inform us of the change.
*/

var req;
var req1;
var index;
var selection;
var length;
var length1;
var max_len;
var min_len;
function get_image(image_id,count) {
	
	this.length= js_array.length;
	max_len=js_array.length;
      for(i=0;i<this.length;i++)
	{
      if(js_array[i]==image_id)
		{
		 
		 this.length1=i;
		 // alert("AAAAA"+this.length1);
         index=true;
		}
    }
	if(image_id){
		img_id = image_id;
	}else{
		img_id = '';
	}
	select_index=count;
   var url = "image_pro.php?id="+img_id+"&count="+select_index;

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function processChange() {
	
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4 && req.status == 200) {
      //alert(req.responseText);
	    response=req.responseText.split("<a");
			//alert(response[1]);
      // Write the contents of this URL to the searchResult layer
	    getObject("showimage").innerHTML = response[0];
	    getObject("lostimage").innerHTML = '';
		
        getObject("prev").innerHTML = "<a"+response[1];

   }
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}
//////////////For next image
function get_next_image(image_id,len) {
	//this.length=js_array.length;
	//alert(this.length1);
	 max_len=len;
	 
	 for(i=0;i<len;i++)
	{
      if(js_array[i]==image_id)
		{ 
		   
		  if(index==true && i!=(len-1) )
			{
           
          img_id = js_array[(this.length1)+1];
		  index=false;
			}
			else
			{
			img_id = js_array[i+1];
			}
			if(i==(len-1))
			{
             if(index==true )
				{
            img_id = js_array[(this.length1)+1];
				}
				else
				{
                img_id = js_array[0]; 
				}

            }

		  
		}
		if(this.length1==(len-1))
		{
      img_id = js_array[0];
		}

	}
			
	 size="&siz="+len;
		
   var url = "image_pro.php?id1="+img_id+size;

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange1;
      req.open("GET", url, true);
      req.send(null);
   }
}

function processChange1() {
	 
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4 && req.status == 200) {
	  //alert(req.responseText);
      // Write the contents of this URL to the searchResult layer
	  var a=req.responseText.split("<a");
	 //alert(a[1]);
	 //alert(a[2]);
	  //alert("<button"+ a[1]);
	  //if((size1 != 0))
	   //{
	    getObject("showimage").innerHTML = a[0];
	   getObject("lostimage").innerHTML = '';
	  // }
	 getObject("prev").innerHTML = "<a"+a[2];
	   getObject("next").innerHTML = "<a"+a[1];

   }
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

/////////////////For prev image

function get_prev_image(image_id,prev_size) {
	var size;
	
	//alert(prev_size);
	var pre_length=this.max_len;
	// alert(js_array[2]);
	 for(i=0;i<pre_length;i++)
	{
       if(js_array[i]==image_id)
		{
		   size= i;
		   this.length1=i;
		if(this.length1==0)
	   {
      img_id=js_array[0];
	   }
	if(this.length1>0)
	{
		
   img_id = js_array[(this.length1)-1];
	}

	}
	}
	
   var url = "image_pro.php?id_prev="+img_id+"&pre="+ size;
   
   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.onreadystatechange = processChange2;
      req.open("GET", url, true);
      req.send(null);
   }
}

function processChange2() {
	 
   // The page has loaded and the HTTP status code is 200 OK
   if (req.readyState == 4 && req.status == 200) {
	  //alert(req.responseText);
      // Write the contents of this URL to the searchResult layer
	  var a=req.responseText.split("<a");
	 //alert(a[1]);
	 //alert(a[2]);
	  //alert("<a"+ a[1]);
	  //if((size1 != 0))
	   //{
	    getObject("showimage").innerHTML = a[0];
	   getObject("lostimage").innerHTML = '';
	  // }
	   getObject("prev").innerHTML = "<a"+a[1];
	   
   }
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}