$(document).ready(function()
{

	var original_image = 'url(images/buttonTop.gif)';
	var open = false;
	var opened;	
	
	var lastnr;
	
	var colors = new Array();
	colors[0] = "ccdc01";
	colors[1] = "cc131b";
	colors[2] = "019a3e";
	colors[3] = "ef8201";
	colors[4] = "801499";
	colors[5] = "3388bc";
	
	var randomnr = Math.round(Math.random() * colors.length);
	
	var links = new Array();
	links[0] = "<a href =\"http://www.josgifts.nl\" target=\"_blank\">www.josgifts.nl</a>";
	links[1] = "<a href =\"http://www.josbv.com/megadiscount\" target=\"_blank\">www.josbv.com/megadiscount</a>";
	links[2] = "<a href =\"http://www.josbv.com/tim\" target=\"_blank\">www.josbv.com/tim</a>";
	links[3] = "<a href =\"http://www.chapeaukado.nl\" target=\"_blank\">www.chapeaukado.nl</a>";
	links[4] = "<a href =\"http://www.smartstoxx.nl\" target=\"_blank\">www.smartstoxx.nl</a>";
	links[5] = "<a href =\"http://www.josbv.com/catalogus\" target=\"_blank\">www.josbv.com/catalogus</a>";
	
	var descriptions = new Array();
	descriptions[0] = "Snel, gemakkelijk en online relatiegeschenk bestellen";
	descriptions[1] = "Relatiegeschenken voor bodemprijzen OP=OP";
	descriptions[2] = "Maatschappelijk verantwoorde relatiegeschenken";
	descriptions[3] = "Cadeaus kiezen omdat smaken verschillen";
	descriptions[4] = "Het systeem voor św relatiegeschenken";
	descriptions[5] = "Zoek een product en vraag direct een offerte aan";

	var logos = new Array();
	logos[0] = "josgifts.png";
	logos[1] = "megadiscount.png";
	logos[2] = "tim.png";
	logos[3] = "chapeau.png";
	logos[4] = "smartstoxx.png";
	logos[5] = "jos_zoekt.png";
			
	$("#buttonTop1").hover(function()
	{
		fillText(0);
		clearInterval( interval );
	});
	
	$("#buttonTop2").hover(function()
	{
		fillText(1);
		clearInterval( interval );
	});	
	
	$("#buttonTop3").hover(function()
	{
		fillText(2);
		clearInterval( interval );
	});

	$("#buttonTop4").hover(function()
	{
		fillText(3);
		clearInterval( interval );
	});
	
	$("#buttonTop5").hover(function()
	{
		fillText(4);
		clearInterval( interval );
	});	
	
	$("#buttonTop6").hover(function()
	{
		fillText(5);
		clearInterval( interval );
	});

	fillText(randomnr);
	var interval = setInterval(function(){ doCycle(); }, 4000);
	
	function doCycle()
	{
	
		if(randomnr < logos.length-1)
		{
		
			randomnr++;
			fillText(randomnr);
		
		}
		else
		{
		
			randomnr = 0;
			fillText(randomnr);
		
		}
		
	}	
	
	function fillText(nr)
	{
		$("#topmenu h1").html(descriptions[nr]);
		document.getElementById("description").style.color = "#"+colors[nr];
		$("#topmenu p").html(links[nr]);
		document.images("topmenuimg").src = "images/"+logos[nr];
		document.getElementById("borderLeftTopMenu").style.backgroundColor = "#"+colors[nr];
		document.getElementById("borderRightTopMenu").style.backgroundColor = "#"+colors[nr];
		document.getElementById("borderBottomTopMenu").style.backgroundColor = "#"+colors[nr];
		
		document.images("borderBottomRightTopMenuImg").src = "images/cornerBottomRight_"+colors[nr]+".gif";
		document.images("borderBottomLeftTopMenuImg").src = "images/cornerBottomLeft_"+colors[nr]+".gif";
	}
	
	var leftmenu = false;
	var rightmenu = false;
	
	$("#slideleftbutton,#leftclosebutton").click(function()
	{
		$("#slideleftfield").animate({width: 'toggle'},300, function()
		{
			if(!leftmenu)
			{				
				leftmenu = true;
				document.getElementById("overlay").style.display = "block";	
			}
			else
			{
				leftmenu = false;
				if(!rightmenu)
				{
					document.getElementById("overlay").style.display = "none";	
				}
			}
		})
	});
	
	$("#sliderightbutton,#rightclosebutton,#contactlink").click(function()
	{
		if(!rightmenu)
		{				
			document.getElementById("sliderightmenu").style.width = "300px";
			$("#sliderightfield").animate({width: 'toggle'},300, function()
			{
				document.getElementById("overlay").style.display = "block";
				rightmenu = true;
			})
		}
		else
		{
			$("#sliderightfield").animate({width: 'toggle'},300, function()
			{
				document.getElementById("sliderightmenu").style.width = "30px";
				rightmenu = false;
				if(!leftmenu)
				{	
					document.getElementById("overlay").style.display = "none";
				}	
			})		
		}	
	});
	
	$("#overlay").click(function()
	{
		if(leftmenu)
		{
			$("#slideleftfield").animate({width: 'toggle'},300, function()
			{
				leftmenu = false;
			})
		}
		if(rightmenu)
		{
			$("#sliderightfield").animate({width: 'toggle'},300, function()
			{
				document.getElementById("sliderightmenu").style.width = "30px";
				rightmenu = false;
			})			
		}
		document.getElementById("overlay").style.display = "none";	
	});
	
});	
