/**
 * bostrailer.js
 *
 * Project specific javascript functions and handlers
 *
 * @version 1.0
 * @author  A.J. de Vries
 * @package www.bostrailer.nl
 * @uses    general.js
 *
 * Copyright (c) 2006 Malibomba
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,
 * WITHOUT THE PERMISION OF THE AUTHOR.
 * Info? Mail to info@malibomba.com
 */
//<![CDATA[


function map( sTitle, sZipcode ) {
	if( sZipcode != '' && sTitle != '' ) {
		var sUrl = '/plattegrond.php?postcode=' + sZipcode.replace('/[^0-9a-z]/i', '');
		makePopup( new Object(), 'slideshow', 333, 313, sTitle, '#284394', '#bf2c34', sUrl );
	}
}


var iSpeed = 5000;
var iDuration = 3;

var aImages = new Array();
aImages[0] = '/pics/1.jpg';
aImages[1] = '/pics/2.jpg';
aImages[2] = '/pics/3.jpg';
aImages[3] = '/pics/4.jpg';
aImages[4] = '/pics/5.jpg';
aImages[5] = '/pics/6.jpg';
aImages[6] = '/pics/7.jpg';
aImages[7] = '/pics/8.jpg';

var iCounter = 0;
var aPreload = new Array();
for( var i = 0; i < aImages.length; i++ ){
   aPreload[i] = new Image();
   aPreload[i].src = aImages[i];
}


/**
 * runSlideShow()
 *
 * Initialize the header (display)
 * slideshow .....................
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  void
 */
addEvent( window, 'load', runSlideShow );
function runSlideShow() {
   if( document.all ) {
      document.images.slideshow_img.style.filter="blendTrans(duration=" + iDuration + ")";
      document.images.slideshow_img.filters.blendTrans.Apply();
   }
   document.images.slideshow_img.src = aPreload[iCounter].src;

   if( document.all )
      document.images.slideshow_img.filters.blendTrans.Play();

   iCounter = iCounter + 1;
   iCounter = ( iCounter > ( aImages.length - 1) ) ? 0 : iCounter;
   setTimeout( runSlideShow, iSpeed );
}



var aTxtScroller = new Array()
aTxtScroller[0]='<b>BARNEVELD<\/b> &raquo; Hanzeweg 12 - 3771 NG <span class="spacer">&nbsp;</span> <b>Tel:<\/b> 0342-418200 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> 0342-418165 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'BARNEVELD &raquo; Hanzeweg 12 - 3771 NG\', \'3771NG\' );" title="Plattegrond">[Plattegrond]<\/a> <![endif]-->';
aTxtScroller[1]='<b>COEVORDEN<\/b> &raquo; De Mars 19 - 7742 PT <span class="spacer">&nbsp;</span> <b>Tel:<\/b> 0524-596584 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> 0524-596586 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'COEVORDEN &raquo; De Mars 19 - 7742 PT\', \'7742PT\' );" title="Plattegrond">[Plattegrond]<\/a> <![endif]-->';

/**
* aTxtScroller[2]='<b>GELDERMALSEN<\/b> &raquo; Poppenbouwing 28 - 4191 NZ <span class="spacer">&nbsp;</span> <b>Tel:<\/b> 0345-588277 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> 0345-288278 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'GELDERMALSEN &raquo; Poppenbouwing 28 - 4191 NZ\', \'4191NZ\' );" title="Plattegrond">[Plattegrond]<\/a> <![endif]-->';
* aTxtScroller[3]='<b>JOURE</b> &raquo; Transportwei 1 - 8501 ZR <span class="spacer">&nbsp;</span> <b>Tel:</b> 0513-412741 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> FAX 0513-417242 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'JOURE &raquo; Transportwei 1 - 8501 ZR\', \'8501ZR\' );" title="Plattegrond">[Plattegrond]\</a> <![endif]-->';
*/
aTxtScroller[2]='<b>NIEUWE PEKELA<\/b> &raquo; Holland Marsh 3 - 9663 AV <span class="spacer">&nbsp;</span> <b>Tel:<\/b> 0597-530530 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> 0597-332010 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'NIEUWE PEKELA &raquo; Holland Marsh 3 - 9663 AV\', \'9663AV\' );" title="Plattegrond">[Plattegrond]<\/a> <![endif]-->';
aTxtScroller[3]='<b>EMMEN<\/b> &raquo; Michael Strogoffstraat  4a - 7821 AL <span class="spacer">&nbsp;</span> <b>Tel:<\/b> 0591-647500 <span class="spacer">&nbsp;<\/span> <b>Fax:</b> 0591-647501 <!--[if IE]> <span class="spacer">&nbsp;<\/span> <a href="javascript:map( \'EMMEN &raquo; Michael Strogoffstraat  4a - 7821 AL\', \'7821AL\' );" title="Plattegrond">[Plattegrond]<\/a> <![endif]-->';


