var IMGpointer = 2;
var headerPointer = 1;
var headerTimer = setTimeout('volgendeHeader()', 5000);
var aanbevolenTimer = 0;
var advertentieIMGpointer = 1;
var tabLocked = 0;
var bannerPointer = 1;
var bannerTimer = setTimeout('volgendeBanner()', 5000);
	
$(document).ready(function() {
  // Logo plaatsen
	  var logoEU = '';
		logoEU += '<div id="site_logo"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="150" height="106">';
		logoEU += '<param name="movie" value="' + webadres + '/swf/logo.swf">';
		logoEU += '<param name=quality value=high>';
		logoEU += '<param name="allowScriptAccess" value="always" />';
		logoEU += '<param name="bgcolor" value="#ffffff" /><param name="SCALE" value="exactfit">';
		logoEU += '<embed bgcolor="#ffffff" src="' + webadres + '/swf/logo.swf" width="150" height="106" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" scale="exactfit"></embed>';
		logoEU += '</object></div>';
		logoEU += '<a href="http://www.europarcs.nl/" title="Europarcs" class="logoVak" style="display: none"></a>';
	
    $('.header .logoEU').html(logoEU);
 
  // Logo
	  $('.logoVak').show();
 
  // Topmenu
	  $('.topli').hover(function() {
		  if ($(this).find('.submenu').length > 0) {
  		  $(this).find('.submenu:hidden').slideDown('fast');
  			$(this).addClass('actiefTopLi');
  			$(this).addClass('openSubmenuLi');
			} else {
  			$(this).addClass('actiefTopLi');
			}
		}, function() {
		  $(this).find('.subsubmenu:visible').slideUp('fast');
		  $(this).find('.submenu:visible').slideUp('fast');
			$(this).removeClass('actiefTopLi');
			$(this).removeClass('openSubmenuLi');
		});
		
	  $('.subli').hover(function() {
      var aantal = $(this).find('.subsubmenu:hidden').length;

		  $(this).find('.subsubmenu:hidden').slideDown('fast');
			$(this).addClass('actiefSubLi');
		}, function() {
		  $(this).find('.subsubmenu:visible').slideUp('fast');
			$(this).removeClass('actiefSubLi');
		});
		
		$('.subsubmenu').hover(function() {
		
		}, function() {
		  $(this).slideUp('fast');
			$(this).removeClass('actiefSubLi');
		});
	
	// Zoekveld
	  $('.zoeken .textbox input').click(function() {
		  if ($(this).val() == 'Trefwoord..') { $(this).val(''); }
		});
		
	  $('.zoeken .textbox input').blur(function() {
		  if ($(this).val() == '') { $(this).val('Trefwoord..'); }
		});
	
	
	// Nieuwsbrief
	  $('.nieuwsbriefNaam input').click(function() {
		  if ($(this).val() == 'Uw naam') { $(this).val(''); }
		});
		
	  $('.nieuwsbriefNaam input').blur(function() {
		  if ($(this).val() == '') { $(this).val('Uw naam'); }
		});
		
	  $('.nieuwsbriefEmail input').click(function() {
		  if ($(this).val() == 'Uw e-mail adres') { $(this).val(''); }
		});
		
	  $('.nieuwsbriefEmail input').blur(function() {
		  if ($(this).val() == '') { $(this).val('Uw e-mail adres'); }
		});
		
  // Parkselectie
	  $('.parkSelectie').click(function() {
		  $(this).find('ul:hidden').slideDown('fast');
		});
		
		
		$('.parkSelectie ul').hover(function() {
		
		}, function() {
		  $(this).parent().find('ul:visible').slideUp('fast');
		});
		
		
	// Footer logo's in nieuw venster
	  $('.footer .logos a').click(function(e) {
		  e.preventDefault();
			window.open($(this).attr('href'));
		});
		
	// Lightbox
	  $('.fotoalbumAfbeelding').lightBox();
		
    $('.thumbnails a, .lightbox').lightBox();

    $('#ad_afbeelding_img').click(function () { $('.thumbnails').find('a:first').click();  });
		
		$('.vorigeIMG img').click(function() {
		   $('.volgendeIMG img').fadeIn();
			 
			 IMGpointer--;
			 
			 var src = $('.thumbnails').find('li:nth-child(' + IMGpointer + ')').find('a').attr('href');
			 var aantal = $('.thumbnails').find('li').length;
			 
			 $('#ad_afbeelding_img').attr('src', src);
			 
			 if (IMGpointer == 2) {
			   $(this).fadeOut();
			 }
		});		
		
		$('.volgendeIMG img').click(function() {
		   $('.vorigeIMG img').fadeIn();
			 
			 IMGpointer++;
			 
			 var src = $('.thumbnails').find('li:nth-child(' + IMGpointer + ')').find('a').attr('href');
			 var aantal = $('.thumbnails').find('li').length;
			 
			 $('#ad_afbeelding_img').attr('src', src);
			 
			 if (IMGpointer >= aantal - 1) {
			   $(this).fadeOut();
			 }
		});
  
	  $('.bottomFotos .vorigeBanner').click(function() {
		  bannerPointer--;
			
			if (bannerPointer < 1) {
			  bannerPointer = $('.bottomFotos .banners .banner').length;
			}
			
			weergeefBanner(bannerPointer);
		});
	
	  $('.bottomFotos .volgendeBanner').click(function() {
		  bannerPointer++;
			
			var aantal = $('.bottomFotos .banners .banner').length;
			
			if (bannerPointer > aantal) {
			  bannerPointer = 1;
			}
			
			weergeefBanner(bannerPointer);
		});	
	
  /* tabbladen */
    $('.tabNav a').click(function(e) {
      e.preventDefault();

      var klasse = $(this).attr('class');
      var mag = klasse.indexOf('actieveTab');

      if (tabLocked == 0 && mag == -1) {        
        $('.tabNav .actieveTab').removeClass('actieveTab');
        $(this).addClass('actieveTab');
        
        $('.tabContent .actieveTab:visible').slideUp('fast', function() {
          $(this).removeClass('actieveTab');
          $('.tabContent .' + klasse + ':hidden').slideDown('fast').addClass('actieveTab');
          tabLocked = 0;
        });
      
      }
    }); 
  
  /* advertentie foto slider */
    if ($('.advertentieFotos .directLijst li').length > 1) {
      setInterval('volgendeAdvertentieFoto()', 5000);
    }
    
    //Galleria.loadTheme('/jsf/galleria/src/themes/classic/galleria.classic.js');    
    
    /*
    $('.advertentieFotos').click(function() {
     var titel = $('.advertentieTitel').text();
     var data = '<div style="position: relative;top: 0; left: 0" class="gallerijOuter"><h1 class="gallerijTitel">' + titel + '</h1><div class="gallerijFotos" style="display: none; width: 660px; height: 600px;">';
     
     $('.advertentieFotosGallerij').find('img').each(function() {
       data += '<img src="' + $(this).attr('src') + '" />';
     });
     
     data += '</div></div>';    
     
      $.fancybox({
        content: data,
        autoDimensions: false,
        height: 620,
        width: 800,
        padding: 0,
        onComplete: function() {
          
          var gallery = new Galleria();
          gallery.init('.gallerijFotos');
          gallery.play(5000);
          $('.gallerijFotos').fadeIn('fast');
        }
      });
    });
    */
    
    $('.advertentieFotos .directLijst a').lightBox();
    
  $('#brochureKnop').click(function() {
    $(this).fadeOut('fast', function() {
      $('#brochureFormulier').html('<iframe src="/php/verwerk/vakantiebrochure.php" border="0" frameborder="0" allowtransparency="true"></iframe><a class="buttonSluiten"></a>').fadeIn();
      $('.buttonSluiten').click(function() {
        $('#brochureFormulier').fadeOut('fast', function() {
          $(this).html('');
          $('#brochureKnop').fadeIn('fast');
        });
      });
    });
  });
	
	if ($('.aanbevolenAdvertenties').length > 0) {
	  aanbevolenTimer = setInterval('aanbevolenNaarRechts(0)', 3000);
	}
	
	$(".pageFlip").hover(function() {
		$(".pageFlip img , .pageFlip .banner").stop()
			.animate({
				width: '307px', 
				height: '319px'
			}, 500); 
		} , function() {
		$(".pageFlip img").stop() 
			.animate({
				width: '60px', 
				height: '58px'
			}, 220);
		$(".pageFlip .banner").stop() 
			.animate({
				width: '50px', 
				height: '50px'
			}, 200);
	});

});


