/*
 * FlashObject embed
 * http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
 *
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 * v1.0.7 - 11-17-2004
 *
 * Create and write a flash movie to the page, includes detection
 *
 * Usage:
 *
 *  myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor","flashvars");
 *  myFlash.altTxt = "Upgrade your Flash Player!";                // optional
 *  myFlash.addParam("wmode", "transparent");                     // optional
 *  myFlash.addVariable("varname1", "varvalue");                  // optional
 *  myFlash.addVariable("varname2", getQueryParamValue("myvar")); // optional
 *  myFlash.write();
 *  aggiunti due parametri: mediaSRC e mediaType . il promo contiene il path ed il secondo il tipo
 *  mediaType: 1=foto, 2=video, 3=audio
 */

FlashObject = function(swf, id, w, h, ver, c, al,strFormato, strTitolo, strDescrizione, strSrc, intDurata) {
    this.swf = swf;
    this.id = id;
    this.width = w;
    this.height = h;
    this.version = ver || 8; // default to 8
    this.align = al || "middle"; // default to middle
	//
	this.strFormato = strFormato;
	this.strTitolo = strTitolo;
	this.strDescrizione = strDescrizione;
	this.strSrc = strSrc;
	this.intDurata = intDurata;
    this.redirect = "upgrade_flash.html";
    this.sq = document.location.search.split("?")[1] || "";
    this.altTxt = "<div style='text-align:center;'>Questa applicazione richiede una versione pił aggiornata di Flash Player.<br><a href='http://www.macromedia.com/go/getflashplayer' target='_blank'><img border='0' src='img/getFlash.gif' alt='Aggiorna Flash Player'></a></div>";
    this.bypassTxt = "<p>Hai gią Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Clicca qui se hai gią Flash Player "+ this.version +" installato</a>.</p>";
    this.params = new Object();
    this.variables = new Object();
    if (c) this.color = this.addParam('bgcolor', c);
    this.addParam('quality', 'high'); // default to high
    this.doDetect = getQueryParamValue('detectflash');
	//modified - fb
	this.addVariable('strFormato',this.strFormato);
	this.addVariable('strTitolo',this.strTitolo);
	this.addVariable('strDescrizione',this.strDescrizione);
	this.addVariable('strSrc',this.strSrc);
	this.addVariable('intDurata',this.intDurata);
	
	//alert('mediaType' + this.mediaType);
}

FlashObject.prototype.addParam = function(name, value) {
    this.params[name] = value;
}

FlashObject.prototype.getParams = function() {
    return this.params;
}

FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}

FlashObject.prototype.addVariable = function(name, value) {
    this.variables[name] = value;
}

FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

FlashObject.prototype.getVariables = function() {
    return this.variables;
}

FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" /><param name="scale" value="exactfit" /><param name="menu" value="false" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" menu="false" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '" scale="exactfit"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
	
	//alert('html_>' +  flashHTML);
    return flashHTML;   
}



FlashObject.prototype.upgradeFlash = function()
	{
    	 var flashHTML = "";
	 flashHTML += "buongiorno stronzi!";
	 flashHTML += "";
	 flashHTML += "";
    	 return flashHTML;   
	}


FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

FlashObject.prototype.write = function(elementId) {
    if(detectFlash(this.version) || this.doDetect=='false') {
        if (elementId) {
            document.getElementById(elementId).innerHTML = this.getHTML();
        } else {
            document.write(this.getHTML());
        }
    } else {
        if (this.redirect != "") {
            //document.location.replace(this.redirect);
	    document.getElementById(elementId).innerHTML = this.altTxt;
        } else {
            if (elementId) {
                document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
            } else {
                document.write(this.altTxt +""+ this.bypassTxt);
            }
        }
    }       
}

function getFlashVersion() {
    var flashversion = 0;
    if (navigator.plugins && navigator.plugins.length) {
        var x = navigator.plugins["Shockwave Flash"];
        if(x){
            if (x.description) {
                var y = x.description;
                flashversion = y.charAt(y.indexOf('.')-1);
            }
        }
    } else {
        result = false;
        for(var i = 15; i >= 3 && result != true; i--){
            execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
            flashversion = i;
        }
    }
    return flashversion;
}

function detectFlash(ver) { 
    if (getFlashVersion() >= ver) {
        return true;
    } else {
        return false;
    }
}

// get value of querystring param
function getQueryParamValue(param) {
    var q = document.location.search;
    var detectIndex = q.indexOf(param);
    var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;
    if(q.length > 1 && detectIndex != -1) {
        return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
    } else {
        return true;
    }
}