//*************************************************************************************************
// nznl.com | nznl.net | nznl.org Internet Productions
// Geert Dekkers Web Studio 2008
// _do.js for zaanprimair.nl
//
//*************************************************************************************************
//-------------------------------------------------------------------------------------------------



// DATA ///////////////////////////////////////////////////////////////////////////////////////////

// Initiate a hash to represent book (top category) colours and background images
Colours = $H({'organisatie': '#f8b334', 'ouders': '#043882', 'scholen': '#dc002e', 'home': '#00ac26', 'show': '#00ac26'}); 	
Backgrounds = $H({'organisatie': 'red-green-red-blue', 'ouders': 'red-orange-red-white', 'scholen': 'green-orange-green-blue', 'home': 'red-orange-red-blue', 'show': 'red-orange-red-blue'});
HomeLinks = $H({'organisatie': '#dc002e', 'ouders': '#f8b334', 'scholen': '#f8b334', 'home': '#004489', 'show': '#004489'}); 	

// Array of divs to be changed
Divs = new Array('submenu', 'right_column');
// Links to '/'												
Links = new Array('header', 'home'); 																		

///////////////////////////////////////////////////////////////////////////////////////////////////



Event.observe(window, 'load', function(){
	// Give the elements in Links an onclick and an onmouseover/onmouseout
	
	
	
	$$('div.menu_inner').each(function(item){
		$(item).appear({duration: .7});
	});
	
	$$('span.chapter').each(function(item){
	// IE doesn't respect :hover on any other element than an anchor
	// so we'll have to resort to this to mark the links
		Event.observe(item, 'mouseover', function(){
			$(item).addClassName('over-' + s);
		});
		Event.observe(item, 'mouseout', function(){
			$(item).removeClassName('over-' + s);
		});
		
	// Observe click event
		Event.observe(item, 'click', function(event){
			if(event.element().id == 'back-to-home'){
				location.href='/home/';
			}else{
				location.href='/' + s + '/' + event.element().id + '/';
			}
		});
		
		if($('dl-home')){
			if(HomeLinks.get(s)){
				$('back-to-home').setStyle({color: HomeLinks.get(s)});
				$('pseudo-list-disc-back-to-home').setStyle({color: HomeLinks.get(s)});
			}else{
				$('back-to-home').setStyle({color: HomeLinks.get('home')});
				$('pseudo-list-disc-back-to-home').setStyle({color: HomeLinks.get('home')});
			}
		}
	});
	
	$$('span.page').each(function(item){
	// IE doesn't respect :hover on any other element than an anchor
	// so we'll have to resort to this to mark the links
		Event.observe(item, 'mouseover', function(){
			$(item).addClassName('over-' + s);
		});
		Event.observe(item, 'mouseout', function(){
			$(item).removeClassName('over-' + s);
		});
		
	// Observe click event
		Event.observe(item, 'click', function(event){
			location.href = event.element().id.replace('-menu','');
		});
	});

	

	Event.observe('active_menu', 'click', function(){
		if (s){
			location.href='/' + s + '/';
		}
	
		});

	// Give the element an effect	
	$('submenu-content-container').appear({duration: .3});

	


	
	
	$$('div.menu_name').each(function(item){
		Event.observe(item, 'click', function(event){location.href='/' + event.element().id + '/';});	
	});
	
	
});

function setBackground(s){
	
			if (s){			
			Divs.each(function(div){// Changes background colour of the divs entered in the Divs array
				if (Colours.get(s)){
				$(div).setStyle({backgroundColor: Colours.get(s)});	
				}else{
					$(div).setStyle({backgroundColor: '#00ac26'});
				}	
			});
			if(Backgrounds.get(s)){
				$('submenu').setStyle({backgroundImage: 'url(/static/img/head_' + Backgrounds.get(s) + '.png)'});
				$('tails').setStyle({backgroundImage: 'url(/static/img/tails_' + Backgrounds.get(s) + '.gif)'});
				$('active_menu').className = 'submenu_' + s; 			// Sets the appropriate class name
			}else{
				
				$('submenu').setStyle({backgroundImage: 'url(/static/img/head_' + Backgrounds.get('home') + '.png)'});
				$('tails').setStyle({backgroundImage: 'url(/static/img/tails_' + Backgrounds.get('home') + '.gif)'});
				$('submenu').setStyle({backgroundPosition: '52px 124px'});
				$('homeImageContainer').setStyle({backgroundImage: 'none'});
				$('active_menu').className = 'submenu_generic';
				$('active_menu').update(s);
				
				
			}
			
			if (s == 'home'){
				$('submenu').setStyle({backgroundPosition: '74px 148px'});
				$('homeImageContainer').setStyle({backgroundImage: 'none'});
			}

			

			}else{
				Divs.each(function(div){
					$(div).setStyle({backgroundColor: Colours.get('home')});
				});
				$('active_menu').className = 'submenu_show_search'; 
			}
	
}

function correctLayout(){
	
	// Sets height for these containers
	bottomContainerHeight = $('bottomContainer').getHeight();
	$('submenu').setStyle({height: bottomContainerHeight + 'px'});
	rightColumnHeight = $('box').getHeight();
	$('right_column').setStyle({height: rightColumnHeight + 'px'});
	
}

function enableMenu(){
	
	// top menu effects
	// see also init in base.html
	
	
	$$('div.top_menu').each(function(item){

		Event.observe(item, 'mouseover', function(){
			new Effect.Morph(item, { style: {top: '5px'}, duration: .2});
		});
		
		
		Event.observe(item, 'mouseout', function(){
			new Effect.Morph(item, {style: {top: '0px'}, duration: .2});
		});


	});
	
	
	
}


//-------------------------------------------------------------------------------------------------
	Ajax.Responders.register({
	    onCreate: function(){Element.show('spinner');},
	    onComplete: function(){Element.hide('spinner');}
	});


function reportError(request) {

	// generic prototype helper
	// uncomment for use in a debug container (and enter the debug container into the DOM, obviously)
	alert('Error: ' + request.status);
	//	$('debug').show();
	//	$('debug').update('Fout: ' + request.status + ' <a href="#" style="float: right" onclick="$(\'debug\').hide()" >X</a>');
	}



function showSearch(){
	// Initiates the search form
	var mAjax = new Ajax.Updater({success:'zp-searchContainer'}, "/show/search/", {method: 'get'});	
}


function fontSize(val){
	current = $('content').getStyle('font-size');

	if(current.endsWith('pt')){

		font_size = parseInt(current.replace('pt',''));
		$('content').setStyle({fontSize: font_size + val + 'pt'});
		
	}else if(current.endsWith('px')){

		font_size = parseInt(current.replace('px',''));
		$('content').setStyle({fontSize: font_size + val + 'px'});

	}
	
}