/* 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)
 */
function positionInfo(object) 
{
						  var p_elm = object;
						  this.getElementLeft = getElementLeft;
						  function getElementLeft() 
  							{
												var x = 0;
												var elm;
												if(typeof(p_elm) == "object")
												{
												  elm = p_elm;
												}
												else 
												{
												  elm = document.getElementById(p_elm);
												}
												while (elm != null) 
												{
												  x+= elm.offsetLeft;
												  elm = elm.offsetParent;
												}
												return parseInt(x,10);
  							}

  							  this.getElementWidth = getElementWidth;
							  function getElementWidth()
							  {
												var elm;
												if(typeof(p_elm) == "object")
												{
												  elm = p_elm;
												} 
												else 
												{
												  elm = document.getElementById(p_elm);
												}
												return parseInt(elm.offsetWidth,10);
							  }
							  this.getElementRight = getElementRight;
							  function getElementRight()
							  {
								return getElementLeft(p_elm) + getElementWidth(p_elm);
							  }

						  this.getElementTop = getElementTop;
						  function getElementTop() 
						  {
												var y = 0;
												var elm;
												if(typeof(p_elm) == "object")
												{
												  elm = p_elm;
												} else {
												  elm = document.getElementById(p_elm);
												}
												while (elm != null) 
												{
												  y+= elm.offsetTop;
												  elm = elm.offsetParent;
												}
												
												
												if(object=="DHtlInfor1" || object=="DHtlInfor2")
												{
												  if(y>250)
												    {
												        y=y-110;
												    }
												}
												else
												{
												    if(y>250)
												    {
												        y=y-180;
												    }
												}
												
												
												return parseInt(y,10);
						  }

						  this.getElementHeight = getElementHeight;
						  function getElementHeight()
						  {
												var elm;
												if(typeof(p_elm) == "object")
												{
												  elm = p_elm;
												}
												else
												{
												  elm = document.getElementById(p_elm);
												}
												return parseInt(elm.offsetHeight,10);
						  }
						  this.getElementBottom = getElementBottom;
						  function getElementBottom()
						  {
							return getElementTop(p_elm) + getElementHeight(p_elm);
						  }
}
var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;
var ObjIdPosX,ObjIdPosY;
var type;
function GB_show(caption, url, height, width) 
{
            type=caption.substring(0,5);
            if(type.toLowerCase()=="alink" || type.toLowerCase()=="rulel" || type.toLowerCase()=="dpric" || type.toLowerCase()=="dalin")
            {
                        GB_HEIGHT =330;
                        GB_WIDTH =600;
                           
            }
			else if(type.toLowerCase()=="temph")
            {
                        GB_HEIGHT =300;
                        GB_WIDTH =650;                       
            }
			
			
			
            else if(type.toLowerCase()=="htlse")
            {
                        GB_HEIGHT =450;
                        GB_WIDTH =650;                       
            }
            else if(type.toLowerCase()=="offer")
            {
                        GB_HEIGHT =330;
                        GB_WIDTH =980;                       
            }  
			
			 else if(type.toLowerCase()=="morei")
            {
                        GB_HEIGHT =650;
                        GB_WIDTH =850;                       
            }  
						
            else
            {
                        GB_HEIGHT =400;
                        GB_WIDTH =1000;                      
            }
            
                        var fieldPos = new positionInfo(caption);
                        ObjIdPosX = fieldPos.getElementLeft();
                        ObjIdPosY = fieldPos.getElementBottom()-150;
                        if(!GB_DONE) 
                        {
                            $(document.body)
                            .append("<div id='GB_overlay'></div><div id='GB_window' scrolling='no'><div id='GB_caption'></div>"+ "<img src='http://www.myvacations.co.uk/images/close.gif' alt='Close window'/></div>");
                            $("#GB_window img").click(GB_hide);
                            $("#GB_overlay").click(GB_hide);
	                        $(window).resize(GB_position);
                            GB_DONE = true;
                        } 
                        $("#GB_frame").remove(); 
                        $("#GB_window").append("<iframe id='GB_frame' src='"+url+"' scrolling='yes' frameborder='0'></iframe>"); 
                        $("#GB_overlay").show();
                        GB_position();                        
             
             if(type.toLowerCase()=="alink" || type.toLowerCase()=="rulel" || type.toLowerCase()=="dpric" || type.toLowerCase()=="dalin")
            {
                        if(GB_ANIMATION)
                        $("#GB_window").slideDown("slow");
                        else
                        $("#GB_window").show();   
            }
            else 
            {
                        $("#GB_window").show(); 
            }
            
}

function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
}

function GB_position() {
	
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  
  $("#GB_window").css({width:(GB_WIDTH+15)+"px",height:(GB_HEIGHT+15)+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  $("#GB_frame").css("height",GB_HEIGHT+"px");
  	$("#GB_window").css("top",ObjIdPosY+"px")
	$("#GB_overlay").css("height",2200+"px")
}

			