var menuSubSubName = '';

$(document).ready(function () {
  $('#nav > li > a').click(function(){
    $('#nav li ul .active').removeClass('active');
    if ($(this).attr('class') != 'active'){
    	$('#nav li a,#nav li').removeClass('active');
      $('#nav li ul').slideUp();
      $(this).next().slideToggle(function(){updateHeights();update();});
      //$('#nav li a,#nav li').removeClass('active');
      $(this).addClass('active');
      
      // set logo
      setLogo($(this).parent().attr('color'));
    }
    //rotateBackground();
  });
  
  $('#nav li a').click(function(){
	  var li = $(this).parent();
	  // show content
      showContent(li.attr('page'));
      // change color?
      if (typeof li.attr('color') != undefined)
    	  $('#menu,#menu-spacer,#newsletter-send').attr('color',li.attr('color'));
  });
  
  // submenu click
  $('#nav ul li a').click(function(){
	  $('#nav li a,#nav li').removeClass('active');
	  // set anchor to active
	  // set parent anchor to active
	  $(this).parent().addClass('active')
	  			.parents('li').find('a').first().addClass('active');
	  //rotateBackground();
  });
  
  update();
  
  //setTimeout("showContent('fotogalerij_loungeclub')", 500);
});

function update()
{
	$('.content').css({minHeight:$('#menu-content').height()});
}

function showContent(id)
{
	// stop all gallery slideshows
	$('.play-stop[status=play]').click();
	
	var time = 500;
	var offset = $('#menu').width();
	//alert('show ' + id);
	
	if ($('.current').length > 0)
	{
		beforeHide();
		var width = $('.current').width();
		$('.current').animate({left:(offset-width)+'px'},time,function(){
			$('.current').removeClass('current');
			$('.content').hide();
			$('#'+id).show().addClass('current');
			updateHeights();
			beforeShow(id);
			$('#'+id).animate({left:offset+'px'},time,function(){afterShow(id)});
			if ($('#'+id).length==0) afterShow(id);
		});
	}
	else
	{
		$('#'+id).show().addClass('current');
		updateHeights();
		beforeShow(id);
		$('#'+id).animate({left:offset+'px'},time,function(){afterShow(id)});
		if ($('#'+id).length==0) afterShow(id);
	}
}

function beforeShow(page)
{
	//if (page=='fotogalerij_loungeclub')
	//	showGallery('Wallpapers','loungeclub-gallery');
	
	if (page=='clubcard') $('#clubcard-top').show();
	
	if (page=='fotogalerij_loungeclub') {
		if ($('#'+page+' .top-menu a').length > 0)
			$('#'+page+' .top-menu a').first().click();
		else
		{
			$('.controls,.slideshow,.image-options,.thumbs-container').hide();
			$('.album-info').html('Foto&#39;s zijn binnenkort beschikbaar.');
		}
	}
	if (page=='fotogalerij_hopkamer') {
		if ($('#'+page+' .top-menu a').length > 0)
			$('#'+page+' .top-menu a').first().click();
		else
		{
			$('.controls,.slideshow,.image-options,.thumbs-container').hide();
			$('.album-info').html('Foto&#39;s zijn binnenkort beschikbaar.');
		}
	}
	
	if (menuSubSubName != '')
		$('#menulink-'+menuSubSubName).click();
	
	menuSubSubName = '';
}
function afterShow(page)
{	
	/*if (gallery != null)
		gallery.gotoIndex(0);*/
	
	checkFacebookLikeFrame();
	
	update();
	
	rotateBackground();
	
	// load Google Maps or other external service
	var iframe = $('#'+page+' iframe');
	if (typeof iframe.attr('src') == 'undefined')
		iframe.attr('src', iframe.attr('src2'));
	iframe.show();
}
function beforeHide()
{
	$('#slideshow').html('');
}
