// JavaScript Document

transition = false;
logo = false;

function isEven(value){
	if (value%2 == 0)
		return true;
	else
		return false;
}

function setPage() {

	var window_height			= 0;
	var window_width			= 0;
	var menu_bar_height			= 0;
	var outer_container_height 	= 0;
	
	if ( navigator.appName.indexOf("Microsoft") != -1 ) {
		window_height = document.documentElement.clientHeight;
		window_width  = document.documentElement.clientWidth;
	} else {
		window_height = window.innerHeight;
		window_width  = window.innerWidth;
	}

	menu_bar_height      = document.getElementById('menu_bar').offsetHeight;	
	
	outer_container_height     = window_height - menu_bar_height;

	sip_pipe_logo_width = document.getElementById('sip_pipe_logo').offsetWidth;

	document.getElementById('outer_container').style.height         = outer_container_height + 'px';
	
	if (window_height > 850) {
		fadeLogo('in');
	}
	else {
		fadeLogo('out');
	}
	
	window_width_even = (isEven(window_width)) ? window_width : window_width +1;
	
	logo_left = (window_width_even/2) - (sip_pipe_logo_width/2);
		
	document.getElementById('sip_pipe_logo').style.left         = logo_left + 'px';

	
}

function fadeLogo(fade) {

	if (fade == 'in' && transition == false && logo == false) {
		transition = true;
		logo = true;
		Spry.Effect.AppearFade('sip_pipe_logo', {duration: 1000, from: 0, to: 100, toggle: false});
		setTimeout(logoTimer, 500);	
	}
	if (fade == 'out' && transition == false && logo == true) {
		transition = true;
		logo = false;
		Spry.Effect.AppearFade('sip_pipe_logo', {duration: 1000, from: 100, to: 0, toggle: false});
		setTimeout(logoTimer, 500);	
	}
	
}

function logoTimer() {
	
	transition = false;

}

window.onresize = setPage;