/** FAQ class: */
var faq = Class.create();
faq.prototype = {
	
	list: null,
	
	initialize: function(id) {
		if($(id)) {
			this.list = $(id);
			
			// Assuming every dt has 1 dd:
			var dt = this.list.getElementsByTagName('dt');
			for(var i=0; i<dt.length; i++) {
				var link = dt[i].getElementsByTagName('a')[0];
				Event.observe(link, 'click', this.toggle.bind(this));
			}
			
		}
	},

	toggle: function(event) {
		var dt = Event.findElement(event, 'dt');
		this.closeAll();
		$(dt).nextSiblings()[0].toggle();
		Event.stop(event);
	},
	
	closeAll: function(not) {
		var dd = this.list.getElementsByTagName('dd');
		for(var i=0; i<dd.length; i++) {
			dd[i].style.display = 'none';
		}
	}
}

/** Contact class */
/*
var contactform = Class.create();
contactform.prototype = {

	form: null,
	url: '/',

	initialize: function(form, url) {
		if($(form)) {
			this.form = $(form);
			this.url = (url ? url : this.form.readAttribute('action'));
			Event.observe(this.form, 'submit', this.submit.bind(this));
		}
	},

	submit: function(event) {
		new Ajax.Request(this.url, {
			method: 'post',
			postBody: this.form.serialize(),
			onSuccess: function(t) {
				var lines = t.responseText.split("\n");
				if(lines[0] != 'ok') {
					alert(t.responseText);
				}else {
					lines[0] = '';
					var string = lines.join("\n");
					var urchinString = this.url+($('trackerPage') ? $F('trackerPage') : '');
					this.form.innerHTML = '<span class="thankyou">'+string+'</span>';
					this.form.innerHTML.evalScripts();
					urchinTracker(urchinString);
				}
			}.bind(this),
			onFailure: function(t) {
				alert('Request failed because: '+t.statusText);
			}
		});
		
		Event.stop(event);
	}

}
*/

// Left-menu

sfHover = function() {
	/*
	var sfEls = document.getElementById("left-menu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			menuitemhover(sfEls[i], true);
		}
		sfEls[i].onmouseout = function(){
			menuitemhover(sfEls[i], false);
		}
	}
	*/
}

function menuitemhover(obj, On){
	if(On)		obj.className+=" sfhover";
	else		obj.className=obj.className.replace(new RegExp(" sfhover\\b"), "");
		
	try {
		obj.getElementsByTagName('ul')[0].style.left = On? 'auto' : '-999999em';
	} catch(e) { }
}


var useRoundCorners = true;
Event.observe(window, 'load', function() {

	if($('content').getElementsByTagName('table').length > 0) {
		useRoundCorners = false;
	}


	// round corners script:
	if(useRoundCorners) {
		var round = new swfir();
		round.specify('src', baseurl+'/js/swfir.swf');
		round.specify('border-color', 'ffffff');
		round.specify('border-radius', '10');
		round.swap("#content img");
	}
	var IEversion = false;
	// get IE version:
	if(navigator.userAgent && document.all) {
		var regex = new RegExp(/MSIE ([0-9\.]{3,})\;/);
		var IEversion = regex.exec(navigator.userAgent)[1];
		IEversion = parseInt(IEversion);
	}
	
	// homepage:
	if(IEversion && IEversion < 8) {
		sfHover();
	}

	var windowWidth = (document.all) ? document.body.clientWidth : window.innerWidth+8; // 8px scrollbar
	var windowHeight = (document.all) ? document.body.clientHeight : window.innerHeight;
	if(windowWidth < 1024)
		document.getElementsByTagName('body')[0].style.overflowX = 'auto';

	new faq('faq');

	/*var allNodes = document.getElementsByClassName("lees_verder");
	for(i = 0; i < allNodes.length; i++) {
		var p = allNodes[i].previous(0);
		var t = "<a class='lees_verder' href='"+allNodes[i]+"'>"+allNodes[i].innerHTML+"</a>";
		p.innerHTML = p.innerHTML + t;
		allNodes[i].remove();
	}*/
	
});

Event.observe(document, "load", function() {

});


function printpage() {
	window.print();  
}

