function init_page( ) {

  // png fix
  if ( typeof(pngfix) == 'function' ) {
    pngfix();
    for ( var i=1; i<=3; i++ ) {
      for ( var j=1; j<=13; j++ ) {
        document.getElementById('menu_'+i+'_vaandel_'+j).style.display = 'none';
      }
      document.getElementById('menu_'+i+'_container').style.visibility = 'visible';
    }
  }

  if ( window.location.search.search( 'open_campagnevoorbeeldpage_id=([0-9]+)' ) != -1 ) {
    var open_campagnevoorbeeldpage_id = window.location.search.substring( window.location.search.search( 'open_campagnevoorbeeldpage_id=' ) + 30, window.location.search.length - window.location.search.search( 'open_campagnevoorbeeldpage_id=[0-9]+' ) + 30 );
    open_campagnevoorbeeldpage( open_campagnevoorbeeldpage_id );
  }

  var emailaddress = 'info';
  emailaddress = emailaddress + '\@';
  emailaddress = emailaddress + 'multimarketeers'
  emailaddress = emailaddress + '.' + 'nl'
  document.getElementById('mailtolink').innerHTML = emailaddress;
  document.getElementById('mailtolink').href = 'mail' + 'to:' + emailaddress;

}

function open_window( url, width, height, left, top, extra_params ) {

  extra_params = extra_params || 'dependent=no,directories=no,location=no,menubar=no,personalbar=no,status=no,resizable=yes,scrollbars=yes';
  width  = width  || 450;
  height = height || 600;
  if ( !left && !top ) {
    var screenX = 30; var screenY = 30; var screenTop = 30; var screenLeft = 30;
    if ( typeof(window.screenLeft) != 'undefined' ) {
    	left = screenLeft + window.screenLeft;
    	top	 = screenTop + window.screenTop;
    } else {
    	left = screenX + window.screenX;
    	top	 = screenY + window.screenY;
    }
  }

  window.open( url, 'popupWindow', 'width='+width+',height='+height+',left='+left+',top='+top+','+extra_params);

}

var menu_interval;
var menu_animatie_stap = 1;
var open_menu = 0;

function mouseover_vaandel( e, which ) {
  if ( open_menu ) {
    vaandel_animatie_hide( open_menu )
  }
  open_menu = which;
  document.getElementById('menu_' + which + '_image').style.display = 'none';
  document.getElementById('menu_' + which + '_vaandel_' + 1).style.display = 'block';
  menu_interval = setInterval( function() { vaandel_animatie_next(which) }, 75 );
  changecss('.keyword_categorie_'+which, 'color', [ '#ea4d25','#1c9dd7','#f77c00' ][which-1] );
  document.onmouseover = mouseout_vaandel;
}

function mouseout_vaandel( e, which ) {

  e = (e) ? e : window.event;
  target = e.target || e.srcElement;

  var top = e.target ? "HTML" : "BODY";
  while (target.tagName != top && typeof(target.id) == 'undefined' ) {
    target = target.parentNode || target.parentElement;
  }

  if ( target.id.search('menu') == -1 && target.id.search('vaadel') == -1 && open_menu ) {
    // hide_menu( open_menu )
    vaandel_animatie_hide(open_menu)
  }

}

function vaandel_animatie_next( which ) {
  document.getElementById('menu_' + which + '_vaandel_' + menu_animatie_stap).style.display = 'none';
  menu_animatie_stap++;
  document.getElementById('menu_' + which + '_vaandel_' + menu_animatie_stap).style.display = 'block';
  if ( menu_interval && menu_animatie_stap == 13 ) {
    show_menu( which );
    clearInterval( menu_interval );
    menu_animatie_stap = 1;
  }
}

function vaandel_animatie_hide( which ) {
  if ( menu_interval ) {
    clearInterval( menu_interval );
  }
  menu_animatie_stap = 1;
  document.getElementById('menu_' + which + '_image').style.display = 'block';
  for ( var i=1; i<=13; i++ ) {
    document.getElementById('menu_' + which + '_vaandel_' + i).style.display = 'none';
  }
  open_menu = 0;
  changecss('.keyword_categorie_'+which, 'color', '#a0a0a0' );
  document.getElementById('menu_'+which+'_items_container').style.display = 'none';
  document.onmouseover = null;
}

function show_menu( which ) {
  document.getElementById('menu_'+which+'_items_container').style.display = 'block';
}

function open_campagnevoorbeeldpage(id, campagnevoorbeeld_id) {

	var url = igorurl + "/get.campagnevoorbeeldpage.pl?id="+id+"&campagnevoorbeeld_id="+campagnevoorbeeld_id;
  var dateobject = new Date();
  url = url + '&' + dateobject.getMilliseconds()
		
	var req;
	if (window.XMLHttpRequest){
		 req = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject){ 
		 req = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
		 if (req.status == 200) {
				show_campagnevoorbeeldpage( req );
		 }	
		}
	}
	req.open("GET", url, true);
	req.send(null);
	
	function show_campagnevoorbeeldpage( req ) {
		var html = req.responseText;
    document.getElementById('campagnevoorbeeldpage_layer').style.display = 'block';
    document.getElementById('campagnevoorbeeldpage_content').innerHTML = html;
    document.getElementById('campagnevoorbeeldpage_layer').style.height = getPageSizeWithScroll()[1] + 'px';
    document.getElementById('campagnevoorbeeldpage_bgimage').style.height = getPageSizeWithScroll()[1] + 'px';
    window.scrollTo(0,0);
  }

}

function hide_campagnevoorbeeldpage() {
  document.getElementById('campagnevoorbeeldpage_layer').style.display = 'none';
}

// gevonden op http://www.shawnolson.net/scripts/public_smo_scripts.js
function changecss(theClass,element,value) {
    //Last Updated on June 23, 2009
    //documentation for this script at
    //http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
    var cssRules;

    var added = false;
    for (var S = 0; S < document.styleSheets.length; S++){

        if (document.styleSheets[S]['rules']) {
            cssRules = 'rules';
        } else if (document.styleSheets[S]['cssRules']) {
            cssRules = 'cssRules';
        } else {
            //no rules found... browser unknown
        }

        for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
            if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
                if(document.styleSheets[S][cssRules][R].style[element]){
                    document.styleSheets[S][cssRules][R].style[element] = value;
                    added=true;
                    break;
                }
            }
        }
        if(!added){
            if(document.styleSheets[S].insertRule){
                document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
            } else if (document.styleSheets[S].addRule) {
                document.styleSheets[S].addRule(theClass,element+': '+value+';');
            }
        }
    }
}

// van http://codylindley.com/Webdev/295/javascript-get-page-height-with-scroll, met een aanpassing van http://www.codehouse.com/javascript/articles/scroll_area/
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else if (document.body.offsetHeight > document.documentElement.scrollHeight) { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	} else {
    xWithScroll = document.documentElement.scrollWidth;
    yWithScroll = document.documentElement.scrollHeight;
  }
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}


