jQuery(function(){
    jQuery("div.svw").prepend("<img src='wp-content/themes/lifestyle_30/images/ajax-loader.gif' class='ldrgif' alt='loading...'/ >"); 
  });
var j = 0;
var quantofamo = 0;
jQuery.fn.slideView = function(settings) {
  settings = jQuery.extend({
      easeFunc: "easeInOutExpo",
      easeTime: 350,
      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("img").width();
      var pictHeight = container.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) {
          // Add navigation link div and empty list
          jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");


          // Add list items
          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>");												
            });


          // Add prev and next links
          jQuery(".prev_arrow").html('<a id="stripPrev'+j+'" title="Previous Image" href="#"><img class="next_arrow_img"  src="wp-content/themes/lifestyle_30/images/prev_arrow.png" width="10" height="20" alt="" border="0" /><div>PREV<br />POST</div></a>');
          jQuery(".next_arrow").html('<a id="stripNext'+j+'" title="Next Image" href="#"><img src="wp-content/themes/lifestyle_30/images/next_arrow.png" width="10" height="20" alt="" border="0" /><div>NEXT<br />POST</div></a>');		  
		  //container.parent().before('<a id="stripPrev'+j+'" title="Prev" href="#">Prev</a>');
          //container.parent().after('<a id="stripNext'+j+'" title="Next" href="#">Next</a>');
 
          
          // Add containers for the date, title and description

		  jQuery(".stripTransmitter ul").before('<div class="gallery_info">' + 
												'<span class="gallery_date" id="stripDate'+j+'"></span>' + 
												'<span class="gallery_divider">&nbsp;|&nbsp</span>' + 
												'<span class="gallery_title" id="stripTitle'+j+'"></span><br />' + 
												'<span class="gallery_desc" id="stripDescription'+j+'"></span>' + 
												'</div>');




          // Bind transmitter list item links
          jQuery("div#stripTransmitter" + j + " ul a").each(function(z) {
              // Main image change function
              jQuery(this).bind("click", function(){
                  // Change the image
                  jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
                  var cnt = -(pictWidth*z);
                  container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);



                  // Change the visibility of the prev and next arrows
                  var j = jQuery(this).parent().parent().parent().attr('id').replace(/stripTransmitter/, '');
                  var prev = jQuery("#stripPrev"+j);
                  var next = jQuery("#stripNext"+j)
                  if(jQuery("#stripTransmitter"+j+" ul a:first").hasClass("current")) {
                    // We're on the first image, so hide prev and show next
                    prev.hide();
                    next.show();
                  } else if(jQuery("#stripTransmitter"+j+" ul a:last").hasClass("current")) {
                    // We're on the last image, so show prev and hide next
                    prev.show();
                    next.hide();
                  } else {
                    // We're on a middle image, so show both prev and next
                    prev.show();
                    next.show();
                  }

                  // Get info for text field change
                  var n = jQuery(this).html();
                  var data = container.find("ul li").eq(n-1);
                  var date = data.find(".date").html();
                  var title = data.find(".title").html();
                  var description = data.find(".description").html();
                  var j = jQuery(this).parent().parent().parent().attr('id').replace(/stripTransmitter/, '');

                  // Change date
                  jQuery("#stripDate"+j).fadeOut('fast', function() {
                      // Change text
                      jQuery(this).html(date);

                      // Fade back in
                      jQuery(this).fadeIn('fast');
                    });

                  // Change title
                  jQuery("#stripTitle"+j).fadeOut('fast', function() {
                      // Change text
                      jQuery(this).html(title);

                      // Fade back in
                      jQuery(this).fadeIn('fast');
                    });

                  // Change description
                  jQuery("#stripDescription"+j).fadeOut('fast', function() {
                      // Change text
                      jQuery(this).html(description);

                      // Fade back in
                      jQuery(this).fadeIn('fast');
                    });

                  return false;
                });
            });
          

          // Bind prev and next links
          jQuery("#stripPrev" + j).bind("click", function() {
              var j = jQuery(this).attr('id').replace(/stripPrev/, '');
              jQuery("#stripTransmitter" + j + " a.current").parent().prev().find("a").trigger("click");
            });
          jQuery("#stripNext" + j).bind("click", function() {
              var j = jQuery(this).attr('id').replace(/stripNext/, '');
              jQuery("#stripTransmitter" + j + " a.current").parent().next().find("a").trigger("click");
            });

          
		  // Bind next action to image click
          jQuery("div#stripTransmitter" + j + " ul a").parent().parent().parent().prev().find("img").each(function(z) {
              jQuery(this).bind("click", function() {
                  var ui = jQuery(this).parent().parent().parent().parent().parent().find(".stripTransmitter ul a");
                  if(z+1 < pictEls) {
                    ui.eq(z+1).trigger("click");
                  } else {
                    // un-comment the line below if you'd like the images to cycle back to the beginning when done
					//ui.eq(0).trigger("click");
                  }
                  return false;
                });
            });
          
          jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
          jQuery("div#stripTransmitter" + j + " ul a:first").trigger("click");
          
          if(settings.toolTip){
            container.next(".stripTransmitter ul").find("a").Tooltip({
                track: true,
                  delay: 0,
                  showURL: false,
                  showBody: false
                  });
          }
        });
      j++;
    });
};
