var duration = 5000;
var autoplay = true;
var width = 411;
var sliderbox;
var thumbnails = [];
var current = 0;
var number;
function initGallery()
{
	if(document.getElementById("gallery"))
	{
		number = $('#gallery li').length;
		sliderbox = $('#gallery');

		//create swicher
		$(this).text($("#thumbs").html("<ul>"));
		for(var i=0; i<number; i++)
		{
			$("#thumbs ul").append("<li><a></a></li>");
		}
		$("#thumbs ul li a")[0].className = 'active';


		thumbnails = $('#thumbs li a');
		$(thumbnails).each(function(el)
		{
			$(thumbnails)[el].href = 'javascript:;';
			$(thumbnails[el]).click(function()
			{
				autoplay = false;
				if(current!=el)
				{
					$(sliderbox).animate({"left": -el*width + "px"}, { duration: 400, queue:false });
					current=el;
					$(thumbnails).removeClass("active");
					$(this).addClass("active");
				}
			});
		});

		setTimeout('rotate()', duration);
	}
}
function rotate()
{
	if(autoplay)
	{
		if(++current>=number)
			current=0;
		$(thumbnails).removeClass("active");
		$(thumbnails[current]).addClass("active");
		$(sliderbox).animate({"left": -current*width + "px"}, { duration: 400, queue:false });
		setTimeout('rotate()', duration);
	}
}

function initInputs()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if ((inputs[i].type == "text" || inputs[i].type == "password") && (inputs[i].name == "brugernavn" || inputs[i].name == "password"))
		{
			inputs[i].onfocus = function ()
			{
				if (this.value == "Brugernavn" || this.value == "********")
					this.value = "";
			}
			inputs[i].onblur = function ()
			{
				if (this.value == "" && this.name == "brugernavn") this.value = "Brugernavn";
				if (this.value == "" && this.name == "password") this.value = "********";
			}
		}
	}
}
if (window.addEventListener)
{
	window.addEventListener("load", initInputs, false);
	window.addEventListener("load", initGallery, false);
}
else if (window.attachEvent)
{
	window.attachEvent("onload", initInputs);
	window.attachEvent("onload", initGallery);
}