/*
 * portal layout resize script (internet)
 * @author volkc
 */

/*
	10.08.09 - lasotapa
	Create event that kicks in when DOM is ready (don't wait for pictures or videos to load)
*/

//create onDomReady Event
window.onDomReady = initReady;

// Initialize event depending on browser
  function initReady(fn)
  {
  	//W3C-compliant browser
  	if(document.addEventListener) {
      document.addEventListener("DOMContentLoaded", fn, false);
    }
  	//IE
  	else {
      document.onreadystatechange = function(){readyState(fn)}
    }
  }

  //IE execute function
  function readyState(func)
  {
  	// DOM is ready
  	if(document.readyState == "interactive" || document.readyState == "complete")
  	{
  		func();
  	}
  }

//execute as soon as DOM is loaded

window.onDomReady(initializeFontSize);


function zoomFontSize(percent) {
	//just do this if percent is a number -10/0/+10 etc...
	if(typeof(percent) == 'number'){
		var currentFontSize = document.body.style.fontSize;

		if(currentFontSize == '' || percent == 0){
			currentFontSize = 100;
		}else{
			currentFontSize = parseInt(currentFontSize);
		}

		// calculate the new font size
		currentFontSize = currentFontSize + percent;

		saveFontSize(currentFontSize + '%');
	}

	resizeLogo();

	//give some other functions the ability to extend the resizer
	if(typeof(adjustContentDimensions) == 'function')
		adjustContentDimensions();
}

function initializeFontSize() {
	var cookies = document.cookie.split(';');
	var size = '';

	for(var i = 0; i < cookies.length; i++){
		/* write array-entry to cookie-variable and replace any spaces */
		var cookie = cookies[i].replace(/ /g, "");

		var posOfEqualsSign = cookie.indexOf('=');

		if(cookie.substring(0, posOfEqualsSign) == 'fontSize'){
			size = cookie.substring(posOfEqualsSign + 1, cookie.length);
			saveFontSize(size);

			break;
		}
	}


}

function saveFontSize(size) {
	/* Set cookies path to root to make it available for any site */

	document.cookie = "fontSize=" + String(size) + ";path=/";
	document.body.style.fontSize = String(size);
}

/*
	Resize banderole to width of sub navigation
*/
function resizeLogo() {
    if (document.getElementById("subNav") != null && document.getElementById("banderole") != null)
    {
		if (document.getElementById("banderole").style.width == null || document.getElementById("banderole").style.width == '')
		{
			document.getElementById("banderole").style.width = '100%';
		}
		document.getElementById("banderole").style.width = document.getElementById("subNav").offsetWidth + "px";

		if(document.getElementById("banderole2") != null) {
			document.getElementById("banderole2").style.width = document.getElementById("subNav").offsetWidth + "px";
		}
		if(document.getElementById("logo") != null) {
			document.getElementById("logo").style.width = document.getElementById("subNav").offsetWidth + "px";
		}
	}
}


