/*
 * --------
 * @file 		dom.js
 * @version 	1.0.0
 * @date 		2010-09-01 11:39:29 +0200 (Wed, 1 Sep 2010)
 * @author 		Matthias Mertiens <mail@mertiens.biz>
 * --------
 * Copyright (c) 2010 mertiens. ideas for communication <http://mertiens.biz>
 */ 


$.fn.mouseoverscroll = function() { // -----------------------------------------------------------------

	
			return this.each(function() {
		    
		    //Get our elements for faster access and set overlay width
		    var div = $(this),
		    	ul = $('ul', this),
		    	ulPadding = 15;
		    
		    //Get menu width
		    var divWidth = div.width();
		
		    //Find last image container
		    lastLi = div.find('li:last-child');
			var anz = div.find('li').length;
			var ulWidth = /* lastLi[0].offsetLeft +  */ anz * lastLi.outerWidth() + ulPadding;

		    ul.css({ width: ulWidth });
			
			//alert(ulWidth);

		    //Remove scrollbars
		    div.css({overflow: 'hidden'});
		    
			var aktuellePos = 0;
		
		    //When user move mouse over menu

		    div.mousemove(function(e){
		    	
		    	//As images are loaded ul width increases,
		    	//so we recalculate it each time
		    	
		    	var posleft = (e.pageX - $(this).offset().left) * (ulWidth - divWidth) / divWidth - 15 - aktuellePos/2;
		    	$(this).scrollLeft(posleft);
		    	
		    	//ul.animate({ left: -ulWidth }, 0);
		    });

		    //div.mouseenter( function(e) { div.stop(); /* aktuellePos = $(this).scrollLeft() + e.pageX; */ } )/* .mouseleave(function() { autoscroll() } ) */;
		
			 
			 
			 function autoscroll() {
			 	if( div.scrollLeft() > 63 ) div.scrollLeft(0);
			 	div.animate({ 
        			scrollLeft : 63 // +ulWidth 
    				}, 2500, 'linear', function() {
    										var firstlist = $('li:first-child',div)
    										firstlist.klon = firstlist.clone();
    										firstlist.remove();
    										div.animate({ scrollLeft: 0 },0);
    										$('ul',div).append(firstlist.klon);
    										delete firstlist;
    										autoscroll();
    										
    										//firstlist.clone().prependTo('ul',div);
    										//firstlist.;
    									});
				

			    }
			
			
			//autoscroll();
			
			}); // return

} // END mouseoverscroll() ----







$(function() {

		$('li', 'menu').hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
			);

		$('.external_link').attr('target','_blank');



		$('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 3000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 900,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
            		pauseOnHover: false             // If true, and autoPlay is enabled, the show will pause on hover
               });

	
	

		$('#thumbnailcontainer').mouseoverscroll();


	
	
	
	
	
});

