// ajax
	function createRequestObject() {
	   var req;
	   if(window.XMLHttpRequest){
		  req = new XMLHttpRequest();
	   } else if(window.ActiveXObject) {
		  req = new ActiveXObject("Microsoft.XMLHTTP");
	   } else {
		  req = NULL;
		  alert('Problem to create XMLHttpRequest object');
	   }
	   return req;
	}
    
    var http = createRequestObject();
	
	function sendRequestArtist(s) {
    
       http.open('get', 'inc/artist_titles.php?id='+s);
       http.onreadystatechange = handleResponseArtist;
       http.send(null);
    
    }
    
    function handleResponseArtist() {
    
       if(http.readyState == 4 && http.status == 200){
          if(http.responseText) {
		     document.getElementById("artist").style.display = "block";
             document.getElementById("artist").innerHTML = http.responseText;
          } else {
			 document.getElementById("artist").innerHTML = "";
          }
       } else {
          document.getElementById("artist").innerHTML = "Searching..";
       }
    }
// end ajax	
	
	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("plizr").sendEvent(typ,prm); };
	function getUpdate(typ,pr1,pr2,pid) {
		if(typ == "time") { currentPosition = pr1; }
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
		pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
		
		if(pid != "null") {
			document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
		}
	};

	// These functions are caught by the feeder object of the player.
	function loadFile(obj) { thisMovie("plizr").loadFile(obj); };
	function addItem(obj,idx) { thisMovie("plizr").addItem(obj,idx); }
	function removeItem(idx) { thisMovie("plizr").removeItem(idx); }
	function getItemData(idx) {
		var obj = thisMovie("plizr").itemData(idx);
		var nodes = "";
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}
		nodes = "<h2 style='margin:0'><a href='http://www.plizr.com/clip"+obj['description']+"'>"+obj['title']+"</a></h2>";
		nodes += "<div style='display:block; float:left; width:210px;'><i>"+obj['author']+"</i></a>";
		nodes += "<br>Share url: <input type='text' value='http://plizr.com/clip"+obj['description']+"'>";
		nodes += "<p><a href=\"javascript:sendEvent('prev')\"><img src='/img/btn_prev.png' alt='previous' class='btn_nav'></a><a href=\"javascript:sendEvent('next')\"><img src='/img/btn_next.png' alt='next' class='btn_nav'></a></p></div>";
		nodes += "<div style='display:block; float:right; width:138px;'><img src='http://img.youtube.com/vi/"+obj['link']+"/1.jpg' class='img_bordered'><br>";
		nodes += "<img src='http://img.youtube.com/vi/"+obj['link']+"/2.jpg' class='img_bordered'><br>";
		nodes += "<img src='http://img.youtube.com/vi/"+obj['link']+"/3.jpg' class='img_bordered'></div>";
		sendRequestArtist(obj['description']);	
		document.getElementById("data").innerHTML = nodes;
		
	};

	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};
