/* 
** by francky:  www.developerscorner.nl ***
*/

function createPrintbutton(){
	if (document.getElementById('printer')){
		var printbuttonP = document.createElement('span');
		printbuttonP.id = "print";
		document.getElementById('printer').appendChild(printbuttonP);
		var htmlCode='<a title="Druk deze pagina af" href="javascript:window.print()"><span ';
		htmlCode +=  'class="invis">Print deze pagina<\/span><\/a>';
		printbuttonP.innerHTML = htmlCode;
	}
}

function createJumpToTop(){
	if ( document.getElementById('jumptop') ) {
		var jumper = document.getElementById('jumptop');
		jumper.setAttribute('onfocus','scrollTo(0,0)');
	}
	if ( document.getElementById('last-link') ) {
		var jumper = document.getElementById('last-link');
		jumper.setAttribute('onkeypress','scrollTo(0,0)');
	}
}
// ************************************************************************************
// lettergrootte-script

function createFontsizeLinks(){
	if(document.getElementById('kopbalk')){
	// making line	
	var fontsizeLine = document.createElement('p');
	fontsizeLine.id = "noshow";
	document.getElementById('kopbalk').appendChild(fontsizeLine);
	var htmlCode='Lettergrootte instellen.';
	fontsizeLine.innerHTML = htmlCode;
	
	// making list	
	var fontsizeList = document.createElement('ul');
	fontsizeList.id = "lettergrootte";
	document.getElementById('kopbalk').appendChild(fontsizeList);
	// filling list
	var statusbarlink = "http:\/\/clientenbelangamsterdam.nl\/LETTERGROOTTE_INSTELLEN" 
	var htmlCode='<li><a id="fsize1" title="KLEIN"      onclick="sizefont(1); return false" href="'+statusbarlink+'"><\/a><\/li>';
	htmlCode +=  '<li><a id="fsize2" title="VRIJ KLEIN" onclick="sizefont(2); return false" href="'+statusbarlink+'"><\/a><\/li>';
	htmlCode +=  '<li><a id="fsize3" title="MIDDEL"     onclick="sizefont(3); return false" href="'+statusbarlink+'"><\/a><\/li>';
	htmlCode +=  '<li><a id="fsize4" title="VRIJ GROOT" onclick="sizefont(4); return false" href="'+statusbarlink+'"><\/a><\/li>';
	htmlCode +=  '<li><a id="fsize5" title="GROOT"      onclick="sizefont(5); return false" href="'+statusbarlink+'"><\/a><\/li>';
	fontsizeList.innerHTML = htmlCode;
	// showing list
	var showKopbalk = document.getElementById('kopbalk');
	showKopbalk.style.display = "block";
	}
}

function startfont(){
	var fontsizeActive = get_cookie("fontsizecookie");
	if ( fontsizeActive == "nothing"){ fontsizeActive = 3; }

	var linkBackground = document.getElementById('fsize'+fontsizeActive+'').style;
	linkBackground.background = "url(http://clientenbelangamsterdam.nl/systemimages/corners.png)";
	
	var bodystyle = document.getElementsByTagName('body')[0].style;
		if ( fontsizeActive == 1 ) { bodystyle.fontSize = "85%";    linkBackground.backgroundPosition = "-789px -53px" ; }
		if ( fontsizeActive == 2 ) { bodystyle.fontSize = "90%";    linkBackground.backgroundPosition = "-808px -53px" ; }
		if ( fontsizeActive == 3 ) { bodystyle.fontSize = "100.1%"; linkBackground.backgroundPosition = "-827px -53px" ; }
		if ( fontsizeActive == 4 ) { bodystyle.fontSize = "106%";   linkBackground.backgroundPosition = "-846px -53px" ; }
		if ( fontsizeActive == 5 ) { bodystyle.fontSize = "117%";   linkBackground.backgroundPosition = "-865px -53px" ; }
}

function sizefont(i){
	var n;
	for (n=1; n<=5; n++){
		if (document.getElementById('fsize'+n+'')){
			var linkBackground = document.getElementById('fsize'+n+'').style;
			linkBackground.background = "none";
		}
		else return false;
	}

	var linkBackground = document.getElementById('fsize'+i+'').style;
	linkBackground.background = "url(http://clientenbelangamsterdam.nl/systemimages/corners.png)";
	
	var bodystyle = document.getElementsByTagName('body')[0].style;
		if ( i == 1 ) { bodystyle.fontSize = "85%";    linkBackground.backgroundPosition = "-789px -53px" ; }
		if ( i == 2 ) { bodystyle.fontSize = "90%";    linkBackground.backgroundPosition = "-808px -53px" ; }
		if ( i == 3 ) { bodystyle.fontSize = "100.1%"; linkBackground.backgroundPosition = "-827px -53px" ; }
		if ( i == 4 ) { bodystyle.fontSize = "106%";   linkBackground.backgroundPosition = "-846px -53px" ; }
		if ( i == 5 ) { bodystyle.fontSize = "117%";   linkBackground.backgroundPosition = "-865px -53px" ; }
	var fontsizeActive = i;
	set_cookie( "fontsizecookie", ""+fontsizeActive+"", "/" );
}

// basics from http://www.elated.com/articles/javascript-and-cookies/
// adapted by francky www.developerscorner.nl

function set_cookie( name, value, path ) {
	  var cookie_string = name + "=" + escape ( value );
	  if ( path )
		        cookie_string += "; path=" + escape ( path );
	  document.cookie = cookie_string;
}

/* http://techpatterns.com/downloads/javascript_cookies.php */
function get_cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';

	var i;
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = '';
		cookie_name = '';
	}
	return "nothing";
}				

/* link in nieuw tabblad of nieuw venster openen (met class="out") */
function createOpenLinkInNewTab(){
	if( document.getElementsByTagName ) { 
		var allLinks = document.getElementsByTagName('a');
    	for( var i=0; i < allLinks.length; i++ ){
			if (allLinks[i].className.match("out")){  
				allLinks[i].setAttribute('target','_blank');
				allLinks[i].target = "_blank"; // reserve voor IE :-)
			}
		}
	}
}

window.onload = function(){
	if ( document.getElementById ) {
		createPrintbutton();
		createJumpToTop();
		createFontsizeLinks();
		startfont();
		createOpenLinkInNewTab();
	}
	if ( document.getElementById('googleSwitch') ) {
		createGoogleSwitch();
	}
}
