var gSelectedNavID = null;

var gPreloadList = [
//	'background.gif',
	'tab_left.gif',
	'tab_right.gif',
	'tab_left_dim.gif',
	'tab_right_dim.gif',
	'tab_right.gif',
	'background_info.gif',
//	'background_header_left.jpg',
//	'background_header_right.jpg',
	'tab_sidebar_off.gif',
	'tab_sidebar_on.gif',
	'background_news.gif',
	'background_cap_white_left.gif',
	'background_cap_white_right.gif',
	'background_box.gif',
	'background_cap_gray_left.gif',
	'background_cap_gray_right.gif',
	'icon_arrow.gif',
//	'tab_table_left_off.gif',
//	'tab_table_right_off.gif',
//	'tab_table_left.gif',
//	'tab_table_right.gif',
//	'icon_plus.gif',
//	'icon_plus_alt.gif',
	'background_cap_modal_left.gif',
	'background_cap_modal_right.gif'
];

var gPreloader = new Image();
for(var z = 0 ; z < gPreloadList.length ; z++) {
	gPreloader.src = "../img_layout/" + gPreloadList[z];
}

function empty() {}

function over (inID) {
	if(gSelectedNavID && inID != gSelectedNavID) {
		var s = document.getElementById("nav_" + gSelectedNavID);
		s.className = s.className.replace("selected","dim");
	}
	
//	var  x = document.getElementById("navinfo_" + inID);
//	x.style.display = "block";
	
	x = document.getElementById("nav_" + inID);
	x.className += " hover";
	
}

function out (inID) {
	if(gSelectedNavID && inID != gSelectedNavID) {
		var s = document.getElementById("nav_" + gSelectedNavID);
		s.className = s.className.replace("dim","selected");
	}
	
//	var  x = document.getElementById("navinfo_" + inID);
//	x.style.display = "none";
	
	x = document.getElementById("nav_" + inID);
	var newClass = x.className.replace("hover","");
	x.className = newClass;

}

function load(inDefault) {
    if(inDefault == null) {
        inDefault = "news";
    }
    selectDefault(inDefault);
}


function selectDefault(inDefault) {
    var tabBody = document.getElementById("newstabbody");
    tabBody.style.display = "block";
    document.getElementById("tab" + inDefault).className += " selected";
    var tabContent = document.getElementById("tab" + inDefault + "_content");
    tabContent.style.display = "block";
    setTimeout(function() {
        tabBody.style.height = tabContent.offsetHeight + "px";
    },1);
}


function select(inID) {
    var tab = document.getElementById(inID);
    var content = document.getElementById(inID + "_content");
    if(tab.className.indexOf("selected") == -1) {
        var tabBody = document.getElementById("newstabbody");
        tabBody.style.display = "block";
        setTimeout(function() {
            // freeze both size
            var startHeight = tabBody.clientHeight - 40;    // 30 padding-top + 10 padding-bottom.   This must be kept in synch with css file
            if(startHeight < 0) { startHeight = 0;}
            tabBody.style.height = startHeight + "px";
            setTimeout(function() {
                deselectAll();
                tab.className = tab.className + " selected";
                content.style.display = "block";
                setTimeout(function() {
                    var t = new Tween(tabBody.style,"height",Tween.regularEaseout,startHeight,content.offsetHeight,.25,"px");
                    t.start();
                },1);
            },1);
        },1);
    }
}

function deselectAll() {
    //document.getElementById("newstabbody").style.display = "none";
	   var tabList = ['tabnews','tabevents'];
	   
	   for(var z = 0 ; z < tabList.length ; z++) {
	       var id = tabList[z];
	       
	       var tab = document.getElementById(id);
	       var content = document.getElementById(id + "_content");
	       if(content.style.display == 'block') {
	           content.style.display = "none";
	           
	           tab.className = tab.className.replace(" selected","");
	       }
	   }
}



function expandAndCollapse(oldWrapper,oldLong,oldShort,newWrapper,newLong,newShort)
{
    // lock wrapper sizes
	if(oldWrapper) {
		oldWrapperStart = oldWrapper.clientHeight;
		oldWrapper.style.height = oldWrapperStart + "px";
	}
    newWrapperStart = newWrapper.clientHeight;
    newWrapper.style.height = newWrapperStart + "px";
    
    setTimeout(function() {
        // swap old and start to shrink
        
        if(oldWrapper) {
			oldLong.style.display = "none";
			oldShort.style.display = "block";
		}
        newShort.style.display = "none";
        newLong.style.display = "block";
        
        setTimeout(function() {
        	if(oldWrapper) {
				var t = new Tween(oldWrapper.style,"height",Tween.regularEaseOut,oldWrapperStart,oldShort.offsetHeight,.25,"px");
				t.addListener({onMotionFinished:function() {
					oldWrapper.style.height = "auto";
				}});
				t.start();
			}
            
            t = new Tween(newWrapper.style,"height",Tween.regularEaseOut,newWrapperStart,newLong.offsetHeight,.25,"px");
            t.addListener({onMotionFinished:function() {
                newWrapper.style.height = "auto";
            }});
            t.start();
            
        },1);
    },1);
    
}


function overBox(box) {
	box.className = "boxhoveron";
}

function outBox(box) {
	box.className = "boxhoveroff";
}


function go(inURL) {
	document.location.href = inURL;
}

