$(document).ready(function(){	
       
	// uitvoeren als pagina is geladen
	$(window).load(function() {
		mainHeight();
    });
	$(window).resize(function() {
		mainHeight();
    });

	
	mainmenu();
	$('#main').equalHeights(true);
	$('.equalHeightsParent').equalHeights(true);
	
	$('img').fixImageUrl();  
	
	$('.lightBox a').lightBox();
		
	$('#imageFade').innerfade({
		speed: 1600,
		timeout: 2000,
		type: 'random_start',
		containerheight: '190px'
	});

	$('#imageFade2').innerfade({
		speed: 1600,
		timeout: 2000,
		type: 'random_start',
		containerheight: '90px'
	});
		

	// uitvoeren als pagina is geladen
	$(window).load(function() {
		//$('#main').equalHeights(true);
		$('#imageFade').show();
		$('#imageFade2').show();
		$('#footer').equalHeights(true);
    });
	$(window).resize(function() {
		//$('#main').equalHeights(true);
    });
	
});

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights" (http://www.filamentgroup.com)
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
--------------------------------------------------------------------*/
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};
	
	
// Back to top link
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200,
		ieOffset: 50
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.css('display','none'); //in case the user forgot
		$(window).scroll(function() {
			//stupid IE hack
			//if(!jQuery.support.hrefNormalized) {
			//	el.css({
			//		'position': 'absolute',
			//		'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
			//	});
			//}
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};

	
function mainmenu(){
	$(" #nav ul ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
		$("#nav li a").removeAttr("title");
		//$("embed").hide();
		$(this).addClass("hover");
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(200);
	},function(){
		//$("embed").show();
		$(this).removeClass("hover");
		$(this).find('ul:first').css({visibility: "hidden"});
	});
}
 

	
$.fn.fixImageUrl = function(){   
	return this.each(function(){   
		var tag = $(this);   
		var src = tag.attr("src");
		var firstCharacter = src.substr(0,1);
	
		if (firstCharacter == "/"){
			$(this).hide();
			 this.src = 'http://www.digitalehuis.nl/' + src;
			 $(this).load(function(){
				 $(this).fadeIn();
			 })
          //  $('#loader').removeClass('loading').append(this);		
		}
		if (firstCharacter == "I"){
			$(this).hide();
			 this.src = 'http://www.digitalehuis.nl/' + src;
			 $(this).load(function(){
				 $(this).fadeIn();
			 })
		}
	});   
};   

// header - main - footer : container maximale hoogte (layout 100% hoog)
// header en footer moeten wel een vaste hoogte hebben in je stylesheet
mainHeight = function() {		

	var headerHeight	= $('#header').outerHeight({ margin: true });
	var mainHeight		= $('#main').outerHeight({ margin: true });
	var footerHeight	= $('#footer').outerHeight({ margin: true });

	var wrapperHeight		= $('#pageWrapper').height();
	var wrapperOuterHeight	= $('#pageWrapper').outerHeight({ margin: true });
	
	var wrapperMargins		= (wrapperOuterHeight-wrapperHeight);
//	alert(wrapperMargins)
	var windowHeight	= $(window).height();
//	alert(mainHeight)
	var newmainHeight = (windowHeight-headerHeight-footerHeight-80);
	
	
	if (newmainHeight>mainHeight) {
		$('#main').height(newmainHeight);
	};

};
	

	