/*  Start /_templates/roottemplate/roottemplate_right_edit.js */

//////////////////////////////////////////////////////////////////////////////////
//	path.js wordt gebruikt voor algemene scripts i.v.m. meerdere roottemplates  //
//////////////////////////////////////////////////////////////////////////////////

/*  End /_templates/roottemplate/roottemplate_right_edit.js */

/*  Start /_templates/path/path.js */

// Page Size
function setPageSize() {
	yScroll = document.viewport.getHeight();
	
	if (self.innerHeight) {
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowHeight = document.body.clientHeight;
	}	
	
	if((yScroll + 58) < windowHeight){
		pageHeight = windowHeight - 58;
	} else { 
		pageHeight = yScroll;
	}

	$('wrapBg').style.height = pageHeight + 'px';
}

// Change Domain
function changeDomain(language) {
	domain = $('International').value;
	lang = $('Language').value;
	
	if (location.href.indexOf('projects.mrxt.nl') == -1) {
		if (language) {
			URL = PGX.Path + '/' + lang + '/';
		} else {
			URL = domain;
		}	
		document.location = URL;
	} else {
		if (language) {
			URL = '/' + lang + '/';
		} else {
			URL = '/?domain=' + domain;
		}
		document.location = PGX.Path + URL;
	}
}

// Scroll Menu
function scrollMenu() {
	yScroll = document.viewport.getScrollOffsets().top;
	iDocHeight = document.viewport.getDimensions().height;
	yPos = (yScroll - 130);
	if (yPos < 0) {
		yPos = 0;
	}
	
	iHeight = 168; // Top en Footer height
	iMenuHeight = $('clmLt').getHeight();
	iContentHeight = $('wrapContent').getHeight();
	iTotalHeight = iHeight + iMenuHeight;
	
	if(yPos < (iContentHeight - iMenuHeight)) {
		new Effect.Move('clmLt', { x: 0, y: yPos, mode:'absolute', duration: 1.1, transition: Effect.Transitions.sinoidal });
	}	

}

function setFooter(action) {
	// Zet de footer eventueel weer op position absolute.
	// Dit is nodig voor de FAQ.
	$('ft').style.position = action;
}

// Submit Search
function submitSearch(url) {
	location = PGX.Path + url + '?search=' + $('Search').value;
}

// Events
Event.observe(document.onresize ? document : window, "resize", function() {
	setPageSize();
	scrollMenu();
	setFooter('absolute');
});

Event.observe(window, "scroll", function() {
	scrollMenu();
});

// News
function getNews(newPage) {
	aParams = {}	
	aParams.page = newPage;
	aParams.source = '/_templates/news/news_right.html';	
	pgx('ajaxNews', 'core.html', aParams);	
}

// Applepie
var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "160";

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}

window.onload = Custom.init;

function showText(element) {	
	if($(element).next(0).innerHTML == '') {
//		alert($(element).next(0).id);
		$(element).next(0).style.display='none';
		$(element).next(0).style.visibility='hidden';
	}
}

function getLink(element) {
	url = $(element).next(0).down(0).href;
	if(url) {
		window.location = url;
	}
}




function showRight(element) {	
	return;
	alert(element);
	if($(element).innerHTML == '') {
			$(element).style.display='none';
	}
}

function toggleElement(element) {
	if($(element).style.display=='none') {
		$(element).style.display='';
	}else{
		$(element).style.display='none';
	}
}

function showTafSend() {
	Effect.BlindUp('taf_form', { duration: 0.4 });
	Effect.BlindDown('taf_send', { duration: 0.4 });
}

function toggleTaf() {
	$('taf_ov').toggle();
}

function showPopup(element) {
	if($(element).next(0).down(0).next(0).innerHTML != '') {
		$(element).next(0).toggle();
	}
}

function productOverview() {		
	var query = window.location.search.substring(1);
	if (query.indexOf('pgxURL=') == -1) {
		$$('.kolom4 .img').each( function(popup) {
			if(popup.previous(0).down(0)) {			
				var sLocation = popup.previous(0).down(0).href;
				Event.observe(popup, 'click', function() {
					window.location = sLocation
				});
			}
		});
	}
}


document.observe("dom:loaded", function() {
	productOverview();
});

/*  End /_templates/path/path.js */

/*  Start /_templates/menu/menu.js */

/*function toggleSubmenu(element, show) {
//	alert($(element).down(0).next(0).innerHTML)

	if (show == true) {
		$(element).down(0).next(0).style.display = '';
	}
	
	if (show == false) {
		$(element).down(0).next(0).style.display = 'none';
	}
}
*/
function checkSubmenuEmpty(element) {
//	alert('blaat');
	if($(element).up(0).previous(0).innerHTML == '') {
		$(element).up(1).style.display='none';
	}
}