function volgendeAdvertentieFoto() {
  advertentieIMGpointer++;
  
  var aantal = $('.advertentieFotos .directLijst li').length;
  
  if (advertentieIMGpointer > aantal) { advertentieIMGpointer = 1; }

  var src = $('.advertentieFotos .directLijst li:visible').html();
  $('.advertentieFotos .bg').html(src);
  $('.advertentieFotos .directLijst li:visible').fadeOut('fast',  function() {
    $('.advertentieFotos .directLijst li:nth-child(' + advertentieIMGpointer + ')').fadeIn('fast');
  });
}

function actieveHeader(nr) {
  headerPointer = nr;
	
  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijst').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (nr - 1) + ')').addClass('actiefHeaderNummer');
	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (nr - 1) + ')').fadeIn('fast').addClass('actieveHeaderFoto');
	
	clearInterval(headerTimer);
  headerTimer = setInterval('volgendeHeader()', 5000);
}

function vorigeHeader() {
  headerPointer--;
	
	if (headerPointer < 1) {
	  headerPointer = $('.headerFoto').length;
	}
	
  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijst').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (headerPointer - 1) + ')').addClass('actiefHeaderNummer');	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (headerPointer - 1) + ')').fadeIn().addClass('actieveHeaderFoto');
	
	clearInterval(headerTimer);
  headerTimer = setTimeout('volgendeHeader()', 5000);
}

