
var CardFlashWidth = 480; 	// 480x435
var CardFlashHeight = 300;
var cardHeight;
var cardWidth;


function CardPreviewSetupParams(imgSrc) {
    var img = new Image();
    img.onload = CardPreviewImageLoaded;
    img.src = imgSrc;
    img.onerror = function() { alert('error'); };
}

function CardPreviewImageLoaded() {
    cardWidth = this.width;
    cardHeight = this.height;
    var ratio = cardWidth / cardHeight;
    cardHeight = 225;
    cardWidth = Math.round(cardHeight * ratio)
    
    var imagesUrl = CardFlashPreviewImages + "%26w%3d" + cardWidth + "%26h%3d" + cardHeight + "%26pagenum%3d";
    var frontURL = imagesUrl + "1";
    var insideLeftURL = imagesUrl + "2";
    var insideRightURL = imagesUrl + "3";
    var backURL = CardFlashPreviewImages + "%26w%3d" + cardWidth + "%26h%3d" + (cardHeight + 6) + "%26pagenum%3d" + "4";

    CardFlashPreviewParams += "&amp;cardWidth=" + cardWidth + "&amp;cardHeight=" + cardHeight + "&amp;frontURL=" + frontURL + "&amp;insideLeftURL=" + insideLeftURL + "&amp;insideRightURL=" + insideRightURL + "&amp;backURL=" + backURL;
    CardFlashPreviewUrl = CardFlashRootUrl + "/" + CardFlashPreviewUrl;
    CardDetectFlash();
    CardEmbedFlash2();

}

function GetMovie(movieName) {
    var tagName = (navigator.appName.indexOf("Microsoft") != -1) ? "object" : "embed";
    var arr = document.getElementsByTagName(tagName)
    if (arr == null) return null;
    for (var i = 0; i < arr.length; i++)
        if (arr[i].name == movieName) return arr[i];
    return null;
}
function TextInterface() {
    this.GetText = function() {
        var str = GetMovie(window._flashConst_Name).CallFunction("<invoke name=\"getCurrentFlashTextField\" returntype=\"javascript\">"
	            + __flash__argumentsToXML([], 0) +
                "</invoke>");
        if (str != null && str != "") {
            str = str.split("\\\"").join("\"");
            if (str.indexOf('"') == 0) str = str.substr(1);
            if (str.lastIndexOf('"') == (str.length - 1)) str = str.substr(0, str.length - 1);
        }
        return str.replace(/<\/?FONT[^>]*>/gi, "");
    }
    this.SetText = function(text) {
        GetMovie(window._flashConst_Name).CallFunction("<invoke name=\"setCurrentFlashTextField\" returntype=\"javascript\">"
	            + __flash__argumentsToXML([text], 0) +
                "</invoke>");
    }
}

//function CheckSpelling()
//{
//	var source = new TextInterface();
//	try { var text = source.GetText(); }
//	catch (error) {
//		alert("Error getting text from the Flash movie. Please check your Flash player plugin. ");
//		return;
//	}	                      
//	var spell = GetRadSpell('');

//	spell.GetDialogOpener().UseClassicDialogs = true;
//	spell.SetTextSource(source);
//	spell.StartSpellCheck();
//}