/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;
function GB_image_show(caption, url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay' style='opacity:0.7; filter: alpha(opacity = 70);'></div><div id='GB_window' onclick='GB_hide();'>"
        + "</div>");
    $("#closeit").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position);
    GB_DONE = true;
  }


  $("#GB_frame").remove();
  var data = '<img src="'+url+'" alt="'+caption+'" title="'+caption+'" id="fullsizeimage" align="middle" />';
 
  $('#GB_window').html(data);

$("#GB_overlay").fadeIn("slow");
$("#GB_overlay").css("filter","alpha(opacity = 70)");
$("#GB_overlay").css("opacity","0.7");
  
  GB_position();

 /* if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else*/
   var de = document.documentElement;
   var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  
    $("#GB_window").fadeIn("slow",function (){setheight();});
	$(document).keypress(function(e){ if(e.keyCode==27){ $("#GB_overlay").fadeOut("slow"); $("#GB_window").fadeOut("slow"); } });
}




function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay' style='opacity:0.7; filter: alpha(opacity = 70);'></div><div id='GB_window'>"
        + "</div>");
    $("#closeit").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position);
	$(window).scroll(GB_position);
    GB_DONE = true;
  }

  $("#GB_frame").remove();
  
  $('#GB_window').html('');

  $.ajax({ url: url,
			cache: false,
			success: function(data){ 
			
			$('#GB_window').html(data);
			} ,
			error: function (){
			alert("Sorry!\n\nAn Error Occured! While fetching data from server.\nDetails: \n\nURL: "+url+"\nDIV: #GB_window\n");
			}
			
			});
  
 // $("#GB_window").append("<iframe id='GB_frame' src='"+url+"' allowtransparency='true' style='filter:chromacolor=#F5FAFD' frameborder='0'></iframe>");

  //$("#GB_caption").html(caption);
  $("#GB_overlay").fadeIn("slow");
  $("#GB_overlay").css("filter","alpha(opacity = 70)");
  $("#GB_overlay").css("opacity","0.7");
  
  GB_position();

 /* if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else*/
    var de = document.documentElement;
   var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  
    $("#GB_window").fadeIn("slow",function (){setheight();});
	$(document).keypress(function(e){ if(e.keyCode==27){ $("#GB_overlay").fadeOut("slow"); $("#GB_window").fadeOut("slow"); } });
	
}

function setheight()
{
	 var de = document.documentElement;
   var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	if($("#GB_window").height()>0 && h>0)
	{
	 if(h <=($("#GB_window").height())) 
	 {  
	 $("#GB_window").css({'overflow-y':'auto'}); 
	 //alert('auto');
	 }  
	 else if(h >($("#GB_window").height())) 
	 {
		 $("#GB_window").css({top: ((h - ($("#GB_window").height()))/2)+"px"}); 
		 //alert($("#GB_window").height()); 
		 //alert(h); 
	 }  
	}
	else
	{
		setTimeout('setheight()',1000);
	}
}

function GB_hide() {
  $("#GB_window,#GB_overlay").fadeOut("slow");
}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  if($("#GB_window").height()>0 && (h >($("#GB_window").height())))
  {
	  //alert($("#GB_window").height());
  $("#GB_window").css({top: ((h - ($("#GB_window").height()))/2)+"px"}) 
  }
  else
  {
	  $("#GB_window").css({top:"10px"}) 
  }
	if($("#GB_window").offsetHeight >GB_HEIGHT) {GB_HEIGHT=$("#GB_window").offsetHeight; }
  $("#GB_window").css({'width':GB_WIDTH+"px",'max-height':(h-20)+"px",
    left: ((w - GB_WIDTH)/2)+"px"});
  //$("#GB_frame").css("min-height",GB_HEIGHT+"px");
}

/////////////////////////////////for download  Box///////////////////////////////////
var DB_DONE = false;
var DB_HEIGHT = 400;
var DB_WIDTH = 400;
function DB_show(caption, url, height, width) {
	
  DB_HEIGHT = height || 0;
  DB_WIDTH = width || 0;
  if(!DB_DONE) {
    $(document.body)
      .append("<div id='DB_overlay' style='opacity:0.7; filter: alpha(opacity = 70);'></div><div id='DB_window'>"
																	 
        + "</div>");
    $("#DB_overlay").click(DB_hide);
    $(window).resize(DB_position);
    DB_DONE = true;
  }

  $("#DB_frame").remove();
  $("#DB_window").append("<iframe id='DB_frame' src='"+url+"' allowtransparency='true' style='filter:chromacolor=#F5FAFD' frameborder='0'></iframe>");

  //$("#DB_caption").html(caption);
  $("#DB_overlay").fadeIn("slow");
  $("#DB_overlay").css("filter","alpha(opacity = 70)");
  $("#DB_overlay").css("opacity","0.7");
  
  DB_position();
//alert(url);
 /* if(DB_ANIMATION)
    $("#DB_window").slideDown("slow");
  else*/
    $("#DB_window").fadeIn("slow");
	$(document).keypress(function(e){ if(e.keyCode==27){ $("#DB_overlay").fadeOut("slow"); $("#DB_window").fadeOut("slow"); } });
}

function DB_hide() {
  $("#DB_window,#DB_overlay").fadeOut("slow");
}

function DB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#DB_window").css({width:DB_WIDTH+"px",height:DB_HEIGHT+"px",
    left: ((w - DB_WIDTH)/2)+"px" });
  $("#DB_frame").css("height",DB_HEIGHT+"px");
}





