/* Entrance */
function changeLogo()
{
	pos = findPos($('init'));
	$('logoChange').style.left = (pos[0]+374)+'px';
	$('logoChange').style.display = 'block';
	Effect.Appear('logoChange'); 
	return false;
}
function changeLogo2()
{
	$('logoChange').style.display = 'none';
	return false;
}
function showQuads()
{ 
	if($('init').style.display != 'none')
	{				
		if( !$('quad').visible() )
		{
	
			$('starbg').blur(); // Deselect (remove square in IE)
			$('balloon').style.display = 'none';
			$('stars').style.display = 'none';
			Effect.Appear('quad', { duration: 2 });
			
			/* Set position of all highlighted quadrants */
			pos = -5;
			$('quadrant-test').setStyle({   
				'top': '0px',   
				'left': (pos + 174) + 'px'
			}); 
			$('quadrant-qualification').setStyle({   
				'top': '250px',   
				'left': (pos + 174) + 'px'
			}); 
			$('quadrant-downloads').setStyle({   
				'top': '0px',   
				'left': (pos + 449) + 'px'
			}); 
			$('quadrant-campaign').setStyle({   
				'top': '250px',   
				'left': (pos + 449) + 'px'
			}); 
		}
		/* forward to specific page */
		else
		{
			window.location.href= "?page=qualification";
		}
	}
}



/* Follow up pages */
var hidden = true;
function showHide()
{
	pos = findPos($('contents'));

	if(hidden == true && $('logo').style.left == pos[0]+'px')
	{
		// Set variables
		docHeight = getDocHeight();
		docWidth = getDocWidth();
		pos = findPos($('contents'));

		// Set dimensions and locations
		$('logo').blur(); // Deselect (remove square in IE)

		if(docHeight > 900) {
			$('quadrants-spacer').style.height = (docHeight - 900 )+ "px";
		}
		$('quadrants').style.height = docHeight + "px";
		$('quadrants').style.left = (pos[0])+'px';

		/* Set position of all highlighted quadrants */
		pos = -5;
		$('quadrant-test').setStyle({   
			'top': '0px',   
			'left': (pos + 174) + 'px'
		}); 
		$('quadrant-qualification').setStyle({   
			'top': '250px',   
			'left': (pos + 174) + 'px'
		}); 
		$('quadrant-downloads').setStyle({   
			'top': '0px',   
			'left': (pos + 449) + 'px'
		}); 
		$('quadrant-campaign').setStyle({   
			'top': '250px',   
			'left': (pos + 449) + 'px'
		}); 

		// Do effects
		new Effect.Move($('logo'), { x: 374, y: 127, duration: 1.0, queue: 'end' });
		setTimeout('Effect.Appear(\'quadrants\', { duration: 1.2, from: 0, to: 0.95, queue: \'end\' });', 500);

		hidden = false;
	}
	else if(hidden == false)
	{
		$('logo').blur(); // Deselect (remove selection square in IE)

		// Do effects
		Effect.Fade('quadrants', { duration: 1.2, queue: 'end' });
		setTimeout('new Effect.Move($(\'logo\'), { x: -374, y: -127, duration: 1.0, queue: \'end\' });', 0);

		hidden = true;
	}
}
    
function hoverQuadrant(quadrant) {
	var quadrants = new Array('test','qualification','downloads','campaign');
	var i=0;
	for (i=0;i<quadrants.length;i++)
	{
		if(quadrants[i] == quadrant) {
			$('quadrant-' + quadrants[i]).style.display = 'block';
		} else {
			$('quadrant-' + quadrants[i]).style.display = 'none';
		}
	}
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}	

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}	

function pageWidth() {
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() {
    return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function changePos()
{
	if(hidden == true) {
		pos = findPos($('contents'));
		$('logo').style.left = pos[0]+'px'
	}
}

function ie6Warning() {
    popW = 400, popH = 200;
    posX = Math.round((pageWidth() / 2) - (popW / 2));
    posY = Math.round((pageHeight() / 2) - (popH / 2));

    $('ie6Warning').style.width = popW+'px';
    $('ie6Warning').style.height = popH+'px';
    $('ie6Warning').style.left = posX+'px';
    $('ie6Warning').style.top = posY+'px';
    $('ie6Warning').style.display = 'block';
}


Event.observe(window, 'load', function() { 

	/* Only execute for follow up pages */
	if($('logo'))
	{
		window.onresize = changePos;
		changePos();
		$('logo').style.display = 'block';

		// Show balloon only x times every session
		Cookie.init({name: 'exin'});
		balloonInner = Cookie.getData('balloonInner');
		if(!balloonInner) {balloonInner = 0;}
		if(balloonInner < 3) {
			balloonInner++;
			Cookie.setData('balloonInner', balloonInner);

			pos = findPos($('contents'));
			$('balloon').style.left = (pos[0]+ 180) + 'px';
			$('balloon').style.top = '30px';
			setTimeout('Effect.Appear(\'balloon\', { duration: 0 });', 1000);
			setTimeout('Effect.Fade(\'balloon\', { duration: 1.2, queue: \'end\' });', 5000);
		}
	}
	
	if($('leftColumn'))
	{
		$('rightColumn').style.height = ($('leftColumn').offsetHeight)+'px'
		pos = findPos($('leftColumn'));
	}
});
