var positionX=30;
var positionY=0;

var dymek=null; 

function posX() {
	return tempX;
	
	var X;
	if (ie) {
	   X=document.body.scrollLeft + event.clientX;
	}
	if (X<0) {
	   X=0;
	}
	return X;
}

function posY(e) {
	return tempY;
	
	var Y;
	if (ie) {
	    Y = event.clientY + document.body.scrollTop;
	}
	if (Y<0) {
	   Y=0;
	}
	return Y;
}

function dymekPokaz(pX, pY, text, title) {
	if (dymek==null)
		dymek=new getObj('preview');
	
	dymek.style.visibility='visible';
	dymek.style.display='block';
	
	if (text!="") {
		film=new getObj('prev_film');
		
		// dymek.style.left=tempX+pX+"px";
		// dymek.style.top=tempY+pY+"px";
		
		if (film.obj!=null)
			film.obj.innerHTML=text;
	}
	
	titleObj=new getObj('prev_center');
	if (titleObj.obj!=null)
		titleObj.obj.innerHTML=title;
	
	
    

}

function dymekPrzesun(pX, pY) {
	if (dymek==null)
		dymek=new getObj('preview');
  
	dymek.style.left=tempX+pX+"px";
	dymek.style.top=tempY+pY+"px";

}

function dymekZamknij() {
	if (dymek==null)
		dymek=new getObj('preview');
		
  dymek_wewn=new getObj('prev_film');
	
	dymek_wewn.obj.innerHTML='&nbsp;';
	dymek.style.display='none';
  
	/*
  //dymek_wewn=new getObj('prev_film');
	
	dymek.style.visibility='hidden';
	
	//dymek.style.display='none';
	
	sendEvent('player','stop');
	
	//so.addVariable('file','');
	
	//sendEvent('player','playpause');
	
	//dymek_wewn.obj.innerHTML='';
  */
}

var deb=0;

function dymekInit(file) {
  //alert(file);
	if (file == null)
    file = '';
  
	// var so = new SWFObject('http://dvdkaraoke.pl/myplayer.swf','player','320','260','8');
	var so = new SWFObject('myplayer.swf','player','320','260','8');
	//so.addParam("allowfullscreen","true");
	so.addParam("allowfullscreen", "false");
	so.addParam("allowscriptaccess", "always");
	so.addParam("bgcolor", "#000000");
	so.addVariable('file', file);
	so.addVariable('linkfromdisplay', 'true');
	so.addVariable('lightcolor', '0x0099CC');
	so.addVariable("width", "320");
	//so.addVariable("height","240");
	
	so.addVariable("autostart", "true");
	so.addVariable("showstop", "true");
	
	so.addVariable('javascriptid', 'player');
	so.addVariable('enablejs', 'true');
	//so.addVariable("bufferlength","15");
	so.addVariable("bufferlength", "5");
	so.write('prev_film');

	
	//dymekPokaz(positionX, positionY, text, title);
	
	
	// TO CENTER A DIV 
	var pos=get('preview');
	var arrPos=CalculateCenter(pos['width'], pos['height']);
	//var arrPos=CalculateCenter(0, 0);
	positionX=arrPos[0];
	positionY=arrPos[1];
	set('preview',positionX, positionY);
	
}

function dymekInit2() {
	var text="";
	var so = new SWFObject('http://dvdkaraoke.pl/mediaplayer.swf','player2','320','260','8');
	//so.addParam("allowfullscreen","true");
	so.addParam("allowfullscreen","false");
	so.addParam("allowscriptaccess", "always");
	so.addParam("bgcolor","#000000");
	so.addVariable('file','');
	so.addVariable('linkfromdisplay','true');
	so.addVariable('lightcolor','0x0099CC');
	so.addVariable("width","320");
	//so.addVariable("height","240");
	
	so.addVariable("autostart","true");
	so.addVariable("showstop","true");
	
	so.addVariable('javascriptid','player2');
	so.addVariable('enablejs','true');
	//so.addVariable("bufferlength","15");
	so.addVariable("bufferlength","5");
	so.write('prev_film2');

}

/* 
	
	var plik=url.split('/');
	plik=plik[plik.length-1];
	var link_new_window=new getObj('prev_new_window');
	//link_new_window.obj.href=Host+"/?show=preview&plik="+plik;
	link_new_window.obj.href=Host+"/prev/"+plik;
	
  	dymekPokaz(positionX, positionY, text, title);
	
	
	// TO CENTER A DIV 
	var pos=get('preview');
	var arrPos=CalculateCenter(pos['width'], pos['height']);
	//var arrPos=CalculateCenter(0, 0);
	positionX=arrPos[0];
	positionY=arrPos[1];
	set('preview',positionX, positionY);
} */

function preview(url, title) {
  
  dymekZamknij();
  
    try {
        dymekInit(url);
        //loadFile('player',{file:url});
    } catch (err) {
        alert ("Wystąpił błąd: " + err);
    }
	
	// var plik=url.split('/');
	// plik=plik[plik.length-1];
	
 /*    // TO CENTER A DIV 
	CenterDiv('preview'); */
    
  	dymekPokaz(positionX, positionY, "", title);

    // TO CENTER A DIV 
	CenterDiv('preview');
/* 
     	// TO CENTER A DIV 
	var pos=get('preview');
	var arrPos=CalculateCenter(pos['width'], pos['height']);
	//var arrPos=CalculateCenter(0, 0);
	positionX=arrPos[0];
	positionY=arrPos[1];
	set('preview',positionX, positionY); */
}

