
$(document).ready(function(){
	
	$.preloadCssImages();
	
	Galleria.loadTheme('galleria_classic/galleria.classic.js');

  // eerste item van elke pagina openen
  $("#content_weddings .content_container:first").show();
  $("#content_studio .content_container:first").show();
  $("#content_events .content_container:first").show();
  
});

/************** CODE VOOR TOGGLE OP CONTENT PAGINA's ***************/

$(function(){
	$(".content_title")
		.mouseover(function(){
							$(this).addClass('togglehover');
							})
		.mouseout(function(){
						  $(this).removeClass('togglehover');
						  })
    .click(function(e){
					    expandOrCollapse($(this));
					    if ($(this).next().text() == "") {
					      //alert("opvullen")
						    $(this).next().load("dynamicContent.php?contentid="+e.target.id.substr(3));
						  }
		          })
});


$('.toggle_collapse').live("mouseover", function(){
   	$(this).addClass('togglehover');
});		   
$('.toggle_collapse').live("mouseout", function(){
   	$(this).removeClass('togglehover');
});
$('.toggle_collapse').live("click", function(e){	
    expandOrCollapse($(this).parent().prev());	  
});	

function expandOrCollapse(titleElement, onlyExpand) {
  if (onlyExpand === undefined)
    onlyExpand=false;
  
  // open of toeklappen van container element
  if (onlyExpand)
    titleElement.next().slideDown("fast");
  else
    titleElement.next().slideToggle("fast");
    
  // achtergrond van title element aanpassen
	if (titleElement.hasClass("contenttitle_toggleup") && !onlyExpand) {
		titleElement.removeClass("contenttitle_toggleup");
		titleElement.addClass("contenttitle_toggledown");
	} else {
		titleElement.removeClass("contenttitle_toggledown");
		titleElement.addClass("contenttitle_toggleup");
	}  
   
}
/**************** MENU *****************/

$.address.externalChange(function(e)
{
	//alert("EXTERNAL: "+e.value);
	if (e.value.indexOf('#',0) == -1)
	{ 
	  if (e.value=='/' || e.value=='')
		  switchToPage('home');
	  else
		  switchToPage(e.value);
	}
});

$.address.internalChange(function(e)
{
	//alert("INTERNAL: "+e.value);
	switchToPage(e.value);
	
});

/*  REGELEN VAN HOVER & ONCLICK BIJ MENU KNOPPEN */
$(function(){
	$('#menulist li')
		.mouseover(function(){
							$(this).addClass('hover');
							})
		.mouseout(function(){
						   $(this).removeClass('hover');
							})
	  .click(function(e){  
						//alert(e.target.id);
						$.address.value(e.target.id.substr(8));		
						})
});

function switchToPage(pageName) {
		var panelName='', previousPage='';
		pageName = pageName.replace("/","");
		
		if (pageName.length > 3) {

			pageVariables = '';
			if (pageName.length > 6 && pageName.substr(0,10) == 'albums.php')
			{
				pageVariables = pageName.substr(10); 
				pageName = pageName.substr(0,6); // we laten de .php vallen
			} 

			// kijken of we een specifiek panel moeten openklappen
			if (pageName.indexOf("@") > -1)
			{
			  panelName = pageName.substr(pageName.indexOf("@")+1);
			  pageName = pageName.substr(0,pageName.indexOf("@"));
			}
      
      if ($('#menulist > li').hasClass('active'))
        previousPage = $('#menulist > li.active').attr("id").substr(8);
      else
        previousPage = '';
        
 			$('#menulist > li.active').removeClass('active');
    	$('#menubtn_'+pageName).addClass('active');			
			
			// enkel indien een andere pagina dan gaan we van panel veranderen
//			alert(pageName);
      if (pageName != previousPage)
      {
  			// nu hiden we alle panels
  			$('#inner_content > div').css('display', 'none');
      
  			// nu het juiste panel gaan activeren
  			$('#inner_content > div[id=content_'+pageName+']').fadeIn('slow');		
      }
    	
      // specifieke actie indien albums: laden van indhoud op basis van evt parameters			
			if (pageName == 'albums')
			{
				$('#content_'+pageName).load(pageName+'.php'+pageVariables);
			} 
    	
			// specifieke togglecontent gaan uitklappen indien parameter meegegeven via @
			/*if (panelName!="")
			{
 			  expandOrCollapse($('#ct_'+panelName), true);
 			  self.scrollTo($('#ct_'+panelName).offset().left, $('#ct_'+panelName).offset().top);
		  }*/
		}
}

/******************* ALBUMS ******************/
		   
$('#content_albums li.album').live("mouseover", function(){
   	$(this).stop().animate({ backgroundColor: "#666666" }, 200);
});		   
$('#content_albums li.album').live("mouseout", function(){
   	$(this).stop().animate({ backgroundColor: "#444444" }, 200);
});	
$('#content_albums li.album').live("click", function(e){
	$.address.value('albums.php?clickedItem='+e.target.id);			
});	
$('#content_albums #breadcrumb span').live("click", function(e){
	//alert(e.target.id);
	$.address.value('albums.php?clickedItem='+e.target.id);			
});	
$('#gallery li').live("mouseover", function(){
   	$(this).addClass('hover');
});		   
$('#gallery li').live("mouseout", function(){
   	$(this).removeClass('hover');
});	
$('#gallery li img').live("click", function(){
	$('#selectedpic').attr('src',$(this).attr('src'));
  	$('#gallery li').removeClass("selected");
  	$(this).parent().addClass("selected");
});	
$('#selectedpic').live("click", function() {
//	$('#gallery li img.selected').parent().next().children().click();
	alert($(this).css());
});

$(".scroll").live("click", function(event){
	//prevent the default action for the click event
	event.preventDefault();

	//get the full url - like mysitecom/index.htm#home
	var full_url = this.href;

	//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
	var parts = full_url.split("#");
	var trgt = parts[1];

	//get the top offset of the target anchor
	var target_offset = $("#"+trgt).offset();
	var target_top = target_offset.top;

	//goto that anchor by setting the body scroll top to anchor top
	$('html, body').animate({scrollTop:target_top}, 500);
	
	expandOrCollapse($('#'+trgt), true);
});


