﻿//Onderstaande functies worden gebruikt door de applicatie, veranderingen aan deze code kan een correcte werking van de applicatie verhinderen
//verkrijg base href als deze aanwezig is voor het corrigeren van iexplorer javascript links
var baseAdres = "";
if( document.getElementsByTagName ) {
	var elems = document.getElementsByTagName('base');
	if( elems.length ) {
		baseAdres = elems[0].href;
	}
}

window.addEvent('domready',function(){
	$$('.block.nieuws').each(function(el){
		if(!$('albumEersteLinks')){
			$("mainContent").setStyle("width","271px");
		}
		el.setStyle("display","block");
	});		
	if($('albumEersteLinks')){$$('.block:not(.nieuws)').setStyle('display','none');}	
	//maak afbeeldingen met popup uitvergrootbaar
	$$('img').each(function(el){									
		if(el.src.toLowerCase().indexOf('upload/0popup-') > -1){
			el.setStyle('cursor','pointer');
			el.addEvent('click',function(){
				showImage(el.src.replace(/0popup-/ig,"0-"));
			});
		}
	});

	$$('.mainMenuActive').each(function(el){									
		var elId = el.get('id').substr(4);
		if($("mainMenuSeperator" + elId)){
			$("mainMenuSeperator" + elId).setStyle("background","none");
		}
		if($("mainMenuSeperator" + (parseInt(elId) + 1))){
			$("mainMenuSeperator" + (parseInt(elId) + 1)).setStyle("background","none");
		}
	});
	$$('.mainMenu').each(function(el){
		$('menuBg' + el.get('id').substr(4)).setStyles({display:'block',opacity:0});

		el.addEvent('mouseover',function(){					
			var elId = this.get('id').substr(4);
			$('menuBg' + elId).get('tween', {property: 'opacity', duration: 200}).start(1);
		});
		el.addEvent('mouseout',function(){
			var elId = this.get('id').substr(4);
			$('menuBg' + elId).get('tween', {property: 'opacity', duration: 300}).start(0);
		});
	});	
	
	var tP = 0;
	$$('.product').each(function(el){
		tP ++;
		$('productBg' + el.get('id').substr(7)).setStyles({display:'block',opacity:0});

		el.addEvent('mouseover',function(){					
			var elId = this.get('id').substr(7);
			$('productBg' + elId).get('tween', {property: 'opacity', duration: 200}).start(0.3);
		});
		el.addEvent('mouseout',function(){
			var elId = this.get('id').substr(7);
			$('productBg' + elId).get('tween', {property: 'opacity', duration: 300}).start(0);
		});
	});	
	$$('.productActive').each(function(el){
		tP ++;
	});
	tP = tP - 1;
	if($("product" + tP)){
		if($("product" + tP).get("class") != 'productActive'){
			$("product" + tP).setStyle("border-bottom","1px solid #141515");
		}
	}
	
	tP = 0;
	$$('.headline').each(function(el){
		tP ++;
		$('headlineBg' + el.get('id').substr(8)).setStyles({display:'block',opacity:0});

		el.addEvent('mouseover',function(){				
			var elId = this.get('id').substr(8);
			$('headlineBg' + elId).get('tween', {property: 'opacity', duration: 200}).start(0.3);
		});
		el.addEvent('mouseout',function(){
			var elId = this.get('id').substr(8);
			$('headlineBg' + elId).get('tween', {property: 'opacity', duration: 300}).start(0);
		});
	});	
	$$('.headlineActive').each(function(el){
		tP ++;
	});
	tP = tP - 1;
	if($("headline" + tP)){
		if($("headline" + tP).get("class") != 'headlineActive'){
			$("headline" + tP).setStyle("border-bottom","1px solid #141515");
		}
	}
});


function printPagina(){
	printVenster = open("","printWindow","width=800,height=400,left=10,top=10,resizable=yes");
	var printTekst = document.getElementById("mainContentDiv").innerHTML;
	printTekst = printTekst.replace(/<div class="etalageAfbeelding".*url\((.*)\).* .*<\/div>/ig,'<img src="$1" alt="" style="float:left;margin-right:10px;"/>');
	printTekst = printTekst.replace(/<div class="paginaAfbeeldingen".*url\((.*)\).* .*<\/div>/ig,'<img src="$1" alt="" style="float:left;"/>');
	printTekst = printTekst.replace(/<div class="etalageAfbeeldingen".*url\((.*)\).* .*<\/div>/ig,'<img src="$1" alt="" style="float:left;"/>');
	printTekst = printTekst.replace(/<div style="width.*url\((.*)\).* no-repeat.*<\/div>/ig,'<img src="$1" alt="" style="float:left;"/>');

	var printHTML = '<HTML><HEAD><TITLE>' + document.title + '</TITLE>';
	if(baseAdres != ""){printHTML += '<base href="' + baseAdres +  '/" />'} 
	printHTML += '<LINK HREF="basic.css" REL="stylesheet" TYPE="text/css"></HEAD><BODY onload="window.print()">'
	printHTML += printTekst;
	printHTML += '</BODY></HTML>'
	printVenster.document.open();
	printVenster.document.write(printHTML);
	printVenster.document.close();
}

//Einde applicatie functies

//handige functies
//menu openklappen
function openMenu(menuID,submenuID){}
//extra menu openklappen
function openExtraMenu(menuID,submenuID){}

//voorkom lelijke omlijning van a elementen door indrukken van tab in sommige browsers
var theahrefs = document.getElementsByTagName('a'); for(var x=0;x!=theahrefs.length;x++){theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};}

var albumActive = false;

//functie om externe links automatisch in nieuw venster te tonen
window.onload = externeLinks;
function externeLinks (){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && obj.target == "" && href.indexOf("javascript")==-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};
