	
	timeout_time=8000; // adjust the time between changing the background images, this should be larger than the fadeIn time
	x=0; // used to skip changing background when page first loads
	// random function
	function randomFunc(size){
		var arr = [];
		while(arr.length < size)
		{
			var randomnumber=Math.floor(Math.random()*size+1);
			var found=false;
			for(var i=0;i<arr.length;i++)
			{
				if(arr[i]==randomnumber){found=true;break}
			}
			if(!found){arr[arr.length]=randomnumber; }
		}
		return arr;
	}
	
	// create image
	function createImg (path,htmlHold){
		for(var i = 0; i < path.length; i++){
			var img = $(path[i]);
			if(i>0){
				img.attr('style', "display:none;");
			}else{
				img.attr('class','current');
				img.attr('style','display:inline');
			}
			img.appendTo(htmlHold);
		}
	}
	
	
	
	// change background images
	function change_image(){
		var img_length=$(".img-bg-container img").length;
		if(img_length > 1) {
		setTimeout("change_image()",timeout_time);
		}
		if(x>0){
			var t=$(".img-bg-container img.current").prevAll("img").length;
			if(t<img_length-1){
				$(".img-bg-container img").removeClass("current");
				$(".img-bg-container img:eq("+t+")").hide();
				$(".img-bg-container img:eq("+t+")").next().fadeIn(600);
				$(".img-bg-container img:eq("+t+")").next().addClass("current");
			}else{
				$(".img-bg-container img").removeClass("current");
				$(".img-bg-container img:eq("+t+")").hide();
				$(".img-bg-container img:eq(0)").fadeIn(600);
				$(".img-bg-container img:eq(0)").addClass("current");
			}
		}
		x++;
	}
	
	
$(document).ready(function(){
	(function(){	
		var zIndex = 10;
		$('#navigation > li:first').addClass('first');
		$('#navigation > li:last').addClass('last');
		$('#navigation > li > ul').each(function(){
			$(this).wrap('<div class="wrapper">')
			});
		$('#navigation > li').each(function(){
				$(this).children('a').wrapInner('<span/>');
				$(this).css('z-index', zIndex);
				zIndex = zIndex - 1;
			});
		$('#navigation > li').mouseover(function(){
					$(this).addClass('active');
				}).mouseleave(function(){
					$(this).removeClass('active');
				});
	})();	
	
	var imageLinks = new Array(); // array of background images
	$('.img-bg-container .image-list img').each(function(index) {
		var new_img='<img src="'+$(this).attr('src')+'" alt="'+$(this).attr('alt')+'" title="'+$(this).attr('title')+'" />';
		imageLinks.push(new_img);
	});
	var htmlHold = $('.img-bg-container .image-list'); // container for the background images
	$(htmlHold).empty();
	
	var imagesCount = 10; //nr of random images, should be equal to the length of imageLinks 
	var mathRandom = randomFunc(imageLinks.length);
	var pathImg = 	[];
	var imgIndex;
	
	
	for(var i = 0; i<imagesCount; i++){
		pathImg[i] = imageLinks[(mathRandom[i])-1];
	}
	createImg (pathImg,htmlHold);
	
	change_image();	
})

 // Random background images for inner page


