$(document).ready(function() {
	//
	if(document.title == 'Trampolines van Kadee') $('#header').addClass('headertrampolines');
	if(document.title == 'Trampolines - Alegria') $('#header').addClass('headertrampolines');
	if(document.title == 'Sauna - Alegria') $('#header').addClass('headersauna');

	if($('#slideShow').size() > 0) runSlideShow();


	$('.lagen').hide();

	if($('#realisations img').size() > 0)
	{
		$('#currentIndex').html(6);
		$('#realisations img').each(function (e) {
			var url = $(this).attr('src');

			var img = $(this).clone();

			$(this).before('<a class="realisation" href="' + url + '" ><img src="' + url + '" /></a>');
			$(this).detach();
		});

		$('.realisation').lightBox({fixedNavigation:true});


		$('#realisations .realisation:gt(5)').hide();

		if($('#realisations .realisation').size() > 6)
		{
			$('#next').click(function(e) {
				e.preventDefault();
				browsePictures('next');
			});
			$('#prev').click(function(e) {
				e.preventDefault();
				browsePictures('prev');
			});

			$('#prev').hide();
		}
		else
		{
			$('#lesliens').hide();
		}
	}

});

//Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
// don't touch this
// to add more images, just continue
// the pattern, adding to the array below



// =======================================
// do not edit anything below this line
// =======================================

var Pic = new Array();

var t;
var j = 1;
var lengths = {aztec: 10, zodiac: 8};

function runSlideShow(){


	var name = $('#slideShow').attr('name');
	var p = parseInt($('#slideshowCount').html());
	console.log(p);

	//prepare source
	var src = '/frontend/files/userfiles/images/' + name + 'slide/' + name + 'slide0';
	if(j < 10) src += '0';
	src += j + '.jpg';

	//set src for image
   $('#slideShow').attr('src',  src);

   //j up
   j++;

   //loop
   if (j > (p-1)) j=1;

   //recurse
   t = setTimeout('runSlideShow()', slideShowSpeed)
}



function browsePictures(where)
{
	var current = parseInt($('#currentIndex').html());

	if(where == 'prev')
	{
		current -= 12;
	}


	var total = $('#realisations .realisation').size();
	var till = current + 6;
	$('#realisations .realisation').show();

	$('#realisations .realisation:gt(' + (till-1) + ')').hide();
	$('#realisations .realisation:lt(' + (current) + ')').hide();


	current += 6;

	$('#prev').show();
	$('#next').show();

	if(current <= 6)
	{
		$('#prev').hide();
	}
	if(current >= total - 1)
	{
		$('#next').hide();
	}

	$('#currentIndex').html(current);


}

function maakzichtbaar(laagnum){
	$('.lagen').hide();
	$('#laag' + laagnum).show();
}

//Popup qui se redimensionne à la taille de l'image ------------------------------------------------------------------
function popImage(img,title) {
	w=open("",'','width=400,height=400,toolbar=no,scrollbars=no,resizable=no,status=yes,location=no');
	w.document.write("<HTML><HEAD><TITLE>"+title+"</TITLE>");
	w.document.write("<SC"+"RIPT language=java"+"script> function checksize()  { if (document.images['img'].complete) {  window.resizeTo(document.images[0].width+6,document.images[0].height+65); window.focus();} else { setTimeout('checksize()',250) } } </"+"SCRIPT></HEAD>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 onBlur=self.close();><IMG src='"+img+"' border=0 name='img'>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

//ShowMe Open Browserwindow //

function showMe (what, where)
{
	open (what, "FullView", "left=20, Top=20, menubar=no," + where);
}
