var main = new function()
{
	var t = this;
    this.init = function()
    {
    	
    	
    	
    	// load external in new page
    	$("a[href^='http://']").addClass('external').attr('target', '_blank');
    	
    	//
    	$('#menu_background').cycle({
    		fx: 'fade',
    		timeout: 6000,
    		speed: 1500,
    		random: true
    	});
        $('#menu_background img').css('visibility', 'visible'); 
    	
    	// zoom overlay
    	$(".reference_photo a").click(function(){
    		
    		var title = $(this).parent('.reference_photo').siblings(".reference_left").find('h2').text();
    		var images = $(this).parent('.reference_photo').siblings(".reference_images").find('ul li img');
    		
    		
    		if (images.length > 0)
    		{
    			var index = 0;
    			$("#zoom").find('.zoom_content img').attr('src', images[0].src);
	    		
	    		$("#zoom a.zoom_prev").click(function()
				{
	        		if (index == 0) index = images.length;
	        		index--;
	        		$("#zoom").find('.zoom_content img').attr('src', images[index].src);
	        		
	        		//scale browser
				var wid = images[index].naturalWidth + 60;
	        		$("#zoom .zoom_container_sub").css('width', wid);
	        		$("#zoom .zoom_container").css('left', -wid/2);
	        		
	        		return false;
	        	});
	    		$("#zoom a.zoom_next").click(function()
				{
	    			index++;
	        		if (index >= images.length) index = 0;
	        		$("#zoom").find('.zoom_content img').attr('src', images[index].src);
	        		
	        		//scale browser
				var wid = images[index].naturalWidth + 60;
	        		$("#zoom .zoom_container_sub").css('width', wid);
	        		$("#zoom .zoom_container").css('left', -wid/2);
	        		return false;
	        	});
    		}
	    	var wid = images[0].naturalWidth + 60;
	        $("#zoom .zoom_container_sub").css('width', wid);
	        $("#zoom .zoom_container").css('left', -wid/2);

    		$("#zoom").find('.zoom_title').html("<strong>"+title+"</strong>");
    		$("#zoom").show();
    		$("#zoom a.zoom_close").click(function()
			{
        		$("#zoom").hide();
        		return false;
        	});
    		
    		return false;
    	});
    	// add key press events to zoom
		$("html").keydown(function(ev)
		{
			switch(ev.keyCode)
			{
				case 37: /*right*/ $("#zoom a.zoom_prev").click(); break;
				case 39: /*left*/ $("#zoom a.zoom_prev").click(); break;
				case 27: /*escape*/ $("#zoom a.zoom_close").click(); break;
			}
			
		}); 
    	/** Carousel **/
    	
    	$(".carousel .carousel_content").jCarouselLite(
    	{
		    btnNext: ".carousel .carousel_next",
		    btnPrev: ".carousel .carousel_prev",
		    visible: 3,
		    speed: 300
		});
    	
		$(".carousel li a").click(function()
		{
			var src = $(this).find('img').attr('src');
			
			var title = 'Vergroting';
    		var images = $(this).parents('ul').find('li img');
    		
    		if (images.length > 0)
    		{
    			var listItem = $(this).find('img');
    			var index = images.index(listItem);
    			
    			$("#zoom").find('.zoom_content img').attr('src', images[index].src);
	    		
	    		$("#zoom a.zoom_prev").click(function()
				{
	        		if (index == 0) index = images.length;
	        		index--;
	        		$("#zoom").find('.zoom_content img').attr('src', images[index].src);
	        		
	        		//scale browser
				var wid = images[index].naturalWidth + 60;
	        		$("#zoom .zoom_container_sub").css('width', wid);
	        		$("#zoom .zoom_container").css('left', -wid/2);
	        		return false;
	        	});
	    		$("#zoom a.zoom_next").click(function()
				{
	    			index++;
	        		if (index >= images.length) index = 0;
	        		$("#zoom").find('.zoom_content img').attr('src', images[index].src);
	        		
	        		//scale browser
				var wid = images[index].naturalWidth + 60;
	        		$("#zoom .zoom_container_sub").css('width', wid);
	        		$("#zoom .zoom_container").css('left', -wid/2);
	        		
	        		return false;
	        	});
    		}
	    	
    		$("#zoom").find('.zoom_title').html("<strong>"+title+"</strong>");
    		$("#zoom").show();
    		$("#zoom a.zoom_close").click(function()
			{
        		$("#zoom").hide();
        		return false;
        	});

			return false;
			
		});
		
		/*carousel_interval_sec = 4000;
		
		
		var carousel_interval = setInterval(function(){$(".carousel .carousel_next").click();}, carousel_interval_sec);
		$(".carousel_auto")
		.mouseout(function()
		{
			carousel_interval = setInterval(function(){$(".carousel .carousel_next").click();}, carousel_interval_sec);
		})
		.mouseover(function()
		{
			clearInterval(carousel_interval);
		});
		*/
    	
    	var height = $("#container_sub").height();
    	var heightMenu = $("#menu_container").height();
    	
    	if (height > heightMenu)
    	{
    		$("#menu_container #menu").height(height-12);
    		var top = height-196;
    		
    		$("#menu_container #menu_footer").css({'position': 'absolute', 'top': top});
    	}

    	
    }
    
    
    
    
}

$(document).ready(function()
{
	main.init();
});		

