/* Opens a CDC popup window.  Takes the product (i.e. "sheds"), the currency,
 * and, optionally, an ID to preload
 */

function cdcDesignCenter (product, configId, priceType) {
  var cdcloc = root_url + '/cdc/design/'+product;
  if (configId) cdcloc += '/'+configId;
  if (priceType) cdcloc += '/'+priceType;
  var width = 780;
  var height = 480;
  var width = 960;
  var height = 550;
  var indenttop = (screen.height - height) / 2;
  var indentleft = (screen.width - width) / 2;
  var popwin = window.open(cdcloc, 'uniplayer', 'width='+width+',height='+height+',top='+indenttop+',left='+indentleft+',scrollbars=no,menubar=no,toolbar=no,status=no,titlebar=no');
  popwin.focus();
}

function cdcEmbedFlash (elemId, prod, currency, config, order_type, swf, width, height, bgcolor) {
  var elem = document.getElementById(elemId);
  var src = swf+'?currency='+currency+'&productCategory='+prod+(config ? '&detailID='+config : '')+(order_type ? '&orderType='+order_type : '');
  // Loath IE, which breaks with proper dom method creation (the obj.appendChild(embed) fails):
  if (navigator.appVersion.toLowerCase().indexOf('msie') != -1) {
    elem.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://macromedia.com/cabs/swflash.cab#version=8,0,0,0" style="width: '+width+'px; height: '+height+'px">' +
      '<param name="movie" value="'+src+'" />' +
      '<param name="quality" value="high" />' +
      '<param name="bgcolor" value="#ffffff" />' +
      '<param name="wmode" value="transparent" />' +
      '<embed src="'+src+'" bgcolor="#ffffff" width="'+width+'" height="'+width+'" type="application/x-shockwave-flash" />';
  }
  else {
    var obj = document.createElement('object', 'foo');
    obj.setAttribute('classid', 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
    obj.setAttribute('codebase', 'http://macromedia.com/cabs/swflash.cab#version=8,0,0,0');
    obj.style.width = width+'px';
    obj.style.height = height+'px';
    var pMovie = document.createElement('param');
    pMovie.setAttribute('name', 'movie');
    pMovie.setAttribute('value', src);
    var pQuality = document.createElement('param');
    pQuality.setAttribute('name', 'quality');
    pQuality.setAttribute('value', 'high');
    var pBgcolor = document.createElement('param');
    pBgcolor.setAttribute('name', 'bgcolor');
    pBgcolor.setAttribute('value', bgcolor);
    var embed = document.createElement('embed');
    embed.setAttribute('src', src);
    embed.setAttribute('bgcolor', bgcolor);
    embed.setAttribute('width', width);
    embed.setAttribute('height', height);
    embed.setAttribute('type', 'application/x-shockwave-flash');
    obj.appendChild(pMovie);
    obj.appendChild(pQuality);
    obj.appendChild(pBgcolor);
    obj.appendChild(embed);
    elem.appendChild(obj);
  }
}

function cdcEmbedReviewFlash (elemId, prod, currency, config, order_type, swf, width, height, sides, bgcolor) {
  var elem = document.getElementById(elemId);
  var src = swf+'?currency='+currency+'&productCategory='+prod+(config ? '&detailID='+config : '')+(order_type ? '&orderType='+order_type : '');
  // Subtract (sides-1) from the width to account for the borders
  var singleWidth = Math.floor((width-sides+1) / sides);
  var cont = document.createElement('div');
  cont.className = 'sides';
  elem.appendChild(cont);
  for (var i = 1; i <= sides; i++) {
    var side = document.createElement('div');
    side.className = 'side';
    if (i == 1) side.className = side.className + ' firstside';
    if (i == sides) side.className = side.className + ' lastside';
    side.style.width = singleWidth + 'px';
    side.style.height = height + 'px';
    cont.appendChild(side);
    // Loath IE, which breaks with proper dom method creation (the obj.appendChild(embed) fails):
    if (navigator.appVersion.toLowerCase().indexOf('msie') != -1) {
      side.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://macromedia.com/cabs/swflash.cab#version=8,0,0,0" style="width: 100%; height: 100%">' +
        '<param name="movie" value="'+src+'&selectedSide='+i+'" />' +
        '<param name="quality" value="high" />' +
        '<param name="bgcolor" value="#ffffff" />' +
        '<param name="wmode" value="transparent" />' +
        '<embed src="'+src+'&selectedSide='+i+'" bgcolor="#ffffff" width="'+singleWidth+'" height="'+height+'" type="application/x-shockwave-flash" />';
    }
    else {
      var obj = document.createElement('object', 'foo');
      obj.setAttribute('classid', 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
      obj.setAttribute('codebase', 'http://macromedia.com/cabs/swflash.cab#version=8,0,0,0');
      obj.style.width = '100%';
      obj.style.height = '100%';
      var pMovie = document.createElement('param');
      pMovie.setAttribute('name', 'movie');
      pMovie.setAttribute('value', src+'&selectedSide='+i);
      var pQuality = document.createElement('param');
      pQuality.setAttribute('name', 'quality');
      pQuality.setAttribute('value', 'high');
      var pBgcolor = document.createElement('param');
      pBgcolor.setAttribute('name', 'bgcolor');
      pBgcolor.setAttribute('value', bgcolor);
      var embed = document.createElement('embed');
      embed.setAttribute('src', src+'&selectedSide='+i);
      embed.setAttribute('bgcolor', bgcolor);
      embed.setAttribute('width', singleWidth);
      embed.setAttribute('height', height);
      embed.setAttribute('type', 'application/x-shockwave-flash');
      obj.appendChild(pMovie);
      obj.appendChild(pQuality);
      obj.appendChild(pBgcolor);
      obj.appendChild(embed);
      side.appendChild(obj);
    }
  }
}


// vim:ft=javascript:sw=2:et
