//Putter knap ind i indkÃ¸bskurven
$("body").ready(function() {
    var url = String(document.location);
// $("body").append("<strong>"+url.substr(0,31)+"</strong>");
    if (url.substr(0,27) == "http://www.datamarked.dk/62" || url.substr(0,23) == "http://datamarked.dk/62" || url.substr(0,31) == "http://www.datamarked.dk/?id=62" || url.substr(0,27) == "http://datamarked.dk/?id=62") {
    	if ($("span.done").text() == "Indkøbskurv")
	        $('body').append('<div align="left" id="divSaveBasket"><a href="#" id="aSaveBasket" style="text-transform:uppercase;color: #8DC32D;font-weight:bold;font-size:10px;"><img border="0" src="/images/19920/save2.jpg" /> Gem indkøbskurv</a><span id="spanBasketSaved" style="text-transform:uppercase;color: #8DC32D;font-weight:bold;font-size:10px;"> - GEMT</span></div>');
        //$("#form1").append('<br />.');
        
        $('#spanBasketSaved').hide();
        $("#aSaveBasket").click(function(e) {e.preventDefault();$("#spanBasketSaved").fadeIn().delay(2000).fadeOut()});
        $("#divSaveBasket").appendTo($("#form1").parent());
    }
	$( "#searchword, .txtDummySearch" ).autocomplete({
			source: "/?id=897&ac",
			minLength: 2,
			select : function(event, ui) {
				var to = setTimeout("andSubmit()",500);
			}
		});
    $("#searchword").focus();
});
function andSubmit() { document.searchform1.submit(); }
$(document).ready( function(){ $('a.kompatibilitet').click(function() { if($("#spareparts_boks").is(":visible")) { $('#spareparts_boks').slideUp("fast"); }else{ $("#spareparts_boks").slideDown("fast"); } }); $("a.kompatibilitet").toggle(function() { $(this).text('Skjul kompatibilitet'); }, function() { $(this).text('Vis kompatibilitet'); }); });


s_ss(1, 3, 9999);
// usage: s_ss(first frame, end frame, delay time);

function s_ss(s_f, e_f, delay) {
 setTimeout(s_s(s_f,s_f,e_f, delay), delay);
}
function s_s(f, s_f, e_f, delay) {
 return (function() {
 $('#frontpage_trustpilot_slideshow' + f).fadeOut();
 if (f == e_f) { f = s_f; } else { f = f + 1; }
 setTimeout("$('#frontpage_trustpilot_slideshow" + f + "').fadeIn();", 600);
 setTimeout(s_s(f, s_f, e_f, delay), delay + 300);
 })
}

/* infinite caroussel - start */
$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () { 
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            
 
 
        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }
 
        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 
 
                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">«</a><a class="arrow forward">»</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
        $(this).bind('next', function () {
	  gotoPage(currentPage + 1);
	});
    });  
};


$("body").ready(function () {
  	var autoscrolling = true;

	$('.infiniteCarousel').infiniteCarousel().mouseover(function () {
	  autoscrolling = false;
	}).mouseout(function () {
	  autoscrolling = true;
	});

	setInterval(function () {
	  if (autoscrolling) {
	    $('.infiniteCarousel').trigger('next');
	  }
	}, 4000);
});


/* infinite caroussel - end */

  $(document).ready( function(){  
    $('a.spareparts_producenter').click(function() {
      if($("#spareparts_boks").is(":visible"))
      {
        $('#spareparts_boks').slideUp("fast");          
      }else{
        $("#spareparts_boks").slideDown("fast");
      }
    });
	
    $("a.spareparts_producenter").toggle(function() {
        $(this).text('Skjul andre producenter');
     }, function() {
        $(this).text('Vis andre producenter');
     });
  });


	// Frontpage Slider - Start //
		$(function(){
			$('#frontpage_slider_slides').slides({
				preload: true,
				preloadImage: 'http://www.datamarked.dk/images/24190/loading.gif',
				play: 5000,
				pause: 2500,
				hoverPause: true,
				animationStart: function(current){
					$('.frontpage_slider_caption').animate({
						bottom:-35
					},100);
					if (window.console && console.log) {
						// example return of current slide number
						console.log('animationStart on slide: ', current);
					};
				},
				animationComplete: function(current){
					$('.frontpage_slider_caption').animate({
						bottom:0
					},200);
					if (window.console && console.log) {
						// example return of current slide number
						console.log('animationComplete on slide: ', current);
					};
				},
				slidesLoaded: function() {
					$('.frontpage_slider_caption').animate({
						bottom:0
					},200);
				}
			});
		});
	// Frontpage Slider - End //
