$(document).ready(function(){
		var color = getCookie('color');
		if (!color) {
			color = '#647f2a';
		}
		
		$('#logo img').css('backgroundColor',color);
	//	var x = logo();
		

		
		var timer = setInterval(function() {
			logo();
		}, 10000);
		
		function logo(){
			var cook = getCookie('color');
			//$('#main-menu').html(cook);
			
			var colors = new Array() 
			colors[0]='#647f2a'
			colors[1]='#d39e00'    
			colors[2]='#db6712'
			colors[3]='#cd071e'
			colors[4]='#d63276'
			colors[5]='#b73576'
			colors[6]='#934c80'
			colors[7]='#006e9c'
			colors[8]='#000000'
			;
			
			
			var randomindex=Math.floor(Math.random()*9);
			var currentbgcolor = $('#logo img').css('backgroundColor'); // get's RGB Color
			var bgcolor = currentbgcolor;


			bgcolor = bgcolor.replace('rgb(',''); // Removes part of the strings to make it comparable
			bgcolor = bgcolor.replace(')',''); 	  //
			bgcolor = bgcolor.replace(/ /g,'');   //
			bgcolor = bgcolor.replace(/,/g,'');	  // End of removing Strings

			var rgbcolor = '';
			var hexcolor = '';

			//Converts HexColors into RGB Colors to compare Background and Color to fade into
			for (var x = 0; x<=2; x++ ) {
				var hexcolor = '';
				for (var y = 1; y<=2; y++ ) {
					var index = 2*x+y;
					hexcolor = hexcolor+colors[randomindex];
				}
				rgbcolor += parseInt(hexcolor,16) ;
			} 

			delCookie ('color');
			setCookie('color',colors[randomindex],1);
			
			//Shots animation if current Background is different from the color in which the animation fades into 
			if (rgbcolor!=bgcolor) {
				$('#logo img').stop().animate( { backgroundColor: colors[randomindex] }, 6000);
			}
			
		}
		
		function getCookie(NameOfCookie)
		{ if (document.cookie.length > 0)
		{ begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{ begin += NameOfCookie.length+1;
		end = document.cookie.indexOf(";", begin);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(begin, end)); }
		}
		return null;
		}



		function setCookie(NameOfCookie, value, expiredays)
		{ var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		document.cookie = NameOfCookie + "=" + escape(value) +
		((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
		}



		function delCookie (NameOfCookie)
		{ if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}

		}
		
		
		
})
