$(window).load(function(){
	//CUFON
	Cufon.replace('h1')('h2');
	Cufon.replace('#nav a, #subnav', { hover : true })
	Cufon.replace('a.newsItemsLink', {
		color: '#051b34'
	});	
   
   //HOME NEWS MASONRY
	$('#content.p_Home .mainContent').masonry({
		columnWidth: 4, 
		itemSelector: '.box'
	});
		
   if (navigator.appName != "Microsoft Internet Explorer" ) {
	   //NAVIGATION LAVALAMP
	   $('#nav ul').lavaLamp({
		   fx: "backout",
		   autoResize:true,
		   speed: 700
	   });
	   
	   //GALLERY
		$("#fotogallery a").gallery();
	
		var fade = '0.9';
	
		$('#fotogallery a').each(function(){
			$(this).hide();
			var img = $(this).delay(randNr()).fadeTo('slow',1);
		})
		
		//NEWSITEMS HOVER
		$('.btn_inner').hover(
			function() {
				Cufon.replace($(this).find('h1'), {
					color: '#CC9900'
				});
			},
			function() {
				Cufon.replace($(this).find('h1'), {
					color: '#051b34'
				});
			}
		);
		//HOME NEWS FADE
		$(function(){	
			$('.box').each(	function(){
				var time = 200;
				$(this).hide().delay($(this).index() * time).fadeTo('slow',1);
			});
		});		
   }
});

function randNr(){

    var numLow = 0;
    var numHigh = 10;

    var adjustedHigh = ( parseFloat(numHigh) - parseFloat(numLow) ) + 1;
    var numRand = Math.floor( Math.random() * adjustedHigh ) + parseFloat(numLow);

    return numRand * 100;

}

$.fn.gallery = function(){

    var fade = '1';
    var speed = '2000';

    $(this).each(function(){
        $(this).hide();
        var img = $(this).delay(randNr()).fadeTo(speed,1,function(){
            $(this).fadeTo(speed,fade);
        });
    })

    $(this).hover(function(){
            $(this).fadeTo('fast','0.5');
        },function(){
            $(this).fadeTo('slow',fade);
        }
    );

}

$(function(){
	//NAVIGATION DROPDOWN
	/*
	$('#nav li').hover(
		function () { $('ul', this).fadeIn(500);	}, 
		function () { $('ul', this).fadeOut(200); }
	);   
	*/
	
   //CYCLE ARTIKEL HOME
   $('#header_cycle').cycle({
       fx: 'fade',
       timeout: 4500,
       random: 1
   });
   //FANCYBOX
    $(".fancybox").fancybox();
   
   //FANCYBOX FLOORPLANNER
    $("a.fancyboxIframe").fancybox({
        'width'				: '90%',
        'height'			: '90%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'type'				: 'iframe'
    });
   
   //FANCYBOX PROJECTEN
   $("a.gallery").fancybox({
       	titlePosition : 'inside',
		titleFormat   : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-inside"><span class="floatRight" style="font-size: 10px; color: #333333;">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span><span class="flaotLeft">'+title+'</span></span>';
		}
   });

});
