$(document).ready(function() {
	
	// ACHTERGRONDKLEUR SUBMENULINKS
	$('.submenu a, .submenu_new a')
	.mouseover(function(){
		$(this).parent().stop().animate({ backgroundColor: "#E7E5E3" }, 100);
	})
	.mouseout(function(){
		$(this).parent().stop().animate({ backgroundColor: "#FFFFFF" }, 100);
	});

	// LOGO-MOUSEOVER
	$('#logo')
	.mouseover(function(){
		$(this).stop().animate({ width: "225px", height:"115px", marginTop:"-4px", marginLeft:"-112.5px" }, { duration: 500, easing: 'easeOutQuad' });
	})
	.mouseout(function(){
		$(this).stop().animate({ width: "215px", height:"107px", marginTop:"0px", marginLeft:"-107.5px" }, { duration: 500, easing: 'easeOutQuad' });
	});

	// MENUKLEUREN MOUSEOVERS
	$('#headermenu a')
	.mouseover(function(){ 																													// WANNEER CURSOR BOVEN TAB
		$(this).parent('td').stop().animate({ backgroundColor: "#FFFFFF" }, { duration: 500, easing: 'easeOutQuad' }); 						// TAB ONDER CURSOR LICHT
		$('#headermenu a').not(this).parent('td').stop().animate({ backgroundColor: "#CFCBC8" }, { duration: 500, easing: 'easeOutQuad' });	// OVERIGE TABS DONKER
		$('#headermenu').stop().animate({ backgroundColor: "#CFCBC8" }, { duration: 500, easing: 'easeOutQuad' }); 							// HEADERMENU DONKER
	})
	.mouseout(function(){ 																													// WANNEER CURSOR VAN TAB AF
		$(this).parent('td').stop().animate({ backgroundColor: "#E7E5E3" }, { duration: 500, easing: 'easeOutQuad' });						// TAB ONDER CURSOR MEDIUM
		$('#headermenu a').not(this).parent('td').stop().animate({ backgroundColor: "#E7E5E3" }, { duration: 500, easing: 'easeOutQuad' });	// OVERIGE TABS MEDIUM
		$('#headermenu').stop().animate({ backgroundColor: "#E7E5E3" }, { duration: 500, easing: 'easeOutQuad' });							// HEADERMENU MEDIUM
	})
	.click(function(){ 																														// WANNEER KLIK OP INACTIEVE TAB
	});
	
	// OPACITY MERKLOGOS SUBMENU
	$('.merklogo').parent('a')
	.mouseover(function(){
		$(this).children('.merklogo').css({ opacity: 1.0 });
	})
	.mouseout(function(){
		$(this).children('.merklogo').css({ opacity: 0.7 });
	});

	// SLUITEN LIGHTBOX
	$('#lightboxbg, #close')
	.click(function(){ 																													// WANNEER KLIK OP ACTIEVE TAB
		$('#lightboxkaderrand, #lightboxbg').fadeOut("fast");	
	});

	$('#lightboxbg2, #close2')
	.click(function(){ 																													// WANNEER KLIK OP ACTIEVE TAB
		$('#lightboxkaderrand2, #lightboxbg2').fadeOut("fast");	
	});

	$('#videolink')
	.click(function(){ 																													// WANNEER KLIK OP ACTIEVE TAB
		if( $(this).parent().children('iframe').height() == '0' ) { 
			$(this).parent().children('iframe').animate({ height:"239px" }, { duration: 500, easing: 'easeOutQuad' });
		} else {
			$(this).parent().children('iframe').animate({ height:"0px" }, { duration: 500, easing: 'easeOutQuad' });
		}
	});

});

// UITKLAPPEN SUBMENUS
function startsub(nr,hoog) {
	$('#menu'+nr).parent().children('.active').fadeIn(500);																// TAB ONDER CURSOR ACTIEF 
	$('.submenu:not(#submenu'+nr+')').children('ul').children('li').children('a').animate({ color:"#FFFFFF" }, 500);	// ANDER SUBMENU INKLAPPEN
	$('#submenu'+nr).animate({ height: hoog+"px" }, 500);																// ANDER SUBMENU INKLAPPEN
	$('#submenu'+nr).children('ul').children('li').children('a').animate({ color:"#5B564C" }, 500);						// ANDER SUBMENU INKLAPPEN
	}