function CenterDiv(id) {
    var pos=get(id);
	var arrPos=CalculateCenter(pos['width'], pos['height']);
	//var arrPos=CalculateCenter(0, 0);
	positionX=arrPos[0];
	positionY=arrPos[1];
	set('preview',positionX, positionY);

}

function dymekLinkPrzesun() {
	dymekPrzesun(positionX, positionY);
}


function dymekSrodekPrzesun() {
	dymekPrzesun(positionX, positionY);
}


var windowState = (function(){
	var readScroll = {scrollLeft:0,scrollTop:0};
	var readSize = {clientWidth:0,clientHeight:0};
	var readScrollX = 'scrollLeft';
	var readScrollY = 'scrollTop';
	var readWidth = 'clientWidth';
	var readHeight = 'clientHeight';
	
	function otherWindowTest(obj){
		if	((document.compatMode)&&
			(document.compatMode == 'CSS1Compat')&&
			(document.documentElement)) {
				return document.documentElement;
		}
		else if(document.body){
			return document.body;
		}
		else{
			return obj;
		}
	};
	
	if ((typeof this.innerHeight == 'number')&&
	(typeof this.innerWidth == 'number')) {
		readSize = this;
		readWidth = 'innerWidth';
		readHeight = 'innerHeight';
	}
	else {
		readSize = otherWindowTest(readSize);
	}
	
	if ((typeof this.pageYOffset == 'number')&&
	(typeof this.pageXOffset == 'number')) {
		readScroll = this;
		readScrollY = 'pageYOffset';
		readScrollX = 'pageXOffset';
	}
	else{
		readScroll = otherWindowTest(readScroll);
	}
	
	return {
		getScrollX:function(){
		return (readScroll[readScrollX]||0);
		},
		getScrollY:function(){
			return (readScroll[readScrollY]||0);
		},
		getWidth:function(){
			return (readSize[readWidth]||0);
		},
		getHeight:function(){
			return (readSize[readHeight]||0);
		}
	};
	
	})();
	
	
// http://www.thescripts.com/forum/thread90674.html
function CalculateCenter(divWidth, divHeight) {
	//alert(divWidth+","+divHeight);

// The effect of including this script is that a global property with the
// name "windowState" is assigned an object that has 4 methods that will
// tell you what you need to know about the viewport/window:-

	var viewPortWidth = windowState.getWidth();
	var viewPortHeight = windowState.getHeight();
	var horizontalScroll = windowState.getScrollX();
	var verticalScroll = windowState.getScrollY();

// That script covers a very wide range of browsers (all that I have
// sufficient details of) but, like any JavaScript, it is possible that it
// will encounter a browser so unusual that it just will not work. In that
// event it defaults to returning zero for all values. It is always
// possible that the real (and accurately reported) value for the viewport
// dimensions are zero so you might want to test for that possibility and
// just place the DIV at the page's 0,0 co-ordinates as a fall-back
// position.

// The horizontal position of the DIV would be calculated as:-

	var hPos = Math.round(horizontalScroll+((viewPortWidth-divWidth)/2));

// And vertical as:-

	var vPos = Math.round(verticalScroll+((viewPortHeight-divHeight)/2));

// - but either value may come out less than zero in which case it should
// probably be defaulted to zero:-

	hPos = (hPos < 0)?0:hPos;
	vPos = (vPos < 0)?0:vPos;
	
	return [hPos, vPos];
}

var mp3_base_url;

function mp3(id, file) {
	
	var so = new SWFObject('play.swf','mp3_'+id,'20','20','8');
	so.addParam("allowScriptAccess", "always");
	so.addParam("wmode","transparent");
	so.addParam("bgcolor","#ffffff");
//	alert(mp3_base_url+file);
	so.addVariable('theFile',mp3_base_url+file);
	//so.addVariable("bufferlength","15");
	so.write('td_'+id);
	
};


// ==============  FROM http://www.jeroenwijering.com/?item=Javascript_interaction ===================

function sendEvent(swf,typ,prm) { 
	thisMovie(swf).sendEvent(typ,prm);
};

function getUpdate(typ,pr1,pr2,swf) {};

function thisMovie(swf, debug) {
	if (debug)
		alert('thisMovie: '+swf);
		
	if (navigator.appName.indexOf("Microsoft") != -1) {
		if (debug)
			alert("window["+swf+"]:"+ window[swf]);
		return window[swf];
	} 
	else {
		if (debug) {
			alert("document["+swf+"]:"+document[swf]);
			alert("document["+swf+"].loadFile:"+document[swf].loadFile);
      alert('return document.getElementById(swf);' + document.getElementById(swf));
		}	
    return document.getElementById(swf);
	}
};

function getUpdate(typ,pr1,pr2,swf) { 
	//alert('typ: '+typ+', pr1:'+pr1+', pr2:'+pr2+', swf:'+swf);
	// if (typ == 'state') { 
		// alert('The current state is: '+pr1); 
	// }
};

function loadFile(swf,obj, debug) {
	thisMovie(swf, debug).loadFile(obj);
};

