


// Marks & Kattens js-scripts by Cocky Days / Jonas Lindeberg - orginal script by Remy Sharp //






/*

$(function () {

    if ($.browser.msie && $.browser.version < 9) return;

    $('#navigation li:not(.current-menu-item),li:not(current_page_parent)')
    .removeClass('menu-item')
    .find('a')
    .append('<span class="hover" />').each(function () {
    	var $span = $('> span.hover', this).css('opacity', 0);
    	$(this).hover(function () {
    		// on hover
    		$span.stop().fadeTo(250, 1);
    	}, function () {
    		// off hover
    		$span.stop().fadeTo(500, 0);
    	});
    });


});
*/












		
$.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. Set the local ID for each implementation on the page
        randID = Math.round(Math.random()*100000000);
        this.id = randID;
        var localID = this.id;
        
        function setBackPos(cp) {
        
        	for(i=1;i<=pages;i++)
			{
			$('#thumb_'+localID+'_'+i).css({'background-position':'top'});
			if(i==cp) $('#thumb_'+localID+'_'+i).css({'background-position':'bottom'});
			}
        }
		
		
		
		// 5. 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;

				setBackPos(currentPage);
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back" title="Go Back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        
        
        // 6. 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);
        });
        
        
        
        // 7. Create a public interface to move to a specific page
            
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });

		this.gotoPage = gotoPage       
        
        
        
        // 8. Build index viewer and index divs (Pagination)
		
		$wrapper.after('<div class="thumbfooter"><div id="thumbs'+randID+'" class="thumbholder"></div></div>');

		for(i=0;i<=pages-1;i++)
			{
				$('#thumbs'+randID).append('<a class="thumb" id="thumb_'+randID+'_'+(i+1)+'">'+(i+1)+'</a>');
				if(i==0) $('#thumb_'+randID+'_1').css({'background-position':'bottom'});
			}
        

		function thumbclick(event)
			{
				target_num = this.id.split('_');
				var ic = document.getElementById(target_num[1]);
				ic.gotoPage(parseInt(target_num[2]));
			};

			$('#thumbs'+randID+' a').bind('click', thumbclick);
		
		$(this).bind('next', function () {
  			gotoPage(currentPage + 1);
		});
		
    });  
};

$(document).ready(function () {

	
	$("ul#startimages a").hover(
		function() {
			$(this).animate({"opacity": "0.7"}, "fast");
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, "fast");
		});

	Cufon.replace('h1', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('h2', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('h3', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.breadcrumb', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.view-stickat-garner a', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.view-stickat-garner label', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.view-stickat-designer label', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.view-broderier label', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('ul#startimages span', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('div.contentbox-body div.view-nyheter div.views-field-title span', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('legend', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('span.introlegend', { fontFamily: 'Neutraface Slab Text' });
	Cufon.replace('a.viewsdisplaytabs-tab', { fontFamily: 'Neutraface Slab Text' });
	
	
	
	
	
	$(".tiphover").tipTip({delay:0, edgeOffset:-20, fadeIn:50, fadeOut:0});
	
  
	var autoscrolling = true;

	$('#widget-0 .view-content').infiniteCarousel().mouseover(function () {
		autoscrolling = false;
	}).mouseout(function () {
		autoscrolling = true;
	});
	
	$('#widget-0b .view-content').infiniteCarousel().mouseover(function () {
		autoscrolling = false;
	}).mouseout(function () {
		autoscrolling = true;
	});
	
	$('#widget-1 .view-content').infiniteCarousel().mouseover(function () {
		autoscrolling = false;
	}).mouseout(function () {
		autoscrolling = true;
	});
	
	$('#widget-2 .view-content').infiniteCarousel().mouseover(function () {
		autoscrolling = false;
	}).mouseout(function () {
		autoscrolling = true;
	});

	setInterval(function () {
		if (autoscrolling) {
			$('#widget-0 .view-content').trigger('next');
			$('#widget-0b .view-content').trigger('next');
    		$('#widget-1 .view-content').trigger('next');
    		$('#widget-2 .view-content').trigger('next');
    	}
	}, 6000);

	
	
	

	
	
});