function startsub2(nr,hoog) {
	$('#menu'+nr).parent().children('.active').fadeIn(1);																// TAB ONDER CURSOR ACTIEF 
	$('.submenu:not(#submenu'+nr+')').children('ul').children('li').children('a').animate({ color:"#FFFFFF" }, 1);	// ANDER SUBMENU INKLAPPEN
	$('#submenu'+nr).animate({ height: hoog+"px" }, 1);																// ANDER SUBMENU INKLAPPEN
	$('#submenu'+nr).children('ul').children('li').children('a').animate({ color:"#5B564C" }, 1);						// ANDER SUBMENU INKLAPPEN
	}

// STANDAARD TOON- & VERBERGFUNCTIES	
function show(toShow) { document.getElementById(toShow).style.display = 'inline'; }
function hide(toHide) { document.getElementById(toHide).style.display = 'none'; }
function showhide(toShowHide)
	{
	if(document.getElementById(toShowHide).style.display == 'none')
		{document.getElementById(toShowHide).style.display = 'inline';}
	else
		{document.getElementById(toShowHide).style.display = 'none';}
	}


var imgHeight;
var imgWidth;

// LIGHTBOX-AFMETINGEN 
function lightboxafm() {

	var viewport_w = viewport()[0];
	var viewport_h = viewport()[1];
	
	if (this.height + 50 > viewport_h) {
		// foto is hoger dan viewport;
		verhouding = this.height / this.width;
		//alert(verhouding);
		imgHeight = viewport_h - 50;
		imgWidth = imgHeight / verhouding;
		}
	else {
		// foto is lager dan viewport;
		imgHeight = this.height;
		imgWidth = this.width;
		}
	//alert('w='+imgWidth+' h='+imgHeight);
	
	halfheight = imgHeight/2;
	halfwidth = imgWidth/2 + 20;
    
    kaderheight = imgHeight+40;
	kaderwidth = imgWidth+80;
	halfkaderheight = kaderheight/2;
	halfkaderwidth = kaderwidth/2;

    kaderrandheight = imgHeight+50;
	kaderrandwidth = imgWidth+90;
	halfkaderrandheight = kaderrandheight/2;
	halfkaderrandwidth = kaderrandwidth/2;

	//alert('margin-left = -'+halfwidth+'px en margin-top = -'+halfheight+'px');

	document.getElementById('fotogroot').style.marginLeft = '-'+halfwidth+'px';
	document.getElementById('fotogroot').style.marginTop = '-'+halfheight+'px';
	document.getElementById('fotogroot').style.width = imgWidth+'px';
	document.getElementById('fotogroot').style.height = imgHeight+'px';

	document.getElementById('lightboxkader').style.width = kaderwidth+'px';
	document.getElementById('lightboxkader').style.height = kaderheight+'px';
	document.getElementById('lightboxkader').style.marginLeft = '-'+halfkaderwidth+'px';
	document.getElementById('lightboxkader').style.marginTop = '-'+halfkaderheight+'px';

	document.getElementById('lightboxkaderrand').style.width = kaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.height = kaderrandheight+'px';
	document.getElementById('lightboxkaderrand').style.marginLeft = '-'+halfkaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.marginTop = '-'+halfkaderrandheight+'px';
	
	$('#lightboxkaderrand').fadeIn("fast");
	$('#lightboxbg').fadeIn("fast");

	return true;
	}

