                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                if(!window.__td){window.__MT=100;window.__ti=0;window.__td=[];window.__td.length=__MT;window.__noTrace=false;}


if(typeof(vp)=="undefined")
{
var vp={};
}

if(!vp.studio)
{
vp.studio={};
}

if(!vp.studio.backside)
{
vp.studio.backside={};
}

var backsideLayer;

vp.studio.backside.showInlineBacksideSelector=function studio_backside_showInlineBacksideSelector()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
vp.studio.backside.init();
backsideLayer.extend();
};

vp.studio.backside.applyBacksideChange=function studio_backside_applyBacksideChange()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
if(backsideLayer.isExtending())
{
return;
}
backsideLayer.applyChange();
backsideLayer.collapse();
};

vp.studio.backside.init=function studio_backside_init()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
if(vp.studio.backside.isInitialize)
{
return;
}

var container=document.createElement("SPAN");

vp.ui.setStyle(
container,
{
position:"absolute",
top:"0px",
left:"0px",
zIndex:10000001
});

var tblBacksides=document.getElementById("tblBacksides");
tblBacksides.parentNode.removeChild(tblBacksides);
container.appendChild(tblBacksides);
container.id="backsideContainer";
document.body.appendChild(container);

backsideLayer=new vp.studio.backside.BacksideLayer(tblBacksides);
backsideLayer.loadBacksides();

vp.studio.backside.isInitialize=true;
};

vp.studio.backside.isInitialize=false;

vp.studio.backside.BacksideLayer=function studio_backside_BacksideLayer(object)
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
var me=this;
var my={
main:object,
middle:document.getElementById("tdMiddle"),
iFrame:document.createElement("IFRAME"),
base:document.getElementById("tblBacksidePreview"),
left:null,
bottom:null,
increaseWidth:31,
increaseHeight:(document.all?20:19),
increaseTimes:20,
step:0,
layerBlock:null,
layerOpacity:0.01
};



my.layerBlock=document.createElement("DIV");
my.layerBlock.className="backgroundBlock";
my.layerBlock.unselectable="on";
my.layerBlock.style.backgroundColor="White";
vp.ui.setOpacity(my.layerBlock,my.layerOpacity);
my.layerBlock.onclick=vp.studio.backside.applyBacksideChange;
document.body.appendChild(my.layerBlock);

my.iFrame.frameBorder="no";
my.iFrame.scrolling="no";
my.iFrame.id="iFrameBacksides";

this.extend=function pb_this_extend()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
if(my.step===0)
{
var pos=vp.studio.backside.getPosition(my.base);

my.left=pos.x;
my.bottom=pos.y+my.base.offsetHeight;

my.layerBlock.style.height=getDocumentHeight()+"px";
my.layerBlock.style.visibility="visible";

my.isExtending=true;
}

vp.ui.setStyle(
my.main,
{
width:my.base.offsetWidth+my.step*my.increaseWidth+"px",
height:my.base.offsetHeight+my.step*my.increaseHeight+"px",
left:my.left+"px",
top:my.bottom-my.base.offsetHeight-my.step*my.increaseHeight+"px",
visibility:"visible"
});

updateInnerElements(0);
my.step++;

if(my.step<my.increaseTimes)
{
my.clock=setTimeout(function(){me.extend();},0);
}
else
{
clearTimeout(my.clock);
my.isExtending=false;
}
};

this.collapse=function pb_this_collapse()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
var properties=
updateInnerElements(-1);
vp.ui.setStyle(
my.main,
{
width:my.base.offsetWidth+my.step*my.increaseWidth+"px",
height:my.base.offsetHeight+my.step*my.increaseHeight+"px",
left:my.left+"px",
top:my.bottom-my.base.offsetHeight-my.step*my.increaseHeight+"px"
});

my.step--;

if(my.step>0)
{
my.clock=setTimeout(function(){me.collapse();},0);
}
else
{
clearTimeout(my.clock);
my.main.style.visibility="hidden";
my.layerBlock.style.visibility="hidden";
}
};

