$(document).ready(function() {

	if (typeof strGA_URL === 'undefined') {
		$("body").attr("url", location.href);
	} else {
		$("body").attr("url", strGA_URL);
	}


    /* svdhout */
    $('.isCollapsed').css("display", "none");
    $('.collapsenext').css("cursor", "pointer");
    $('.collapsenext').click(function() {
      var $box = $(this).next()
  	  if ($box.hasClass('isCollapsed')) {
  	    $box.show();
	    $box.removeClass('isCollapsed');
	  }
	  else {
	    $box.hide();
	    $box.addClass('isCollapsed');
      }
    });
	
	$("#videolink").click(function() { // TSD-film (BBeun)
		$.fancybox({
				'padding'		: 0,
				'autoScale'	: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: '',
				'width'		: 640,
				'height'		: 380,
				'href'			: this.href,
				'type'			: 'iframe',
				'swf'			: {
					 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
		return false;
	});
	

	$("a#admintoggle").click(function() { /* BBeun */
		$("#admin #admin").toggle(); 
	});

	$("div.tooltip").each( /* BBeun */
		function(iNr){
			strID = ($(this).attr("id"));
			$("a[rel=" + strID + "]").tooltip({
				bodyHandler: function() {
					return $($(this).attr("rel")).html();
				},
				showURL: false
			});
		}
	);	
	
	$("span.leesmeer").each( /* BBeun */
		function(iNr){
			strHTML = $(this).html(); 
			$(this).html($("<span />").addClass("tekst").html(strHTML));
			$(this).append($("<span />").addClass("meerknop").html('... ').append($("<a />").attr("href", "#").html("lees meer").click(function(){
				$("span.meerknop").show(); 
				$("span.tekst").hide(); 
				$(this).parent().parent().find("span.tekst").css("display", "inline"); 
				$(this).parent().parent().find("span.meerknop").css("display", "none"); 
				return false;
			}) ));
		}
	).ready(function(){
		$("span.leesmeer span.tekst").hide();
		$("span.leesmeer span.tekst:first").show();
		$("span.leesmeer span.meerknop:first").hide();
	});	
	
	$("span.leesmeerfr").each( /* xx */
			function(iNr){
				strHTML = $(this).html(); 
				$(this).html($("<span />").addClass("tekst").html(strHTML));
				$(this).append($("<span />").addClass("meerknop").html('... ').append($("<a />").attr("href", "#").html("en savoir plus").click(function(){
					$("span.meerknop").show(); 
					$("span.tekst").hide(); 
					$(this).parent().parent().find("span.tekst").css("display", "inline"); 
					$(this).parent().parent().find("span.meerknop").css("display", "none"); 
					return false;
				}) ));
			}
		).ready(function(){
			$("span.leesmeerfr span.tekst").hide();
			$("span.leesmeerfr span.tekst:first").show();
			$("span.leesmeerfr span.meerknop:first").hide();
		});	
	
	
	$("span.leesmeeren").each( /* xx  */
			function(iNr){
				strHTML = $(this).html(); 
				$(this).html($("<span />").addClass("tekst").html(strHTML));
				$(this).append($("<span />").addClass("meerknop").html('... ').append($("<a />").attr("href", "#").html("read more").click(function(){
					$("span.meerknop").show(); 
					$("span.tekst").hide(); 
					$(this).parent().parent().find("span.tekst").css("display", "inline"); 
					$(this).parent().parent().find("span.meerknop").css("display", "none"); 
					return false;
				}) ));
			}
		).ready(function(){
			$("span.leesmeeren span.tekst").hide();
			$("span.leesmeeren span.tekst:first").show();
			$("span.leesmeeren span.meerknop:first").hide();
		});	
	
	$("body.nl span.meerwetendropdown").each( /* BBeun */
		function(iNr){
			strHTML = $(this).html(); 
			$(this).html($("<span />").addClass("tekst").html(strHTML));
			$(this).append($("<span />").addClass("meerknop").append(
				$("<a />").attr("href", "#pLM" + iNr).attr("class", "jellygrijs").html("Meer weten").click(function(){
				$("span.meerknop").show(); 
				$("span.tekst").hide(); 
				$(this).parent().parent().find("span.tekst").css("display", "inline"); 
				$(this).parent().parent().find("span.meerknop").css("display", "none"); 
				event.stopPropagation();
				return false;
				})
			).append(
				$("<a />").attr("name", "pLM" + iNr)
			));
		}
	).ready(function(){
		$("body.nl span.meerwetendropdown span.tekst").hide();
		$("body.nl span.meerwetendropdown span.tekst:first").show();
		$("body.nl span.meerwetendropdown span.meerknop:first").hide();
	});	
	
	$("body.fr span.meerwetendropdown").each( /* BBeun */
			function(iNr){
				strHTML = $(this).html(); 
				$(this).html($("<span />").addClass("tekst").html(strHTML));
				$(this).append($("<span />").addClass("meerknop").append(
					$("<a />").attr("href", "#pLM" + iNr).attr("class", "jellygrijs").html("En savoir plus").click(function(){
					$("span.meerknop").show(); 
					$("span.tekst").hide(); 
					$(this).parent().parent().find("span.tekst").css("display", "inline"); 
					$(this).parent().parent().find("span.meerknop").css("display", "none"); 
					event.stopPropagation();
					return false;
					})
				).append(
					$("<a />").attr("name", "pLM" + iNr)
				));
			}
	).ready(function(){
		$("body.fr span.meerwetendropdown span.tekst").hide();
		$("body.fr span.meerwetendropdown span.tekst:first").show();
		$("body.fr span.meerwetendropdown span.meerknop:first").hide();
	});	
	
	$("body.en span.meerwetendropdown").each( /* BBeun */
			function(iNr){
				strHTML = $(this).html(); 
				$(this).html($("<span />").addClass("tekst").html(strHTML));
				$(this).append($("<span />").addClass("meerknop").append(
					$("<a />").attr("href", "#pLM" + iNr).attr("class", "jellygrijs").html("Read more").click(function(){
					$("span.meerknop").show(); 
					$("span.tekst").hide(); 
					$(this).parent().parent().find("span.tekst").css("display", "inline"); 
					$(this).parent().parent().find("span.meerknop").css("display", "none"); 
					event.stopPropagation();
					return false;
					})
				).append(
					$("<a />").attr("name", "pLM" + iNr)
				));
			}
	).ready(function(){
		$("body.en span.meerwetendropdown span.tekst").hide();
		$("body.en span.meerwetendropdown span.tekst:first").show();
		$("body.en span.meerwetendropdown span.meerknop:first").hide();
	});	
	
	/* Gert */
	var showText='<img src="http://graphics.tn-media.be/tsd3/pijl_down.png"/>';
	var hideText='<img src="http://graphics.tn-media.be/tsd3/pijl_up.png"/>';
    //Hide (Collapse) the toggle containers on load
    $(".toggle_container").hide(); 
    $(".toggle_container.standaardopen").show(); 
    $("h3.trigger span").html(hideText);
    //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
    $("h3.trigger").click(function(){
     //   $(this).toggleClass("active").next().slideToggle(500);
      //  $(this).find("span").html( ($(this).hasClass("active"))? showText : hideText);
		/*aanpassing fcantineau */
		//Close the previous container
		$(".toggle_container").hide();
		$("h3.trigger span").html(hideText);
		$("h3.active").removeClass('active');
		$(this).addClass("active");
        $(this).find("span").html(showText);
		$(this).next().slideToggle(500);
    });
	
	/* h2opensnextdiv (BBeun) - node 1673 */
	$(".h2opensnextdiv h2").click(function(){
        $(this).next("div").toggle(); 
		$(this).toggleClass("open"); 
    });
	$(".h2opensnextdiv h2").each(function() { 
		$(this).next("div").hide(); 
	});
	
	$("dl.clickopen dd").hide(); // BBeun (wordt gebruikt op node 581 - lijst met clickopens ) 
	$("dl.clickopen dt").click(
		function (event){
			$(this).parent().children("dd").hide();
			$(this).next("dd").show();
		}
	);
	

	$(".shoplink").click(
		function(event){
			$("#shoplinksbox").show(); 
			return(true);
		}
	);
	
	/* Google analytics (BBeun) */
	$("input[type!='checkbox'],textarea,select").focus( // alle formulieren: GA-event sturen bij aanklikken veld
		function(){
			_gaq.push(['_trackEvent' , $("body").attr("url"), 'aangeklikt', GA_getformname($(this).attr("name"))]); 
		}
	); 
	/*$("input#txtSearch").click( 
		function(){
			_gaq.push(['_trackEvent' , $("body").attr("url"), 'zoeken', $("#txtSearch").attr("value")]); 
		}
	);*/ 
	$("input#btnzoek").click( 
		function(){
			_gaq.push(['_trackEvent' , $("body").attr("url"), 'zoeken', $("#txtSearch").attr("value")]); 
			setTimeout( function() { $("#txtSearch").parent().submit() }, 500 );
			return false; 
		}
	); 
	
	$("input[type='radio']").click( // alle formulieren: GA-event sturen bij aanklikken veld
		function(){
			_gaq.push(['_trackEvent' , $("body").attr("url"), 'aangeklikt', GA_getformname($(this).attr("name")) + ":" + $(this).attr("value")]); 
		}
	); 
	$("input[type='checkbox']").click( // alle formulieren: GA-event sturen bij aanklikken veld
		function(){
			_gaq.push(['_trackEvent' , $("body").attr("url"), 'aangeklikt', GA_getformname($(this).attr("name")) + ":" + $(this).attr("value")]); 
		}
	); 
	$(".messages.error ul li").each(function() { // iedere foutmelding tracken bij GA, samen met anonieme sessie-id
		_gaq.push(['_trackEvent' , $("body").attr("url"), 'foutmelding', $(this).text()]); 
	});
	
	$("body.soho a.glossary-term").each(function() { // glossary-items op soho niet klikbaar maken
		$(this).replaceWith($(this).html()); 
	});
	
	$("input.form-submit:not(.knopgrijs)").attr("value", ""); // submit-knoppen-value's wissen (zit in background-image) / .knopgrijs laten zijn
	
	$('a').filter(function() {/* BBeun - GA op  externe links/files - pagetrack "huidigepagina.html/vp?externelink " */
		return this.href.match(/^(http|https):\/\/(?!telenet\.be)/); 
    }).filter(function() {/* int eruit filteren  */
		return this.href.match(/^(http|https):\/\/(?!([a-z]+\.)+telenet-esp\.be)/); 
    }).filter(function() {/* BBeun - ook tn-media niet " */
		return this.href.match(/^(http|https):\/\/(?![a-zA-Z]+\.tn-media\.be)/); 
    }).click(function() { 
		_gaq.push(['_trackPageview', $("body").attr("url") + "/vp?" + $(this).attr("href").replace("http://", "").replace("https://", "")]);
		if (!($(this).attr('target'))) { // als er geen target gedefineerd staat verder doen
			if (!($(this).hasClass('overlayer'))) { // als het niet over een overlayer gaat
				if ($(this).attr('id')!="headcontactbutton") { // als het niet de popupwindow is (ook shadowbox)
					if (!($(this).hasClass('fancybox'))) { // als het niet over een overlayer gaat
				setTimeout('document.location = "' + $(this).attr("href") + '"', 100); // binnen 1/10 sec. pagina openen (zodat er tijd is voor tracking signaal)
			return false; 
		}
		}
		}
		}
	});
	
	$("input.OptieCheckbox").click( /* BBeun */
		function() {
			strOpt = $(this).attr("value"); 
			if (this.checked){
				$("input.OptieCheckbox:checked").each(function() { // -> alle checkboxen overlopen 
					if ($(this).attr("value") != strOpt) { // en van de andere 
						strWeg = $(this).attr("value");  
						$("a.shoplink").each(function() { 
							$(this).attr("href", $(this).attr("href").replace("," + strWeg, "")) // de link wegdoen 
						});
						this.checked = false;  // en unchecken
					}
				}); 
				$("a.shoplink").each(function() {  // -> alle shoplinks overlopen 
					$(this).attr("href", $(this).attr("href") + "," + strOpt) // en link product bijvoegen
				});
			} else {
				$("a.shoplink").each(function() { // -> alle shoplinks overlopen 
					$(this).attr("href", $(this).attr("href").replace("," + strOpt, "")) // en link product wegdoen
				});
			}
		}
	);
	
	$("input.OptieCheckbox2").removeAttr("checked"); /*saerts */
	$("input.OptieCheckbox3").removeAttr("checked");
	
	$("input.OptieCheckbox2").click( /* BVanAutreve */
		function() {
			strOpt = $(this).attr("value");
			strRel = $(this).attr("rel");
			strTariff = parseFloat($(this).attr("tariff"));
			if (this.checked){
				$("a.shoplink").each(function() {  // -> alle shoplinks overlopen 
					if ($(this).attr("rel") == strRel) {
						$(this).attr("href", $(this).attr("href") + "," + strOpt) // en link product bijvoegen
					}
				});
				$("span.ChangePriceTagPrice").each(function() {
					if ($(this).attr("rel") == strRel) {
						fltPrice = parseFloat($(this).attr("tariff"));
						totalPrice = fltPrice + strTariff;
						totalPrice = new Number(totalPrice);
						totalPrice = totalPrice.toFixed(2);
						$(this).attr("tariff", totalPrice);
						totalPrice = String(totalPrice).replace(".", ",");
						$(this).html(totalPrice);
					}
				});
			} else {
				$("a.shoplink").each(function() { // -> alle shoplinks overlopen
					if ($(this).attr("rel") == strRel) { 
						$(this).attr("href", $(this).attr("href").replace("," + strOpt, "")) // en link product wegdoen
					}
				});
				$("span.ChangePriceTagPrice").each(function() {
					if ($(this).attr("rel") == strRel) {
						fltPrice = parseFloat($(this).attr("tariff"));
						totalPrice = fltPrice - strTariff;
						totalPrice = new Number(totalPrice);
						totalPrice = totalPrice.toFixed(2);
						$(this).attr("tariff", totalPrice);
						totalPrice = String(totalPrice).replace(".", ",");
						$(this).html(totalPrice);
					}
				});
			}
		}
	);
	
	
	$("input.OptieCheckbox3").click( /*saerts */
		function() {
			strOpt = $(this).attr("value");
			strRel = $(this).attr("rel");
			strTariff = parseFloat($(this).attr("tariff"));
			if (this.checked){
				$("a.shoplink").each(function() {  // -> alle shoplinks overlopen 
					if ($(this).attr("rel") == strRel) {
						$(this).attr("href", $(this).attr("href") + strOpt) // en link product bijvoegen
					}
				});
				$("span.ChangePriceTagPrice").each(function() {
					if ($(this).attr("rel") == strRel) {
						fltPrice = parseFloat($(this).attr("tariff"));
						totalPrice = fltPrice + strTariff;
						totalPrice = new Number(totalPrice);
						totalPrice = totalPrice.toFixed(2);
						$(this).attr("tariff", totalPrice);
						totalPrice = String(totalPrice).replace(".", ",");
						$(this).html(totalPrice);
					}
				});
			} else {
				$("a.shoplink").each(function() { // -> alle shoplinks overlopen
					if ($(this).attr("rel") == strRel) { 
						$(this).attr("href", $(this).attr("href").replace(strOpt, "")) // en link product wegdoen
					}
				});
				$("span.ChangePriceTagPrice").each(function() {
					if ($(this).attr("rel") == strRel) {
						fltPrice = parseFloat($(this).attr("tariff"));
						totalPrice = fltPrice - strTariff;
						totalPrice = new Number(totalPrice);
						totalPrice = totalPrice.toFixed(2);
						$(this).attr("tariff", totalPrice);
						totalPrice = String(totalPrice).replace(".", ",");
						$(this).html(totalPrice);
					}
				});
			}
		}
	);
	
	/* Resize images frontpage*/
	$('.visuals img').resizeOnApproach({
	'elementDefault': 132,
	'elementClosest': 140,
	'triggerDistance': 1,
	'setWidthAndHeight':true
	});
  
  /* TIP voorbeeld tabs JDeRidder */
  $("#tabs").tabs();
  
  /* Algemeen tabs-script (BBeun) (bv node/2121) */ 
	$(".tabs .tab-content").hide(); 
	$(".tabs .tab-content.active").show(); 
	$(".tabs ul.tab-nav li a").click(function() {
		$(".tabs ul.tab-nav li").removeClass("active"); 
		$(this).parent().addClass("active"); 
		$(".tabs .tab-content").hide(); 
		$(".tabs #" + $(this).attr("href").replace("#", "")).show(); 
		return false; 
	}); 
  
 
	$("#headcontactbutton").fancybox({
		'width'		:	415, 
		'height'		:	230, 
		'padding': 0, 
		'autoDimensions': false
});

	$("#dropdownbutton").click(function() {$("#inloggedeelte").toggleClass('Activated')});   

	$(".TopPanel_nl .esaleswinkelmandje").attr("href", "http://shop.telenet.be/shop/nl/order/ajax-basket-overlay?iframe=1");
	$(".TopPanel_fr .esaleswinkelmandje").attr("href", "http://shop.telenet.be/shop/fr/order/ajax-basket-overlay?iframe=1");
	$(".esaleswinkelmandje").fancybox({'width': 320,'height': '80%','autoScale': false,'transitionIn': 'none','transitionOut': 'none','type': 'iframe'});  

	/* FANCYBOX (BBeun) */
	$(".fancybox").fancybox({'width': 640,'height': 400,'autoScale': false,'transitionIn': 'none','transitionOut': 'none','type': 'iframe'});  
	$(".mobile div.bestellink a.preorder").fancybox({'width':640, 'height':480, 'padding': 10, 'autoDimensions': false });
  
});


function GA_getformname(strName){
	var arNames = {
		"words" : "zoeken",
		"00N20000000jMDh[Internet]" : "meerwetenover",
		"00N20000000jMDh[Telefonie]" : "meerwetenover",
		"00N20000000jMDh[Datacommunicatie]" : "meerwetenover",
		"00N20000000jMDh[Hosted Services]" : "meerwetenover",
		"00N20000000jMDh[Data Security]" : "meerwetenover",
		"00N20000000jMDh[TV voor business]" : "meerwetenover",
		"00N20000000jMDh[Draadloos internet]" : "meerwetenover",
		"00N20000000jMDh[andere oplossingen]" : "meerwetenover",
		"00N20000000jDlr" : "uw_vraag",
		"00N200000010Lwr" : "aantal_werknemers",
		"00N20000000jDlv" : "aantal_vestigingen",
		"00N200000010MAK" : "BTW_nummer", 
		"submitted[vraag][uw_vraag_betreft]" : "uw_vraag_betreft", 
		"op" : "verzenden"
	}
	strName = (arNames[strName])?arNames[strName]:strName; // vervangen indien in Array

	var oReg = /submitted\[gegevens]\[([a-zA-Z_-]*)]/i;
	if (oReg.test(strName)) strName = strName.replace(oReg, "$1"); 

	var oReg = /submitted\[field_advies]\[([a-zA-Z_-]*)]/i;
	if (oReg.test(strName)) strName = strName.replace(oReg, "$1"); 
	

	var oReg = /submitted\[vraag]\[([a-zA-Z_-]*)]/i;
	if (oReg.test(strName)) strName = strName.replace(oReg, "$1"); 
	
	return strName; 
}

function gettimer(){ /* BBeun */
	var nu = new Date();
	return nu.getTime();
}
function afdrukken(){ /* BBeun */
	print(); 
	return false; 
}

$(document).ready(function() {
 
	$('.tabs a').click(function(){
		switch_tabs($(this));
	});
 
	switch_tabs($('.defaulttab'));
 
});
 
function switch_tabs(obj)
{
	var id = obj.attr("rel");
	
	if( id ) {
	
		$('.tab-content').hide();
		$('.tabs a').removeClass("defaulttab selected");
 
		$('#'+id).show();
		obj.addClass("defaulttab selected");
	}
}

function generateBasket(o){
    if(o['numberOfProducts']>0){
        $(".esaleswinkelmandje").html(o['numberOfProducts']);
        $("#winkelgedeelte").show();
    }
}