function lightboxafm_shop() {

	var viewport_w = viewport()[0];
	var viewport_h = viewport()[1];
	
	if (this.height + 50 > viewport_h) {
		// foto is hoger dan viewport;
		verhouding = this.height / this.width;
		//alert(verhouding);
		imgHeight = viewport_h - 50;
		imgWidth = imgHeight / verhouding;
		}
	else {
		// foto is lager dan viewport;
		imgHeight = this.height;
		imgWidth = this.width;
		}
	//alert('w='+imgWidth+' h='+imgHeight);
	
	halfheight = imgHeight/2;
	halfwidth = imgWidth/2 + 20;
    
    kaderheight = imgHeight+40;
	kaderwidth = imgWidth+80;
	halfkaderheight = kaderheight/2;
	halfkaderwidth = kaderwidth/2;

    kaderrandheight = imgHeight+50;
	kaderrandwidth = imgWidth+90;
	halfkaderrandheight = kaderrandheight/2;
	halfkaderrandwidth = kaderrandwidth/2;

	//alert('margin-left = -'+halfwidth+'px en margin-top = -'+halfheight+'px');


	document.getElementById('fotogroot').style.marginLeft = '-'+halfwidth+'px';
	document.getElementById('fotogroot').style.marginTop = '-'+halfheight+'px';
	document.getElementById('fotogroot').style.width = imgWidth+'px';
	document.getElementById('fotogroot').style.height = imgHeight+'px';

	document.getElementById('lightboxkader').style.width = kaderwidth+'px';
	document.getElementById('lightboxkader').style.height = kaderheight+'px';
	document.getElementById('lightboxkader').style.marginLeft = '-'+halfkaderwidth+'px';
	document.getElementById('lightboxkader').style.marginTop = '-'+halfkaderheight+'px';

	document.getElementById('lightboxkaderrand').style.width = kaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.height = kaderrandheight+'px';
	document.getElementById('lightboxkaderrand').style.marginLeft = '-'+halfkaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.marginTop = '-'+halfkaderrandheight+'px';
	
	$('#lightboxkaderrand').fadeIn("fast");
	$('#lightboxbg').fadeIn("fast");
	$('#lb_arrow_prev').fadeOut("fast");
	$('#lb_arrow_next').fadeOut("fast");

	return true;
	}
 
function lightboxafm2() {
	imgHeight = this.height;
	imgWidth = this.width;
	
	halfheight = imgHeight/2;
	halfwidth = imgWidth/2 + 20;
    
    kaderheight = imgHeight+40;
	kaderwidth = imgWidth+80;
	halfkaderheight = kaderheight/2;
	halfkaderwidth = kaderwidth/2;

    kaderrandheight = imgHeight+50;
	kaderrandwidth = imgWidth+90;
	halfkaderrandheight = kaderrandheight/2;
	halfkaderrandwidth = kaderrandwidth/2;

	document.getElementById('fotogroot2').style.marginLeft = '-'+halfwidth+'px';
	document.getElementById('fotogroot2').style.marginTop = '-'+halfheight+'px';

	document.getElementById('lightboxkader2').style.width = kaderwidth+'px';
	document.getElementById('lightboxkader2').style.height = kaderheight+'px';
	document.getElementById('lightboxkader2').style.marginLeft = '-'+halfkaderwidth+'px';
	document.getElementById('lightboxkader2').style.marginTop = '-'+halfkaderheight+'px';

	document.getElementById('lightboxkaderrand2').style.width = kaderrandwidth+'px';
	document.getElementById('lightboxkaderrand2').style.height = kaderrandheight+'px';
	document.getElementById('lightboxkaderrand2').style.marginLeft = '-'+halfkaderrandwidth+'px';
	document.getElementById('lightboxkaderrand2').style.marginTop = '-'+halfkaderrandheight+'px';
	
	$('#lightboxkaderrand2').fadeIn("fast");
	$('#lightboxbg2').fadeIn("fast");

	return true;
	}

function lightbox(imgPath) {
	var myImage = new Image();
	myImage.name = 'http://www.amelink.com/fotos/'+imgPath+'.jpg';
	myImage.onload = lightboxafm;
	myImage.src = 'http://www.amelink.com/fotos/'+imgPath+'.jpg';
	document.getElementById('fotogroot').src = 'http://www.amelink.com/fotos/'+imgPath+'.jpg';
	}

function lightbox_shop(imgPath) {
	var myImage = new Image();
	myImage.name = imgPath;
	myImage.onload = lightboxafm_shop;
	myImage.src = imgPath;
	document.getElementById('fotogroot').src = imgPath;
	}

function lightbox2(imgNumber) {
	imgPath = js_imglist[imgNumber];
	//alert(imgPath);
	var myImage = new Image();
	myImage.name = 'http://www.amelink.com/images/referenties/'+imgPath+'.jpg';
	myImage.onload = lightboxafm2;
	myImage.src = 'http://www.amelink.com/images/referenties/'+imgPath+'.jpg';
	document.getElementById('fotogroot2').src = 'http://www.amelink.com/images/referenties/'+imgPath+'.jpg';
	document.getElementById('fotogroot2').name = imgNumber;
	//document.getElementById( "prevlink2" ).onclick = function() {lightbox2(newprev);}
	//document.getElementById( "nextlink2" ).onclick = function() {lightbox2(newnext);}
	}


