//S7: this fucntion will be called by the embedded vierwer when the "view larger" button is clicked. The function receive 
//Boolean flag altViewsAvailable and the Integer index inIdx - the current image index, that will be used by the popup viewer 
//as initialFrame.

function embedOTCViewer(){	
	//S7: Add Viewer to page into the embeddedViewerHolder div element, at embeddedViewerWidth x embeddedViewerHeight pixels.
	swfobject.embedSWF(embeddedViewerUrl, "embeddedViewerHolder", embeddedViewerWidth, embeddedViewerHeight, "7.0.14.0", "", flashvars, params, attributes);
};

function openPopup(altViewsAvailable, inIdx,inPersonalization) {
		var popupWidth = popupViewerWidth_noAlt;
		var popupHeight = popupViewerHeight_noAlt;
		
		if (altViewsAvailable) {
			popupWidth = popupViewerWidth_alt;
			popupHeight = popupViewerHeight_alt;
		}

		var popupHtml = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' 		codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='"+popupWidth+"' height='"+popupHeight+"' id='" + popupInstanceName + "' align=''> <param name='movie' value='" + popupUrl + '&personalization=' + encodeURIComponent(inPersonalization) + '&initialFrame=' +  inIdx + "'> <param name='allowScriptAccess' value='always'>	<param name='quality' value='high'> <param name='bgcolor' value='#ffffff'> <param name='wmode' value='opaque'> <embed src='" + popupUrl  + '&personalization=' + encodeURIComponent(inPersonalization) + '&initialFrame=' +  inIdx +  "' quality='high' bgcolor='#ffffff' width='"+popupWidth+"' height='"+popupHeight+"' wmode='opaque' name='" + popupInstanceName + "' align='' type='application/x-shockwave-flash' allowScriptAccess='always' pluginspage='http://www.macromedia.com/go/getflashplayer'> </embed> </object>";

		document.getElementById('popupViewerHolder').innerHTML = popupHtml;
		document.getElementById('popupViewerOverlay').style.width = popupWidth + 'px';
		document.getElementById('popupViewerOverlay').style.height = popupHeight + 'px';

		if (!altViewsAvailable){
				//S7: in case if the alt views are not available we are changing the modal window apple effect background to the appropreate size image. 
				document.getElementById('popupViewerOverlay').style.backgroundImage = 'url(/images/scene7/bgSmall.gif)';
		}
		$("#popupViewerOverlay").dialog({modal:true,width:popupWidth, height:popupHeight,dialogClass: 's7-dialog',resizable: false});
};

function setPersonalizationhandler(){
	var tempArray = eval('(' + $('#pznHiddenData').val() + ')');
	var pznImgName = $('#pznImageName').val();
	var pznImgUrl = 'http://s7.orientaltrading.com/is/image/OrientalTrading/'+pznImgName+'-p01';
	var pznUrlParam = '';
	var tempCount = 1;
	 for (var ii = 0; ii < tempArray.length; ii++){
		 for (jj = 0; jj < tempArray[ii]; jj++) {
	            var pznValue = $("#pz_" + ii + "_" + jj).val();
	            pznUrlParam = pznUrlParam + '&$personalize'+tempCount+'='+pznValue.replace('&','%2526').replace("'","%2527");
	            tempCount++;
		 }
	 }
	setPersonalization(pznImgUrl+pznUrlParam);
};
function coremetricstracking(inArg1) {
	var tempSku = $('#productId').val();
	var tempShortDesc = $('#ShortDesc').val();
	cmCreatePageElementTag('S7 VIEWER:'+inArg1, 'S7:VIEWER', tempSku+'-_-'+tempShortDesc);
}
function coremetricstrackingViewLarger(inArg1) {
	var tempSku = $('#productId').val();
	var tempShortDesc = $('#ShortDesc').val();
	cmCreatePageElementTag('S7 VIEWER:VIEW LARGER IMAGE:'+inArg1, 'S7:VIEWER', tempSku+'-_-'+tempShortDesc);
}

//S7: this function should be called by the cliens code in order to pass the personalization values to the embedded viewer.
function setPersonalization(inPersonalization) {
	if (document.embeds[instanceName]) {
		document.embeds[instanceName].setPersonalization(inPersonalization);
	} else if(document.getElementById(instanceName)) {
		document.getElementById(instanceName).setPersonalization(inPersonalization);
	}
};

