/*CVS Add-ins*/
/*
$Revision: 1.2 $
$Date: 2006/05/16 10:09:36 $
$RCSfile: flashbehaviour.js,v $
author: JDE
Copyright (c) A&B.face2net GmbH
*/

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/*
    behaviour.js for Praevention: various additional javascripts
    23.01.2006 JDE
*/
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */

var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var op = (agt.indexOf("opera") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
var pluginlist = "";
var latestpluginVer = 15;
var pluginVer=0;
var unknown_pluginVer = -1;
var isMs = false;

if (ie ){	pluginVer = detectIEFlashVersion(latestpluginVer); }

function detectIEFlashVersion(latestpluginVer) {
  var doc = '<scr' + 'ipt language="VBScript"\> \n';
	      doc += 'On Error Resume Next \n';
	      doc += 'Dim obFlash \n';
	      doc += 'For i = ' + latestpluginVer + ' To 3 Step -1 \n';
	      doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
	      doc += '   If IsObject(obFlash) Then \n';
	      doc += '      pluginVer = i \n';
	      doc += '      Exit For \n';
	      doc += '   End If \n';
	      doc += 'Next \n';
	      doc += '</scr' + 'ipt\> \n';
	      document.write(doc);
          return pluginVer; 
}


/**
* executes functions when the page loads.
* @param func_name name of function
*/
function addLoadEvent(func_name) {
	var lastonload = window.onload;
	if (typeof window.onload != 'function') 
		{ window.onload = func_name; } 
	else {	window.onload = function() {
      			lastonload(); func_name(); }
  	}
}


/**
* detects the installed flash version of the client
* @return pluginVer version of installed flash plugin;
*/		
function get_flashversion(){
		var latestpluginVer = 15;
		var agent = navigator.userAgent.toLowerCase(); 
		
		if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) { 
			pluginVer = 0; 
			return pluginVer
		}
		// NS3+, Opera3+, IE5+ Mac:  check for plugIn in plugin array
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			var flashPlugin = navigator.plugins['Shockwave Flash'];
			if (typeof flashPlugin == 'object') { 
				for (var i = latestpluginVer; i >= 3; i--) {
		            if (flashPlugin.description.indexOf(i + '.') != -1) {
		               pluginVer = i; break;
		            }
				
	            }
				return pluginVer;
			}
		}
		// IE:  already attempted to create an ActiveX object using VBScript
		else if (ie) { }
			
		else { pluginVer = unknown_pluginVer; return pluginVer; }
}



/**
* diverse functions for setting special attributes to a node.
* @param elem name of node
* @param attr kind of attribute
* @param value attribute value
*/
function set_attr(elem, attr, value) {			var myNode = elem; myNode.setAttribute(attr, value ); }
function set_href(elem, url) {					var myNode = elem; myNode.setAttribute("href",url );  }
function set_title(elem, title) {				var myNode = elem; myNode.setAttribute("title", title ); }
function set_width(elem, width) {				var myNode = elem; myNode.setAttribute("width", width ); }
function set_height(elem, height) {				var myNode = elem; myNode.setAttribute("height", height ); }

/**
* sets a textnode to a parent node.
* @param par name of parent
* @param text value of title
*/		
function set_textNode(par, text) {
	if (!document.createTextNode) return false;
 	var myNode = par; myNode = document.createTextNode(text); }

/**
* creates a flash object.
* @param width width of flash movie
* @param height height of flash movie
* @param path path of flash movie
* @return myObject Flashobject with attributes;
*/		
 function create_object(width, height, path ) {
	if (!document.createElement) return false;
 	var myObject 	= document.createElement("object");
	set_attr(myObject, "type", "application/x-shockwave-flash") ;
	set_attr(myObject, "data", path) ;
	set_attr(myObject, "width", width) ;
	set_attr(myObject, "height", height) ;
	return myObject;
}

/**
* creates a param tag.
* @param path path of flash movie
* @return myObject Flashobject with attributes;
*/		
function create_param(path) {
	if (!document.createElement) return false;
 	var myParam 	= document.createElement("param");
	set_attr(myParam, "name", "movie") ;
	set_attr(myParam, "value", path) ;
	return myParam;
}


/**
* creates the markup for embedding a flashmovie 
* @param containerID: id of the parent element
* @param path: path of flash movie
* @param height: height of flash movie
* @param weight: weight of flash movie
*/		

function create_flashobject( containerID,width, height, path ){
	if (!document.getElementById) return false;
	var myMovie = document.getElementById(containerID);
	if (ie){// IE doesn't support the event-module of DOM
			myMovie.innerHTML = '<object  data="/flash/spaziergang/spaziergaenge.swf?path=/flash/spaziergang/spaziergaenge.xml" type="application/x-shockwave-flash" width="356" height="472"><param name="movie" value="/flash/spaziergang/spaziergaenge.swf?path=/flash/spaziergang/spaziergaenge.xml"></object>';
	}else{
		if (document.getElementById( containerID )){
			myObject 	= create_object(width, height, path);
			myParam 	= create_param(path);
			myMovie.appendChild(myObject);
			myObject.appendChild(myParam);
		}
	}
}

function remove_allchildren( containerID ){
	if (!document.getElementById) return false;
	var myParent 	= document.getElementById(containerID);
    var myChildren 	= myParent.childNodes;   
    var numChildren = myChildren.length; 
    for(var i = numChildren-1; i >= 0; i--) {  
        var c = myParent.removeChild(myChildren[i]); 
    }
}

function change_style( containerID ){
	if (!document.getElementById) return false;
	var myContainer	= document.getElementById(containerID);
    myContainer.style.padding="0px";
	myContainer.style.background="transparent";
}


/**
* creates a link with title, url, id and onclick event.
* @param txt link text
* @param ltitle link title
* @param url  link destination
* @param id  value of link id
* @param onclick  value of onclick-attribute
* @return link element (a);
*/			
function create_link(ltitle, url, id, onclick ) {
 	var myNode = document.createElement("a");
	set_title(myNode, ltitle);
	set_href(myNode, url) ;
	set_attr(myNode, "id", id) ;
	set_attr(myNode, "onclick", onclick); 
	return myNode;}
/**
* creates a print icon with the following attributes: alt, src, width, height and border 
*/			





/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* loaded events  */

function create_flashbox(){
	width="356px"; height="472px"; path="/flash/spaziergang/spaziergaenge.swf?path=/flash/spaziergang/spaziergaenge.xml"; containerID="flashBox";
	/*if (pluginlist.indexOf("Flash")==-1) return false; old version of flash detection see F2N 
	project documentation for more information*/
	if(!ie) pluginVer = get_flashversion();
	if (pluginVer>=6){
	var myContainer = document.getElementById(containerID);
	if (document.getElementById(containerID)){
		remove_allchildren( containerID );
		change_style( containerID );
		create_flashobject(containerID, width, height, path);
	}
	}
}
/*addLoadEvent(get_flashversion);*/
addLoadEvent(create_flashbox);