this.loadBacksides=function pb_this_loadBacksides()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
var oQS=new vp.web.QueryString(document.location.search);
oQS.setItem("backside_mck_id",Editor.backsideManagedContentKeyId||"0");

document.getElementById("backsideIframeContainer").appendChild(my.iFrame);
my.iFrame.src="/vp/ns/studio/backsides.aspx?"+oQS.toString();
};

var updateInnerElements=function pv_updateInnerElements(cov)
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
my.iFrame.style.width=my.main.offsetWidth+cov*my.increaseWidth-20+"px";
my.iFrame.style.height=my.main.offsetHeight+cov*my.increaseHeight-90+"px";
my.middle.style.height=my.main.offsetHeight+cov*my.increaseHeight-54+"px";
};

this.isExtending=function pb_this_isExtending()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
return my.isExtending;
};

var getDocumentHeight=function pv_getDocumentHeight()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
if(document.all)
{
return document.body.scrollHeight;
}
else
{
return document.documentElement.clientHeight;
}
};

this.applyChange=function pb_this_applyChange()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
var callBack=function pv_callBack(iBacksideManagedContentKeyId,sPreviewSrc)
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
Editor.backsideManagedContentKeyId=iBacksideManagedContentKeyId;
Editor.setDocumentChanged(true);
document.getElementById("imgBacksidePreview").src=sPreviewSrc;

var oTitle=document.getElementById("backsideSelectorTitle");
document.getElementById("backsideSelectorTitle").innerHTML=oTitle.getAttribute("selected-title");
};

if(my.iFrame.contentWindow.vp&&
my.iFrame.contentWindow.vp.studio&&
my.iFrame.contentWindow.vp.studio.backsidePage&&
my.iFrame.contentWindow.vp.studio.backsidePage.applyChange)
{
my.iFrame.contentWindow.vp.studio.backsidePage.applyChange(callBack);
}
};
};

vp.studio.backside.getPosition=function studio_backside_getPosition(obj)
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}
var x=0;
var y=0;
while(obj.offsetParent)
{
x+=obj.offsetLeft;
y+=obj.offsetTop;

obj=obj.offsetParent;
if(!obj)
{
return{x:x,y:y};
}
}
if(obj.x)
{
x+=obj.x;
y+=obj.y;
}
return{x:x,y:y};
};



vp.studio.backside.updateControlOnComboChange=function studio_backside_updateControlOnComboChange()
{if(!window.__noTrace){__td[__ti]=arguments;__ti=__ti>=__MT?0:__ti+1;}

var currentIcParts=Editor.icParts;
var currentComboId=Editor.comboID;
var currentDominantImageId=Editor.dominantImageID;
var currentImageList=Editor.imageList;


Editor.oncombochange.addHandler(function()
{
if(Editor.icParts!=currentIcParts||Editor.comboID!=currentComboId)
{

currentIcParts=Editor.icParts;
currentComboId=Editor.comboID;
currentDominantImageId=Editor.dominantImageID;
currentImageList=Editor.imageList;


var oElement=vp.ui.get('imgBacksidePreview');
if(oElement)
{

if(Editor.docID)
{

var oURL=new vp.web.URL(oElement.src);


oURL.removeItem("combo");
oURL.removeItem("combo_id");
oURL.removeItem("dominant_image_id");
oURL.removeItem("image_list");


oURL.setItem(EditorConst.renderingTechnologyParam,Editor.renderingTechnology);


oURL.setItem("doc_id",Editor.docID);

oURL.setItem("matching_backside",true);


oURL.setItem("random",Math.random()*10000000);


oElement.src=oURL.toString();
}
}


oURL=new vp.web.URL(EditorConst.backsideGalleryURL);


if(currentComboId===0)
{

oURL.removeItem("combo_id");
}
else
{
oURL.setItem("combo_id",currentComboId);
}


oURL.setItem("dominant_image_id",currentDominantImageId);
oURL.setItem("image_list",currentImageList);


oURL.setItem("combo",Editor.icParts);


EditorConst.backsideGalleryURL=oURL.toString();
}
});
};