//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	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;
}

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	}
});
function reportError(request) {
    Element.update($('tab-content'), "Error loading content:"+request);
}
var showOnlyOnce = 0;
function initializeWelcomeSplash() {

	showOnlyOnce = showOnlyOnce + 1;
	if (showOnlyOnce > 1) { clearSplash(true); return; }
	if (document.cookie.indexOf('hidesplash') > 0) { clearSplash(true); return; }
	
	if ($('ministries-list')) Element.hide('ministries-list');
	if ($('sponsors-list')) Element.hide('sponsors-list');
	if (!$('overlay')) return
	
    var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	new Effect.Opacity('overlay', {from:1, to:0.80, duration:1, delay:5});

    var speakers = $('splash').select('.speaker');
    for (var i=0;i<speakers.length;i++) {
        Element.update(speakers[i], '<span id="hover-'+speakers[i].id+'">'+speakers[i].innerHTML+'</span>');
        speakers[i].onmouseover = function() {
            Element.addClassName('hover-'+this.id, 'hover');
        }
        speakers[i].onmouseout = function() {
            Element.removeClassName('hover-'+this.id, 'hover');
        }
        
    }
    
	//getSplash();
}

function clearSplash(fast) {
    //new Effect.Fade('splash', {duration:0.5});
    //alert(document.cookie)
    if ($('ministries-list')) Element.show('ministries-list');
	if ($('sponsors-list')) Element.show('sponsors-list');

	Element.hide('splash');
	fast = true;
	
	if (fast) {
		Element.hide('overlay');
	} else {
	    new Effect.Fade('overlay', {duration:1});
	}
    
    document.cookie = "hidesplash=1; path=/"
    if ($('splash-nevershow') && $('splash-nevershow').checked) {
        document.cookie = "hidesplashforever=1; expires=Fri, 1 Jan 2010 01:00:00 UTC; path=/; "
    } else {
        document.cookie = "hidesplashforever=1; expires=Sat, 1 Jan 2000 01:00:00 UTC; path=/; "
    }
    return false;
}
