var pageHideSpeed       = 500;
var pageShowSpeed       = 500;

var fishEyeZoomInSpeed  = 200;
var fishEyeZoomOutSpeed = 200;

var backgrounds = new Array("back1.png", "back2.png", "back3.png", "back4.png", "back5.png", "back6.png", "back7.png");


$(document).ready(function(){
  $("body").css("backgroundImage", "url(./images/" + backgrounds[rand(backgrounds.length)] + ")");

  $(".navigationList a").click(function(){
    if (!$(this).hasClass("currentPage")) {
      $(".navigationList a").removeClass("currentPage");
      $(this).addClass("currentPage");
      loadContentPage($(this).attr("href"));
    }
    return false;
  });

  $(".contentBox").hide();
  loadContentPage("front.htm");
  
  $(".navigationList li").mouseover(function(){
    $(this).animate({  fontSize: "140%"  }, fishEyeZoomInSpeed);    
  });
  
  $(".navigationList li").mouseout(function(){
    $(this).animate({  fontSize: "100%"  }, fishEyeZoomOutSpeed);    
  });  
});


function loadContentPage(page) {
  $(".contentBox").hide(pageHideSpeed, function(){
    ajax(page, function(response){
      $(".contentBox").html(response);
      window.scrollTo(0, 0);
      
      $(".contentBox").show(pageShowSpeed);
      
      $(".backToTop").click(function(){        
        window.scrollTo(0, 0);
        return false;
      });
    });  
  });


}


function ajax(url, callbackFunction) {
	var xmlHttp;

	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch (e) {
				callbackFunction("ERROR: AJAX not supported");
				return false;
			}
		}
	}	

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			callbackFunction(xmlHttp.responseText);
		}
	};

	try {
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	} catch (e) {
		callbackFunction("ERROR: Cannot access URL");
	}
}


function rand(max) {
	return Math.floor(Math.random() * max);
}