/*  End /_templates/menu/menu.js */

/*  Start /_templates/menu/contact.js */

function toggleContact(show) {
	if (show == true) {
		$('contactPop').style.display = '';
	}
	
	if (show == false) {
		$('contactPop').style.display = 'none';
	}
}

/*  End /_templates/menu/contact.js */

/*  Start /_templates/roottemplate/roottemplate.js */

//////////////////////////////////////////////////////////////////////////////////
//	path.js wordt gebruikt voor algemene scripts i.v.m. meerdere roottemplates  //
//////////////////////////////////////////////////////////////////////////////////
function setDemonstratie() {
	if($('Demonstratie').checked == true){
		$('hiddenDemonstratie').value = 'Ja';
	} else {
		$('hiddenDemonstratie').value = 'Nee';
	}
}

function saveMailCheckForm(form) {
	
			var submitFunction = function() {
			var aParams = $(form).serialize(true);
			aParams.fromName = $('Name').value;
			aParams.fromEmail = $('Email').value;
			aParams.toName = 'Spirotech';
			aParams.toEmail = 'noreply@spirotech.nl';
			aParams.mailSubject = 'Support Center';
			aParams.onComplete = function() {
				if ($(form).action) {
					location.href = $(form).action;
				}
			}
			pgx('local.savemail', aParams);
		}
		eval('pgxForm_' + form + '.submitFunction = submitFunction;');
		PGX.form.check(form);
}

/*  End /_templates/roottemplate/roottemplate.js */

/*  Start /_templates/news/news_right.js */

function toggleNews(id, show) {
	if (show == true) {
		$('news_' + id).style.display = '';
	}
	
	if (show == false) {
		$('news_' + id).style.display = 'none';
	}
}

function showMore(sHref) {
	if(sHref == '' ) {
		$('readmore').hide();
	}
}

/*  End /_templates/news/news_right.js */

/*  Start /_templates/events/events_right.js */

var iZindex = 10000;

var EventsClass = Class.create({
															 
	changePhoto:function(bSecond) {
		aPhotos = $$('[rel="eventPhoto"]');
		iLength = aPhotos.length;
		if(iLength > 1) {
			iTime = 4;
			aPhotos.each( function(photo, index) {
				iDelay = ((index+1)*iTime);
				iZindex = iZindex - 1;
				photo.setStyle( { 'zIndex':iZindex} );
				
				new Effect.SlideUp(photo, {
					delay: iDelay,
					afterFinish: function() {
						photo.show();
						iZindex = photo.getStyle('zIndex')-iLength;
						photo.setStyle( { 'zIndex' : iZindex} );
						if(iLength == (index+1)) {
							Events.changePhoto(true);
						}
					}
				});
				
			});
		}
	}
	
});

var Events = new EventsClass();



var currentEvent = 0;

function changeEvent(change) {
	aElements = $$('div[change="' + change + '"]');
	
	currentEvent++;
	if (currentEvent > aElements.length) {
		currentEvent = 1;
	}
	
	count = 0;
	aElements.each(function(element) {
		count++;
		
		// Show
		if (count == currentEvent) {
			$(element).show();
			
		}
		
		// Hide
		check = (currentEvent - 1);
		if (check <= 0) {
			check = aElements.length;
		}
		
		if (count == check && aElements.length != 1) {
			if ($(element)) {
				$(element).style.display = 'none';
				alert('notoke');
			}
		}
		
		
	});
	
	setTimeout(function() {
		changeEvent(change);
	}, 5000);
}












/*  End /_templates/events/events_right.js */

/*  Start /_templates/recommendation/recommendation_right.js */

var currentRec = 0;

function changeRec(change) {
	aElements = $$('div[change="' + change + '"]');
	
	currentRec++;
	if (currentRec > aElements.length) {
		currentRec = 1;
	}
	
	count = 0;
	aElements.each(function(element) {
		count++;
		
		// Show
		if (count == currentRec) {
			$(element).appear();
		}
		
		// Hide
		check = (currentRec - 1);
		if (check <= 0) {
			check = aElements.length;
		}
		
		if (count == check && aElements.length != 1) {
			if ($(element)) {
				$(element).style.display = 'none';
			}
		}
		
		
	});
	
	setTimeout(function() {
		changeRec(change);
	}, 5000);
}

/*  End /_templates/recommendation/recommendation_right.js */

