﻿var Huge = new Object();
Huge.enabled = false;
Huge.blader = new Array(true, true, 'slide');
Huge.backdrop = true; //zwart transparant
Huge.closeImgSrc = '/sites/478/images/sluiten.jpg';

var Big = new Object();
Big.enabled = true;
Big.blader = new Array(true, false, 'slide2');

var Tiny = new Object();
Tiny.enabled = true;
Tiny.direction = "Y";
Tiny.showImage = true;
Tiny.sizeX = 1;
Tiny.sizeY = 3;
Tiny.e = "click";
Tiny.blader = new Array(true, false, 'slide');

var Huge2 = new Object();
Huge2.enabled = false;
var Big2 = new Object();
Big2.enabled = true;
//Big.blader = new Array(true, true, 'slide');
Big2.autoviewer = new Array('slide', 6, 3, false);
var Tiny2 = new Object();
Tiny2.enabled = false;

PT.Sites.WPBCE = {
	onLoad: function () {
		if (!PT.Sites.General.EditorActive()) {
			if (get$('colleditor2')) {
				PT.Instances.ShowImg1 = new PT.Sites.General.ShowImgAlt("divrep", "/sites/478/images/sluiten.jpg", true);
			}
			if (get$('imagerow')) {
				PT.Instances.ShowImg1 = new PT.Sites.General.ShowImgAlt("imagerow", "/sites/478/images/sluiten.jpg", true);
			}
			if (get$('imagerow_gal')) {
				var newObject = new PT.Sites.General.Fotoviewer('editor_add', 'fotoviewer2', Huge, Big, Tiny);
			}
			var arr = new Array('facebook', 'linkedin', 'twitter');
			PT.Social.addThis(arr);
		}
	},
	placeAanmeldform: function () {
		if (PT.Sites.General.EditorActive()) {
			$.ajax({
				url: "http://cms.paradesk.nl/sites/478/getxml.aspx",
				type: 'GET',
				dataType: 'xml',
				contentType: 'text/xml',
				error: function () {
					alert('Error loading XML document');
				},
				success: function (xml) {
					var arr = [];
					$(xml).find("group").each(function () {
						var id = this.attributes.getNamedItem("id").value
						var name = this.attributes.getNamedItem("name").value
						arr.push({ id: id, name: name });
					});
					var selects = PT.Sites.General.GetElementsByClass(document, 'verzendgroepselectbox');
					for (var i = 0; i < selects.length; i++) {
						selects[i].removeChild(selects[i].options[0]);
						for (var j = 0; j < arr.length; j++) {
							var optNew = new Option();
							optNew.text = arr[j].name;
							optNew.value = arr[j].id;
							if (get$('ds_events_aanmelden_'+selects[i].id).innerHTML.indexOf(arr[j].id+'|') != -1) {
								optNew.selected = true;
							}
							selects[i].appendChild(optNew);
						}
					}
				}
			});
		}
		else {
			$.ajax({
				url: "/sites/478/getxml.aspx",
				type: 'GET',
				dataType: 'xml',
				contentType: 'text/xml',
				error: function () {
					alert('Error loading XML document');
					PT.Sites.WPBCE.footerPlace();
				},
				success: function (xml) {
					if (get$('nbform')) {
						var arr = [];
						$(xml).find("group").each(function () {
							var id = this.attributes.getNamedItem("id").value
							var name = this.attributes.getNamedItem("name").value
							arr.push({ id: id, name: name });
						});
						for (var m = 0; m < arr.length; m++) {
							//alert(arr[m].id);
							get$('group_' + arr[m].id).className += ' onzichtbaar';

							// find label
							var els = get$('nbform').getElementsByTagName('label');
							for (var n = 0; n < els.length; n++) {
								if (els[n].getAttribute('for') == 'group_' + arr[m].id || els[n].htmlFor == 'group_' + arr[m].id) {
									els[n].className += ' onzichtbaar';
								}
							}
						}
						var workshops = PT.Sites.General.GetElementsByClass(document, 'workshoplabelverzendgroep');
						var groepen = PT.Sites.General.GetElementsByClass(document, 'workshopgroepverzendgroep');
						for (var i = 0; i < workshops.length; i++) {
							var pNew = document.createElement('p');
							pNew.innerHTML = workshops[i].innerHTML;
							get$('workshops').appendChild(pNew);
							var groepids = get$('ds_events_aanmelden_verzendgroep_' + workshops[i].id.substring(workshops[i].id.indexOf('workshop'), workshops[i].id.length));
							groepids = groepids.innerHTML.substring(0, groepids.innerHTML.length - 1).split('|');
							for (var j = 0; j < groepids.length; j++) {
								if (PT.Sites.General.GetElementsByClass(document, 'ie6').length > 0 || PT.Sites.General.GetElementsByClass(document, 'ie7').length > 0) {
									var radioNew = document.createElement('<input name="' + 'workshop' + i + '"/>');
								}
								else {
									var radioNew = document.createElement('input');
									radioNew.name = 'workshop' + i;
								}
								radioNew.type = 'radio';
								radioNew.id = 'workshop' + i + 'groep' + j;
								if (j == 0) {
									radioNew.checked = true;
								}
								var labelNew = document.createElement('label');
								labelNew.setAttribute('for', 'workshop' + i + 'groep' + j);
								labelNew.innerHTML = PT.Sites.WPBCE.arrGetNameFromId(arr, groepids[j]);
								radioNew.value = groepids[j] + '|' + labelNew.innerHTML;
								var brNew = document.createElement('br');
								get$('workshops').appendChild(radioNew);
								get$('workshops').appendChild(labelNew);
								get$('workshops').appendChild(brNew);
							}
						}
						for (var k = 0; k < groepen.length; k++) {
							get$('workshops').removeChild(groepen[k]);
						}
						for (var l = 0; l < workshops.length; l++) {
							get$('workshops').removeChild(workshops[l]);
						}
					}
					PT.Sites.WPBCE.footerPlace();
				}
			});
		}
	},

	arrGetNameFromId: function (arr, id) {
		for (var i = 0; i < arr.length; i++) {
			if (arr[i].id == id) {
				return arr[i].name;
			}
		}
	},
	saveVerzendgroep: function (select) {
		if (PT.Sites.General.EditorActive()) {
			var id = 'ds_events_aanmelden_' + select.id;
			get$(id).innerHTML = '';
			for (var i = 0; i < select.options.length; i++) {
				if (select.options[i].selected) {
					get$(id).innerHTML += select.options[i].value + '|';
				}
			}
			var pm = feleditor.pageManager;
			pm.UpdateElement(id, "site", get$(id).innerHTML, "", "", "", false);
		}
	},
	/**
	* News fader class.
	* Takes main div containing news item divs and a delay time in
	* seconds between transitioning from one news items the the next.
	*/
	NewsFader: function (divId, delayTime) {
		var dsl = '';
		if (document.getElementById(divId)) {
			dsl = document.getElementById(divId);
		}
		else {
			dsl = PT.Sites.General.GetElementsByClass('', 'h_eventsdsl');
			dsl = dsl[0];
			if (dsl == null) return;
		}

		this.newsMainDiv = dsl;
		this.newsItems = this.newsMainDiv.getElementsByTagName("div");
		this.newsItem = 0;
		this.newsOpacity = 0;
		this.newsDelay = delayTime;
		this.newsTimer = null;

		/**
		* Initialize the news fader.
		*/
		this.init = function () {
			if (this.newsItems.length == 0) return;

			for (var i = 0; i < this.newsItems.length; i++) {
				this.newsItems[i].style.position = "absolute";

				if (i != this.newsItem) {
					this.newsItems[i].style.filter = "alpha(opacity=0)";
					this.newsItems[i].style.opacity = "0";
					this.newsItems[i].style.display = "none";
				}
			}

			var ref = this;
			this.newsTimer = setTimeout(function () { ref.nextNewsItem(); }, this.newsDelay * 1000);
		}


		/**
		* Start transitioning between two news items.
		*/
		this.nextNewsItem = function () {
			this.newsItem++;
			if (this.newsItem == this.newsItems.length) this.newsItem = 0;
			this.newsOpacity = 0;
			this.newsItems[this.newsItem].style.display = "block";

			this.transition();
		}


		/**
		* Fading transition between two news items.
		*/
		this.transition = function () {
			this.newsOpacity += 0.1;

			var lastItem = (this.newsItem == 0) ? this.newsItems.length - 1 : this.newsItem - 1;

			this.newsItems[lastItem].style.filter = "alpha(opacity=" + (100 - (this.newsOpacity * 100)) + ")";
			this.newsItems[lastItem].style.opacity = (1.0 - this.newsOpacity);

			this.newsItems[this.newsItem].style.filter = "alpha(opacity=" + (this.newsOpacity * 100) + ")";
			this.newsItems[this.newsItem].style.opacity = (this.newsOpacity);

			var ref = this;
			if (this.newsOpacity < 1.0) {
				this.newsTimer = setTimeout(function () { ref.transition(); }, 100);
			} else {
				this.newsTimer = setTimeout(function () { ref.nextNewsItem(); }, this.newsDelay * 1000);
				this.newsItems[lastItem].style.display = "none";
			}
		}

		this.init();
	},
	moviePlay: function (code) {
		alert('movie ' + code);
	},
	footerPlace: function () {
		var footer = get$('footer');
		var pageY = get$('content').offsetHeight + 407;
		var pageFull = document.body.clientHeight;
		footer.style.display = "block";
		if ((pageY > pageFull))
			footer.style.marginTop = pageY + "px";
		else
			footer.style.marginTop = pageFull - 11 + "px";
	},
	submitSearch: function (form) {
		if (document.getElementById("dssearchquery").value == "Search") { document.getElementById("dssearchquery").value = ""; }
		document.getElementById("dssearchquery").value = document.getElementById("dssearchquery").value.replace(/[^a-zA-Z0-9\s]/g, "");

		var terms = document.getElementById("dssearchquery").value

		form.action = "/search." + terms + ".html";
		form.submit();
	}
	/*highlightCart:function(){
	opac = 0;
	changeOpac();
	}
	
	//change the opacity for different browsers 
	changeOpac:function() {
	var opacity = Math.sin(opac)*50; 
	var object = get$('carthighlight').style; 
	var placeholder = get$('carttd2').clientHeight;
		
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")";
	object.display="block";
	object.width="180px";
	object.height=placeholder+"px";
	object.marginTop="-"+placeholder+"px";
		
	opac += (Math.PI/15.7);
	if(opac<Math.PI){
	setTimeout("changeOpac()",50);
	}
	else{
	object.display='none';
	}
	}*/
}

PT.Sites.General.RegisterEvent(window, "load", function() {PT.Sites.WPBCE.onLoad();} );
