var subViews = {
	overlayZindex: 10,
	elementZindex: 11,
	prods: ["bc", "pc", "pc55x85", "pc4x55", "pc5x7", "pc6x11", "pc85x11", "gc4x55", "gc55x85", "pc4x9", "pc2x6", "br85x11", "lt", "st80", "st100", "mag2x35", "mag4x6", "tshirt", "env10", "pstr11x17"],
		
	initDeliveryTimeBoxes: function() {
		for (var i=0;i<subViews.prods.length;i++) {
			if ($('deliveryTimeDiv_'+subViews.prods[i])) {
				Event.observe($('deliveryTimeLink_'+subViews.prods[i]), 'click', function(event) { subViews.spotLight(event); });
				Event.observe($("closeDeliveryTimeDiv_"+subViews.prods[i]), "click", function(event) {subViews.hideOverlay(); subViews.hideElement(event.target.rel); return false;});
			}
		}
	},
	showOverlay: function() {
		if ($('bgOverlay')) {
			$('bgOverlay').style.display = 'block';
		} else {
			// create the overlay
			var overlay = document.createElement('div');
            Element.extend(overlay);
			overlay.id = 'bgOverlay';
			var info = this.getPageSize();
			var vinfo = document.viewport.getHeight();
            var height = vinfo > info.height ? vinfo : info[1];
            overlay.style.height = height + 'px';
            overlay.style.width = '100%';
            overlay.display = 'block';
            overlay.zIndex = this.overlayZindex;
            overlay.addClassName('bgOverlay');
            document.body.appendChild(overlay);
		}
	},
	hideOverlay: function() {
		$('bgOverlay').style.display = 'none';
	},
	hideElement: function(id) {
		$(id).style.display='none';
	},
	displayElement: function(id) {
		var offsets = document.viewport.getScrollOffsets();
        var center  = Math.round(((document.viewport.getHeight() /2 ) - ($(id).getHeight()/2)));
        var newY     = offsets[1];
        if (center > 0) {
            newY += center;
        }
        $(id).style.top = newY+'px';
        
        $(id).style.left = ((document.viewport.getWidth() /2 ) - ($(id).getWidth()/2))+'px';
		document.body.appendChild($(id));
		$(id).style.zIndex = this.elementZindex;
		$(id).style.display = 'block';
		Event.observe($('bgOverlay'), 'click', function() {
				$(id).style.display='none';
				subViews.hideOverlay();
			});
	},
	hideElement: function(id) {
		$(id).style.display = 'none';
	},
	spotLight: function(event) {
		id = event.target.axis;
        if (!id) {
            //try parent
            id = event.target.parentNode.axis;
        }
		this.showOverlay();
		this.displayElement(id);
	},
	// getPageSize()
    // Returns array with page width, height and window width, height
    // Core code from - quirksmode.org
    // Edit for Firefox by pHaez
    //
    getPageSize: function(){
        var xScroll, yScroll;

        if (window.innerHeight && window.scrollMaxY) {
            xScroll = document.body.scrollWidth;
            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;
        if (self.innerHeight) { // all except Explorer
            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;
        }

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


        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
        return arrayPageSize;
    }
}
