/* ecards.js
 *
 * Orchaestrate interaction with ecard swf. Ecard swf must attach a callback to
 * getCardObject, and call loadCardObject. This will allow it to persist its ecard-customization
 * 
 * Actionscript3: ExternalInterface.callback("getCardObject",yourFunctionThatReturnsAnObject);
 *                var yourObject:Object=ExternalInterface.call("loadCardObject");
 *
 * Note: the card object retrieved will have the following additional parameters added: 
 *   personalMessage
 *   fromName
 *   toName
 *
 * So be sure to leave these parameters alone 
 */

// Called by flash to retrieve the object   
function loadCardObject(){ return card_object; } 

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName];
    } else { return document[movieName]; }
}

// Grab object from flash and stuff into id_card_object hidden input
// We stick the persnalMessage parameter from the form in here
function prepsubmit(){
    var cobj=thisMovie("ecard_swf").getCardObject();
    cobj["personalMessage"]=$("#id_personal_message").val();
    cobj["fromName"]=$("#id_your_name").val();
    cobj["toName"]=$("#id_recipient_name").val();
    $('#id_card_object').val($.toJSON(cobj));
}

// Loads ecard. target is id to insert into, and editable will be passed to flash to signal
// if we are in 'create' or 'view' mode
function loadEcard(swfurl,width,height,target,editable){
    var params = {scale: "noscale",wmode: "transparent"};
    var flashvars = {};
    if(editable){ flashvars["editable"]=true; }
    swfobject.embedSWF(swfurl,target,width,height,"8", "", flashvars, params,{});
}

function previewsubmit(){
    $('#ecard_form').append('<input type="hidden" name="preview" value="preview" />');
}

