var MC = {
  SlideShow: function(frame, imageReferences) {
    this.frame = frame;
    this.imageReferences = imageReferences;
    this.images = [];
    this.index = 0;
    
    this.preload = function() {
      for (var i = 0; i < this.imageReferences.length; i++) {
        var image = document.createElement("img");
        image.src = this.imageReferences[i];
        $j(image).css({opacity: 0.0});
        this.images.push(image);
      }
      
      var firstImage = this.images[this.index];
      $j(firstImage).css({opacity:1.0});
      this.frame.append(firstImage);
    };
    
    this.transitionToImage = function(nextImage) {
      var image = $j(this.frame).find('img');
      var frame = this.frame;
      image.animate({opacity:0}, 500, "linear", function() {
        image.remove();
        frame.append(nextImage);
        $j(nextImage).animate({opacity:1.0}, 500);
      });
    };
    
    this.back = function() {
      if (this.index > 0) {
        this.transitionToImage(this.images[--this.index]);
      }
      else if (this.index == 0) {
        this.transitionToImage(this.images[this.images.length-1]);
        this.index = this.images.length-1;
      }
    };
    
    this.forward = function() {
      if (this.index + 1 < this.images.length) {
        this.transitionToImage(this.images[++this.index]);
      }
      else if (this.index + 1 == this.images.length) {
        this.transitionToImage(this.images[0]);
        this.index = 0;
      }
    };
    
    this.preload();
    
    return true;
  }
}

$j(document).ready(function() {

  if(navigator.appName == 'Microsoft Internet Explorer')
{
var ss = new MC.SlideShow($j("#phones"), ["images/all-platforms-mashup-ie.png", "images/mashup-2-ie.png", "images/mashup-3-ie.png", "images/mashup-4-ie.png", "images/mashup-5-ie.png"]);
}
else
{
    var ss = new MC.SlideShow($j("#phones"), ["images/all-platforms-mashup.png", "images/mashup-2-sized.png", "images/mashup-3-sized.png", "images/mashup-4-sized.png", "images/mashup-5-sized.png"]);
}



  
  $j("#goleft").click(function(event) {
    ss.back();
  });
  
  $j("#goright").click(function(event) {
    ss.forward();
  });
});

function getInternetExplorerVersion()
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

