// Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
// Below function taken from: 
// -----------------------------------------------------------------------------------
//
//	Lightbox v2.03.3
//	by Lokesh Dhakar - http://www.huddletogether.com
//	5/21/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
};
$(document).ready(function(){
	if ( $.browser.msie ) {
	 document.execCommand("BackgroundImageCache", false, true)
	}
	
	 $(".topNav").hover(function(){
		$(this.firstChild.firstChild).show(450);
		if (this.getElementsByTagName('ul')[0]) {
			$(this.getElementsByTagName('ul')[0]).show(550);
		}
	 },function(e){
		if (this.getElementsByTagName('ul')[0]) {
			var left = findPos(this.getElementsByTagName('ul')[0])[0];
			var top = findPos(this.getElementsByTagName('ul')[0])[1];
			width = this.getElementsByTagName('ul')[0].offsetWidth;
			var right = left+width;
			height = this.getElementsByTagName('ul')[0].offsetHeight;
			var bottom = top+height;
			
			var x = e.pageX;
			var y = e.pageY;
			 
			if (x > left && x < right && y > top && y < bottom) {
				
			} else {
				$(this.getElementsByTagName('ul')[0]).hide(350);
				$(this.firstChild.firstChild).fadeOut(1000);
			}
		} else {
			$(this.firstChild.firstChild).fadeOut(1000);
		}  
	}); 

	

	
	$("#links").hover(function(){
		$(this.firstChild).fadeIn(450);
	 },function(){
		$(this.firstChild).fadeOut(1000);
	 });

	$("#specials").hover(function(){
		$(this.firstChild).fadeIn(450);
	 },function(){
		$(this.firstChild).fadeOut(1000);
	 });

	$("#topNav ul").hide();
	$("#topNav li").removeClass("noJS");
	

	$("body").append("<div id=\"dimmer\"><div></div></div>");
	var arrayPageSize = getPageSize();
	$("#dimmer").height(arrayPageSize[1]);

	$(".lightbox").click(function(){
		setOverlaySize();
		link = this.href;
		caption = this.title;
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		var lightboxLeft = arrayPageScroll[0];
		
		$("#dimmer").fadeIn(200,function() {
			$("body").append("<div class=\"lightboxBig\" style=\"top:"+lightboxTop+"px;left:"+lightboxLeft+"px;\"><div class=\"lightboxBigInner\"><p><a href=\"\" class=\"closeLightbox\">Close</a><a href=\"\" class=\"printLightBox\">Print</a>&nbsp;</p><img src=\""+link+"\"/><p id=\"caption\">"+caption+"</p><p id=\"saveIns\">To save this image right-click it and select 'Save Image As' or similar.</p></div></div><h3 id=\"printCall\">Curtiss Landscape<br/>Working with you to shape your dreams into reality<br/>Call Today for a Consultation<br/>508-481-2368</h3>");
			$(".lightboxBig").show(300);
			$("body").addClass('print');
			$(".closeLightbox, #dimmer").click(function(){
				$(".lightboxBig").hide(500,function() {
					$(".lightboxBig").remove();
					$("#dimmer").hide(0);
					$("#printCall").remove();
					
					$("body").removeClass('print');
				});
				return false;
			});
			$(".printLightBox").click(function(){
				$("#dimmer").hide();
				window.print();
				
				return false;
			});


		});

		return false;
	});
	
});
function setOverlaySize () {
var arrayPageSize = getPageSize();
$("#dimmer").height(arrayPageSize[1]);
}
window.onresize = setOverlaySize;