var Marquee = Class.create();
Marquee.prototype = {
	// Settings:
	direction: 'left',
	speed: 0.085,
	// Working variables:
	parentElement: null,
	parentWidth: 0,
	currentPosition: 0,
	timer: null,
	numItems: 0,


	initialize: function(element, speed, direction) {
		if($(element)) {

			if(speed && speed.match(new RegExp(/[1-9][0-9]{1,}/))) {
				this.speed = speed/100;
			}

			if(direction) {
				switch(direction) {
					case 'left':
					case 'right':
						this.direction = direction;
						break;
					case 'l':
						this.direction = 'left';
						break;
					case 'r':
						this.direction = 'right';
						break;
				}
			}

			this.parentElement = $(element);
			this.parentWidth = this.parentElement.offsetWidth;

			this.items = this.parentElement.getElementsByTagName('li');

			this.numItems = this.items.length;

			Event.observe(this.parentElement, 'mouseover', this.pause.bind(this));
			Event.observe(this.parentElement, 'mouseout', this.resume.bind(this));

			this.start();

		} else { /* fail silently for pages without a marquee */ }
	},

	start: function() {
		if(this.numItems > 0) {
			var totalWidth = 0;
			for(var i=0; i<this.numItems; i++) {
				totalWidth += this.items[i].offsetWidth;
			}
			if(totalWidth > this.parentWidth) {
				this.timer = new PeriodicalExecuter(this.update.bind(this), this.speed);
			}
		}
	},

	stop: function() {
		if(this.timer)
			this.timer.stop();
	},

	pause: function() {
		this.stop();
	},

	resume: function() {
		this.start();
	},

	// roep deze functie aan om de marquee te bewegen
	update: function() {
		// update the position:
		this.currentPosition = (this.currentPosition < this.parentWidth) ? ((this.direction == 'left') ? this.currentPosition-1 : this.currentPosition+1) : 0;
		this.parentElement.style.textIndent = this.currentPosition+'px';
		//
		if(0-this.currentPosition == this.items[0].offsetWidth) {
			// get the content:
			var content = this.items[0].innerHTML;
			// add the new message at the end of our marquee:
			new Insertion.Bottom(this.parentElement, '<li>'+content+'</li>');
			// remove the first message:
			Element.remove(this.items[0]);
			// update our internal array:
			this.items = this.parentElement.getElementsByTagName('li');
			this.parentElement.style.textIndent = 0;
			this.currentPosition = 0;

			// check for valid total width of the remaining items
			/*var totalWidth = 0;
			for(var i=0; i<(this.numItems-1); i++) {
				totalWidth += this.items[i].offsetWidth;
			}

			// remain items are not big enough, copy first item to the back

			if(totalWidth < this.parentWidth) {
				content = this.items[0].innerHTML;
				new Insertion.Bottom(this.parentElement, '<li>'+content+'</li>');
				this.items = this.parentElement.getElementsByTagName('li');
				this.numItems = this.items.length;
			}*/
		}
	}
}

Event.observe(window, "load", function() {

	var ticker = new Marquee('marquee');

});

//var AllCatIds = new Array();
function openDealerDocSubItem(catId){
	var ObjParent 	= $('dealerloginDocuments'+catId);
	var bln_Close 		= false;
	
	for(var i=0;i<ObjParent.childNodes.length;i++) {
        if (ObjParent.childNodes[i].style != undefined && ObjParent.childNodes[i].className.indexOf('dealerloginSubItem') != -1){
		    if(ObjParent.childNodes[i].className.indexOf('ofMainItem'+catId) != -1){
				if (ObjParent.childNodes[i].style.display == 'block')
					bln_Close = true
           		i = ObjParent.childNodes.length;
			}
		}
    }
	
	for (var i = 0; i < AllCatIds.length; i++)
		closeDealerDocSubItem(AllCatIds[i]);
	
	if(bln_Close == false){
		for(var i=0;i<ObjParent.childNodes.length;i++) {
			if (ObjParent.childNodes[i].style != undefined && ObjParent.childNodes[i].className.indexOf('dealerloginSubItem') != -1){
				if(ObjParent.childNodes[i].className.indexOf('ofMainItem'+catId) != -1){
					ObjParent.childNodes[i].style.display='block';
				}
			}
		}
	}
}
/*function openDealerDocSubItem(catId){
	var ObjParent = $('dealerloginDocuments'+catId);
	
	for (var i = 0; i < AllCatIds.length; i++)
		closeDealerDocSubItem(AllCatIds[i]);
	
	for(var i=0;i<ObjParent.childNodes.length;i++) {
        if (ObjParent.childNodes[i].style != undefined && ObjParent.childNodes[i].className.indexOf('dealerloginSubItem') != -1){
		    if(ObjParent.childNodes[i].className.indexOf('ofMainItem'+catId) != -1)
           		ObjParent.childNodes[i].style.display='block';
		}
    }
	
}*/
function closeDealerDocSubItem(catId){
	//alert(catId);
	var ObjParent = $('dealerloginDocuments'+catId);
	
	for(var i=0;i<ObjParent.childNodes.length;i++) {
        if (ObjParent.childNodes[i].style != undefined && ObjParent.childNodes[i].className.indexOf('dealerloginSubItem') != -1){
           	ObjParent.childNodes[i].style.display='none';
		}
    }
	
}


