function removeElement(id, kulsoid) {
	var d = document.getElementById(kulsoid);
	var olddiv = document.getElementById(id);
	d.removeChild(olddiv);
}

function play(media, id, kulsoid, width, height, aktnum, vidnum) {

	document.getElementById('video_akt_szam'+aktnum).innerHTML = vidnum;

	id = id + aktnum;
	kulsoid = kulsoid + aktnum;

	removeElement(id, kulsoid);

	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",id);

	document.getElementById(kulsoid).appendChild(newdiv);


	var type = media.substring(media.lastIndexOf('.') + 1, media.length);

	if(type=="avi" || type=="mpg" || type=="wmv") {

		document.getElementById(id).innerHTML=
			'<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
			+'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
			+'type="application/x-oleobject" width="'+width+'" height="'+height+'">'
			+'<param name="showcontrols" value="true">'
			+'<param name="filename" value="'+media+'">'
			+'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="'+width+'" height="'+height+'" src="'+media+'" showcontrols=1><\/embed><\/object>';
	}

	if(type=="mov") {

		document.getElementById(id).innerHTML=
			'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
			+'codebase="http://www.apple.com/qtactivex/qtplugin.cab"'
			+'width="'+width+'" height="'+height+'">'
			+'<param name="controller" value="true">'
			+'<param name="filename" value="'+media+'">'
			+'<embed pluginspage="http://www.apple.com/quicktime/download/" width="'+width+'" height="'+height+'" src="'+media+'" controller="true"><\/embed><\/object>';
	}

	if(type=="flv") {

		var flashvars = {
			file: "../"+media,
			autostart: "true",
			backcolor: "8d0606", //vezérlő háttere
			frontcolor: "ffffff", //gombok színei
			lightcolor: "d00302", //csúszka színe
			screencolor: "000000" //előtér színe
		}

		var params = {
			allowfullscreen: "true", 
			allowscriptaccess: "always"
		}

		var attributes = {}

		swfobject.embedSWF("js/player.swf", id, width, height, "9.0.115", false, flashvars, params, attributes);
	}
}

var player = null;

function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
}

function stopflash() {
	if(player != undefined) {
		player.sendEvent('STOP');
	}
}

function play_galeria(media, width, height, popup_id, sorsz) {

	document.getElementById(popup_id+"_sorsz_ment").value = sorsz;

	gal_select(popup_id, sorsz);
	
	var flashvars = {
		file: "../"+media,
		autostart: "true",
		backcolor: "626061", //vezérlő háttere
		frontcolor: "ffffff", //gombok színei
		lightcolor: "383838", //csúszka színe
		screencolor: "000000" //előtér színe
	}

	var params = {
		allowfullscreen: "true", 
		allowscriptaccess: "always"
	}

	var attributes = {}


	id = 'mediaplayer' + popup_id;

	swfobject.embedSWF("js/player.swf", id, width, height, "9.0.115", false, flashvars, params, attributes);
}

function teker(merre, popup_id, width, height) {

	img_ment = document.getElementById(popup_id+"_img_ment").value;
	sorsz_ment = document.getElementById(popup_id+"_sorsz_ment").value;
	total = document.getElementById(popup_id+"_total_ment").value;

	if(img_ment.indexOf(" | ") > "-1") {

		myArray = img_ment.split(' | ');

		if(merre == "e") { // előre
			if(sorsz_ment != total) {
				sorsz = parseInt(sorsz_ment) + 1;

				aktimg = myArray[sorsz-1];
			}

			else {
				sorsz = 1;

				aktimg = myArray[0]; // első elem
			}
		}

		else { // vissza
			if(sorsz_ment > 1) {
				sorsz = parseInt(sorsz_ment) - 1;

				aktimg = myArray[sorsz-1];
			}

			else {
				sorsz = total;

				aktimg = myArray[total-1]; // utolsó elem
			}
		}
	}

	else {
		aktimg = img_ment;
		sorsz = 1;
	}

	gal_delselect(popup_id);

	play_galeria("admin/upload/galeria/videos/" + aktimg + ".flv", width, height, popup_id, sorsz);
}

function gal_delselect(popup_id) {
	sorsz_ment = document.getElementById(popup_id+"_sorsz_ment").value;

	document.getElementById(popup_id+"_"+sorsz_ment).style.borderColor = '#000000';
}

function gal_select(popup_id, sorsz) {

	gal_delselect(popup_id);

	document.getElementById(popup_id+"_"+sorsz).style.borderColor = '#ffcc00';

	document.getElementById('video_akt_szam'+popup_id).innerHTML = sorsz;

	sorsz_ment = sorsz;
}

function gal_over(m) {
	if(RGBtoHex(m.style.borderColor) != '#ffcc00') {
		m.style.borderColor = '#ffffff';
	}
}

function gal_out(m) {
	if(RGBtoHex(m.style.borderColor) != '#ffcc00') {
		m.style.borderColor = '#000000';
	}
}

function RGBtoHex(color) {
	color = color.toLowerCase();

	if(color.substring(0,1) != "#") { // ha RGB
		color = color.replace("rgb(", "");
		color = color.replace(")", "");
		color = color.replace(" ", "");

		szinek = color.split(",");

		hex = "#" + toHex(szinek[0])+toHex(szinek[1])+toHex(szinek[2]);

		return hex.toLowerCase();
	}

	else {
		return color;
	}
}

function toHex(N) {
	if (N==null)
		return "00";

	N=parseInt(N);
	
	if (N==0 || isNaN(N))
		return "00";

	N=Math.max(0,N);
	N=Math.min(N,255);
	N=Math.round(N);

	return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}