function ShowIt(width, height, targetDiv, playerId, videoWidth, videoHeight, stretchVideo, launcherId){
	this.width = width;
	this.height = height;
	this.targetName = targetDiv;
	this.playerId = playerId;
	this.wmode = 'window';
	this.videoWidth = videoWidth;
	this.videoHeight = videoHeight;
	this.stretchVideo= stretchVideo;
	this.startControl = launcherId == undefined ? null : launcherId;
	if(launcherId == null){
		initialize(this);
	}
	else{
		initializeLauncher(this);
	}
}

function setWmode(aWmode){
	with(this) this.wmode = aWmode;
}

ShowIt.prototype.setWmode = setWmode;

//the Property holder
var theShowIt;
//the existing div the player is attached to
var theHolder;
//the created div the flash is attached to
var thePlayer;



var lastState = "";

function initialize(showIt){
	theShowIt = showIt;
	window.addEvent('domready', function(){
		load(theShowIt);
	});
	if(window.ie){
		window.addEvent('unload', function(){
			unload(theShowIt);
		});
	}
}

/**
	initialize function if a launcher id is defined
*/
function initializeLauncher(showIt){
	theShowIt = showIt;
	$(theShowIt.startControl).addEvent('click', loadEvent);
	if(window.ie){
		$(theShowIt.startControl).style.cursor='hand';
	}
	else{
		$(theShowIt.startControl).style.cursor='pointer';
	}
	if(window.ie){
		window.addEvent('unload', function(){
			unload(theShowIt);
		});
	}
}


function unload(showIt){
	if(theHolder != undefined){
		theHolder.parentNode.removeChild(theHolder);
	}
}

function loadEvent(e){
	$(theShowIt.startControl).style.visibility = "hidden";
	load(theShowIt);
}

function load(showIt){
	theHolder = document.getElementById(showIt.targetName);
	if(theHolder == undefined){
		alert('SHOW_IT_ERROR: ' + showIt.targetName + ' is not defined');
		return;
	}
	if(document.getElementById(showIt.playerId) != undefined){
		alert('SHOW_IT_ERROR: ' +'cannot create ' + showIt.playerId +', id already in use, choose a different player-id');
		return;
	}
	/*$(showIt.targetName).setStyles({
	   position:'absolute',
	   padding:0,
	   margin:0,
	   zIndex:100,
	   display:'block'
	});*/
	//theHolder.style.position='absolute';
	//theHolder.style.top= showIt.y + 'px';
	thePlayer = document.createElement('div');
	var idAttribute = document.createAttribute('id');
	idAttribute.nodeValue = showIt.playerId;
	thePlayer.setAttributeNode(idAttribute);
	document.getElementById(showIt.targetName).appendChild(thePlayer);
	
	$(showIt.playerId).setStyles({
	   position:'relative',
	   padding:0,
	   margin:0,
	   border:'none',
	   width: showIt.width,
	   height:showIt.height,
	   zIndex:100,
	   display:'block'
	});
	$(showIt.targetName).setStyles({
	   padding:0,
	   margin:0,
	   border:'none',
	   width: showIt.width,
	   height:showIt.height,
	   zIndex:100,
	   display:'block'
	});
	if(configPath.indexOf("?") > 0){
		configPath = configPath + "$forcedWidth=";
	}
	else{
		configPath = configPath + "?forcedWidth=";
	}
	configPath = configPath + showIt.videoWidth + "$forcedHeight=" + showIt.videoHeight + "$keepFormat=" + showIt.stretchVideo;
	var browser;
    if(window.ie){
        browser = "msie";
    }
    else if(window.gecko){
        browser = "firefox";
    }
    else if(window.webkit){
        browser = "safari";
    }
	var so = new SWFObject(swfBase + "showIt.swf", "flashMovie", showIt.width, showIt.height,"9.0.115");
			try {
            	so.useExpressInstall('http://iptv.cdn.tv1.de/iptv/swf/expressinstall.swf');
        	}
        	catch(e){}
			so.addParam("menu","false");
			so.addParam("wmode",showIt.wmode); // transparent, opaque <- nicht bei allowFullScreen=true
			so.addParam("quality","high");
			so.addParam("swLiveConnect","true");		
			so.addParam("allowFullScreen", "true");
			so.addParam("scaleMode", "showall");
			so.addParam("allowScriptAccess","always");
			so.addVariable("plugin_version", "9.0.115");
			if(configPath){
				so.addVariable("configXml",configPath );
			}
			if(bandwidthPath){
				so.addVariable("bandwidthPath",bandwidthPath);
			}
			so.addVariable("homePage", window.location.href);
			so.addVariable("domain", document.domain);
			so.addVariable("browser", browser);	
			so.addVariable("debug", "true");			
			so.addVariable("swfBase", swfBase);
			so.write(showIt.playerId);
	
	if (!window.ie && ! window.gecko) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = function(e){
		
		var flashMovie = getFlashMovieObject("flashMovie");
		var isAllowed = false;
		if(window.opera) isAllowed = true;
		else{
			isAllowed = flashMovie.onMouseMovedOutside != undefined;
		}
		if(isAllowed){
			var pos = getMouseXY(e);
			var mX = pos[0];
			var mY = pos[1];	
			var aWidth = thePlayer.style.width;
			aWidth = aWidth.substr(0, aWidth.length -2);
			var width = parseInt(aWidth);
			var aHeight = thePlayer.style.height;
			aHeight = aHeight.substr(0, aHeight.length -2);
			var height = parseInt(aHeight);
			var playerRect = new Object();
			var pX = getPlayerDX();
			pX = pX.substr(0, pX.length -2);
			var pY = getPlayerDY();
			pY = pY.substr(0, pY.length -2);
			playerRect.x = parseInt(pX);
			playerRect.y =  parseInt(pY);
			playerRect.width = width;
			playerRect.height = height;
			
			var newState = (containsCoordinates(playerRect, mX, mY))?"in" : "out";
			if(lastState != newState){
				lastState = newState;
				if(lastState == "out"){
					flashMovie.onMouseMovedOutside();
				}
			}
		}		
	}
}