function lightboxfoto_resize() {
	//document.getElementById('report').innerHTML = tempImage.height; //'foto='+tempImage.height+' viewport='+viewport_h;
	//document.getElementById('report').innerHTML = 'foto='+tempImage.height+' viewport='+viewport_h;
    }

function lightbox_resize() {
	var viewport_w = viewport()[0];
	var viewport_h = viewport()[1];
	
	// alert(viewport_w+' '+viewport_h);

	//document.getElementById('report').innerHTML = 'foto='+document.getElementById('fotogroot').height+' viewport='+viewport_h;
	fotosrc = document.getElementById('fotogroot').src;
	
	//document.getElementById('report').innerHTML = fotosrc; //'foto='+tempImage.height+' viewport='+viewport_h;

    tempImage = new Image();
    //tempImage.onload = lightboxfoto_resize;
    tempImage.src = fotosrc;

	//document.getElementById('report').innerHTML = tempImage.height; //'foto='+tempImage.height+' viewport='+viewport_h;

	if (tempImage.height + 50 > viewport_h) {
		// foto is hoger dan viewport;
		
		verhouding = tempImage.height / tempImage.width;
		//alert(verhouding);
		imgHeight = viewport_h - 50;
		imgWidth = imgHeight / verhouding;
		}
	else {
		// foto is lager dan viewport;
		imgHeight = tempImage.height;
		imgWidth = tempImage.width;
		}
		
	//alert('w='+imgWidth+' h='+imgHeight);
	
	halfheight = imgHeight/2;
	halfwidth = imgWidth/2 + 20;
    
    kaderheight = imgHeight+40;
	kaderwidth = imgWidth+80;
	halfkaderheight = kaderheight/2;
	halfkaderwidth = kaderwidth/2;

    kaderrandheight = imgHeight+50;
	kaderrandwidth = imgWidth+90;
	halfkaderrandheight = kaderrandheight/2;
	halfkaderrandwidth = kaderrandwidth/2;

	//alert('margin-left = -'+halfwidth+'px en margin-top = -'+halfheight+'px');

	document.getElementById('fotogroot').style.marginLeft = '-'+halfwidth+'px';
	document.getElementById('fotogroot').style.marginTop = '-'+halfheight+'px';
	document.getElementById('fotogroot').style.width = imgWidth+'px';
	document.getElementById('fotogroot').style.height = imgHeight+'px';

	document.getElementById('lightboxkader').style.width = kaderwidth+'px';
	document.getElementById('lightboxkader').style.height = kaderheight+'px';
	document.getElementById('lightboxkader').style.marginLeft = '-'+halfkaderwidth+'px';
	document.getElementById('lightboxkader').style.marginTop = '-'+halfkaderheight+'px';

	document.getElementById('lightboxkaderrand').style.width = kaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.height = kaderrandheight+'px';
	document.getElementById('lightboxkaderrand').style.marginLeft = '-'+halfkaderrandwidth+'px';
	document.getElementById('lightboxkaderrand').style.marginTop = '-'+halfkaderrandheight+'px';
	
	}
	
	
var basepath='http://www.amelink.com/';
var basepath2='http://amelink.com/';

function changenext(afbvar) {
	var newnextlink = 'referenties/'+afbvar;
	document.getElementById( "nextlink2" ).onclick = function() {lightbox2(newnextlink);}
	}

function changeprev(afbvar) {
	var newprevlink = 'referenties/'+afbvar;
	document.getElementById( "prevlink2" ).onclick = function() {lightbox2(newprevlink);}
	}

function changenext2(newnext) {
	document.getElementById( "nextlink2" ).onclick = function() {lightbox2(newnext); changenext2open();}
	}

function changeprev2(newprev) {
	document.getElementById( "prevlink2" ).onclick = function() {lightbox2(newprev); changeprev2open();}
	}

function changenext2open() {
	document.getElementById('value').innerHTML = document.getElementById('fotogroot2').name;
	var lightboxnr = document.getElementById('fotogroot2').name;
	var nextnr = eval(eval(lightboxnr)+1);
	var prevnr = eval(eval(lightboxnr)-1);
	document.getElementById( "prevlink2" ).onclick = function() {lightbox2(prevnr); changeprev2open();}
	document.getElementById( "nextlink2" ).onclick = function() {lightbox2(nextnr); changenext2open();}
	}

