var showFoto = true;


$(document).ready(function(){
	
	if ($.browser.msie == true){
		
		$("#content_col").width("690");
			
		
	}
	else{
		$("#content_col").width("680");
		$("#logo_footer").css("bottom","0px");
		$("#header_menu_bedrijven").css("bottom","24px");
		$("#header_menu_consumenten").css("bottom","24px");
	}
	
	


	
	//add active menu item
	var activeMenu = $(document.createElement("div"));
	var activeMenuLeft = $(document.createElement("div"));
	var activeMenuRight = $(document.createElement("div"));
	
	activeMenu.addClass("active_menu");
	activeMenu.width($(".menu1-level1-act").width()+20);
	
	activeMenuLeft.addClass("active_menu_left");
	activeMenuRight.addClass("active_menu_right");
	
	if($(".menu1-level1-act").position() != undefined){
		var left = $(".menu1-level1-act").position().left + $("#header_menu_sub").position().left - 10;
			
		activeMenu.css({"top":"105px","left":left+"px"})
	
	
	
		activeMenu.append(activeMenuLeft).append(activeMenuRight);
	
	
		$("#page").append(activeMenu)
	
	
	}
	
	
	$(".active_menu div").pngFix();
	
	
		if(showFoto ==true && $("#banner_image").length > 0){

		$("#banner_image").height(351);
		$("#banner").height(351);		
		loadGallery();
	}
	
	setContentHeight();
	

	
});

var galleryArray = [];
galleryArray[0] = {url:"1.jpg",loaded:false,id:0}
galleryArray[1] = {url:"2.jpg",loaded:false,id:1};
galleryArray[2] = {url:"3.jpg",loaded:false,id:2};
galleryArray[3] = {url:"4.jpg",loaded:false,id:3};
galleryArray[4] = {url:"5.jpg",loaded:false,id:4};
galleryArray[5] = {url:"6.jpg",loaded:false,id:5};
galleryArray[6] = {url:"7.jpg",loaded:false,id:6};
galleryArray[7] = {url:"8.jpg",loaded:false,id:7};
galleryArray[8] = {url:"9.jpg",loaded:false,id:8};
galleryArray[9] = {url:"10.jpg",loaded:false,id:9};
galleryArray[10] = {url:"11.jpg",loaded:false,id:10};
galleryArray[11] = {url:"12.jpg",loaded:false,id:11};
galleryArray[12] = {url:"13.jpg",loaded:false,id:12};
galleryArray[13] = {url:"14.jpg",loaded:false,id:13};

var galleryUrl = "fileadmin/templates/memoria/images/header/";
var curGalleryId = -1;

var startId = 0;

if($.cookie("curGalleryId") > 0){

	startId = $.cookie("curGalleryId");
}

var timer = null;

function loadGallery(){

	$(galleryArray).each(function(){
		
		var img = $(new Image());
		img.attr("src",galleryUrl + this.url);
		img.attr("img_id",this.id);
		img.attr("id","banner_image_"+this.id);
		img.load(function(){
			
			galleryArray[$(this).attr("img_id")].loaded = true;	
			
			if(curGalleryId == -1 && $(this).attr("img_id") == startId){
				
				curGalleryId = $(this).attr("img_id") - 1;
				
				$("#banner_image_" + startId).fadeIn(0,function(){
					
					$("#banner_image").css("background-image","none");
				});
				playGallery()
				
			}
		})
		
		
		$("#banner_image").append(img);
		
	});
	
	
}

function playGallery(){
	
	newId = curGalleryId + 1;
	cookieId = curGalleryId -1 ;
	$.cookie("curGalleryId",cookieId,{"path":"/"});

	
	if(newId >= galleryArray.length){
	
		newId = 0;
	}
	
	if(cookieId >= galleryArray.length){
	
		cookieId = 0;
	}
	
	if(galleryArray[newId].loaded == false){
	
		playGallery();
	}
	else{
		
		if(curGalleryId  != -1){
			
			
			$("#banner_image_"+curGalleryId ).fadeOut(2000);
		}
		
		$("#banner_image_"+newId).fadeIn(2000);
		
		$.cookie("curGalleryId",newId,{"path":"/"});

		
		timer = self.setTimeout("playGallery()", 10000)
	}


	curGalleryId = newId;
	

	//alert($.cookie("curGalleryId"));
	

}




$("#content_col1").onImagesLoad(setContentHeight);
$("#content_col2").onImagesLoad(setContentHeight);

function setContentHeight(){
	
	
	
	if($("#content_col1").height() < $("#content_col2").height()){
		
		$("#content_col1_content").height($("#content_col2").height());
	}
	else{
		
		$("#content_col2_content").height($("#content_col1").height());
	}
}

function setScale(scale){
	
	
	switch(scale){
		
		case "small":
			$("body").css("font-size","62.5%");
			$("#header_font_size a:link").css("text-decoration","none");
			$("#header_font_size_small a:link").css("text-decoration","underline");
			setContentHeight();
		break;	
		
		case "medium":
			$("body").css("font-size","72.5%");
			$("#header_font_size a:link").css("text-decoration","none");
			$("#header_font_size_medium a:link").css("text-decoration","underline");
			setContentHeight();
		break;	
		
		case "large":
			$("body").css("font-size","82.5%");
			$("#header_font_size a:link").css("text-decoration","none");
			$("#header_font_size_large a:link").css("text-decoration","underline");
			setContentHeight();
		break;	
	}
}