function containsCoordinates(rectangle, x,y){
	if(x < rectangle.x) return false;
	if(x > rectangle.x + rectangle.width) return false;
	if(y < rectangle.y) return false;
	if(y > rectangle.y + rectangle.height) return false;
	
	return true;
}

function onMouseMovedInside(){
	lastState = "in";
}

function debug(message){
	if(document.getElementById("debugger")){
		document.getElementById("debugger").innerHTML += message;
		document.getElementById("debugger").innerHTML += '<br/>';
	}
}

function resizePlayer(width, height, callback){
	thePlayer.style.width = width + 'px';
	thePlayer.style.height = height + 'px';
}

function setForcedDimension(width, height){
	theHolder.style.width = width + 'px';
	theHolder.style.height = height + 'px';
	thePlayer.style.width = width + 'px';
	thePlayer.style.height = height + 'px';
	document.getElementById('flashMovie').style.width = width + 'px';
	document.getElementById('flashMovie').style.height = height + 'px';
}

function slideOut(e){
	//not implemented
}

function getMouseXY(e) {
  if (window.ie) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}  
  var res = new Array();
  res[0] = tempX;
  res[1] = tempY;
  return res;
}

function getAvailableWidth(){
	if(!window.ie){
		var dWidth = top.window.outerWidth - top.window.innerWidth;
		return top.screen.availWidth - dWidth;
	}
	else{
		return top.screen.availWidth;
	}
}

function getPlayerDX(){
	return theHolder.style.left;
}

function getPlayerDY(){
	return theHolder.style.top;
}

function pageWidth() {
	var res = window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?  
	     document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
	return res;
}
function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  
	document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function posLeft() {
		return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
	}
	
function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
function posRight() {
	return posLeft()+pageWidth();
}
function posBottom() {
	return posTop()+pageHeight();
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (!window.ie)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}