/**
* Common functions...
*/


/**
* font size routines
*/
function buildFontSizeMenu(){
	o = document.getElementById('fontSizeMenu');
	if(o){
		d = o.getElementsByTagName('div');
		for(i=0;i<d.length;i++){
			if(d[i].className == 'print')
				d[i].innerHTML = '<img src="/domains/skoop.nl/images/print.png" width="14" height="14" alt="" />';
			else
				d[i].innerHTML = 'A';
		}
	}
}
//trigger
function setFontSize(obj){
	loadCSS("/domains/skoop.nl/css/size_" + obj.className + ".css");
}
//print window...
function printPage(){
	window.print();
}
//load new CSS style sheet and activate...
function loadCSS(newCSS){
	var headElem = document.getElementsByTagName("head")[0];
	var cssLinkElem = document.createElement("link");
	cssLinkElem.setAttribute("href", newCSS);
	cssLinkElem.setAttribute("type", "text/css");
	cssLinkElem.setAttribute("rel", "stylesheet");
	headElem.appendChild(cssLinkElem);
}


//hold the anchor menu...
function staticAnchorMenu(){
	obj = document.getElementById('firstAnchorMenu');
	if(obj && obj.getElementsByTagName('ul').length > 0){
		y = document.all ? (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) : window.pageYOffset;
		if(y >= 153){
			obj.style.position = navigator.userAgent.toLowerCase().indexOf('msie') > 0 && navigator.userAgent.toLowerCase().indexOf('6') > 0 ? 'absolute' : 'fixed';
			obj.style.top = '2px';
			if(obj.style.position != 'fixed')
				obj.style.top = (y + 2) + 'px';
		}else{
			obj.style.top = '';
			obj.style.position = 'static';
		}

		//timer
		if(obj.staticAnchorTmr)
			obj.staticAnchorTmr = window.clearTimeout(obj.staticAnchorTmr);
		obj.staticAnchorTmr = window.setTimeout(function(){staticAnchorMenu()},10);
	}
}

//make room beneeth the anchors...
function addAnchorSpace(obj){
	a = document.getElementsByTagName('a');
	for(i=0;i<a.length;i++){
		if(!a[i].href && a[i].name && a[i].name.indexOf('record_') < 0){
			a[i].className = "anchorSpace";
		}
	}
}


function debug(str){
	document.getElementById('DEBUG').innerHTML = str;
}


/**
* Patch main template, disable empty columns...
*/
function resizeMiddle(){
    //adjust width of middle column depanding on the left and right column...
    if(document.getElementById('middle')){
        if(document.all)
        	w = parseInt(document.getElementById('middle').currentStyle.width);
        else
        	w = parseInt(document.defaultView.getComputedStyle(document.getElementById('middle'), '').getPropertyValue('width'));
		if(document.getElementById('left').innerHTML.toLowerCase() == '<div></div>')
			w = w + 200;
		if(document.getElementById('right').innerHTML.toLowerCase() == '<div></div>'){
			document.getElementById('middle').style.paddingRight = "10px";
			w = w + 320;
        }
		document.getElementById('middle').style.width = w + "px";
	}
}


/**
* Nice buttons
*/
//builder
function niceButtons(){
	buts = document.getElementsByTagName('input');
	for(i=0;i<buts.length;i++){
		if(buts[i].type == 'submit' || buts[i].type == 'button'){
			//get data
			v = buts[i].value;
			n = buts[i].name;
			if(buts[i].type == 'submit')
				t = buts[i].type;
        	else
            	t = buts[i].getAttribute("onclick");

            //change form ID?
            if(!buts[i].form.id)
				buts[i].form.id = 'niceFormId' + i;

			//event
            evnt = " onclick=\"niceButtonClick(document.getElementById('" + buts[i].form.id + "'),'" + escape(t) + "','" + n + "','" + v + "')\"";

			//build new stuff...
			newBut = document.createElement("div");
			newBut.className = "submit_container";
			newBut.innerHTML+= "	<div class=\"left\""+ evnt +"><span></span></div>";
			newBut.innerHTML+= "	<div class=\"submit\""+ evnt +">" + v + "</div>";
			newBut.innerHTML+= "	<div class=\"right\""+ evnt +"><span></span></div>";
            newBut.innerHTML+= "<input type=\"hidden\" />"; // patch disapearing inputs

			buts[i].parentNode.replaceChild(newBut,buts[i]);
		}
	}
}
//trigger
function niceButtonClick(frm,t,n,v){
	obj = document.createElement('input');
	obj.type = 'hidden';
	obj.name = n;
	obj.value = v;
	frm.appendChild(obj);
    if(t == 'submit')
		frm.submit();
	else
		eval(unescape(t) + ';');
}



// **********************************************************
// Do some onloads
window.onload = function(){
//     if(document.all) //not for ff, only to test in MSIE... Have to loose this!!To much space above every anchor
	fixSWFwmode(document.getElementById('content'));
 		addAnchorSpace();
	staticAnchorMenu();
	buildFontSizeMenu();
// 	resizeMiddle();
	niceButtons();

	//patch strange behavour of MSIE and flash files...
	//		they don't autostart... and with this patch they do...
	//		it seems something to do with a legal somthing of Microsoft and activeX?
	if(document.all){
		o = document.getElementsByTagName("object");
		for(i=0;i<o.length;i++)
			o[i].outerHTML = o[i].outerHTML;
	}
}

$(document).ready(function(){
	//submenus
	$("#mainmenu ul li").hover(
		function(){
			if($(this).children('ul:eq(0)').is(':hidden'))
				$(this).children('ul:eq(0)').css('display','block');
		},
		function(){
			if($(this).children('ul:eq(0)').is(':visible'))
				$(this).children('ul:eq(0)').css('display','none');
		}
    );
});