/*
    swfbanner.js		
*/


/* constructor */
function SwfBanner() {
    this.swfFile = null;
    this.width = null;
    this.height = null;
    this.clickTags = new Array();
    this.clickTagDestinations = new Array();	
    this.backupImage = null;	
    this.backupTarget = null;
    this.backupHref = null;
    this.paramNames = new Array();
    this.paramValues = new Array();
    this.id = null;
    this.attributeNames = new Array();
    this.attributeValues = new Array();
}

SwfBanner.prototype.setSwfFile = function(filename) {
    this.swfFile = filename;
}

SwfBanner.prototype.setWidth = function(width) {
    this.width = width;
}

SwfBanner.prototype.setHeight = function(height) {
    this.height = height;
}

SwfBanner.prototype.setDimensions = function(width, height) {
    this.width = width;
    this.height = height;
}

/*
 *  Deprecated! Use addAttribute('id', 'xxx') instead.
 */

SwfBanner.prototype.setId = function(id) {
    this.addAttribute('id', id);
}

/*
 *  Deprecated! Use addClickTag instead.
 */
SwfBanner.prototype.setClickTag = function(clickTag, destinationUrl) {
    this.addClickTag(clickTag, destinationUrl);
}

SwfBanner.prototype.addAttribute = function(attributeName, attributeValue) {
    this.attributeNames.push(attributeName);
    this.attributeValues.push(attributeValue);
}


SwfBanner.prototype.addClickTag = function(clickTag, destinationUrl) {
    this.clickTags.push(clickTag);
    this.clickTagDestinations.push(destinationUrl);
}

SwfBanner.prototype.setBackupImage = function(imagefile) {
    this.backupImage = imagefile;
}

SwfBanner.prototype.setBackupTarget = function(target) {
    this.backupTarget = target;
}

SwfBanner.prototype.setBackupHref = function(href) {
    this.backupHref = href;
}

SwfBanner.prototype.addParam = function(name, value) {
    this.paramNames.push(name);
    this.paramValues.push(value);
}

SwfBanner.prototype.write = function() {
    if ((this.swfFile != null) && (this.width != null) && (this.height != null)) {
        swfFullUrl = this.swfFile;
        var firstClickTag = true;
        for (var i = 0; i < this.clickTags.length; i++) {
            if (firstClickTag) {
                swfFullUrl += "?";
                firstClickTag = false;
            }
            else {
                swfFullUrl += "&";
            }
            
            if ((this.clickTags[i] != null) && (this.clickTagDestinations[i] != null)) {
                swfFullUrl += this.clickTags[i] + "=" + this.clickTagDestinations[i];
            }
        }		
        document.write('<object type = "application/x-shockwave-flash" data = "' + swfFullUrl + '" width = "' + this.width + '" height = "' + this.height + '"');		
        // write the attributes
        for (var i = 0; i < this.attributeNames.length; i++) {
            document.write(' ' + this.attributeNames[i] + '="' + this.attributeValues[i] + '"');
        }
        document.write('>');
        document.write('<param name = "movie" value= "' + swfFullUrl + '" />');

        // write the extra params		
        for (var i = 0; i < this.paramNames.length; i++) {
            document.write('<param name = "');
            document.write(this.paramNames[i]);
            document.write('" value = "');
            document.write(this.paramValues[i]);
            document.write('" />');						
        }
        
        if (this.backupImage != null) {            
            var aElementOpened = false;
            if ((this.backupHref != null) || ((this.clickTagDestinations.length > 0) && (this.clickTagDestinations[0] != null))) {            
                var backupHref = this.clickTagDestinations[0];
                if (this.backupHref != null) {
                    backupHref = this.backupHref;
                }
                
                document.write('<a href = "' + backupHref + '"');
                if (this.backupTarget != null) {
                    document.write(' target = "' + this.backupTarget + '"');
                }	
                document.write('>');
                aElementOpened = true;
            }			
            document.write('<img src = "' + this.backupImage + '" width = "' + this.width + '" height = "' + this.height + '" border = "0" />');
            if (aElementOpened) {
                document.write('</a>');
            }
        }
        document.write('</object>');
    }
}
