function ShowIt(x, y, width, height, targetDiv, playerId, launcherId){
	this.width = width;
	this.height = height;
	this.x = x;
	this.y = y;
	this.targetName = targetDiv;
	this.playerId = playerId;
	this.wmode = 'window';
	this.slideDuration = 1000;
	this.sliding = true;
	this.config = "";
	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;

function attachSlideInButton(buttonId){
	with(this) this.buttonId = buttonId;
	$(this.buttonId).style.visibility = 'hidden';
}

ShowIt.prototype.attachSlideInButton = attachSlideInButton;

function setConfig(configPath){
	with(this) this.config = configPath;
}

ShowIt.prototype.setConfig = setConfig;

function createSlideInButton(buttonId, styleObj, buttonText){
	with(this) this.buttonId = buttonId;
	with(this) this.buttonStyle = styleObj;
	with(this) this.createButton = true;
	with(this) this.buttonText = buttonText;
}

ShowIt.prototype.createSlideInButton = createSlideInButton;

function disableSliding(){
	with(this) this.sliding = false;
}

ShowIt.prototype.disableSliding = disableSliding;

function setSlideDuration(duration){
	if(duration > 0){
		with(this) this.slideDuration = duration;
	}
}

ShowIt.prototype.setSlideDuration = setSlideDuration;

//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;
//the Button for slideIn
var theButton;

var mySlide;


var lastState = "";

/**
	standard initialize function
*/
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){
	var theX = getAbsoluteX(document.getElementById("testerich"));
	var theY = getAbsoluteY(document.getElementById("testerich"));
	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;
	}
	theHolder.style.position = 'absolute';
	theHolder.style.zIndex = 100;
	theHolder.style.display = 'block';
	/*$(showIt.targetName).setStyles({
	   position:'absolute',
	   padding:0,
	   margin:0,
	   zIndex:100,
	   display:'block'
	});*/
	//theHolder.style.position='absolute';
	//theHolder.style.top= showIt.y + 'px';
	if(typeof showIt.x == 'number'){
		theHolder.style.left= showIt.x + 'px';
	}
	theHolder.style.top= showIt.y + 'px';
	if(showIt.createButton){
		var buttonName = showIt.buttonId;
		if(document.getElementById(buttonName) != undefined){
			alert('SHOW_IT_ERROR: ' +'cannot create ' + buttonName +', id already in use, choose a different player-id');
			return;
		}
		theButton = document.createElement('div');
		var targetDiv = document.getElementsByTagName("body")[0];
		var idAttribute = document.createAttribute('id');
		idAttribute.nodeValue = buttonName;
		theButton.setAttributeNode(idAttribute);
		var buttonStyle = showIt.buttonStyle;
		theButton.innerHTML = showIt.buttonText;
		targetDiv.appendChild(theButton);
		$(showIt.buttonId).setStyles(buttonStyle);
		setupButton();
	}
	else if(showIt.buttonId){
		if(document.getElementById(showIt.buttonId) == undefined){
			alert('SHOW_IT_ERROR: ' + showIt.buttonId + ' is not defined');
			return;
		}
		theButton = document.getElementById(showIt.buttonId);
		setupButton();
	}
	thePlayer = document.createElement('div');
	var idAttribute = document.createAttribute('id');
	idAttribute.nodeValue = showIt.playerId;
	thePlayer.setAttributeNode(idAttribute);
	if(showIt.sliding){
		mySlide = new Fx.SlideAbs(showIt.targetName, {mode:'horizontal', duration: showIt.slideDuration});
	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'
	});
	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");
	//var so = new SWFObject("http://192.168.1.104:8080/iptv/swf/xflv/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", "8.0.22");
			if(showIt.config != ""){
				so.addVariable("configXml",showIt.config);
			}
			else 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.setAttribute("style"," ");
			so.write(showIt.playerId);
	}
	if(typeof showIt.x == 'string'){
		if(showIt.x == "center"){
			optimizePosition();
			window.onresize= optimizePosition;
		}
	}
	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 playerRect = getPlayerRect();
			var newState = (containsCoordinates(playerRect, mX, mY))?"in" : "out";
			if(lastState != newState){
				lastState = newState;
				if(lastState == "out"){
				    try{
						flashMovie.onMouseMovedOutside();
					}
					catch(e){
					}
				}
			}
		}		
	}
	hideAllOverlappingElements();
}

function hideAllOverlappingElements(){
	var objects = document.getElementsByTagName("object");
	hideOverlappingElements(objects);
	var embeds = document.getElementsByTagName("embed");
	hideOverlappingElements(embeds);
	var version=parseFloat(navigator.appVersion);
	if(window.ie && version < 7){
		var selects = document.getElementsByTagName("select");
		hideOverlappingElements(selects);
	}
}

function showAllOverlappingElements(){
	var objects = document.getElementsByTagName("object");
	showOverlappingElements(objects);
	var embeds = document.getElementsByTagName("embed");
	showOverlappingElements(embeds);
	var version=parseFloat(navigator.appVersion);
	if(window.ie && version < 7){
		var selects = document.getElementsByTagName("select");
		showOverlappingElements(selects);
	}
	/*for(var i = 0; i < theShowIt.hiddenElements.length; i++){
		var id = theShowIt.hiddenElements[i].key;
		var target = document.getElementById(id);
		target.innerHTML = theShowIt.hiddenElements[i].value;
	}*/
	
}

function getPlayerRect(){
	var playerRect = new Object();
	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 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;
	return playerRect;
}