function changeprev2open() {
	document.getElementById('value').innerHTML = document.getElementById('fotogroot2').name;
	var lightboxnr = document.getElementById('fotogroot2').name;
	var nextnr = eval(eval(lightboxnr)+1);
	var prevnr = eval(eval(lightboxnr)-1);
	document.getElementById( "prevlink2" ).onclick = function() {lightbox2(prevnr); changeprev2open();}
	document.getElementById( "nextlink2" ).onclick = function() {lightbox2(nextnr); changenext2open();}
	}

function lightboxnext() {
	var pfitems = $('.fotothumb').length;
	var fotosrc = document.getElementById('fotogroot').src;
	fotosrc = fotosrc.replace('http://www.amelink.com/fotos/','');
	fotosrc = fotosrc.replace('http://amelink.com/fotos/','');
	//alert(fotosrc); /* http://www.amelink.com/2010/fotos/ */
	fotoarr = fotosrc.split('_');
	fotocurr = fotoarr[1].replace('.jpg','');
	// alert(fotoarr[1]);
	if(fotocurr == pfitems) 	{ fotonext = '1';}
	else				 		{ fotonext = eval(fotocurr)+1; }
	if(fotonext<10) {fotonext='0'+fotonext;}
	lightbox(fotoarr[0]+'_'+fotonext);
	}

function lightboxprev() {
	var pfitems = $('.fotothumb').length;
	var fotosrc = document.getElementById('fotogroot').src;
	fotosrc = fotosrc.replace('http://www.amelink.com/fotos/','');
	fotosrc = fotosrc.replace('http://amelink.com/fotos/','');
	//alert(fotosrc); /* http://www.amelink.com/2010/fotos/ */
	fotoarr = fotosrc.split('_');
	fotocurr = fotoarr[1].replace('.jpg','');
	// alert(fotoarr[1]);
	if(fotocurr == 1) 			{ fotoprev = pfitems;}
	else				 		{ fotoprev = eval(fotocurr)-1; }
	if(fotoprev<10) {fotoprev='0'+fotoprev;}
	lightbox(fotoarr[0]+'_'+fotoprev);
	}

function clearform(el,mssg) {
	if(el.value == mssg) {
		el.value = '';
	}
}

function fillform(el,mssg) {
	if(el.value == '') {
		el.value = mssg;
	}
}

/*
function lightboxprev() {
	if( document.getElementById('fotogroot').src == basepath+'images/insp_franslandhuis.jpg' || 
		document.getElementById('fotogroot').src == basepath2+'images/insp_franslandhuis.jpg')
		{ lightbox('insp_engelsecottage'); }
	else if(document.getElementById('fotogroot').src == basepath+'images/insp_newclassic.jpg' || 
			document.getElementById('fotogroot').src == basepath2+'images/insp_newclassic.jpg')
		{ lightbox('insp_franslandhuis'); }
	else if(document.getElementById('fotogroot').src == basepath+'images/insp_engelsecottage.jpg' || 
			document.getElementById('fotogroot').src == basepath2+'images/insp_engelsecottage.jpg')
		{ lightbox('insp_newclassic'); }
	}

function lightboxnext() {
	if(	document.getElementById('fotogroot').src == basepath+'images/insp_franslandhuis.jpg' || 
		document.getElementById('fotogroot').src == basepath2+'images/insp_franslandhuis.jpg')
		{ lightbox('insp_newclassic'); }
	else if(document.getElementById('fotogroot').src == basepath+'images/insp_newclassic.jpg' || 
			document.getElementById('fotogroot').src == basepath2+'images/insp_newclassic.jpg')
		{ lightbox('insp_engelsecottage'); }
	else if(document.getElementById('fotogroot').src == basepath+'images/insp_engelsecottage.jpg' || 
			document.getElementById('fotogroot').src == basepath2+'images/insp_engelsecottage.jpg')
		{ lightbox('insp_franslandhuis'); }
	}
*/

// FOTONAVIGATIE MET PIJLTJESTOETSEN
$(document).keydown(function(e){
	if ( $('#lightboxbg').is(':visible')){
	    if (e.keyCode == 37) { // 37 = LEFT
	       lightboxprev();
	       return false;
		}
	    if (e.keyCode == 39) { // 39 = RIGHT
	       lightboxnext();
	       return false;
		}
	    if (e.keyCode == 27) { // 27 = ESCAPE
		   $('#lightboxkaderrand, #lightboxbg').fadeOut("fast");	
	       return false;
		}
	}
});
