//Shadowbox.init({
//	players : ['img'],
//	language : 'nl'
	//skipSetup: true
//});

//Shadowbox.init();

window.addEvent('domready', function() {
	// open links in new window
	$$('a[rel=external]').set('target', '_blank');
	
	// set a random header background
	//$('header').setStyle('background-image', "url('/_images/header" + Math.floor(Math.random() * 4 + 1) + ".jpg')");

	//$('header').getElement('div.slide').fade('out');

	if (location.href.search(/winkels/) == -1 && $('content').getSize().y < 750) {
		$('content').setStyle('height', '750px');
    }

	//Shadowbox.setup();

	//$$('img[src*=_images/fotos]').each(function(img) {
	//	img.set('src', 'http://www.meesterbakker.nl' + img.get('src'));
	//});

	//$$('a[href*=_images/fotos]').each(function(a) {
	//	a.set('href', 'http://www.meesterbakker.nl' + a.get('href'));
	//});

  /*var heads = ['/_images/headers/1.jpg','/_images/headers/2.jpg','/_images/headers/3.jpg','/_images/headers/4.jpg','/_images/headers/5.jpg'];
  var myImages = new Asset.images(heads);
  myImages.each(function(img) {
    img.inject($('headslides'));
  });
  var mySlideShow = new mooSimpleSlide(myImages,{period:4000});*/

 
	//initSlideHeader();
});

window.addEvent('load', function() {

if (location.host != 'voskamp.meesterbakker.nl' && location.host != 'meesterbakker.online.lan') {

  var obj = new Swiff('/_images/flash/slideshow-endsample.swf', {
      id: 'headflash',
      width: 197,
      height: 111,
    params: {
          wmode: 'opaque',
          bgcolor: '#FFF'
      }
  }).inject($('headslides'));

} else {
  // tijdelijk andere header voor voskamp
  $('header').setStyle('background-image','url(/_images/header-voskamp.jpg)');
  $('hleft').setStyle('display','none');
}
});

var lastSlide = null;

var initSlideHeader = function() {
	var el = $('header').getElement('div.slide');

	if (!el) return;

	var slide = el.getElement('img');

	if (!slide) return;

	lastSlide = Math.floor(Math.random() * 4 + 1);

	slide.set('src', '/_images/headers/' + lastSlide + '.jpg');

	setTimeout('slideHeader()', 5000);
}

var getNewSlide = function() {
	var newSlide = Math.floor(Math.random() * 4 + 1);
	return newSlide !== lastSlide ? newSlide : getNewSlide();
}

var slideHeader = function() {
	var el = $('header').getElement('div.slide');

	var fadeIn, fadeOut = new Fx.Tween(el);

	fadeOut.onComplete = function() {
		lastSlide = getNewSlide();
		this.getElement('img').set('src', '/_images/headers/' + lastSlide + '.jpg');
		fadeIn = new Fx.Tween(this);
		fadeIn.onComplete = function() {
			setTimeout('slideHeader()', 5000);
		}
		fadeIn.start('opacity', '0', '1');
	}.bind(el)
	fadeOut.start('opacity', '1', '0');
}

//window.addEvent('load', function() {
	//Shadowbox.setup('a[rel=shadowbox]');
//});

var currentObj;

function swap(obj, state) {
  if (state != "") {
    if (state == 2) {
      obj.src = "/_images/" + obj.name + "_o.gif";
    } else if (state == 1) {
      obj.src = "/_images/" + obj.name + ".gif";
    }
    if (currentObj != null) {
      currentObj.src = "/_images/" + currentObj.name + "_o.gif";
    }
  }
}

// -----------------------------------------------------------------------------

var image = null;
 
function ShowFoto(etage, image) {
  var inner = "<img src=\"../_images/"+image+"\" id=\"overlayImg\" onclick=\"HideFoto();\" align=\"center\"/>";
  $("showfoto").innerHTML = inner;

  var divwidth    = $("overlayImg").width;
  var divheight   = $("overlayImg").height;
  var width       = document.body.clientWidth;
  var height      = document.body.clientHeight + document.body.scrollTop;
  var marginleft  = (width - divwidth) / 2;
  if (etage == 0) {
    var margintop   = 650; //(height - divheight) /2;
  } else if (etage == 1) {
    var margintop   = 1000;//(height - divheight) /2;
  }

  var bodywidth   = document.body.scrollWidth;
  var bodyheight  = document.body.scrollHeight;
 
  $("a_overlay").style.width  = bodywidth;
  if (height > bodyheight) {
    $("a_overlay").style.height = height;
  }
  else $("a_overlay").style.height = bodyheight;
 
  $("showfoto").style.width  = divwidth;
  $("showfoto").style.height = divheight;
  $("showfoto").style.top = margintop + (document.body.scrollTop / 2);
  $("showfoto").style.left = (width / 2) - 330; //marginleft;
  
  $("showfoto").style.display  = "block";
  $("a_overlay").style.display  = "block";
}
 