function showOverlappingElements(elementArray){
	for(var i = 0; i < elementArray.length; i++){
		var element = elementArray[i];
		if(element.id != "flashMovie" && element.parentNode != thePlayer){
			element.style.visibility = "visible";
		}
	}
}

function hideOverlappingElements(elementArray){
	var playerRect = getPlayerRect();
	for(var i = 0; i < elementArray.length; i++){
		var element = elementArray[i];
		if(element.id != "flashMovie" && element.parentNode != thePlayer){
			var x0 = getAbsoluteX(element);
			var y0 = getAbsoluteY(element);
			var x1 = x0 + element.clientWidth;
			var y1 = y0 + element.clientHeight;
			var hide = false;
			if(containsCoordinates(playerRect, x0, y0)){
				hide = true;
			}
			if(! hide){
				if(containsCoordinates(playerRect, x0, y1)){
					hide = true;
				}
			}
			if(!hide){
				if(containsCoordinates(playerRect, x1, y0)){
					hide = true;
				}
			}
			if(!hide){
				if(containsCoordinates(playerRect, x1, y1)){
					hide = true;
				}
			}
			if(hide){
				/*if(element.parentNode.id.indexOf('hide') == 0){
					var obj = new Object();
					obj.key = element.parentNode.id;
					obj.value = element.parentNode.innerHTML;
					theShowIt.hiddenElements[theShowIt.hiddenElements.length] = obj;
					element.parentNode.innerHTML = '';
					
				}
				else{*/
				element.style.visibility = "hidden";
				//}
			}
			else{
				element.style.visibility = "visible";
			}
		}
	}
}

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 optimizePosition() {
	var optimizedPos = null;
	var containerWidth;
	if(thePlayer.style.width == ""){
		containerWidth = theShowIt.width;
	}
	else{
		var theWidth = thePlayer.style.width;
		var idx = theWidth.indexOf('px');
		theWidth = theWidth.substring(0,idx);
		containerWidth = parseInt(theWidth);
	}
	var availWidth = (window.innerWidth) ? window.innerWidth : (window.document.body.offsetWidth) ? window.document.body.offsetWidth : containerWidth;
	availWidth = Math.max(availWidth, containerWidth);
	
	optimizedPos = ((availWidth - containerWidth) /2)+ 'px';
	theHolder.style.left = optimizedPos;
	hideAllOverlappingElements();
}

function setupButton(){
	$(theShowIt.buttonId).addEvent('click', slideIn);
	if(window.ie){
		theButton.style.cursor='hand';
	}
	else{
		theButton.style.cursor='pointer';
	}
	//theButton.style.display = 'none';
	$(theShowIt.buttonId).style.visibility = 'hidden';
}

function debug(message){
	if(document.getElementById("debugger")){
		document.getElementById("debugger").innerHTML += message;
		document.getElementById("debugger").innerHTML += '<br/>';
	}
}




function resizePlayer(width, height, callback){
	document.getElementById('flashMovie').style.width = width + 'px';
	document.getElementById('flashMovie').style.height = height + 'px';
	thePlayer.style.width = width + 'px';
	thePlayer.style.height = height + 'px';
	if(callback){
		if(getFlashMovieObject("flashMovie").onResized){
			getFlashMovieObject("flashMovie").onResized();
		}
	}
	if(typeof showIt.x == 'string'){
		if(showIt.x == "center"){
			optimizePosition();
		}
	}
	hideAllOverlappingElements();
}



function slideIn(e){
	var flashMovie = getFlashMovieObject("flashMovie");
	if(window.opera){
        thePlayer.style.visibility='visible';
        theHolder.style.visibility='visible';
    }
	if(flashMovie.onJSSlideIn){
		flashMovie.onJSSlideIn();
	}
	$(theShowIt.buttonId).style.visibility = 'hidden';
	
	e = new Event(e);
	mySlide.slideIn();
	if(e != null){
		e.stop();	
	}
	setTimeout("hideAllOverlappingElements()", theShowIt.slideDuration);
}

function slideOut(e){
	if(theShowIt.sliding){
		if(window.opera){
			thePlayer.style.visibility='hidden';
			theHolder.style.visibility='hidden';
			showButton();
			return;
		}
		setTimeout("showButton()", theShowIt.slideDuration);
		if(e == null){		
			e = new Event(e);
		}	
		mySlide.slideOut();	
		if(e != null){
			e.stop();
		}
	}
}

function showButton(){
	$(theShowIt.buttonId).style.visibility = 'visible';
	showAllOverlappingElements();
}

function getPlayerDX(){
	return getAbsoluteX(theHolder);
}

function getPlayerDY(){
	return getAbsoluteY(theHolder);
}

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 getAbsoluteX(element){
	if(! element){
		return -1;
	}
	var curleft = 0;
	if(element.offsetParent){
		while(1){
			curleft += element.offsetLeft;
          	if(!element.offsetParent)
            	break;
			element = element.offsetParent;
		}
	}
	else if(element.x){
		curleft += element.x;
		return curleft;
	}
	return curleft;
}

function getAbsoluteY(element){
	if(! element){
		return -1;
	}
	var curtop = 0;
	if(element.offsetParent){
		while(1){
			curtop += element.offsetTop;
          	if(!element.offsetParent)
            	break;
			element = element.offsetParent;
		}
	}
	else if(element.y){
		curtop += element.y;
		return curtop;
	}
	return curtop;
}

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);
  }
}