	var removed = true;
	
	function obj_selected( id ) {
		$("#list li").css("color", "");
		$("#li"+id).css("color", "#ff0000");
	}
	
	// FLV-Player //
	function FLVPlayer( flv, id ) {
		if(removed) {
			cPlayer();
			removed = false;
		}
		flowplayer("flvPlayer", "flowplayer-3.2.1/flowplayer-3.2.1.swf", { 
			clip: {
				autoBuffering: true,
				scaling: 'orig',
				url: flv
			},
			plugins: {
				controls: {
					stop: true,
					playlist: true
				}
			}
		});
		obj_selected(id);
	}
	function cPlayer() {
		var elem = document.createElement("DIV");
		document.getElementById("flvPlayerBox").appendChild(elem);
		elem.id = "flvPlayer";
	}
	function rPlayer() {
		document.getElementById("flvPlayerBox").removeChild(document.getElementById("flvPlayer"));
		removed = true;
	}
	// END //
	
	// MP3-Player //
	function MP3Player( mp3, id ) {
		//alert(mp3);
		var elem = document.createElement("DIV");
		document.getElementById("mp3PlayerBox").appendChild(elem);
		elem.id = "mp3Player";
        AudioPlayer.setup("audio-player/player.swf", {  
			width: "100%",
            initialvolume: 75,
            transparentpagebg: "yes",
            left: "000000",
            lefticon: "FFFFFF",
            animation: "no",
			buffer: 2,
            autostart: "yes"
        });
        AudioPlayer.embed("mp3Player", {
            soundFile: mp3
			//titles: "Titolo",
			//artists: "Artista"
			
        });
		obj_selected(id);
	}
	// END //

	// TEXT - Reader //	
    function TXTReader(txt, id) {
		//dataRead( txt );
		//alert(txt);
        $.ajax({
				url: "src/read_file.php",
				type: "GET",
				data: "doc=" + txt,
				dataType: "html",
				success:
					function(response) {
						$("#txtReaderBox").html(response);
					},
				error:
					function() {
						alert("Chiamata fallita!!! ");
					}
			});
		obj_selected(id);		
    }		
	// END //

	// IMAGE - Reader //	
    function IMGReader(img, id) {
		var image = document.getElementById("imgReader");
		image.src = img;
		obj_selected(id);
    }		
	// END //
	
    /*function getScreenWidth() {
		var head = document.getElementById("head");
		var topbox = document.getElementById("top_box");
		var foot = document.getElementById("foot");
        var sW = (screen.width-20) / 12;
        $("#wrapper").css("width", sW+"em");			
		if(screen.height <= 900) {
			$("#list").css("height", "520px");
			$("#flvPlayerBox").css("height", "550px");
			$("#imgReader").css("height", "550px");
		} else if(screen.height > 900) {
			$("#list").css("height", "650px");
			$("#flvPlayerBox").css("height", "680px");
			$("#imgReader").css("height", "680px");
		}
    }*/
	
	function login(arg1) {
		if(!removed) {
			rPlayer();
		}
	   	$("#dialog1").dialog({
			autoOpen: false,
			width: 400,
            height: 270,
            position: ['center', 150],
            show: 'slide',
			title: 'Area Editori :: Login',
			modal: true,
			buttons: {"Annulla": function() { $(this).dialog("close"); },
					  "Login": function()
								{
									var form = document.getElementById("frmLogin");
									//alert(form.user.value);
									//form.submit();
									axLogin(form.user.value, form.pass.value);
						     	}
					 }
		});			
		// Events
        $( "#dialog1" ).dialog({
           beforeclose: function(event, ui)
						{
							var elem = document.getElementById("frmLogin");
							for (i=0; i<elem.length; i++ ) {
								elem[i].value = "";
							}
						}
        });			
        $( "#dialog1" ).dialog({
			close: function(event, ui) {
				if(arg1 === "Video") { FLVPlayer(); }
			}
        });			
		// Metods
    	$("#dialog1").dialog("open");
	}
	
    function axLogin(u, p) {
		$("#frmLoginMsg").html("").show();
        $.ajax({
	            url: "src/cpeditori/login.php",
	            type: "POST",
	            data: "u="+u + "&p="+p,
	            dataType: "html",
	            success: function(response)
							{
								if (response === "1") {
									location.href = "src/cpeditori/admin.php";
								} else if (response === "0") {
									$("#frmLoginMsg").html("utente non autorizzato").fadeOut(5000);
								}
					        },
		        error: function()
							{
								alert("Chiamata fallita!!! ");
				            }
        });
	}
	
	
	/* Start: Data Read Routines */
	/*
	function CreateXmlHttpReq(handler) {
		var xmlhttp = null;
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		//	xmlhttp = new XMLHttpRequest();
		
		xmlhttp.onreadystatechange = handler;
		return xmlhttp;
	}	
	//
	function data_write() {
		if(httpRequest.readyState == 4 && httpRequest.status == 200) {
			document.getElementById("txtReaderBox").innerHTML = httpRequest.responseText;
		}
	}	
	//
	function dataRead( id ) {
		var getStr = "?doc=" + id + "&rand=" + escape(Math.random());
		httpRequest = CreateXmlHttpReq(data_write);
		
		// GET Method
		httpRequest.open("GET", "src/read_file.php" + getStr, true);
		httpRequest.setRequestHeader("connection", "close");
		httpRequest.send(null);
	}
	*/
	/* End: Data Read Routines */


