
ssobject = (function(){
  
  var fade = function(img, conteiner){
    if (img) {
      if (window.attachEvent && !browser.opera) {
        var opacity = parseInt(img.style.filter.slice(14, 17)); 
      } else {
        var opacity = img.style.opacity * 100;
      }

      if (opacity < 100) {
        if (window.attachEvent && !browser.opera) {
          img.style.filter = 'Alpha(Opacity='+(opacity += 5)+')';
        } else {
          img.style.opacity = parseFloat((opacity / 100) + 0.05); 
        }
        
        setTimeout(function(){
          fade(img, conteiner);
        }, 1);
      } else {
        if (conteiner.childNodes) {
          if (conteiner.lastChild.previousSibling.tagName == 'IMG') {
            conteiner.removeChild(conteiner.lastChild.previousSibling);
          }
        }
      }
    }
  };
  
  var next = function(options, current){
    if (options.conteiner != '') {
      var conteiner = document.getElementById(options.conteiner);
      
      if (conteiner) {
        conteiner.style.position = 'relative';  
        
        var img = document.createElement('img');
        
        if (img) {
          img.style.position = 'absolute';
          img.style.left = 0;
          img.style.top = 0;

          if (options.fade === true) {
            if (window.attachEvent && !browser.opera) {
              img.style.filter = 'Alpha(Opacity=0)'; // IE 6
            } else {
              img.style.opacity = 0;
            }
          }
            
          if (options.type == 'random') {
            current = Math.floor(Math.random() * options.photos.length);
          } else if (options.type == 'sequence') {
            if (current == options.photos.length - 1) {
              current = 0;
            } else {
              current++;
            }
          }
          
          img.src = options.photos[current];
          conteiner.appendChild(img);
          
          if (options.fade === true) {
            setTimeout(function(){
              fade(img, conteiner)
            }, 1);
          }
          
          setTimeout(function(){
            next(options, current)
          }, options.speed);
        }
      }
    }
  };
  
  return (function(options){
    if (options.photos.length) {
      for (var i = 0; i < options.photos.length; i++) {
        var loader = new Image;
        loader.src = options.photos[i];
      }

      if (options.speed > 0) {
        setTimeout(function(){
          next(options, 0)
        }, options.speed);
      }
    }
  });
  
})();
