jQuery(function(){
   jQuery("div.svw").prepend("<img src='svwloader.gif' class='ldrgif' alt='loading...'/ >");
});
var j = 0;
var quantofamo = 0;
jQuery.fn.slideView = function(settings) {
      settings = jQuery.extend({
     easeFunc: "easeInOutExpo",
     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("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);
        $("a.dark-more").after("<a class='next' href='#'>Next</a>");

        jQuery("a.next").bind("click", function(){

            //find the n position current image
             var id = jQuery("div#stripTransmitter" + j).find("a.current").attr("title");
             //alert(id);
             //alert("old current " + id);
            //move to n+1 position
            var dist;
            var new_id;
            if(id == 1){
                dist = -990;

                //new current will be 2
                new_id = 2;
             }
            if(id == 2){
                dist = -1980;

                //new current will be 3
                new_id = 3;
            }
            if(id == 3){
                dist = -2970;

                //new current will be 4
                new_id = 4;
            }
            if(id == 4){
                dist = -3960;

                //new current will be 5
                new_id = 5;

            }
            if(id == 5){
                dist = 0;

                //new current will be 1
                new_id = 1;
           }


            container.find("ul").animate({ left: dist}, settings.easeTime, settings.easeFunc);
            jQuery("div#gallery_wrapper").find("ul").animate({ left: dist}, settings.easeTime, settings.easeFunc);

            //remove the old current
            jQuery("div#stripTransmitter" + j).find("a.current").removeClass("current");
            //set the new current image by incrementing the id
            jQuery("div#stripTransmitter" + j).find("a[title='" + new_id + "']").addClass("current");
            id = jQuery("div#stripTransmitter" + j).find("a.current").attr("title");
            //alert("new current " + id);
            if(id == 1){
                //new current will be 2
                //change content
                document.getElementById('dark-box-header').innerHTML = "Commercial Solutions";
                document.getElementById('dark-box-content').innerHTML = "Klune Industries is supporting all major players in the Commercial Aerospace industry both in the US and overseas. These programs include Large Commercial Aircraft, Regional and Business Jets.";
                $("a.dark-more").attr("href",SITE_URL+"commercial");
            }
            if(id == 2){

                //new current will be 3

                //change content
                document.getElementById('dark-box-header').innerHTML = "One-Stop-Shop";
                document.getElementById('dark-box-content').innerHTML = "Klune Industries is continuously promoting the integration of its Metal Forming, Machining and Casting divisions in order to work as a one-stop-shop. We develop partnerships with key suppliers to offer services beyond our capabilities.";

                $("a.dark-more").attr("href",SITE_URL+"capabilities/one_stop");
    }
            if(id == 3){
                //new current will be 4

                //change content
                document.getElementById('dark-box-header').innerHTML = "30 Years of Experience";
                document.getElementById('dark-box-content').innerHTML = "Klune Industries was founded in 1972 in Southern California. Three decades later, through dedicated customer service, Klune Industries has become a preferred supplier to the aerospace and defense industry.";
                $("a.dark-more").attr("href",SITE_URL+"capabilities/experience");

            }
                    if(id == 4){

                        //new current will be 5

                        //change content
                        document.getElementById('dark-box-header').innerHTML = "A Safer World";
                        document.getElementById('dark-box-content').innerHTML = "Klune Industries is supporting a series of major military platforms for the US government. These programs include Missile Systems, Helicopters, Fighter Jets and Ground Support equipment.";
                        $("a.dark-more").attr("href",SITE_URL+"military");
                    }
                    if(id == 5){
                        //new current will be 1

                        //change content
                        document.getElementById('dark-box-header').innerHTML = "Our Core Competencies";
                        document.getElementById('dark-box-content').innerHTML = "Our wide range of equipment can accept any type of alloy including hard metals that are typically difficult to cast, form or machine. We master a series of patented processes to manufacture components within the tightest tolerances.";
                        $("a.dark-more").attr("href",SITE_URL+"capabilities");

                    }
            return true;
         });

        container.each(function(j) {
            //$("div.more-box").after("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><ul><\/ul><\/div>");


            $("a.next").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);
                container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);

                //find the n position current image
                var id = jQuery("div#stripTransmitter" + j).find("a.current").attr("title");
                 //alert(id);
                 if(id == 1){
                     //change content
                       document.getElementById('dark-box-header').innerHTML = "Commercial Solutions";
                       document.getElementById('dark-box-content').innerHTML = "Klune Industries is supporting all major players in the Commercial Aerospace industry both in the US and overseas. These programs include Large Commercial Aircraft, Regional and Business Jets.";
                       $("a.dark-more").attr("href",SITE_URL+"commercial");
                    }
                    if(id == 2){

                        //new current will be 3

                        //change content
                        document.getElementById('dark-box-header').innerHTML = "One-Stop-Shop";
                        document.getElementById('dark-box-content').innerHTML = "Klune Industries is continuously promoting the integration of its Metal Forming, Machining and Casting divisions in order to work as a one-stop-shop. We develop partnerships with key suppliers to offer services beyond our capabilities.";
                        $("a.dark-more").attr("href",SITE_URL+"capabilities/one_stop");
                }
                    if(id == 3){
                        //new current will be 4

                    //change content
                      document.getElementById('dark-box-header').innerHTML = "30 Years of Experience";
                      document.getElementById('dark-box-content').innerHTML = "Klune Industries was founded in 1972 in Southern California. Three decades later, through dedicated customer service, Klune Industries has become a preferred supplier to the aerospace and defense industry.";
                      $("a.dark-more").attr("href",SITE_URL+"capabilities/experience");
                }
                    if(id == 4){

                        //new current will be 5

                        //change content
                        document.getElementById('dark-box-header').innerHTML = "A Safer World";
                        document.getElementById('dark-box-content').innerHTML = "Klune Industries is supporting a series of major military platforms for the US government. These programs include Missile Systems, Helicopters, Fighter Jets and Ground Support equipment.";
                        $("a.dark-more").attr("href",SITE_URL+"military");
                    }
                    if(id == 5){
                        //new current will be 1

                        //change content
                        document.getElementById('dark-box-header').innerHTML = "Our Core Competencies";
                        document.getElementById('dark-box-content').innerHTML = "Our wide range of equipment can accept any type of alloy including hard metals that are typically difficult to cast, form or machine. We master a series of patented processes to manufacture components within the tightest tolerances.";
                        $("a.dark-more").attr("href",SITE_URL+"capabilities");

                    }


                   });
                });


                // next image via image click    14/01/2009
                jQuery("div#stripTransmitter" + j + " a").parent().parent().parent().prev().find("img").each(function(z) {
                jQuery(this).bind("click", function(){


                    var ui     =     jQuery(this).parent().parent().parent().next().find("a");
                    if(z+1 < pictEls){
                        ui.eq(z+1).trigger("click");
                    }
                    else ui.eq(0).trigger("click");
                   });
                });



            jQuery("div#stripTransmitter" + j).css("width" , 83);
            jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
            if(settings.toolTip){
            container.next(".stripTransmitter ul").find("a").Tooltip({
                track: true,
                delay: 0,
                showURL: false,
                showBody: false
                });
            }
            });
        j++;

  });

};
