$(document).ready(function(){
	$('#content div.centerbox div.box220:not(:first)').addClass('spacer220');

	$('#shoutbox div.centerbox h2').css('marginTop', ($('#shoutbox div.centerbox').height() - $('#shoutbox div.centerbox h2').height()) / 2);
	$('#shoutbox div.centerbox p').css('marginTop', ($('#shoutbox div.centerbox').height() - $('#shoutbox div.centerbox p').height()) / 2);
	
	$('#content div.centerbox div.box450:not(:even)').addClass('spacer450');

	$("#promo_items").scrollable({ circular: true, mousewheel: true }).navigator({
		// select A tags inside the navigator to work as items (not direct children)
		naviItem: 'a',
 
		// assign "current" class name for the active A tag inside navigator
		activeClass: 'current',
 
		// make browser's back button work
		history: true
 
	}).autoscroll({ interval: 8000 });;
	
	var hbloglist = $('#bloglist').height();
	var hblogoptions = $('#blogoptions').height();
	if (hbloglist < hblogoptions) $('#bloglist').height(hblogoptions); else $('#blogoptions').height(hbloglist);
	
	if ($('body').height() < $(window).height())
	{
		var margintop =  $(window).height() - $('body').height();
		$('#footer').css('marginTop', margintop);  
		
	}
	
	var initialWidth = $('#content pre:first').width(); //store the initial width of code-boxes for the reset on mouse out
	
	$('pre').hover(function() { //on mouse over
			if($(this).height() > $(this).children().height()) 
			{ //if <pre> is higher than <code>
				var openSpace = Math.round(($('body').width() - initialWidth) / 2 - 10); //calculate the space to the right with a margin-right of 10px
		
				if($(this).width() == initialWidth) 
				{ //start animation only when we are at starting point (initial width)
					$(this).animate({ width : initialWidth + openSpace }, 'fast'); //increase the width with animation
				}
			}
		}, function() { //on mouse out
			$(this).animate({ width : initialWidth }, 'fast'); //reset to initial width with animation
		});
	
	$('#content pre').each(function() { //on each code box do
			$(this)
			.before('<a href="#" class="codeswitch">View this source in Plain Text</a>') //write a code right before the code-box
			.after('<textarea rows="' + ($(this).children().html().split("\n").length-1) + '" cols="50">' + $(this).children().html() + '</textarea>'); //write a textarea with the content of the code-box after it
		});
	
	$('.codeswitch').toggle(function() { //hide code-box and show textarea
			$(this)
			.text('View this source as Highlighted Code') //change text of the link
			.next().hide().next().show(); //first next is code-box, second is textarea
		}, function() { //hide textarea and show code box
			$(this)
			.text('View this source in Plain Text')
			.next().show().next().hide();
		});
		
	$('#shoutbox a').click(function() { return false } );
	
	if ($('#googlemap').length > 0)	
	{
		$('#googlemap').googleMap({ 
					//all the custom declarations go in here 
					zoomLevel: 15,
					center: 'Lijmbeekstraat 196, 5612 NJ, Eindhoven',
					image: '/images/logo.png',
					imagewidth: 253,
					imageheight: 56
				}).load();
	} 
});

function getUrlVars() {
	var map = {};
	var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
		map[key] = value;
	});
	return map;
}

/*
* Afhandeling zoekfunctie voor CMS gestuurde sites
* Author: Colin Myerscough
*/

function doSearch()
{
    if (document.getElementById('zoekquery').value.length > 2)
    {
    	document.getElementById('zoekform').action = window.jsRootPath + 'zoeken.php';
    	document.getElementById('zoekform').submit();
    }
	else
    {
        alert('Zoekterm is te kort, minimaal 3 tekens nodig');
    }
}

function submitSearch()
{
    if (document.getElementById('zoekquery').value.length > 2)
    {
        document.getElementById('zoekform').action = window.jsRootPath + 'zoeken.php';
         return true;
    } else
    {
        alert('Zoekterm is te kort, minimaal 3 tekens nodig');
        return false;
    }
}

function printElement(strid)
{
	var prtContent = document.getElementById(strid);
	var WinPrint =
	window.open('','','left=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
	WinPrint.document.write(prtContent.innerHTML);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();
	prtContent.innerHTML=strOldOne;
}

