// JavaScript Document

window.onload =function() {  
	nonObtrusiveNav();
	initLightbox();

}

function nonObtrusiveNav() {	
	//loop over <a> tags inside nav div 
	// add onclick to make ajaxcall
	// add &ajax=true to end of each A tag 
	

	navlist= document.getElementById('main_holder');	
	navlistlinks= navlist.getElementsByTagName('a');
	for (i=0;i<navlistlinks.length;i++) {	
		if ( navlistlinks[i].target=='_blank' || navlistlinks[i].target=='_self') {	
			navlistlinks[i].onclick=function() {				
				return true;						
			}	

		
		} // or else just add ajax=true to all links so only the content refreshes and not the media player
		else {	
			navlistlinks[i].onclick=function() {		
				ajaxcall(this.href+"&ajax=true");
				return false;	
			}	
		}	
//alert(navlistlinks[i].onmouseover);
	}
}

function ajaxcall(info) {
// holder is on the index.tpl page
	loadPage(info,'main_holder');
	
}

var page;
function loadPage(url, containerid) {	

	_uacct = "NEED SHARON'S ACCT #";
	urchinTracker(url);
	page = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) { 
    	try {
			page = new XMLHttpRequest(); 
        } catch(e) {
			page = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	page = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          	page = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          	page = false;
        	}
		}
    }

	if(page) {
		page.onreadystatechange = function() {
			popdiv(page, containerid);			
		}
		page.open("GET", url, true);

		page.send("");
	} else {
		alert('no page');
	}	
	
}

function popdiv(page, containerid) { 
	if (page.readyState == 4 && (page.status==200 || window.location.href.indexOf("http")==-1)) { 
				
		document.getElementById(containerid).innerHTML=page.responseText;
		
		document.getElementById(containerid).scrollTop = 0; 
		nonObtrusiveNav();
		initLightbox();
	}
}
