
/**
 * ProductViewerClass Class
 */

function ProductViewerClass() {
  this.id = null
  this.src = null
  this.width = 380
  this.height = 420
  this.imgFile = []
  this.bgcolor = '#ffffff'
}

/* run */
ProductViewerClass.prototype.run = function() {
  var hasFlashVer = DetectFlashVer(9, 0, 0);
  if (hasFlashVer) {
    AC_FL_RunContent(
      'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
      'width', this.width,
      'height', this.height,
      'src', this.src, /* if 'src' is modified, update 'movie' property */
      'quality', 'high',
      'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
      'align', 'middle',
      'play', 'true',
      'loop', 'true',
      'scale', 'showall',
      'wmode', 'transparent',
      'devicefont', 'false',
      'id', this.id,
      'FlashVars', this.getFlashVars(),
      'bgcolor', this.bgcolor,
      'name', this.id,
      'menu', 'false',
      'allowFullScreen', 'false',
      'allowScriptAccess','sameDomain',
      'movie', this.getMovieProperty(), /* same as 'src' property without 'swf' file extension */
      'salign', ''
    );
    return true;
  } else {
    // USER MESSAGE
    // TODO : DO BETTER - Tell user that flash is required (instruction message should be displayed into page).
    alert('This page requires Adobe Flash Player');
    return false;
  }
}

/* getFlashVars */
ProductViewerClass.prototype.getFlashVars = function() {
  /*
  FLASH IMAGE PARAMETER FOR SINGLE COLOR => ONE IMAGE
  ImgFile=image.png

  FLASH IMAGE PARAMETER FOR DOUBLE COLORS => TWO IMAGES
  ImgFile=image1.png&amp;ImgFile2=image2.png
  */
  var img = 'ImgFile';
  var res = '';
  for (var i=0; i<this.imgFile.length; i++ ) {
    if(i==0) {
      res = res.concat(img, '=', this.imgFile[i]);
      continue;
    }
    res = res.concat('&amp;', img, i+1, '=', this.imgFile[i]);
  }
  //alert(res);
  return res;
}

/* getMovieProperty */
ProductViewerClass.prototype.getMovieProperty = function() {
  return this.src.sub(/\.swf$/, '');
}

/* setSource */
ProductViewerClass.prototype.setSource = function(src) {
  this.src = src;
}

/* setId */
ProductViewerClass.prototype.setId = function(id) {
  this.id = id;
}

/* setWidth */
ProductViewerClass.prototype.setWidth = function(px) {
  this.width = px;
}

/* setHeight */
ProductViewerClass.prototype.setHeight = function(px) {
  this.height = px;
}

/* addImage */
ProductViewerClass.prototype.addImage = function(path) {
  this.imgFile.push(path);
}

/* setColor */
ProductViewerClass.prototype.setColor = function(label) {
  if(!ColorMapping.initialized) {
    ColorMapping.init();
  }
  var color = ColorMapping.getColor(label);

  if(color) {
    document[this.id].changeColor(color);
  }
}

var ProductOrientation = {
  change: function (sideId) {
    var sideObj =  {normal:1, reverse:-1};
    document['ProductViewer'].changeSide(sideObj[sideId]);
  }
}

