//Opacity Function for News/Events Widget

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

//News/Events widget and also gallery changing code
function change(numItems, cycleTime, elementName, newContent, arrayNum)
{
	opacity(elementName, 100, 0, 500);
	setTimeout('changeContent('+newContent+', \''+elementName+'\', '+numItems+', '+cycleTime+', '+arrayNum+')', 500);
	setTimeout('opacity(\''+elementName+'\', 0, 100, 500)', 600);				
}
			
function changeContent(newContent, elementName, numItems, cycleTime, arrayNum){
	document.getElementById(elementName).innerHTML = contentList[arrayNum][newContent];
	var currentItemNum = newContent+1;
	if (numItems > currentItemNum) {
		newContent++;
	}
	else {
		newContent = 0;
	}
	
	if(numItems <= 1){
		return;
	}
	
	if (cycleTime > 0) {
		setTimeout('change('+numItems+', '+cycleTime+', \''+elementName+'\', '+newContent+', '+arrayNum+')', cycleTime);
	}
}

function ajaxRequest(){
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }
}

function basicajax(page, id, direction){
	
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  //Alter Gallery Images Here...possibly use a 3D javascript array to print out thumbnails originally and simply update that?
	  }
	}
	xmlhttp.open("GET",page+"?id="+id+"&direction="+direction,true);
	xmlhttp.send(null);
}