/***********************************************
* Pausing up-down scroller- � Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
	this.content = content
	this.tickerid = divId
	this.delay = delay
	this.mouseoverBol = 0
	this.hiddendivpointer = 1
	var scrollerinstance = this;

	document.write('<div id="'+divId+'" class="'+divClass+'" style="position:relative; overflow:hidden; color: #fff;"><div style="position:absolute; color: #fff; width:100%;" id="'+divId+'1">' + content[0] + '</div><div class="innerDiv" style="position:absolute; width:100%; color: #fff; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')

	if( this.content.length >= 2 ) {
		if (window.addEventListener) //run onload in DOM2 browsers
			window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
		else if (window.attachEvent) //run onload in IE5.5+
			window.attachEvent("onload", function(){scrollerinstance.initialize()})
		else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
			setTimeout(function(){scrollerinstance.initialize()}, 500)
	}
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"

	var scrollerinstance=this
	document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
	if(window.attachEvent) //Clean up loose references in IE
		window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------
pausescroller.prototype.animateup=function(){
	var scrollerinstance=this
	if(parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
		this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
		this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
		setTimeout(function(){scrollerinstance.animateup()}, 50)
	} else {
		this.getinline(this.hiddendiv, this.visiblediv)
		this.swapdivs()
		setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
	}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
	var scrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
		setTimeout(function(){scrollerinstance.setmessage()}, 100)
	else{
		var i=this.hiddendivpointer
		var ceiling=this.content.length
		this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
		this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
		this.animateup()
	}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
	if (tickerobj.currentStyle)
		return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
		return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
		return 0
}















/**
 * render()
 *
 * This function will only effect 'safari' or 'gecko'
 * based browsers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * Include an alternative stylesheet called 'saop.css'
 * and resize the height of some <div> elements .....
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  void
 */
addEvent( window, 'load', render );
function render() {
	if( objIS.safari || objIS.opera ) {
		var eHead = document.getElementsByTagName('HEAD')[0];
		var eStyle = eHead.appendChild( document.createElement('LINK') );
		eStyle.rel = 'stylesheet';
		eStyle.type = 'text/css';
		eStyle.href = '/css/saop.css';
	}

	if( !objIS.ie )
		getElement( 'canvas_div' ).style.height = getElement( 'centered_div' ).offsetHeight + 'px';
}


function enableField(field) {

	if(field != '') {
		_D.getElementById(field).className = '';
		_D.getElementById(field).disabled = false;
		_D.getElementById(field).focus();

		return true;
	} else {
		return false;
	}

} // End of Function


function disableField(field) {

	if(field != '') {
		_D.getElementById(field).className = 'disabled-area';
		_D.getElementById(field).disabled = true;
		return true;
	} else {
		return false;
	}

} // End of Function





/**
*	CRIR - Checkbox & Radio Input Replacement
*	Author: Chris Erwin (me[at]chriserwin.com)
*	www.chriserwin.com/scripts/crir/
*
*	Updated July 27, 2006.
*	Jesse Gavin added the AddEvent function to initialize
*	the script. He also converted the script to JSON format.
*/

