/* Utility functions */
function addEvent(obj, evType, fn) {
  /* adds an eventListener for browsers which support it Written by Scott Andrew */
  if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
  else if (obj.attachEvent) { var r = obj.attachEvent("on"+evType, fn); return r; }
  else { return false; }
}
function element(id) {
  var e = false;
  if (document.getElementById) { e = document.getElementById(id); }
  else if (document.all) { e = document.all(id); }
  return e;
}
// login
function toPassword(objOldInput) {
	var objNewElement = document.createElement('input');
	objNewElement.setAttribute('type', 'password');
    objNewElement.setAttribute('name', objOldInput.name);
	objOldInput.parentNode.replaceChild(objNewElement, objOldInput);
	toPassword.el = objNewElement;
	setTimeout('toPassword.el.focus()',100);
	return true;
}
// menu.js
function hasULchildren(linode) {
	var uls = linode.getElementsByTagName('ul')[0];
	if(uls) return true;
	return false;
}
function efMenu(menuid, menutype) {
	var menudiv = element(menuid);
	var listitems = menudiv.getElementsByTagName('li');
	if(listitems){
		for(var i=0; i<listitems.length; i++){
			var listitem = listitems[i];
			if(hasULchildren(listitem)) {
				listitem.onmouseover = function (e) {
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
						else { this.firstChild.className = 'mouse'; }
					}
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
					}
					return false;
				};
				// onmouseout function
				listitem.onmouseout = function (e) {
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
					}
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active'; }
						else { this.firstChild.className = ''; }
					}
					return false;
				};
			}
		}
	}
	return void(0);
}
// de functie displayResultBox wordt ook gebruikt in xdis.js
function displayResultBox(string){
	var objResultBox = element('results');
	if(objResultBox) objResultBox.innerHTML = string;
}
// config for EFbox
function EFdata(){
	this.href = '';
	this.title = '';
	this.content = '';
	this.hideble = false;
}
// config for google maps
function classConfig(){
	this.host = '';
	this.search = '';
}
var popup = '';
function openPopup(url, name, w, h, menubar, scroll){
	var centerX, centerY, windowLeft, windowTop;
	if(document.getElementById) {
		centerX = parseInt(screen.width / 2);
		centerY = parseInt(screen.height / 2);
	} else {
		centerX = parseInt(screen.availWidth / 2);
		centerY = parseInt(screen.availHeight / 2);
	}
	windowLeft = centerX - parseInt(w/2);
	windowTop = centerY - parseInt(h/2);
	var parameters  = 'toolbar=no,location=no,resizable=yes,menubar=' + menubar;
	parameters += ',width=' + w + ',height=' + h + ',top=' + windowTop + ',left=' + windowLeft;
	if(scroll != null) parameters += ',scrollbars=yes';
	if (!popup.closed && popup.location) {
  		popup.location.href = url;
 	} else {
 		popup = window.open(url, name, parameters);
  		if(!popup.opener) popup.opener = self;
 	}
	if (window.focus) {popup.focus()}
	return false;
}

/* Better(?) Image cross fader (C)2004 Patrick H. Lauke aka redux */
var	previousImage=new Array();
var currentImage=new Array();
var galleryImages=new Array();
var gallery, arrGalleryId = ['horizontaal','verticaal','diagonaal']; /* general variables */
function preInit() { /* hide the image gallery list before even onload is triggered */
	for( var i =0; i <galleryId.length; i++)
	{
		if ((document.getElementById)&&(gallery=document.getElementById(galleryId[i]))) {
			gallery.style.visibility = "hidden";
			clearTimeout(preInitTimer);
		} else { preInitTimer = setTimeout("preInit()",2); }
	}
}
function fader(galleryNr,imageNumber,opacity) {
	var obj=galleryImages[galleryNr][imageNumber];
	if(!isNaN(opacity/100)){
		if (obj.style.MozOpacity!=null ) { obj.style.MozOpacity = (opacity/100) - .001; }
		else if (obj.style.opacity!=null) { obj.style.opacity = (opacity/100) - .001; }
		else if (obj.style.filter!=null) { obj.style.filter = "alpha(opacity="+opacity+")"; }
	}
}
function fadeInit(galleryId,galleryNr) {
	if (document.getElementById) { //preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		var gallery=document.getElementById(galleryId);
		if(gallery){
			galleryImages[galleryNr] = gallery.childNodes; /* get all child nodes... */
			for(i=0;i<galleryImages[galleryNr].length;i++) {
				galleryImages[galleryNr][i].style.position='absolute';
				galleryImages[galleryNr][i].style.top=0;
				galleryImages[galleryNr][i].style.zIndex=0;
				fader(galleryNr,i,0); /* set their opacity to transparent */
			}
			gallery.style.visibility = 'visible'; /* make the list visible again */
			currentImage[galleryNr]=0; /* initialise a few parameters to get the cycle going */
			previousImage[galleryNr]=galleryImages[galleryNr].length-1;
			opacity=100;
			fader(galleryNr,currentImage[galleryNr], 100);
			window.setTimeout("crossfade("+galleryNr+",100)", 2500); /* start the whole crossfade process after a second's pause */
			return void(0);
		}
		else { return false; }
	}
	else { return false; }
}
function crossfade(galleryNr,opacity) {
    if (opacity < 101) {
        fader(galleryNr,currentImage[galleryNr],opacity);
        opacity += 5;
        window.setTimeout("crossfade("+galleryNr+","+opacity+")", 100);
    } else {
        fader(previousImage[galleryNr],0);
        previousImage[galleryNr]=currentImage[galleryNr];
        currentImage[galleryNr]+=1;
        if (currentImage[galleryNr]>=galleryImages[galleryNr].length) { currentImage[galleryNr]=0; }
        galleryImages[galleryNr][previousImage[galleryNr]].style.zIndex = 0;
        galleryImages[galleryNr][currentImage[galleryNr]].style.zIndex = 10;
        opacity=0;
        window.setTimeout("crossfade("+galleryNr+","+opacity+")", 2500);
    }
}
function startfaders(){
	for(var i=0; i<arrGalleryId.length; i++){
		fadeInit(arrGalleryId[i],i);
	}
}
/* initialise fader by hiding image object first */
//addEvent (window,'load',startfaders);

function checkBrochurePostDownload() {
	var parent, obj_check, elem, holder=null;
	var block = element('frmContainer');
	if(block) { var divs = block.getElementsByTagName('span'); }
	if(divs){
		for(var i=0;i<divs.length;i++){ if(divs[i].className == 'extraFields'){ holder = divs[i];} }
	}
	if(holder) { holder.style.display = 'none'; }
	if (block) {
		var inputs = block.getElementsByTagName('input');
		for(var i=0;i<inputs.length;i++) {
			obj_check = inputs[i];
			if(obj_check.id == 'post') {
				if(obj_check.checked) { holder.style.display = 'block'; }
				obj_check.onclick = function() { if (this.checked) { holder.style.display = 'block'; } }
			} else if(obj_check.id == 'download') {
				obj_check.onclick = function() { if (this.checked) {  holder.style.display = 'none'; } }
			} 
		}
	} 
}
addEvent(window, "load", checkBrochurePostDownload);

$(document).ready(function(){
//	$('popupbanner').show();
	if(document.location.href.indexOf( 'suncircle.ca' ) > -1 ){
		$('#popupbanner').hide();
	}
	
	$('#linkToHome').click(function(){
		$('#popupbanner').hide();
	});
	
});


