function GetXmlHttpObject(handler){
    var objXMLHttp=null
    if (window.XMLHttpRequest){
        objXMLHttp=new XMLHttpRequest()
    }else if (window.ActiveXObject){
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

/* AJAX FUNCTION SECTION */
function home_loadPlaylist(url, qStr, def_vid_id, def_title, def_thumb){
	/*
	if ( qStr !=null ) {
		home_getFile(def_vid_id,def_title,def_thumb);
		return;
	}
	*/
	if (url.length==0){
		document.getElementById("playlist_wrapper").innerHTML=""; 
		return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	      alert ("Browser does not support HTTP Request");
	      return;
	}
			
	if(qStr=='')
		url=url+"?id="+document.getElementById("playlist_wrapper").value;
	else
	 	url=url+"?"+qStr; 
		//url=url+"&sid="+Math.random();
			
	xmlHttp.onreadystatechange=function(){
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			fireMyPopup("playlist_wrapper");
			document.getElementById('playlist_wrapper').innerHTML = xmlHttp.responseText;
			home_getFile(def_vid_id,def_title,def_thumb);
		}
	}
	document.getElementById('playlist_wrapper').innerHTML='<div id="preloader2"><div class="loader" style="left:45%; top:36%;"><img src=\"/wp-content/plugins/video/images/loader.gif\"></div></div>';
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadHomeFile(url, qStr, img_thumb){
	if (url.length==0){
	        document.getElementById('video_player').innerHTML=""; 
		
	        return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	      alert ("Browser does not support HTTP Request");
	      return;
	}
			
	if(qStr=='')
		url=url+"?id="+document.getElementById('video_player').value;
	else
	 	url=url+"?"+qStr; 
		url=url+"&sid="+Math.random();
			
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById('video_player').innerHTML = xmlHttp.responseText;
		}
					
	}
	document.getElementById('video_player').innerHTML='<div id="preloader" style="height:289px;"><img src="/wp-content/plugins/video/files/thumb/'+ img_thumb + '" width="524" height="289"><div class="loader"><div class="loader_container"><img src="/wp-content/plugins/video/images/loader2.gif" alt="" /><br/>LOADING</div></div></div>';					
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// CALLING AJAX FUNCTION
function home_getList(cat_id, def_vid_id, def_title, def_thumb){
	home_loadPlaylist('/wp-content/plugins/video/home_getplaylist.php','catID=' + cat_id, def_vid_id, def_title, def_thumb);
}

function home_getFile(vid_id,title,thumb){
	document.getElementById('vid_title').innerHTML=title;
	loadHomeFile('/wp-content/plugins/video/home_getplayfile.php','vID=' + vid_id, thumb);
}
function load_list_file(cat_id, def_vid_id, def_title, def_thumb) {	
	home_getFile(def_vid_id,def_title,def_thumb);
	home_getList(cat_id);
}

// Browser safe opacity handling function
function setOpacity( value, div_id) {
    var div_cont = null;
	if(div_id==null)
	   div_cont = 'playlist_wrapper';
	else
	   div_cont = div_id;
	var div_container = document.getElementById(div_cont);

	div_container.style.opacity = value / 10;
	div_container.style.filter = 'alpha(opacity=' + value * 10 + ')';	
}

function fadeInMyPopup(div_id) {
 var fade_cont = div_id;	
 for( var i = 0 ; i <= 100 ; i++ )
   setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
}
function fireMyPopup(div_id){
 setOpacity( 0, div_id);
 document.getElementById(div_id).style.display = "block";
 fadeInMyPopup(div_id);
}