var pageImagesGlobal=new Array();function _paging_nextImage(){var current=document.getElementById("component").src;for(var i=0;i<pageImagesGlobal.length;i++){if(current.indexOf(pageImagesGlobal[i])!=-1){if(i==(pageImagesGlobal.length-1)){document.getElementById("component").src=pageImagesGlobal[0];i=pageImagesGlobal.length;}else{document.getElementById("component").src=pageImagesGlobal[i+1];i=pageImagesGlobal.length;}}}}
function _paging_backImage(){var current=document.getElementById("component").src;for(var i=0;i<pageImagesGlobal.length;i++){if(current.indexOf(pageImagesGlobal[i])!=-1){if(i==0){document.getElementById("component").src=pageImagesGlobal[pageImagesGlobal.length-1];i=pageImagesGlobal.length;}else{document.getElementById("component").src=pageImagesGlobal[i-1];i=pageImagesGlobal.length;}}}}
function setImagesForPagingComponent(type){var images=new Array();for(i=1;i<=3;i++){images[i-1]="http://web1.shutterfly.com/img_/MIAM/miam_"+type+"_pip_content0"+i+".jpg";}
return images;}
function photogiftSlideshowFunction2(param){var imageHeader="http://web1.shutterfly.com/img_/MIAM/miam_"+param.type+"_pip_header.jpg";pageImagesGlobal=setImagesForPagingComponent(param.type);var str="";str="<table widht=\"445\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#"+param.bgcolor+"\">";str=str+"<tr><td colspan=4>";str=str+"<img src=\""+imageHeader+"\" width=\"445\"/>";str=str+"</td></tr><tr><td colspan=4 style=\"vertical-align: top;\">";str=str+"<img id=\"component\" src=\""+pageImagesGlobal[0]+"\">";str=str+"</td></tr><tr>";str=str+"<td width=\"19\"><a href=\"javascript:_paging_backImage();\"><img id=\"left\" src=\"http://web1.shutterfly.com/img_/MIAM/miam_pip_larrow.gif\" width=18></a></td>";str=str+"<td width=\"203\" align=\"left\" style=\"vertical-align: middle\">&nbsp;&nbsp;<a id='peekBackLink' href=\"javascript:_paging_backImage();\">Back</a></td>";str=str+"<td width=\"204\" align=\"right\" style=\"vertical-align: middle\"><a id='peekNextLink' href=\"javascript:_paging_nextImage();\">Next</a>&nbsp;&nbsp;</td>";str=str+"<td width=\"19\"><a href=\"javascript:_paging_nextImage();\"><img id=\"right\" src=\"http://web1.shutterfly.com/img_/MIAM/miam_pip_rarrow.gif\" width=18></a></td>";str=str+"</tr></table>";document.write(str);}
function photogiftSlideshowFunction(param){var imageHeader="http://web1.shutterfly.com/img_/MIAM/miam_"+param.type+"_pip_header.jpg";setImagesForPagingComponent(param.type);if(param.customImage!=null&&param.customImage!=""){pageImagesGlobal[0]=param.customImage;}else{pageImagesGlobal=setImagesForPagingComponent(param.type);}
var str="";str="<div style='width:445px; border:0;cellspacing:0;background-color:#"+param.bgcolor+"'>"
+"<div style='float:left;width=445px'>"
+"<img src='"+imageHeader+"'>"
+"</div>"
+"<div style='float:left;width:445px'>"
+"<img id='component' src='"+pageImagesGlobal[0]+"'>"
+"</div>"
+"<div style='clear:both;height:18px;'>"
+"<div style='float:left;'>"
+"<a href='javascript:_paging_backImage();'><img id='left' src='http://web1.shutterfly.com/img_/MIAM/miam_pip_larrow.gif' width='18'></a>"
+"<span style='vertical-align:50%;*vertical-align:40%'><a id='peekBackLink' href='javascript:_paging_backImage();'>Back</a></span>"
+"</div>"
+"<div style='float:right;'>"
+"<span style='vertical-align:50%;*vertical-align:40%'><a id='peekNextLink' href='javascript:_paging_nextImage();'>Next</a></span>"
+"<a href='javascript:_paging_nextImage();'><img id='right' src='http://web1.shutterfly.com/img_/MIAM/miam_pip_rarrow.gif' width='18'></a>"
+"</div>"
+"</div>"
+"</div>";document.write(str);}
function displayImage(param){var str="";if(param.customImage!=null&&param.customImage!=""){str="<div style='width:500px; border:0;cellspacing:0;background-color:#"+param.bgcolor+"'>"
+"<img alt='' src='"+param.customImage+"'/>"
+"</div>";}
document.write(str);}
function renderPagingComponent(param){if(param.functionName!=null&&param.functionName!=""&&param.functionName.indexOf("Function")>0){eval(param.functionName)({type:param.type,bgcolor:param.bgcolor});}else if(param.customImage!=null&&param.customImage!=""){displayImage({customImage:param.customImage});}else if(param.html!=null&&param.html!=""){document.write(param.html);}else{}}
dojo.provide("sfly.component.sflystore.ProductPreview");dojo.require("sfly.component.PageComponent");dojo.declare("sfly.component.sflystore.ProductPreview",sfly.component.PageComponent,{constructor:function(options){this._events={"skuProductChangedAction":"skuProductChangedAction"};this._subscribeToEvent(new sfly.framework.EventDependency(this._events.skuProductChangedAction,this,"skuProductHasChanged"));this._maxNumViews=options.maxNumViews;this._labels=options.labels;this._currentSkuCode=options.skuCode;this._errorImage=options.errorImage;this._defaultLargeView=options.defaultLargeView;this._ALTVIEWSIZE=options.altViewSize;this._productImages={};this._handlers=[];if(typeof(options.videoGuids)!="undefined"){this._videoGuids=options.videoGuids;this._attachVideoEvents();this._innerVideoCode="<a href=\"#\" onclick=\"return(false);\" rel=\"videoGUID=_v_key_&\" style=\"display:block;width:640px;height:360px\" id=\"_v_key_\" width=\"640\" height=\"360\">MediaMix</a>";}},_attachVideoEvents:function(){var _self=this;dojo.connect(dojo.byId("productPreviewArea"),"click",function(event){_self._replaceVideo(event);});},_replaceVideo:function(event){var _target=event.target;if(_target.className=="productPreviewSmall"){var videoGuid=this._videoGuids[dojo.attr(_target,"order")];document.getElementById("videoCode").innerHTML=this._innerVideoCode.replace("_v_key_",videoGuid,'gi');var vScript=document.createElement('script');vScript.src="http://360.sorensonmedia.com/"+videoGuid+"/embedv2.js";vScript.type="text/javascript";document.getElementById("videoCode").appendChild(vScript);}},skuProductHasChanged:function(eventActionObj){var skuCode=eventActionObj.skuCode;this.setCurrentSkuCode(skuCode);},setCurrentSkuCode:function(skuCode){this._currentSkuCode=skuCode;this.setLargeImage(this._defaultLargeView);this.setSmallImages();},setLargeImage:function(imageView){var imageUrl=null;try{imageUrl=this.getProductImage(this._currentSkuCode,imageView);}catch(e){}
if(imageUrl==null)
imageUrl=this._errorImage;dojo.byId("pipLargePreview").src=imageUrl;},setSmallImages:function(){var parentNode=dojo.byId("productPreviewArea");if(parentNode==null)
return;this._removeSmallImages(parentNode);var skuCode=this._currentSkuCode,altViews=this.getAltViews(skuCode);if(altViews!=null){var len=altViews.length;for(var i=0;i<len;i++){this._createSmallImage(skuCode,i,parentNode);}}},showLabel:function(altView){dojo.style('productPreviewTitle_'+altView,'visibility','visible');},hideLabel:function(altView){dojo.style('productPreviewTitle_'+altView,'visibility','hidden');},_createSmallImage:function(skuCode,index,parentNode){var preview=document.createElement('img'),altViews=this.getAltViews(skuCode),altview=altViews[index];if(this._labels){var div=document.createElement("div");div.className="productPreviewTitle";div.id="productPreviewTitle_"+altview;div.innerHTML=this._labels[altview];parentNode.appendChild(div);}
preview.id="productPreviewImg_"+index;preview.className="productPreviewSmall";preview.src=this.getProductImage(skuCode,"MERCHSMALL_"+altview);preview.height=preview.width=this._ALTVIEWSIZE;this._handlers.push(dojo.connect(preview,"onclick",dojo.hitch(this,"setLargeImage","MERCHLARGE_"+altview)));if(this._labels){this._handlers.push(dojo.connect(preview,"onmouseover",dojo.hitch(this,"showLabel",altview)));this._handlers.push(dojo.connect(preview,"onmouseout",dojo.hitch(this,"hideLabel",altview)));}
parentNode.appendChild(preview);},_removeSmallImages:function(parentNode){while(parentNode.hasChildNodes()){parentNode.removeChild(parentNode.firstChild);}
var len=this._handlers.length;for(var i=0;i<len;i++){dojo.disconnect(this._handlers[i]);}
this._handlers=[];},addProductImage:function(skuCode,imageKey,url){if(!this._productImages[skuCode])
this._productImages[skuCode]={};this._productImages[skuCode][imageKey]=url;},getProductImage:function(skuCode,imageKey){try{var images=this._productImages[skuCode];if(images){if(images[imageKey])
return images[imageKey];}}catch(e){return null;}
return null;},getAltViews:function(skuCode){var images=this._productImages[skuCode],altViews=[];for(var key in images){if(key.indexOf("MERCHSMALL_")==0)
altViews.push(key.substring(11));}
return altViews;}});
