var photostabloaded=0;
var articlestabloaded=0;
var linkstabloaded=0;
var docstabloaded=0;

function initHTTPObject(){
	var xHRObjectSp = false;
	if (window.XMLHttpRequest) {  // Mozilla
		xHRObjectSp = new XMLHttpRequest();
		} 
	else if (window.ActiveXObject) {  // IE
		try {
		xHRObjectSp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				xHRObjectSp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!xHRObjectSp) {
		alert('Your web browser is not compatible');
		return false;
	}		
	return xHRObjectSp;		
}


$(document).ready(function(){
	//Updating the video grid in 5 minuts after the page ended loading
	setTimeout("videostab()",300000);	
});

function tab1(){

}

function tab2(){
	if(photostabloaded==0){
  		//alert('photos tab clicked');
  		photostab();
  		photostabloaded=1;
	}
}

function tab3(){
	if(articlestabloaded==0){
	  	//alert('articles tab clicked');
	  	articlestab();
	  	articlestabloaded=1;
	}
}

function tab4(){
	if(linkstabloaded==0){
	  	//alert('links tab clicked');
	  	linkstab();
	  	linkstabloaded=1;
	}
}

function tab5(){
	if(docstabloaded==0){
	  	//alert('docs tab clicked');
	  	docstab();
		docstabloaded=1;
	}
}

//Updating the video tab via AJAX
function videostab(){
	var xhr=initHTTPObject();
		xhr.onreadystatechange = function() {
		if(xhr.readyState==0){}
		if(xhr.readyState==1){}
		if(xhr.readyState==2){}
		if(xhr.readyState==3){} 
		if(xhr.readyState==4 && xhr.status==200){
			var docXML=xhr.responseXML;
			var videostabcontent=docXML.getElementsByTagName("allvideoscontent");
			//updating the tab html by the retreived data
			$('#videostabcontent').html(''+videostabcontent.item(0).firstChild.data);
			//Executing the same function every 5 minutes to update the tab content
			setTimeout("videostab()",300000);
		} 
	}
	xhr.open("GET","/index/allvideostab",true);
    xhr.send(null);
}

//Updating the photos tab via AJAX
function photostab(){
	var xhr=initHTTPObject();
		xhr.onreadystatechange = function() {
		if(xhr.readyState==0){}
		if(xhr.readyState==1){}
		if(xhr.readyState==2){}
		if(xhr.readyState==3){} 
		if(xhr.readyState==4 && xhr.status==200){
			var docXML=xhr.responseXML;
			var photostabcontent=docXML.getElementsByTagName("allalbumstabcontent");
			//updating the tab html by the retreived data
			$('#albumstabcontent').html(''+photostabcontent.item(0).firstChild.data);
			//Executing the same function every 5 minutes to update the tab content
			setTimeout("photostab()",300000);
		} 
	}
	xhr.open("GET","/index/allalbumstab",true);
    xhr.send(null);
}

//Updating the articles tab via AJAX
function articlestab(){
	var xhr=initHTTPObject();
		xhr.onreadystatechange = function() {
		if(xhr.readyState==0){}
		if(xhr.readyState==1){}
		if(xhr.readyState==2){}
		if(xhr.readyState==3){} 
		if(xhr.readyState==4 && xhr.status==200){
			//alert('response ok');
			var docXML=xhr.responseXML;
			var articlestabcontent=docXML.getElementsByTagName("allarticlestabcontent");
			//updating the tab html by the retreived data
			$('#articlestabcontent').html(''+articlestabcontent.item(0).firstChild.data);
			//Executing the same function every 5 minutes to update the tab content
			setTimeout("articlestab()",300000);
		} 
	}
	xhr.open("GET","/index/allarticlestab",true);
    xhr.send(null);
}

//Updating the links tab via AJAX
function linkstab(){
	var xhr=initHTTPObject();
		xhr.onreadystatechange = function() {
		if(xhr.readyState==0){}
		if(xhr.readyState==1){}
		if(xhr.readyState==2){}
		if(xhr.readyState==3){} 
		if(xhr.readyState==4 && xhr.status==200){
			var docXML=xhr.responseXML;
			var linkstabcontent=docXML.getElementsByTagName("alllinkstabcontent");
			//updating the tab html by the retreived data
			$('#linkstabcontent').html(''+linkstabcontent.item(0).firstChild.data);
			//Applying thickbox to the newly added elements
			initthickbox();
			//Executing the same function every 5 minutes to update the tab content
			setTimeout("linkstab()",300000);
		} 
	}
	xhr.open("GET","/index/alllinkstab",true);
    xhr.send(null);
}

//Updating the docs tab via AJAX
function docstab(){
	var xhr=initHTTPObject();
		xhr.onreadystatechange = function() {
		if(xhr.readyState==0){}
		if(xhr.readyState==1){}
		if(xhr.readyState==2){}
		if(xhr.readyState==3){} 
		if(xhr.readyState==4 && xhr.status==200){
			var docXML=xhr.responseXML;
			var docstabcontent=docXML.getElementsByTagName("alldocstabcontent");
			//updating the tab html by the retreived data
			$('#docstabcontent').html(''+docstabcontent.item(0).firstChild.data);
			//Executing the same function every 5 minutes to update the tab content
			setTimeout("docstab()",300000);
		} 
	}
	xhr.open("GET","/index/alldocstab",true);
    xhr.send(null);
}



