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 dgallery(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	   document.getElementById('div-player').innerHTML = xmlHttp.responseText;
	   //PopUpPlayer(document.getElementById('player-content').innerHTML,'PHOTO GALERY');
	   //getGalleryList('');
	   //alert(xmlHttp.responseText);
	}
}

function loadGallery(url, qStr){
	if (url.length==0){
	        document.getElementById("div-player").innerHTML="";

	        return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	      alert ("Browser does not support HTTP Request");
	      return;
	}

	if(qStr=='')
		url=url+"?id="+document.getElementById("div-player").value;
	else
	 	url=url+"?"+qStr;
		url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById('div-player').innerHTML	= dgallery();
		}

	}
	displayLoader();
	document.getElementById('div-player').innerHTML='<div id="preloader2"><div class="loader" style="left:31%;"><img src=\"/wp-content/plugins/video/images/loader.gif\"></div></div>';
	xmlHttp.open("GET",url,true) ;
	xmlHttp.send(null);
}

function loadGal(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
	   document.getElementById('playlist_wrapper').innerHTML = xmlHttp.responseText;
	   alert(xmlHttp.responseText);
	}
}

function loadGallerylist(url, qStr, cat_id, album_id, album_name){
	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;
			getGalleryFile(cat_id, album_id, album_name );
		}

	}
	document.getElementById('playlist_wrapper').innerHTML='<div id="preloader2"><div class="loader" style="left:44%;top:45%;"><img src=\"/wp-content/plugins/photos/images/loader.gif\"></div></div>';
	xmlHttp.open("GET",url,true) ;
	xmlHttp.send(null);
	
}

function loadGalleryFile(url, qStr){
	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 class="loader" style="left:44%;top:33%;"><div class="loader_container"><img src="/wp-content/plugins/photos/images/loader2.gif" alt="" /><br/>LOADING</div></div>';
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// CALLING AJAX FUNCTION
function getGallery(){
	loadGallery('/wp-content/plugins/photos/show_gallery.php','');
}

function getGalleryList(cat_id, album_id, album_name){
	loadGallerylist('/wp-content/plugins/photos/get_album_list.php','catID=' + cat_id, cat_id, album_id, album_name);
}

function getGalleryFile(cat_id, album_id, title){
	document.getElementById('vid_title').innerHTML=title;
	loadGalleryFile('/wp-content/plugins/photos/get_gallery_file.php','aID=' + album_id + '&catID='+cat_id);
}
function getPage(url){
	if ( url.indexOf("?") > -1 ){
		var strQueryString = url.substr(url.indexOf("?")).toLowerCase();
		var getQueryStr = strQueryString.split("?");
		var getAlbum = document.getElementById('curr_album').value;
		loadGalleryFile('/wp-content/plugins/photos/get_gallery_file.php',getQueryStr[1] + '&aID=' + getAlbum);
	}
}
// 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() {
 //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);
}
function fadeOutMyPopup() {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
 }

 setTimeout('closeMyPopup()', 800 );
}
function closeMyPopup() {
 document.getElementById("video_player").style.display = "none"
}