// 
// navPop.js 
// popup code based on CodaEffects.js & Effects.js - (C) 2007 Panic, Inc.
//

var myWidth = 0; 
var myHeight = 0; 
var myScroll = 0; 
var myScrollWidth = 0; 
var myScrollHeight = 0; 

var currentFamily = 0;

function contentSwitch (id){

	if(currentFamily!=0 && currentFamily!=id){
		new Effect.toggle(currentFamily,'appear', { duration: .25 });
	}
	if(currentFamily!=id){
		new Effect.toggle(id, 'appear', { duration: .25 });
		currentFamily = id;
	}	
}

function showLargePopup(projectName) {

    var popFullscreen = document.getElementById('fullscreen');
    var popLarge = document.getElementById(projectName);
    var popLargeDivs = popLarge.getElementsByTagName('div');   
    // Make fullscreen thing really full screen, and show it
    getSize();
    popFullscreen.style.height = myScrollHeight + 'px';
    popFullscreen.style.display = 'block';
    
    // Position pop-up
    //hack to get the offset
    popLarge.style.visibility = 'hidden';
    popLarge.style.display = 'block';
    var popupLeft = ((myWidth - popLarge.offsetWidth))/2;
    var popupTop = (((myHeight - popLarge.offsetHeight)) + myScroll)/2;
    popLarge.style.left = popupLeft + 'px';
    popLarge.style.top = popupTop + 'px';    

	//get the actual background div and set the background image position
    for (i=0; i<popLargeDivs.length; i++) {
		//Get all tags with the specified class name.
		if (popLargeDivs[i].className=='pop-up-inner')
			popLargeDivs[i].style.backgroundPosition = popupLeft + 'px ' +  (popupTop - (796-popLarge.offsetHeight)) + 'px';
	}
    //hack to get the offset (back to original state)
    popLarge.style.display = 'none';
    popLarge.style.visibility = 'visible';

    new Effect.Appear(popFullscreen, {duration: .25});
    new Effect.Grow(popLarge, {duration: .5});
}

function setLocation(loc) {
	window.location = loc;
}

function hideLargePopup(projectName) {
    var popFullscreen = document.getElementById('fullscreen');
    var popLarge = document.getElementById(projectName);
    new Effect.Shrink(popLarge, {duration: .5});
    new Effect.Fade(popFullscreen, {duration: .16});
    
    //popLarge.style.visibility = 'hidden';
    //popFullscreen.style.display = 'none';
}

// Utility: Get the size of the window, and set myWidth and myHeight
// Based on code from panic.com

function getSize() {
	if (document.all && navigator.userAgent.indexOf("Opera")==-1) {
		// IE4+ or IE6+ in standards compliant and a test to exclude Opera
		myWidth  = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
		myHeight = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
		myScroll = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	} else {
		// Non-IE
		myWidth = self.innerWidth;
		myHeight = self.innerHeight;
		myScroll = self.pageYOffset;
	}
	
	// Core code from - quirksmode.org
    if (window.innerHeight && window.scrollMaxY) {	
        myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		//have to manually add the div height that wasn't visible when the page loaded
		myScrollHeight = document.body.offsetHeight + document.getElementById(currentFamily).offsetHeight;
	}
	//fix for gecko - if there's no scroll it won't get the right myScrollHeight
	if(myScrollHeight < myHeight){
		myScrollHeight = myHeight;
	}
}
