/*!
* slideViewer 1.2
* Examples and documentation at: 
* http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html
* 2007-2010 Gian Carlo Mingati
* Version: 1.2.1 (19-FEBRUARY-2010)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* 
* Requires:
* jQuery v1.4.1 or later, jquery.easing.1.2
* 
*/

var j = 0;
var quantofamo = 0;
var z1= 1;
var checkInterval;

jQuery.fn.slideView = function(settings) {
    settings = jQuery.extend({
        easeFunc: "easeInOutExpo",
        easeTime: 1000,
        toolTip: false,
        ttOpacity: 0.9
    }, settings);
    return this.each(function(){
        var container = jQuery(this);
        container.find("img.ldrgif").remove();
        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);
        container.css("width" , pictWidth);
        container.css("height" , pictHeight);
        // image number
        var imageNumber = container.find("img").length;
        container.each(function(i) {

            jQuery("div#stripTransmitter" + j + " a").each(function(z, obj) {
                jQuery(this).bind("click", function(){
                    clearInterval(checkInterval);
                    automate();
                    jQuery(this).addClass("current").parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
                    jQuery(this).addClass("current").parent().find("a").not(jQuery(this)).children("img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_off.png");
                    var cnt = -(pictWidth*z);
                    container.find("ul").animate(
                    { left: cnt}, 
                    {
                        duration: settings.easeTime, 
                        easing: settings.easeFunc, 
                        queue: false, 
                        complete: function(){
                            if (z >= imageNumber - 1) z1 = 0; else z1 = z + 1;
                        }
                    });

                    jQuery("a.current img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_on.png");
                    return false;

                    z1 = z + 1;
                });
            });

            automate();
            function automate() {
            checkInterval = setInterval(function()
            {
                // automatic
                var cnt = -(pictWidth*z1);
                jQuery(".stripTransmitter").addClass("current").parent().find("a").not(jQuery(this)).removeClass("current");
                jQuery(".stripTransmitter a:eq(" + z1 + ")").addClass("current").siblings("a").children("img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_off.png");
                jQuery("a.current img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_on.png");
                //jQuery("#stripTransmitter0 a[href='#" + z1 + "']").children("img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_on.png");
                container.find("ul").animate(
                { left: cnt}, 
                {
                    duration: settings.easeTime, 
                    easing: settings.easeFunc, 
                    queue: false, 
                    complete: function(){
                        if (z1 == jQuery("a.current").index())
                            if (++z1 > jQuery(this).children().length - 1) z1 = 0; 
                    }
                });

                //jQuery(".current img").attr("src", siteUrl + "/wp-content/themes/softbi/images/slide_on.png");

            },6000); 
            }

            // next image link
            jQuery("#slider_right a").bind("click", function(){
                if (jQuery("#stripTransmitter0 .current").next().html() == null) {
                    jQuery("#stripTransmitter0 a:first").trigger("click");
                } else {
                    jQuery("#stripTransmitter0 .current").next().trigger("click");
                }
                return false;
            });

            // previous image link
            jQuery("#slider_left a").bind("click", function(){
                if (jQuery("#stripTransmitter0 .current").prev().html() == null) {
                    jQuery("#stripTransmitter0 a:last").trigger("click");
                } else {
                    jQuery("#stripTransmitter0 .current").prev().trigger("click");
                }
                return false;
            });

            jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
            jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
            jQuery('body').append('<div class="tooltip" style="display:none;"><\/div>');

        });
        j++;
    });	
};

