(function($){
	
	$.extend( $.easing,	{
		easeYuma: function (x, t, b, c, d) {
			if ((t/=d/2) < 1) return c/2*t*t*t + b;
			return c/2*((t-=2)*t*t + 2) + b;	
		}
	})
	
	$.fn.yuma = function(options) {  

		var settings = {'slidespeed':400,'dropspeed':400,'width':960,'start':0, 'autoslide':4};

		return this.each(function() {
			if (options) { 
				$.extend( settings, options );
			}
			
			var sliderContainer=$(this).find('#slidercontainer');
			var imgCount=sliderContainer.find('.sliderpic').length;
			var sliderLeft=$(this).find('#sliderleft');
			var sliderRight=$(this).find('#sliderright');
			var currentId=0;
			var timer=null;
			
			sliderContainer.css('width', settings.width*imgCount+'px');
			
			function setSlider() {
				sliderLeft.css('display',(currentId==0)?'none':'block');
				sliderRight.css('display',(currentId==imgCount-1)?'none':'block');
			}
			
			function scrollRight() {
				if (currentId<imgCount-1) {
					currentId++;
					scrollContainer();
				}
				return false;
			}

			function scrollLeft() {
				if (currentId>0) {
					currentId--;
					scrollContainer();
				}
				return false;
			}

			function advanceSlide() {
				currentId++;
				if (currentId>imgCount-1) {
					currentId=0;
				} 
				scrollContainer();
			}
			
			function scrollContainer() {
				sliderContainer.animate({'left':-settings.width*currentId},{'duration':settings.slidespeed, 'easing':'easeYuma'});
				setSlider();
			}
			
			function setContainer() {
				sliderContainer.css({'left':-settings.width*currentId});
				setSlider();
			}
			
			function startTimer() {
				if (timer == null) {
					if (settings.autoslide > 0) {
						timer = window.setInterval(advanceSlide, settings.autoslide*1000);
					}
				}				
			}
			
			function stopTimer() {
				if (timer!=null) {
					window.clearInterval(timer);
					timer=null;
				}
			}
			
			
			currentId=settings.start;
			
			setContainer();
			setSlider();
			
			if (settings.menuOgg!='' & settings.menuMP3!="") {
				$('body').append("<audio class='menuaudio' preload='auto'><source src='"+settings.menuOgg+"' type='audio/ogg' /><source src='"+settings.menuMP3+"' type='audio/mpeg' /></audio>");
			}
			
			var menuAudio=$('.menuaudio');	
			
			$(window).load(function() {
				startTimer();			
				sliderRight.click(scrollRight);
				sliderLeft.click(scrollLeft);
				sliderRight.hover(stopTimer, startTimer);
				sliderLeft.hover(stopTimer, startTimer);
			})
			
			
			$(this).children('ul').hover(function() {
				if (menuAudio.length > 0) {
					try {
						if (!!(menuAudio.get(0).canPlayType)) {
							menuAudio.get(0).pause();
							menuAudio.get(0).currentTime = 0;
							menuAudio.get(0).play();
						}
					}
					catch (ex) {}
				}
				$(this).stop().animate({'height':'300px'},{'duration': settings.dropspeed, 'easing':'easeYuma'});
				stopTimer();
			}, function () {
				$(this).stop().animate({'height':'40px'},{'duration': settings.dropspeed, 'easing':'easeYuma'});
				startTimer();				
			});	
			
			$(this).children('ul').find('li').mouseover(function() {
				var currentIndex=$(this).index();
				var currentParent=$(this).parent();
				
				currentParent.find('li').each(function() {
					if ($(this).index()==currentIndex) {
						$(this).addClass('sel');
					} else {
						$(this).removeClass('sel');
					}
				})
			});
    	});
  	};
})(jQuery);
