window.onload = loaded;

var ie = document.all?true:false, ie6 = false;
var language = 'nl';
function loaded(){
	if(typeof document.body.style.maxHeight == "undefined"){
		ie6 = true;
	}
	
	preloadimages('contact_over.png', 'home_over.png', 'mijn_regoparcis.png', 'mobiele_communicatie_over.png', 'wagenpark_active.png');
	
	/*new Effect.Pulsate('hole', {pulses: 1, from: 0.3, duration: 3});
	
	window.setInterval(function(){
		new Effect.Pulsate('hole', {pulses: 1, from: 0.3, duration: 3});
	}, 15000);*/
	
	if($('notice')){
		new Effect.Appear('notice');
		
		window.setTimeout(function(){
			new Effect.Fade('notice');
		}, 10000);
	}
}

var headlines, Headlines = Class.create();
Headlines.prototype = {
	initialize: function(obj){
		this.headlines = [];
		this.obj = $('headlines');

		this.active = -1;
		
		elements = this.obj.select('div');
		for(i=0; i<elements.length; i++){
			elements[i].hide();
			this.headlines[i] = elements[i];
		}
		
		this.play();
	},
	
	play: function(){
		if(this.active+2 > this.headlines.length){
			this.active = 0;
		} else {
			this.active++;
		}
		
		window.setTimeout(function(){
			headlines.obj.fade({duration: 0.5});
		
			
			window.setTimeout(function(){
				headlines.obj.appear({duration: 0.5});
				
				headlines.headlines.each(function(headline){
					headline.hide();
				});
				
				headlines.headlines[headlines.active].show();
			}, 550);
		}, 1000);
		
		window.setTimeout(function(){
			headlines.play();
		}, 8000);
	}
}

var tooltips, Tooltips = Class.create();
Tooltips.prototype = {
	initialize: function(controller, action){
		this.controller = controller;
		this.action = action;
		
		new Ajax.Request('/parcis/meldingen/tooltips', {parameters: {c: controller, a: action}});
	},
	
	create: function(element, message, tip_options){	
		element = $$(element)[0];
	
		options = new $H({
				stem: 'bottomMiddle',
				hook: { tip: 'topMiddle', target: 'topMiddle'},
				showOn: false,
				hideOn: { element: 'closeButton', event: 'click' },
				hideAfter: 10});
		options = options.merge(tip_options);
	
		tooltip = new Tip(element, message, options.toObject());
		element.prototip.show();
		
		element.observe('prototip:hidden', function() {
			element.removeClassName('tooltipped');
		});
		
		element.addClassName('tooltipped');
	}
}

/* COMMON FUNCTIONS */
function addcodetofunction(func,code){
	if(func == undefined){
		return code;
	} else {
		return function(){
			func();
			code();
		}
	}
}

function preloadimages() { 
	var d=document; 
	if(d.images){ 
		if(!d.MM_p){
			d.MM_p=new Array();
		} 
			
		var i,j=d.MM_p.length,a=preloadimages.arguments; 
		
		for(i=0; i<a.length; i++){
			if (a[i].indexOf("#")!=0){ 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src ='/images/header/navigation/' + language + '/' + a[i]; 
			}
		}
	}
}