// Preload images
var preloadFlag = false;
if (document.images) {
  // Preload main nav
  n_home_reg = newImage("images/n_home_reg.gif");
  n_home_sel = newImage("images/n_home_sel.gif");
  n_coinfo_reg = newImage("images/n_coinfo_reg.gif");
  n_coinfo_sel = newImage("images/n_coinfo_sel.gif");
  n_products_reg = newImage("images/n_products_reg.gif");
  n_products_sel = newImage("images/n_products_sel.gif");
  n_contact_reg = newImage("images/n_contact_reg.gif");
  n_contact_sel = newImage("images/n_contact_sel.gif");
  n_sitemap_reg = newImage("images/n_sitemap_reg.gif");
  n_sitemap_sel = newImage("images/n_sitemap_sel.gif");
  
  preloadFlag = true;
}

if (window.location.hostname == "www.flying-fish.net" || window.location.hostname == "flying-fish.net" || window.location.hostname == "www.flying-fish.com" || window.location.hostname == "flying-fish.com") {
  window.location = "http://www.porticolearning.com" + window.location.pathname;
}

var menuHover = false;
var menuOff = false;

function pageLoad(buttonID, menuID) {
	if (menuHover && ! menuOff)
	{
		var button = document.getElementById(buttonID);
		if (button != null)
		{
			displayMenu(button, menuID, true);
		}
		menuHover = false;
	}
	menuOff = false;
}

// Preload new image function
function newImage(imageLocation) {
  if (document.images) {
    imageResult = new Image();
    imageResult.src = imageLocation;
    return imageResult;
  }
}

// Turn on nav function 
function turnOnNav (imageName) {
  changeImage(imageName,imageName+"_sel");
}

// Turn off nav function 
function turnOffNav (imageName) {
  changeImage(imageName,imageName+"_reg");
}

// Swap image function 
function changeImage (imageName, fileName) {
  if (document.images) {
    document[imageName].src = eval(fileName + ".src");
  }
}

// Swap two images function
function changeImages (imageName,fileName,secImageName,secFileName) {
  if (document.images) {
    document[imageName].src = eval(fileName + ".src");
    document[secImageName].src = eval(secFileName + ".src");
  }
}

// Close window
function closeWindow() {
  window.close();
}

// Popup window function
function openWindow(url, name, size, scroll) {
  popupWin=window.open(url, name, '"toolbar=no,' + size +',left=15,top=15,status=no,' + scroll +',resizable=yes,menubar=no"');
}

// Array function
function makeArray(len) {
  for (var i = 0 ; i < len; i++) this[i] = null;
  this.length = len;
}

function popCourseDemo(url, name) {
  var str = "left=0,screenX=0,top=0,screenY=0,resizable,status=yes,scrollbars=yes";
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10
    str += ",height=" + ah;
    str += ",innerHeight=" + ah;
    str += ",width=" + aw;
    str += ",innerWidth=" + aw;
  }
  win=window.open(url, name, str);
  win.focus;
}

function swap (id, txt) {
  document.getElementById(id).innerHTML = txt;
}

//-------------------------------------------------------------------------------
// Date functions
//-------------------------------------------------------------------------------

// Array of day names
var dayNames=new makeArray(7);
dayNames[0] = "Sunday";
dayNames[1] = "Monday";
dayNames[2] = "Tuesday";
dayNames[3] = "Wednesday";
dayNames[4] = "Thursday";
dayNames[5] = "Friday";
dayNames[6] = "Saturday";

// Array of month names
var monthNames = new makeArray(12);
monthNames[0] = "January";
monthNames[1] = "February";
monthNames[2] = "March";
monthNames[3] = "April";
monthNames[4] = "May";
monthNames[5] = "June";
monthNames[6] = "July";
monthNames[7] = "August";
monthNames[8] = "September";
monthNames[9] = "October";
monthNames[10] = "November";
monthNames[11] = "December";

// Elements of Date object assigned to variables
var now = new Date();
var day = now.getDay();
var month = now.getMonth();
var year = now.getYear();
if (year == 99)
  year = 1999;
else if (year > 99 && year < 2000)
  year = 1900 + year;
var date = now.getDate();

//-------------------------------------------------------------------------------
// Cookie functions
//-------------------------------------------------------------------------------

// Cookie code - added on 5/8/05
/**
 * Read the JavaScript cookies tutorial at:
 *   http://www.netspade.com/articles/javascript/cookies.xml
 */

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie in days (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    // set time in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    
    // Set expires for x number of days
    if (expires) {
    	// expires = days * hours * minutes * seconds * milliseconds
    	expires = expires * 24 * 60 * 60 * 1000;
    }
    var expires_date = new Date(today.getTime() + (expires));
    
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires_date.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}