
var $$ = $.fn;

$$.extend({


    SplitID: function () {
        return this.attr('id').split('-').pop();
    },

    Slideshow: {


        Ready: function () {

            var currentID;

            $('li.tmpSlideshowControl')
        .hover(
          function () {
              var id;

              if ($(this).attr('id').split('-').pop() != currentID) {

                  currentID = $(this).attr('id').split('-').pop();

                  id = $('img#tmpSlide-' + $(this).attr('id').split('-').pop());
                  $('img.tmpSlide').fadeOut('slow');
                  $('li.tmpSlideshowControl').removeClass('current').removeClass('active');
                  $(this).addClass('active');
                  //$(this).css('opacity', 0.8);
                  $(id).fadeIn('slow',
			function () {
			    $$.Slideshow.Counter = $(this).attr('id').split('-').pop();
			});

                  $(this).addClass('current');
                  //$(this).css('opacity', 1);

              } else {
                  //this.Interrupted = true; $$.Slideshow.Counter = $(this).attr('id').split('-').pop();
              }

              //  

          },
          function () {
              //if ($(this).attr('id').split('-').pop() != $$.Slideshow.Counter - 1) {
              $(this).removeClass('active');
              //	};
          }

        );
            this.Counter = 1;
            this.Interrupted = false;

            this.Transition();
        },

        Transition: function () {
            if (this.Interrupted) {
                return;
            }

            var total = $('.tabs').children("li").length;

            this.Last = this.Counter - 1;

            if (this.Last < 1) {
                this.Last = total;
            }
            /*
            $('img#tmpSlide-' + this.Last).fadeOut(
            'slow',
            function() {
            $('li#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('current').removeClass('active');
            $('li#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('current');
            $('img#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

            $$.Slideshow.Counter++;

            if ($$.Slideshow.Counter > 6) {
            $$.Slideshow.Counter = 1;
            }

            setTimeout('$$.Slideshow.Transition();', 5000);
            }
            );
            */
            $('img#tmpSlide-' + this.Last).fadeOut('slow');
            //$('img#tmpSlide-' + this.Last).fadeOut(0);
            //$('li#tmpSlideshowControl-' + $$.Slideshow.Last).css('opacity', 0.8);
            $('li#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('current').removeClass('active');
            $('li#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('current');
            $('img#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');
            //$('li#tmpSlideshowControl-' + $$.Slideshow.Counter).css('opacity', 1);
            $$.Slideshow.Counter++;

            if ($$.Slideshow.Counter > total) {
                $$.Slideshow.Counter = 1;
            }

            setTimeout('$$.Slideshow.Transition();', 7000);
        }
    }
});


function Tabs() {

    $('.tabs').each(function() {

        var slide = $(this);
        var total = slide.children("li").length;

        var o = new Tabs($(this), total);

    });

    function Tabs(e, total) {

        var o = {
            init: function () {
                o.ul = $(e);
                o.firstItem = $('li.first', o.ul);
                o.lastItem = $('li.last', o.ul);
                o.active = $('li.current', o.ul);
                o.items = $('li', o.ul);

                o.monitor();

            },
            monitor: function () {


                if (total == 4) {


                    var width = Math.floor(948 / total);
                    $(o.items).css('margin-left', '1px');
                    $(o.firstItem).css('margin-left', '0px');
                    //$(o.items).css('opacity', 0.8);
                    //$(o.active).css(' opacity', 0.8);

                    if ($.browser.msie) {

                        $(o.items).css('width', 233);
                        $(o.firstItem).css('width', 240);
                        $(o.lastItem).css('width', 241);

                    } else {
                        $(o.items).css('width', 233);
                        $(o.firstItem).css('width', 240);
                        $(o.lastItem).css('width', 241);
                    }

                } else {
                    if (total < 6) {

                        var width = Math.floor(945 / total);
                        $(o.items).css('width', width);
                        //$(o.items).css('opacity', 0.8);
                        //$(o.active).css(' opacity', 0.8);

                        $(o.firstItem).css('width', width + 3);


                    }



                }


                $(o.items).click(function () {
                    var href;
                    href = $('a', $(this)).attr('href');
                    window.location = href;

                });




            }



        };

        //call to initialize
        o.init();
        return o;

    };

}


 $(document).ready(
 
  function() {

 Tabs();
 
      $$.Slideshow.Ready();
  }
);


