//
// 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";
	}
});
var currentTab = 'mission';
function gotoTab(id) {
    if (id == currentTab) return;
    Element.removeClassName('tab-link-'+currentTab, 'selected')
    Element.addClassName('tab-link-'+id, 'selected')
    loadContent(id)
    currentTab = id
    return false;
}



function loadContent(tab) {
    Element.update('tab-content', '')
    Element.addClassName('tab-content', 'loading');
    var url = '/wp-content/themes/silaspartners/plugins/welcome-splash-load.php';
    var params = 'tab=' + tab+'&rand='+Math.random();
    var ajax = new Ajax.Updater(
        {success: 'tab-content'},
        url,
        {method: 'get', 
        parameters: params, 
        onFailure: reportError,
        onComplete: finishLoad });
}
function finishLoad(request) {
    Element.removeClassName('tab-content', 'loading');
    var ahrefs = $('splash-container').getElementsByTagName('a');
    for (var i=0; i<ahrefs.length; i++) {
        if (!ahrefs[i].onclick) ahrefs[i].onclick = function() { 
            setSplashCookie();
            return true;
        }
    }
    
}

function reportError(request) {
    Element.update($('tab-content'), "Error loading content:"+request);
}

function initializeWelcomeSplash() {
    var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	getSplash();
}

function clearSplash() {
    //new Effect.Fade('splash', {duration:0.5});
    new Effect.Fade('overlay', {duration:1});
    if ($('splash')) Element.hide('splash');
    setSplashCookie();
    return false;
}
function setSplashCookie() {
    if ($('splash-nevershow').checked) {
        document.cookie = "hidesplashforever=1; expires=Fri, 1 Jan 2011 01:00:00 UTC; domain=crossroadslive.com; path=/; "
    } else {
        document.cookie = "hidesplashforever=1; expires=Sat, 1 Jan 2000 01:00:00 UTC; domain=crossroadslive.com; path=/; "
    }
    document.cookie = "hidesplash=1;  domain=crossroadslive.com; path=/"
}

function displaySplash() {
    var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	Element.setOpacity('overlay', 0);
	$('overlay').style.display='block';
	new Effect.Opacity('overlay', {from:0, to:0.80, duration:1, queue:'end'});

	//Element.setOpacity('splash-container', 0);
    if (!$('splash')) {
        getSplash();
    } else {
        Element.show('splash');
    }
    
	return false;
}
function getSplash() {
    var url = '/wp-content/themes/silaspartners/plugins/welcome-splash-load-container.php';
    var params = 'rand='+Math.random();
    var ajax = new Ajax.Updater(
        {success: 'splash-container'},
        url,
        {method: 'get', 
        parameters: params, 
        onFailure: reportError,
        onComplete: function() { 
            new Effect.Opacity('overlay', {from:1, to:0.80, duration:1, delay:3});
            Element.show('splash'); 
            loadContent('default') ;
        } });
}