crir = {
	init: function() {
		arrLabels = document.getElementsByTagName('label');

		searchLabels:
		for (var i=0; i<arrLabels.length; i++) {
			// get the input element based on the markup style of the label
			if (arrLabels[i].getAttributeNode('for') && arrLabels[i].getAttributeNode('for').value != '') {
				labelElementFor = arrLabels[i].getAttributeNode('for').value;
				inputElement = document.getElementById(labelElementFor);
			}
			else {
				continue searchLabels;
			}

			inputElementType = inputElement.getAttributeNode('type').value;
			inputElementClass = inputElement.className;

			// if the input is specified to be hidden intiate it
			if (inputElementClass == 'crirHiddenJS') {
				inputElement.className = 'crirHidden';
				arrLabels[i].getAttributeNode('for').value = 'crir_' + labelElementFor; //change the for attribute so the browser doesn't trigger the input element when we click on the label.

				// add the appropriate event listener
				if (inputElementType == "checkbox") {
					arrLabels[i].onclick = crir.toggleCheckboxLabel;
				}
				else {
					arrLabels[i].onclick = crir.toggleRadioLabel;
				}

				// set the initial label state
				if (inputElement.checked) {
					if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_checked'}
					else { arrLabels[i].className = 'radio_checked' }
				}
				else {
					if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_unchecked'}
					else { arrLabels[i].className = 'radio_unchecked' }
				}
			}
			else if (inputElementType == 'radio') { // this so even if a radio is not hidden but belongs to a group of hidden radios it will still work.
				arrLabels[i].onclick = crir.toggleRadioLabel;
				inputElement.onclick = crir.toggleRadioLabel;
			}
		}
	},

	findLabel: function (inputElementID) {
		arrLabels = document.getElementsByTagName('label');

		searchLoop:
		for (var i=0; i<arrLabels.length; i++) {
			if (arrLabels[i].getAttributeNode('for')) {
				if (crir.originalForValue(arrLabels[i].getAttributeNode('for').value) == inputElementID) {
					return arrLabels[i]; // is this right?
					break searchLoop;
				}
			}
			else {
				if (arrLabels[i].childNodes[1].getAttributeNode('id').value == inputElementID) {
					return arrLabels[i]; // is this right?
					break searchLoop;
				}
			}
		}
	},

	// this removes the 'crir_' we added to the for attributes during init.
	originalForValue: function(labelElementFor) {
		if (labelElementFor.substr(0,5) == 'crir_') {
			return labelElementFor.substr(5, (labelElementFor.length - 5));
		}
		else {
			return labelElementFor;
		}
	},

	toggleCheckboxLabel: function () {
		labelElementFor = crir.originalForValue(this.getAttributeNode('for').value);
		inputElement = document.getElementById(labelElementFor);

		if(this.className == 'checkbox_checked') {
			inputElement.checked = false;
			this.className = "checkbox_unchecked";
		}
		else {
			inputElement.checked = true;
			this.className = "checkbox_checked";
		}
	},

	toggleRadioLabel: function () {
		if (this.nodeName == 'LABEL') { // the label was clicked
			labelElement = this;
			labelElementFor = crir.originalForValue(labelElement.getAttributeNode('for').value);
			clickedInputElement = document.getElementById(labelElementFor);
		}
		else { //the actual radio button was clicked
			labelElement = crir.findLabel(this.getAttributeNode('id').value);
			labelElementFor = crir.originalForValue(labelElement.getAttributeNode('for').value);
			clickedInputElement = this;
		}

		clickedInputElementName = clickedInputElement.getAttributeNode('name').value;

		arrInputs = document.getElementsByTagName('input');

		// uncheck (label class) all radios in the same group
		for (var i=0; i<arrInputs.length; i++) {
			inputElementType = arrInputs[i].getAttributeNode('type').value;
			inputElementName = arrInputs[i].getAttributeNode('name').value;
			inputElementClass = arrInputs[i].className;
			// find radio buttons with the same 'name' as the one we've changed and have a class of chkHidden
			// and then set them to unchecked
			if (inputElementType == 'radio' &&  inputElementName == clickedInputElementName && inputElementClass == 'crirHidden') {
				inputElementID = arrInputs[i].getAttributeNode('id').value;
				labelElement = crir.findLabel(inputElementID);
				labelElement.className = 'radio_unchecked';
				arrInputs[i].checked = false;
			}
		}

		// if the radio clicked is hidden set the label and radio to checked
		if (clickedInputElement.className == 'crirHidden') {
			this.className = 'radio_checked';
			clickedInputElement.checked = true;
		}
	},

	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener)
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	}
}
crir.addEvent(window, 'load', crir.init, false);







/* tabs for matrix */

//** Tab Content script- � Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: June 29th, 06

var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
	var ulid=linkobj.parentNode.parentNode.id //id of UL element
	var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
	for (var i=0; i<ullist.length; i++){
	ullist[i].className=""  //deselect all tabs
	if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
	document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
	}

	linkobj.parentNode.className="selected"  //highlight currently clicked on tab
	document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
	saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
	if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
	tabcontentIDs[ulid]=new Array()
	tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
	if (enabletabpersistence==1) //if persistence feature turned on
	setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
	var ullist=document.getElementById(ulid).getElementsByTagName("li")
	for (var i=0; i<ullist.length; i++){
	if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
	return ullist[i].getElementsByTagName("a")[0]
	break
	}
	}
}

function initializetabcontent(){
	for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
		if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
			setCookie(arguments[i], "")
			var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
			var ulobj=document.getElementById(arguments[i])
			var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
			for (var x=0; x<ulist.length; x++){ //loop through each LI element
			var ulistlink=ulist[x].getElementsByTagName("a")[0]
			if (ulistlink.getAttribute("rel")){
			savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
			ulistlink.onclick=function(){
			expandcontent(this)
			return false
			}
			if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
			expandcontent(ulistlink) //auto load currenly selected tab content
			}
			} //end inner for loop
			if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
			var culistlink=getullistlinkbyId(arguments[i], clickedontab)
			if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
			expandcontent(culistlink) //auto load currenly selected tab content
			else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
			expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
			}
		} //end outer for loop
	}


function getCookie(Name){
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
	return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

function setCookie(name, value){
	document.cookie = name+"="+value //cookie value is domain wide (path=/)
}










//]]>
