/*
 *	$Id: banner_localconnection.js 579 2007-02-08 14:19:59Z NORD\FabianJ $
 *
 * FlashObject embed
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 * v1.1.1 - 05-17-2005
 *
 * writes the embed code for a flash movie, includes plugin detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.write("objId");
 *
 * for best practices, see:
 *  http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
 *
 */

//Get Elements
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }
  return elements;
}


var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";

	this.params = new Object();
	this.variables = new Object();

	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
	this._hasFlash = false;
}

var FOP = FlashObject.prototype;

FOP.hasFlash = function() { return this._hasFlash; }

FOP.addParam = function(name, value) { this.params[name] = value; }

FOP.getParams = function() { return this.params; }

FOP.getParam = function(name) { return this.params[name]; }

FOP.addVariable = function(name, value) { this.variables[name] = value; }

FOP.getVariable = function(name) { return this.variables[name]; }

FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" name="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
	flashHTML += '<script language="JavaScript" event="FSCommand(strCmd, strArg)" for="'+self.flashId+'">\n';
	flashHTML += self.flashId+'_DoFSCommand(strCmd, strArg);\n';
	flashHTML += '</script>\n';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '" swLiveConnect="true">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
	return flashHTML;	
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
    	variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
		this._hasFlash = true;
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else if (this.altTxt) {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}


/* ---- detection functions ---- */
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
			if(flashversion=='0'){
				flashversion='10';
			}
		}
	} 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 query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		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 "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}

//Local Connection Params
var Ads_rdm_swf_1 = Math.random();
var Ads_rdm_swf_2 = Math.random();
var Ads_rdm_swf_3 = Math.random();
var Ads_rdm_swf_4 = Math.random();

function SetAd(){
	
	var self = this;
	self.flashId = "";
	self.swfsrc = "";
	self.swfwidth = "";
	self.swfheight = "";
	self.Ads_ClickUrl = "";
	self.browser_max_x = "";
	self.browser_max_y = "";
	self.posx = "";
	self.posy = "";
	self.obj = "";
	
	self.init = function(flashId) {
		self.flashId = flashId;
	}
	
	self.SetObjName = function(obj) {
		self.obj = obj;
	}
	
	self.SetFlashfile = function(filename) {
		self.swfsrc = filename;
	}
	
	self.SetDimension = function(width,height) {
		self.swfwidth = width;
		self.swfheight = height;
	}
	self.SetPosition = function(posx,posy) {
		self.posx=posx;
		self.posy=posy;
		self.RefreshPosition();
	}
		
	self.RefreshPosition = function() {
		self.CheckMaxDimensions();
		self.SetPosX();
		self.SetPosY();
	}
	
	self.SetPosX = function(){
		if(!self.IsNumeric(self.posx)){
			if(self.posx=="left"){
				$(self.flashId).style.left=0;
			} else if(self.posx=="center"){
				$(self.flashId).style.left=self.browser_max_x/2-self.swfwidth/2;
			} else if(self.posx=="right"){ 
				$(self.flashId).style.right=0;
			}
		} else {
			$(self.flashId).style.left=self.posx+"px"; 
		}
	}
	
	self.SetPosY = function(){
		if(!self.IsNumeric(self.posy)){
			if(self.posy=="top"){
				$(self.flashId).style.top=0;
			} else if(self.posy=="center"){
				$(self.flashId).style.top=self.browser_max_y/2-self.swfheight/2;
			} else if(self.posy=="bottom"){ 
				$(self.flashId).style.bottom=0;
			}
		} else {
			$(self.flashId).style.top=self.posy+"px"; 
		}
	}
	
	self.CheckMaxDimensions = function(){
		if(self.innerWidth) {
			self.browser_max_x = self.innerWidth;
			self.browser_max_y = self.innerHeight;
		}
		else if(document.body) {
			self.browser_max_x = document.body.clientWidth;
			self.browser_max_y = document.body.clientHeight;
		}
		else if(document.width) {
			self.browser_max_x = document.width;
			self.browser_max_y = document.Height;
		}
		else if(self.screen){
			self.browser_max_x = self.screen.availWidth;
			self.browser_max_y = self.screen.availHeight;
		} else {
			self.browser_max_x=1024;
			self.browser_max_y=768;
		}
	}
	self.IsNumeric = function (sText){
		var ValidChars = "0123456789.";var IsNumber=true;var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++){ 
			Char = sText.charAt(i); 
			if (ValidChars.indexOf(Char) == -1){IsNumber = false;}
		}
		return IsNumber;
	}
	
	self.SetAdClickUrl = function(url) {
		self.Ads_ClickUrl = url;
	}
	
	self.CloseAd = function() {
		$(self.flashId).style.visibility='hidden'; 
	}
	
	self.FSCommand = function(command,args) {
		if (command == "adlayerhider") {
			self.CloseAd();
		}
	}

	self.WriteAd = function() {
			
		var fo = new FlashObject(self.swfsrc, "FlashMovie_"+self.flashId, self.swfwidth, self.swfheight, 6, "#FFFFFF");
		fo.addVariable("clickTag", self.Ads_ClickUrl);
		fo.addVariable("Ads_rdm_swf_1", Ads_rdm_swf_1);
		fo.addVariable("Ads_rdm_swf_2", Ads_rdm_swf_2);
		fo.addVariable("Ads_rdm_swf_3", Ads_rdm_swf_3);
		fo.addVariable("Ads_rdm_swf_4", Ads_rdm_swf_4);
		fo.addParam("wmode", "transparent");
		fo.write(self.flashId);

		script='<script type="text/javascript">\n';
		script+='function FlashMovie_'+self.flashId+'_DoFSCommand(command, args) {\n';
		script+=self.obj+'.FSCommand(command,args);\n';
		script+='}\n';
		script+='window.onresize = '+self.obj+'.RefreshPosition;\n';
		script+='</script>\n';
		script+='<script type="text/vbscript"> \n';
		script+='on error resume next \n';
		script+='Sub FlashMovie_'+self.flashId+'_FSCommand(ByVal befehl, ByVal laufStatus)\n';
		script+='  call FlashMovie_'+self.flashId+'_DoFSCommand(befehl, laufStatus)\n';
		script+='end sub\n';
		script+='</script\> \n';
		document.write(script);

	}
	
	
	
}
	

