/*****************************/
/* Written by : Jet Eloriaga */
/* March 2009                */
/*****************************/

var request = false;
var offset = 1;

function show_news_item(){
    if (request){
        var url = "flash_news_item.php?offset=" + offset;
        sendGETRequest(request, url, show_current_news_item);
        offset++;
    }
    setTimeout(show_news_item, 4000);
}

function show_current_news_item(){
	if ( request.readyState == 4 )
		if ( request.status == 200 ){
			var response = request.responseText;
			document.getElementById("front_news_item").innerHTML = response;
		}
}

/*****************************/
/*** fade in - fade out    ***/
/*****************************/

var img1_opa = 0;
var img2_opa = 100;
var change = 2;

var center_name = "Informatics Computer Education";
var center_titles = new Array();
var center_photos = new Array();
var indexer = 0;

function get_center_names(){
    if (request){
        var url = "get_center_names.php";
        sendGETRequest(request, url, set_center_names_array);
    }
}
function set_center_names_array(){
	if ( request.readyState == 4 )
		if ( request.status == 200 ){
			var response = request.responseText;
			center_titles = response.split('|');
		}
}
function get_center_photos(){
    if (request){
        var url = "get_center_photos.php";
        sendGETRequest(request, url, set_center_photos_array);
    }
}
function set_center_photos_array(){
	if ( request.readyState == 4 )
		if ( request.status == 200 ){
			var response = request.responseText;
			center_photos = response.split('|');
		}
}

function fade_in(){
    img1_opa += change;
    img2_opa -= change;
    
    if ( img1_opa == 0 || img1_opa == 100 ){
        change *= -1;
        if ( center_name == "Informatics Computer Education" ){
            if ( center_titles[indexer] ){
                document.getElementById("center_name").innerHTML = "34 Local Centers";        
                document.getElementById("img2").src = "./images/" + center_photos[indexer];
            }
            center_name = center_titles[indexer];
            indexer = ( indexer < center_titles.length ? ++indexer : 0 );

       }else{
            document.getElementById("center_name").innerHTML = "Informatics Computer Education";
            center_name = "Informatics Computer Education";
       }
    }

    if (change > 0){
        document.getElementById( "img1" ).style.display = "";
        document.getElementById( "img2" ).style.display = "none";
    }else{
        document.getElementById( "img1" ).style.display = "none";
        document.getElementById( "img2" ).style.display = "";
    }

    if (navigator.appName == "Microsoft Internet Explorer"){
        document.getElementById( "img1" ).style.filter = "alpha(opacity=" + img1_opa + ")";
        document.getElementById( "img2" ).style.filter = "alpha(opacity=" + img2_opa + ")";
    }else if(navigator.appName == "Netscape" || navigator.appName == "Mozilla"){
        document.getElementById( "img1" ).style.MozOpacity = img1_opa / 100;
        document.getElementById( "img2" ).style.MozOpacity = img2_opa / 100;
    }else{
        document.getElementById( "img2" ).style.visibility = "hidden";
    }
    
    setTimeout( "fade_in()", 100 );
}

/*****************************/

/*****************************/
/** third-party codes       **/
/*****************************/

/* 	
    Banner Rotator v1.0
	Created by: Ben K. (ben@webhostreview.biz)
*/

var displayTime, speed, wait, banner1, banner2, bannerIndex, bannerLocations;

function initVar() {
	displayTime = 5; // The amount of time each banner will be displayed in seconds.
	speed = 5; // The speed at which the banners is moved (1 - 10, anything above 5 is not recommended).
	wait = true; 

	banner1 = document.getElementById("banner1");
	banner2 = document.getElementById("banner2");

	banner1.style.left = 0;
	banner2.style.left = 500;

	bannerIndex = 1;
	
	/* 	 Important: In order for this script to work properly, please make sure that the banner graphic and the 
		 URL associated with it have the same index in both, the bannerLocations and bannerURLs arrays.
		 Duplicate URLs are permitted. */
	
		
	// Enter the location of the banner graphics in the array below.
	bannerLocations = new Array("./images/thames.gif", "./images/oxford.jpg", 
        "./images/nottingham.gif", "./images/uportsmouth.gif", "./images/uwales.jpg");
	
	// Enter the URL's to which the banners will link to in the array below. 
	bannerURLs = new Array("","","","","");
}
function moveBanner(){
	if(!wait){
		
		banner1.style.left = parseInt(banner1.style.left) -  (speed * 5);
		banner2.style.left = parseInt(banner2.style.left) - (speed * 5);
		
		
		if(parseInt(banner1.style.left) <= -500){
			banner1.style.left = 500;
			bannerIndex = (bannerIndex < (bannerLocations.length - 1)) ? ++bannerIndex :0;
			banner1.src = bannerLocations[bannerIndex];
			link1.href = bannerURLs[bannerIndex];
			wait = true;
		}
		
		if(parseInt(banner2.style.left) <= -500){
			banner2.style.left = 500;
			bannerIndex = (bannerIndex < (bannerLocations.length - 1)) ? ++bannerIndex :0;
			banner2.src = bannerLocations[bannerIndex];
			link2.href = bannerURLs[bannerIndex];
			wait = true;
		}

		setTimeout("moveBanner()",100);		
	} else {
		wait = false;
		setTimeout("moveBanner()", displayTime * 1000);
	}
}

/***    end banner rotator ***/
/*****************************/
