////////////////////////////////////////////////////////////////////////////////////////////
//
//	File:		smarts_flashswitch.js
//	Author:		Alexander Jung
//	Copyright:	Copyright (c) 2007 Zebworx Interactive All Rights Reserved.
//	Datum:		11.2006
//
////////////////////////////////////////////////////////////////////////////////////////////

// 	smarts_flash('zielelement',Flashversion,{'src':'flash.swf'[,...]}[,'<img ... />']);
var smarts_flash=function(){
    this.target=(typeof(arguments[0])=='string')?document.getElementById(arguments[0]):arguments[0];
    this.flashversion=arguments[1];
    this.properties=arguments[2]||{};
	this.altTag=arguments[3]||'';
	
	if(this.target.getElementsByTagName('div').length>0){
		this.altTag=this.target.getElementsByTagName('div')[0].innerHTML.replace(/&lt;/,'<');
		this.altTag=this.altTag.replace(/&gt;/,'>');
	}

	this.version=-1;
    this.available=false;
    this.maxVersion=15;
    this.ActiveX=false;
    this.Embed=false;
    this.plugin='Shockwave Flash';

    this.getVersion();

    if(this.checkVersion()){
        this.flashObject();
        this.writeFlash();
    }else{
        this.writeNoFlash();
    }
}

smarts_flash.prototype.getVersion=function(){
    for(var i=3;i<this.maxVersion;i++){
        try{
            this.AX=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+i);
            this.ActiveX=true;
            this.version=i;
            this.versionStr=this.AX.GetVariable("$version");
            this.versionStr=this.versionStr.match(/\w+\ (.*?)$/);
            this.versionStr=RegExp.$1;
            this.embedTag=false;
			this.Embed=false;
        }catch(e){}
    }

    if(navigator.plugins){
        if(navigator.plugins[this.plugin+' 2.0']||navigator.plugins[this.plugin]){
            this.description=navigator.plugins[this.plugin+(navigator.plugins[this.plugin+' 2.0']?' 2.0':'')].description;

            this.description.match(/\w+\ \w+\ (.*?)\.(.*?)(\ r(.*?))(\ r(.*?))?$/);
            this.versionStr=RegExp.$1+','+RegExp.$2+','+RegExp.$4+','+(RegExp.$6==''?'0':RegExp.$6);
            this.version=RegExp.$1;
			this.Embed=true;
        }
    }

    if(navigator.userAgent.indexOf('WebTV')!=-1){
        this.version=3;
    }
}

smarts_flash.prototype.checkVersion=function(){
    this.available=(this.version>=this.flashversion)?true:false;

    return this.available;
}

smarts_flash.prototype.flashObject=function(){
    this.objectTag='<object ';
    this.embedTag='<embed ';

    this.properties.allowScriptAccess='sameDomain';

    this.properties.movie=(!this.properties.src)?this.properties.movie:this.properties.src;

    if(this.ActiveX){
		this.objectTag+='classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
		this.objectTag+='codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.versionStr+'" ';
		this.objectTag+='type="application/x-shockwave-flash" ';

		this.objectTag+='id="'+this.properties['id']+'" ';
		this.objectTag+='width="'+this.properties['width']+'" ';
		this.objectTag+='height="'+this.properties['height']+'">';
    }else{
        this.objectTag+='data="'+this.properties.src+'">';
    }

	this.embedTag+='type="application/x-shockwave-flash" ';
	this.embedTag+='pluginspage="http://www.macromedia.com/go/getflashplayer" ';

	if(this.properties.flashvars){
		this.properties.movie+='?'+this.properties.FlashVars;
	}

	for(attribute in this.properties){
		if(attribute!='movie'){
			this.embedTag+=attribute+'="'+this.properties[attribute]+'" ';
		}

		this.objectTag+='<param name="'+attribute+'" value="'+this.properties[attribute]+'">';
	}

	this.objectTag+='</object>';
	this.embedTag+='/>';
}

smarts_flash.prototype.writeFlash=function(){
	if(typeof SmartS_UI=='object'){
		this.target.innerHTML='<div class="smarts_noscript">'+this.altTag+'</div>'+((!this.Embed)?this.objectTag:this.embedTag);
	}else{
		this.target.innerHTML=(!this.Embed)?this.objectTag:this.embedTag;
	}
}

smarts_flash.prototype.writeNoFlash=function(){
    this.target.innerHTML=this.altTag;
}

