/* $Revision: 17816 $ $Date: 2010-11-08 18:18:22 +0100 (Mon, 08 Nov 2010) $ */

function switchPreviewCardPanelsAmount(amount) {
	try {
		var flashComponent = getFlashComponent();
		if((typeof flashComponent.setNumberOfpanels)!="undefined") {
				flashComponent.setNumberOfpanels(amount);
		}
	} catch (ex) {
		window.console.error("An error occurred calling setNumberOfpanels for flash preview", ex);
	}
}

function setPreviewFlashParameters(definitionId,ratio,orientation,numberOfPanels,hasDesignedBackside){
	try {
		var flashComponent = getFlashComponent();
		if((typeof flashComponent.setParams)!="undefined") {			
			flashComponent.setParams(definitionId,orientation,ratio,numberOfPanels,hasDesignedBackside);
	}		
	} catch (ex) {
		window.console.error("An error occurred calling setParams for flash preview", ex);
	}
}

function reEmbedFlashPreview(definitionId,cardRatio,orientation,numberOfPanels,hasDesignedBackside,issoundcard,soundid,soundartist,soundtitle) {
	var flashSettings = document.previewFlashInit;
	var flashVarsStr = "{ cardid : '"+definitionId+"'";
	flashVarsStr += ",hasdesignedbackside : '"+hasDesignedBackside+"'";
	flashVarsStr += ",numberofpanels : '"+numberOfPanels+"'";
	flashVarsStr += ",ratio : '"+cardRatio+"'";
	flashVarsStr += ",orientation : '"+orientation+"'";
	flashVarsStr += ",previewurltemplate : '"+flashSettings.previewUrlTemplate+"'";
	flashVarsStr += ",issoundcard : '"+issoundcard+"'";
	if(soundid!=null) {
		flashVarsStr += ",soundpreviewurl : '"+flashSettings.soundPreviewUrlTemplate.replace("{soundid}",soundid)+"'";
		if(soundartist!=null) {
			flashVarsStr += ",soundartist : '"+soundartist+"'";
		}
		flashVarsStr += ",soundtitle : '"+soundtitle+"'";
	}
	flashVarsStr+="}";
	// Creating flash vars
	var flashVars = window.eval("("+flashVarsStr+")");
	var attributes = {
			wmode:"transparent"
	};
	var htmlAttibutes = {
			"class":"flashmovie"
	};
	swfobject.embedSWF(flashSettings.swfUrl,flashSettings.flashComponentId, flashSettings.width, flashSettings.height, "9.0.0",null,flashVars,attributes,htmlAttibutes);
}

function getFlashComponent() {
	return  document.getElementById(document.previewFlashInit.flashComponentId);
}
