/*
 * Requires jQuery and jQuery Easing Plugin.
 *
 */

jQuery.fn.alljoSlideShow = function(settings) {
  settings = jQuery.extend(
    {
      easeFunc: "easeInOutExpo", 
      easeTime: 600
    }, 
    settings
  );
  
  return this.each(function(){
    var alljoSlideShowCurrentIndex = 0;
    
    var container = jQuery(this);
    
    var slideWidth = container.children('ul').children('li').eq(0).width();
    var slideHeight = container.children('ul').children('li').eq(0).height();
    var numberOfSlides = container.children('ul').children('li').size();
    
    container.children('ul').css('width', slideWidth * numberOfSlides);
    container.children('ul').css('height', slideHeight);
    
    
    function moveTo(index) {
      // Move the slide
      var distance = - (slideWidth * index);
      container.children('ul').animate({ left: distance}, settings.easeTime, settings.easeFunc);
      
      // handle displaying of current index
      jQuery('.alljo-slideshow-direct').removeClass('current-slide');
      jQuery('.alljo-slideshow-direct').filter('[rel*=' + index + ']').addClass('current-slide');
    }
    
    
    // initialise
    moveTo(alljoSlideShowCurrentIndex);
    
    // add prev, next and direct links on click event
    // .alljo-slideshow-prev
    // .alljo-slideshow-next
    // .alljo-slideshow-direct rel => SlideNumber (SlideNumber starts at 0!!!)
    
    jQuery('.alljo-slideshow-prev').click(function() {
      if((alljoSlideShowCurrentIndex - 1) < 0) {
        alljoSlideShowCurrentIndex = (numberOfSlides + (alljoSlideShowCurrentIndex - 1)) % numberOfSlides;
      }
      else {
        alljoSlideShowCurrentIndex = (alljoSlideShowCurrentIndex - 1) % numberOfSlides
      }
      moveTo(alljoSlideShowCurrentIndex);
      return false;
    });
    
    jQuery('.alljo-slideshow-next').click(function() {
      alljoSlideShowCurrentIndex = (alljoSlideShowCurrentIndex + 1)  % numberOfSlides;
      moveTo(alljoSlideShowCurrentIndex);
      return false;
    });
    
    jQuery('.alljo-slideshow-direct').click(function() {
      alljoSlideShowCurrentIndex = parseInt(jQuery(this).attr('rel'));
      moveTo(alljoSlideShowCurrentIndex);
      return false;
    });
    
    
  });
  
  
}







var j = 0;
jQuery.fn.slideView = function(settings) {
	  settings = jQuery.extend({
     easeFunc: "easeInOutExpo", /* <-- easing function names changed in jquery.easing.1.2.js */
     easeTime: 750,
     toolTip: false
  }, settings);
	return this.each(function(){
		var container = jQuery(this);
		container.find("img.ldrgif").remove(); // removes the preloader gif
		container.removeClass("svw").addClass("stripViewer");		
		var pictWidth = container.find("li").find("img").width();
		var pictHeight = container.find("li").find("img").height();
		var pictEls = container.find("li").size();
		var stripViewerWidth = pictWidth*pictEls;
		container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL	
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		container.each(function(i) {
			jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + j + "'><ul><\/ul><\/div>");
			jQuery(this).find("li").each(function(n) {
						jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'>"+(n+1)+"<\/a><\/li>");												
				});
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){
				jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
				var cnt = - (pictWidth*z);
				jQuery(this).parent().parent().parent().prev().find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				return false;
				   });
				});
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			jQuery("div#stripTransmitter" + j + " a:eq(0)").addClass("current");
			if(settings.toolTip){
			container.next(".stripTransmitter ul").find("a").Tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: false
				});
			}
			});
		j++;
  });	
};