function volgendeHeader() {
  headerPointer++;
	
	if (headerPointer > $('.headerFoto').length) {
	  headerPointer = 1;
	}
	
  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijst').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (headerPointer - 1) + ')').addClass('actiefHeaderNummer');	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (headerPointer - 1) + ')').fadeIn().addClass('actieveHeaderFoto');
	
	clearInterval(headerTimer);
  headerTimer = setTimeout('volgendeHeader()', 5000);
}

function aanbevolenNaarRechts(handmatig) {
 if(handmatig) { clearInterval(aanbevolenTimer); }

 var links = $('.aanbevolenAdvertenties .advertentieGroepen').scrollLeft();
 var breed = $('.aanbevolenAdvertenties .advertentieGroepen .innerGroep').width();
 
 if (links + 625 >= breed) {
   $('.aanbevolenAdvertenties .advertentieGroepen').scrollTo( {top: 0, left:0}, 400 );
 } else {
   $('.aanbevolenAdvertenties .advertentieGroepen').scrollTo( {top: 0, left:'+=625px'}, 400 );
 }
}

function aanbevolenNaarLinks(handmatig) {
 if(handmatig) { clearInterval(aanbevolenTimer); }

 $('.aanbevolenAdvertenties .advertentieGroepen').scrollTo( {top: 0, left:'-=625px'}, 400 );
}

function volgendeBanner() {
  bannerPointer++;
	
	var aantal = $('.bottomFotos .banners .banner').length;
	
	if (bannerPointer > aantal) {
	  bannerPointer = 1;
	}
	
	weergeefBanner(bannerPointer);
}

function weergeefBanner(nr) {
  $('.banners .banner:visible').fadeOut('fast', function() {
    $('.banners .banner:nth-child(' + nr + ')').fadeIn();
    
    var titel = $('.banners .banner:nth-child(' + nr + ')').attr('title');
    
    $('.bottomFotos .kop').html(titel);
	});
	
	clearInterval(bannerTimer);
  bannerTimer = setTimeout('volgendeBanner()', 5000);	
}
