// JavaScript Document

var my_imges=new Array();
var my_key='';
var length='';
var newImg = new Image();
var height=0; 
var width=0; 
var myval=0;
		
$(document).ready (function(){
							
   $('#greyblack').css("position","fixed");
   $('#greyblack').css("height",($(window).height()+ "px"));
   $('#greyblack').css("width",($(window).width()+ "px"));
  
     var hg=$(window).height();
	  var dhg=$(document).height();
  
  var top_loc=dhg-hg+27;
   $('#imageborder').css('top',top_loc+'px');

							
});

function hide_me()
{
	$('#greyblack').css('display','none');
	$('#imageborder').css('display','none');
	
}
function show_graybox(my_path)
{
	var img=$("#img_arr").val();
	$("#total_img1").remove();
	my_imges=img.split(",");
	length=my_imges.length;
	my_key = array_key(my_imges,my_path);
	
	
	$('#total_img').append('<span id="total_img1">'+length+'</span>');
	
	myval=my_key+1;
	$("#total_number").remove();
	$('#cur_img').append('<span id="total_number">'+myval+'</span>');
	
	getImgSize(my_path);
	
	
	
	$('#greyblack').css('display','block');
	$('#image_window').css('background-image','url('+my_path+')');
	
	$('#imageborder').css('display','block');
	$('#image_window').css('display','block');
	/*$('#imageborder').css("top","240px");
    $('#imageborder').css("left","362px");*/
	/*$('#imageborder').css("height",($(window).height() - $('#imageborder').height()) / 2+ "px");
   $('#imageborder').css("width",($(window).width() - $('#imageborder').width()) / 2+ "px"); set width=600 and height=500	
   
   */
   



	
		
}

newImg.onload = function(){
	
	/*if(width != 0 || height != 0)
	{
  $("#image_window").animate({"width":+width+"px"}, "slow");
  $("#image_window").animate({"height":+height+"px"}, "slow");
	}*/
};
function getImgSize(imgSrc)
{


newImg.src = imgSrc;
height = newImg.height;
width = newImg.width;
var size='width:'+width+'height:'+height;


if(width != 0 || height != 0)
{
  
  //alert("width: "+width);
  //alert("height: "+height);
  $('#footer_gray').css('display','block');
 
  $("#footer_gray").animate({"width":+width+20+"px"}, "slow");
  $("#image_window").animate({"width":+width+"px"}, "slow");
  $("#image_window").animate({"height":+height+"px"}, "slow");
}

width=0;
height=0;

return width;
}

function array_key(a, obj)
{
 
  for(var i = 0; i < a.length; i++) {
	 
    if(a[i] == obj){
		
		
      return i;
	  
	  
    }
  }
  
}

function previous_img()
{

	
$('#image_window').css('background-color','#FFF');
$('#image_window').css('background-image','url(greybox/images/loading.gif)');
var my_val=my_imges[my_key];
var my_arkey=array_key(my_imges, my_val);

my_arkey=my_arkey-1;



if(my_arkey == -1)
{
	my_arkey=length-1;
}
my_key=my_arkey;
myval=my_key+1;


$("#total_number").remove();
$('#cur_img').append('<span id="total_number">'+myval+'</span>');

getImgSize(my_imges[my_arkey]);
$('#image_window').css('background-image','url('+my_imges[my_arkey]+')');

	
}
function next_img()
{
	
/*alert("next_img is called");
alert("my_arr:"+my_imges);
alert("my_key"+my_key);
alert("my_imges key"+my_imges[my_key]);*/

$('#image_window').css('background-image','url(greybox/images/loading.gif)');
var my_val=my_imges[my_key];

/*alert("my_val;"+my_val);*/
var my_arkey=array_key(my_imges, my_val);

/*alert(my_arkey);*/

var last_val=length;

my_arkey=my_arkey+1;
if(my_arkey == last_val)
{
  my_arkey=0;	
}
my_key=my_arkey;
myval=my_key+1;

	$("#total_number").remove();
	$('#cur_img').append('<span id="total_number">'+myval+'</span>');


/*
alert("path:"+my_imges[my_arkey]);*/
getImgSize(my_imges[my_arkey]);
//alert("next is work");
$('#image_window').css('background-image','url('+my_imges[my_arkey]+')');

	
}


function dis_pre(){$('.pre_div').css('display','block');}
function out_pre(){$('.pre_div').css('display','none');}

function dis_next(){ $('.next_div').css('display','block');}
function out_next(){$('.next_div').css('display','none');}
