function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function setFooter() {
    if (document.getElementById) {
        var windowHeight=getWindowHeight();
        if (windowHeight>0) {
            var contentHeight = document.getElementById('content').offsetHeight;
            var footerElement= document.getElementById('footer');
            var footerHeight = footerElement.offsetHeight;
            if (windowHeight-(contentHeight+footerHeight)>=0) {
                footerElement.style.position='relative';
                footerElement.style.top=(windowHeight - (contentHeight+footerHeight))+'px';
            }
            else {
                footerElement.style.position='static';
            }
        }
    }
}

function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }       
    else {
        if (document.body&&document.body.clientHeight) {
            windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

function setWrapHeight(){
    if(!document.getElementById) return false;
    if(!document.getElementById('wrap')) return false;
    divWrap = document.getElementById('wrap');
    bBottom = document.getElementById('bottomBorder');
    divWrapHeight = divWrap.offsetHeight;
    pageHeight = getWindowHeight();
    // If height of the content is less than height of page then display bottom border
    if(divWrapHeight < pageHeight)
        bBottom.style.display = 'block';
    // If height of the content is less than height of page then set the content to page bottom minus small amount
    //if(divWrapHeight < pageHeight)
        //divWrap.style.height = pageHeight -30 + 'px';
        
}

function captions(){
	if (!document.getElementsByTagName) return false;
	divs = document.getElementsByTagName("div");
	for (var i=0; i < divs.length; i++) {	
		className = divs[i].className;
		if (className.substring(0,7) == "caption") {
			divs[i].onmouseover = function() {	
				var thisCaption = this.getElementsByTagName("div");
				for (var j=0; j < thisCaption.length; j++) {	
					if (thisCaption[j].className == "captionText")
						thisCaption[j].style.display = 'block';
				}
				return false; 
			}
			divs[i].onmouseout = function() {	
				var thisCaption = this.getElementsByTagName("div");
				for (var j=0; j < thisCaption.length; j++) {	
					if (thisCaption[j].className == "captionText")
						thisCaption[j].style.display = 'none';
				}
				return false; 
			}
		} 	
	}
	setTimeout("hideCaption(divs)",5000);
	
}

function hideCaption(divs){
	for (var i=0; i < divs.length; i++) {	
		if (divs[i].className == "captionText")
			divs[i].style.display = "none";	
	}
	return true
}

function enquiry(){
    if(!document.getElementById) return false;
    if(!document.getElementById('make')) return false;
    if(!document.getElementById('opaqueLayer')) return false;
    
    makeEnquiry = document.getElementById('make');
    opaque = document.getElementById('opaqueLayer');
    
    makeEnquiry.onclick = function(){
        
        opaque.style.display =  'block';
        return false;
        
    }
    
}

function getHTTPObject() {
  var xhr = false;
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xhr = false;
      }
    }
  }
  return xhr;
}

function grabFile(file) {
  var request = getHTTPObject();
  if (request) {
    //displayLoading(document.getElementById("details"));
    request.onreadystatechange = function() {
      parseResponse(request);
    };
    request.open("GET", file, true);
    request.send(null);
    return true;
  } else {
    return false;
  }
}

    function fetchSize(type) {
        var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
        }
        
        //window.alert( 'Width = ' + myWidth );
        //window.alert( 'Height = ' + myHeight );
        
        if(type == 'width')
            return myWidth;
        else
            return myHeight;
}

function parseResponse(request) {
  if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
      var details = document.getElementById("ajaxReplace");
      //details.style.top = '100px';
      details.innerHTML = request.responseText;
      
      height = fetchSize('height');
      
      var move = function() {
        var details = document.getElementById("ajaxReplace");
        if(details.style.top == ''){
            boxPosL = -200;
            details.style.display = 'block';
        }
        else {
            boxPosL = boxPosL + 10;            
        }
        
        if(boxPosL > 0) boxPosL = 0;
        
        details.style.top = boxPosL + 'px';
        
        if(boxPosL < 0)
            setTimeout(move,50);
    };
    
    setTimeout(move,1);
      
          $(function(){
         //Carousel with pagination
        $(".carouselDIV").carousel( { 
                pagination: true, 
                paginationPosition: 'outside', 
                btnsPosition: 'inside',
                prevBtnInsert: 'appendTo',
                nextBtnInsert: 'appendTo',
                prevBtn: '<span><span class="pgNum">&nbsp; page &nbsp;&nbsp; of 3</span><img src="/img/Title-pg-previous-bt.png" height="15" width="15"alt="Previous" /></span>',
                nextBtn: '<span><img src="/img/Title-pg-next-bt.png" height="15" width="15"alt="Next" /></span>'   
        } );
    });
      //fadeUp(details,255,255,153);
    }
  }
}

function initialize() {
  if (GBrowserIsCompatible()) {
    if(document.getElementById("map_canvas")){
        setWrapHeight();
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(53.2976334, -1.0737513), 14);
        map.setUIToDefault();

        var point = new GLatLng(53.2976334, -1.0737513);
        map.addOverlay(new GMarker(point));
        map.enableRotation();
    }
  }
}


function ajax(){
//var query = this.getAttribute("href").split("?")[1];
      //var url = "people.php?"+query;
      return !grabFile('/ajax/test/');
}

//addLoadEvent(setFooter);
addLoadEvent(setWrapHeight);
addLoadEvent(enquiry);
//addLoadEvent(captions);

