/**
 * original by: Andre Mohren
 * modified by: Johannes Wüller
 */
//registering .htmlslideshow()
jQuery.fn.htmlslideshow = function(params) {

   //setting and overiding options
   var options = {'content': [], 'speed': 1000, 'time': 5000};
   jQuery.extend(options, params);
   //do nothing when there is no content
   if (options['content'].length == 0) {
      return;
   }

   //applying htmlslideshow to each matched element
   jQuery(this).each(function() {
      if (options['content'].length > 0) {
      //function for sliding an element
      var slideElement = function() {
         var element = htmlslideshow.find('span:first');
         element.clone().appendTo(htmlslideshow);
         //this is somehow extreme ugly, but ie dont want to do it else
         if (jQuery.browser.msie && jQuery.browser.version < 8) {
            jQuery('.slideshowPic').css({'margin-right': '1px'});
            element.css({
               'position': 'absolute',
               'left': '0px',
               'top': '0px'
            }).animate({
               'left': '-' + (element.width() + 1) + 'px'
            }, options['speed']).siblings().css({
               'left': element.width() + 1 + 'px'
            }).animate({
               'left': '0px'
            }, options['speed'], function() {
               element.remove();
            });
            if (jQuery.browser.version < 7 && typeof(animFix) == "undefined") {
               element.siblings().css({
                  'position': 'relative',
                  'display': 'block',
                  'float': 'left',
                  'left': '200px',
                  'top': '0px'
               });
            }
         } else {
            htmlslideshow.children('span').animate({
               'left': '-' + element.width() + 'px'
            }, options['speed'], function() {
               htmlslideshow.children('span').css({'left': '0px'});
               element.remove();
            });
         }
      };

      //our htmlslideshow container
      var htmlslideshow = jQuery('<div></div>').css({
         'overflow': 'hidden', 'position': 'relative', 'white-space': 'nowrap',
         'width': jQuery(this).parent().css('width')
      }).appendTo(this);

      //creating all contents and put them into the htmlslideshow
      for (var i = 0; i < options['content'].length; i++) {
         jQuery('<span>' + options['content'][i] + '</span>').appendTo(htmlslideshow);
      }
      
      //ie6 buggy damn thingy
      if (jQuery.browser.msie && jQuery.browser.version < 8) {
         jQuery(this).css({
            'overflow': 'hidden',
            'position': 'relative',
            'height': '250px',
            'width': jQuery(this).parent().width()
         });
         htmlslideshow.css({
            'height': '250px',
            'width': jQuery(this).parent().width() * 2
         });
         jQuery(this).find('.slideshowPic').css({
            'float': 'left',
            'display': 'block',
            'margin-right': '3px'
         });
      }
      jQuery(this).find('.slideshowPic').each(function() {
         if (jQuery(this).width() < 403) {
            jQuery(this).css('padding-right',403-jQuery(this).width()+'px');
         } else if (jQuery(this).width() > 403) {
            jQuery(this).find('img').css({
               'height': '250px',
               'width': '403px'
            });
         }
      });
      
      // firefox 2.x "display: inline-block;"-fix
      if (jQuery.browser.mozilla && parseFloat(jQuery.browser.version.substr(0,3)) < 1.9) {
         // somehow the text disappears here O_o (referring to the start-page)
         jQuery('.slideshowPic, .slideshowPicStart').css('display', '-moz-inline-box');
      }

      //activate sliding
      if (options['content'].length > 2)
         window.setInterval(slideElement, options['time']);
      }
   });

};