//------------------------------------------------------------------------------
function HideFoto() {
  $("showfoto").style.display  = "none";
  $("a_overlay").style.display  = "none";
}

// -----------------------------------------------------------------------------

<!--

/*function random_imghead() {
  var headerimage=new Array()
  //Headerplaatjes
  //headerimage[1]="/_images/header2.jpg"
  //headerimage[2]="/_images/header3.jpg"
  //headerimage[3]="/_images/header4.jpg"
  //headerimage[4]="/_images/header5.jpg"
  //headerimage[5]="/_images/header6.jpg"
   headerimage[1]="/_images/header.jpg"
   headerimage[2]="/_images/header2.jpg"
   headerimage[3]="/_images/header3.jpg"
   headerimage[4]="/_images/header4.jpg"
   headerimage[5]="/_images/header5.jpg"
   //headerimage[6]="/_images/header6.jpg"
   //headerimage[7]="/_images/header7.jpg"
   //headerimage[8]="/_images/header8.jpg"
   //headerimage[9]="/_images/header9.jpg"
 // headerimage[7]="/_images/header7.jpg"
 // headerimage[8]="/_images/header8.jpg"
  //headerimage[9]="/_images/header9.jpg"
 // headerimage[10]="/_images/header2.jpg"
 // headerimage[11]="/_images/header6.jpg"
 // headerimage[12]="/_images/header3.jpg"
 // headerimage[13]="/_images/header.jpg"
 // headerimage[14]="/_images/header8.jpg"
  //headerimage[15]="/_images/header7.jpg"
  //headerimage[16]="/_images/header4.jpg"

  //Linkerkolom
  //var productimage=new Array()
  //productimage[1]="/_images/pie.png"
 // productimage[2]="/_images/saucijzen.png"
 // productimage[3]="/_images/snijkoek.png"
  //productimage[4]="/_images/brood.png"
  //productimage[5]="/_images/taartje.png"
  //productimage[6]="/_images/witbr.png"
  //productimage[7]="/_images/broodje.png"
  //productimage[8]="/_images/brood.png"
  // productimage[9]="/_images/snijkoek.png"
 // productimage[10]="/_images/witbr.png"
 // productimage[11]="/_images/taartje.png"
  //productimage[12]="/_images/brood.png"
 // productimage[13]="/_images/pie.png"
 // productimage[14]="/_images/saucijzen.png"
 // productimage[15]="/_images/broodje.png"
 // productimage[16]="/_images/witbr.png"
  
  var ry = Math.floor(Math.random()*headerimage.length)

  if (ry == 0)
     ry=1
     document.write("<style>#header {background-image: url('"+headerimage[ry]+"');}</style>");
	 //document.write('<div class="decal"><img src="'+productimage[ry]+'" width="200" height="144"></div>');
	 }
*/

//-------------------------------------------------------------------------------------------//

var image = null;

function ShowFoto(image) {
  var divwidth    = 600;
  var divheight   = 470;
  var width       = document.body.clientWidth;
  var height      = document.body.clientHeight + document.body.scrollTop;
  var marginleft  = (width - divwidth) / 2;
  var margintop   = (height - divheight) /2;
  var bodywidth	  = document.body.scrollWidth;
  var bodyheight  = document.body.scrollHeight;

  $("a_overlay").style.width  = bodywidth;
  if (height > bodyheight) {
    $("a_overlay").style.height = height;
  }
  else $("a_overlay").style.height = bodyheight;

  $("showfoto").style.width  = divwidth;
  $("showfoto").style.height = divheight;
  $("showfoto").style.top    = margintop + (document.body.scrollTop / 2);
  $("showfoto").style.left   = marginleft;
  
  var inner = "<img src=\ "+image+"\ onclick=\"HideFoto();\" /><br /><span class=\"sluitfoto\">Klik op de foto om deze af te sluiten</span>"

  $("showfoto").innerHTML = inner;
  
  $("showfoto").style.display  = "block";
  $("a_overlay").style.display  = "block";
}

function HideFoto() {
  $("showfoto").style.display  = "none";
  $("a_overlay").style.display  = "none";
}

/*if (location.href.search(/winkels/) == -1) {
  window.addEvent('domready',function() {
    if ($('content').getSize().y < 600) {
      $('content').setStyle('height','600px');
    }
  });
}*/
//-->
