/***********************************************************************

Author:     Ilse van Gemert
Company:    Tiekstramedia
URL:        http://www.tiekstramedia.nl

***********************************************************************/


/* Initialize behaviour on page or DOM load
-------------------------------------------------------------------- */
$(document).ready(function() {
	if (arguments.callee.done) {
		return;
	}
	
	arguments.callee.done = true;
	
	if (typeof(document.getElementById) == 'undefined') {
		document.getElementById = function(id) {
			return document.all[id];
		};
	}
	
	setColumnHeights();
	setToggleSearchArchive();
	setHorizon();

	window.onresize = positionHorizon;
		
});



/*
-------------------------------------------------------------------- */
function setColumnHeights() {
	
	var primary = document.getElementById('primaryContent');
	var secondary = document.getElementById('secondaryContent');
	
	if (!primary || !secondary) { 
		return false;
	}
	
	else if (primary.offsetHeight < secondary.offsetHeight) {
		primary.style.height = secondary.offsetHeight + 'px';
	}
	
}


/*
-------------------------------------------------------------------- */
function setToggleSearchArchive() {
	
	var toggle = document.getElementById('toggleSearch');
	var search = document.getElementById('searchForm');
	
	if (toggle && search) {

		toggle.style.display = 'block';		
		search.style.display = 'none';
		
		toggle.onclick = function() {
			document.getElementById('searchForm').style.display = 'block';
			this.style.display = 'none';
			setColumnHeights();
		};
		
	}
}


/*
-------------------------------------------------------------------- */
function setHorizon() {
	// check if all the requirements are met
	if (!document.getElementById('container')) return;

	$("#container").before('<div id="horizon"><img src="assets/layout/bg.header-addon.jpg" alt="" /></div>');
	
	$("#horizon img").load(function() {
		positionHorizon();
	});
}


/*
-------------------------------------------------------------------- */
function positionHorizon() {

	// check if all the requirements are met
	if (!document.getElementById('container') || !document.getElementById('horizon')) return;
	
	// variables
	var container = document.getElementById('container');
	var horizon = document.getElementById('horizon');
	
	// dimensions
	if (self.innerHeight) { // all except Explorer
		correction = 17;
	} else {
		correction = 18;
	}



	// //container minus padding
	// var containerOffsetWidth = container.offsetWidth - 18;
	// 
	// horizon.style.width = (document.body.clientWidth - containerOffsetWidth) / 2 + correction + "px";
	// 
	// // position
	// horizon.style.left = container.offsetLeft +  container.offsetWidth - 17 + "px";


	
	horizon.style.width = (document.body.clientWidth - container.offsetWidth) / 2 + correction + "px";
	
	// position
	horizon.style.left = container.offsetLeft +  container.offsetWidth - correction + "px";
}



/*
-------------------------------------------------------------------- */
function getWindowDimension(heightOrWidth) {

	var windowHeight = 0;
	var windowWidth = 0;

	if (typeof(window.innerHeight) == 'number') {

		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;

	} else {

		if (document.documentElement && document.documentElement.clientHeight) {

			windowHeight = document.documentElement.clientHeight;
			windowWidth = document.documentElement.clientWidth;

		} else {

			if (document.body && document.body.clientHeight) {

				windowHeight = document.body.clientHeight;
				windowWidth = document.body.clientWidth;

			}

		}

	}
	
	if (heightOrWidth == "heigth") {
		return windowHeight;
	} else if (heightOrWidth == "width") {
		return windowWidth;
	}


}

var x,y;
if (self.innerHeight) // all except Explorer
{
	x = self.innerWidth;
	y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	x = document.documentElement.clientWidth;
	y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
	x = document.body.clientWidth;
	y = document.body.clientHeight;
}