/*
 * jQuery JavaScript Library v1.3.2
 */
 $(document).ready(function(){
		
		$("#searchBox").focus(function() {
            
                $(this).val('');
            
	
        });

		// tæl .wide_frontpage lav controller til antal felter i elementet .slider_control
		
		var n = $(".wide_frontpage").children().size();
		var currentdot = 1;
		
		for(i=0; i<n; i++){
			add_dot(i);
		}
		
		
		var references = n+1;
		//var move_width = 700;
		var move_width = $(".wide_frontpage .large_container").width();
		var max_width = -1*(move_width*references);
		var timeonscreen = 6000;
		
		var autoslide = true;
		
		function autosliding(){
			if(autoslide == true){
				$(".dot_active").removeClass("dot_active").addClass("dot_inactive");			
				if(currentdot < n){
					currentdot++;
				}else{
					currentdot  = 1;
				}
				/*
	
				*/
				var element = $("#"+currentdot);
	
				$("#"+(currentdot-1)).removeClass("dot_inactive").addClass("dot_active");			
				var nextmargin = (currentdot-1)*move_width;
				slide_to_margin(-nextmargin);
				// slide to currentdot
				
			}
		}		

		var timer = window.setInterval(autosliding, timeonscreen);
		
		
		// add navigation dots
		
		function add_dot(int){
			if(int != 0){
				$(".slider_control").append('<a href="Home-1.aspx#next" class="dot_inactive dot" id="'+int+'">Dot</a>');	
			}else{
				$(".slider_control").append('<a href="Home-1.aspx#next" class="dot_active dot" id="'+int+'">Dot</a>');		
			}
		}
		
		$(".dot").click(function(){
			//			alert('activate: '+$(this).attr('id'));
			$(".dot_active").removeClass("dot_active").addClass("dot_inactive");			
			$(this).removeClass("dot_inactive").addClass("dot_active");			
			var nextmargin = parseInt($(this).attr('id'))*move_width;
			currentdot = parseInt($(this).attr('id'))+1;
			slide_to_margin(-nextmargin);
			window.clearInterval(timer);
			timer = window.setInterval(autosliding, timeonscreen);
	//		alert('currentdot: '+currentdot)
			return false;
		});
		
		function slide_to_margin(margin){
			//alert(margin)
			$('.wide_frontpage').stop().animate({"marginLeft": (margin) + "px"});			
		}
		
		
//		$(this).stop().animate(	{backgroundPosition:"(0 -250px)"}, {duration:500});
		$('#top_level_navigation a')
		.mouseover(function(){
			if($(this).attr('id') != 'activeitem'){
				if($(this).attr('class') == 'firstitem' || $(this).attr('class') == 'lastitem'){
					$(this).stop().animate({"backgroundPosition": "-113px -10px"},  'fast', 'swing');
				}else{

					$(this).stop().animate({"backgroundPosition": "0px -10px"}, 'fast', 'swing');			
				}
				
			}

			
		})
		.mouseout(function(){
			if($(this).attr('id') != 'activeitem'){
				// type
	
				if($(this).attr('class') == 'firstitem' || $(this).attr('class') == 'lastitem'){

						$(this).stop().animate({"backgroundPosition": "0px -10px"},  'fast', 'swing');							
				}else{

					$(this).stop().animate({"backgroundPosition": "-110px -10px"},  'fast', 'swing');			
				}
			}						   
			
		})
		
		
		
		
		/*
		
		
	
		
		function showNext(){
			if(currentposition - move_width > max_width+move_width){
				currentposition -= move_width;
			
			}else{
				currentposition = 0;
			}
			
//			$("#slideshow_holder").fadeOut("fast").animate({marginLeft: currentposition+"px"}).fadeIn("fast");
			$("#slideshow_holder").animate({marginLeft: currentposition+"px"});			
			
		}
		
		function showPrev(){
		//alert('currentposition: '+currentposition+' max_width: '+max_width)					
			if(currentposition +move_width > 0){
				currentposition = max_width+(2*move_width);
			}else{
				currentposition += move_width;
			}
			//$("#slideshow_holder").fadeOut("fast").animate({marginLeft: currentposition+"px"}).fadeIn("fast");
			$("#slideshow_holder").animate({marginLeft: currentposition+"px"});	
		}
		
		
		$("#next_reference").click(function()
  		{
			showNext();
			return false;

		});	
		*/

 });