/** Swinburne University of Technology Website: js functions javascript
 *  javascript file including functions destined to the 
 *  implementation of visual effects in the website
 *
 *  MODIFIED:
 *  version 1.0, 12 July 2004.
 * @version 1.1, 28 July 2004.
 * @version 1.2, 27 October 2004. added text size and cookie functions
 * @version 1.3, 6 January 2005. added domain parameter for the text size and cookie functions
 * @author David Jimenez david@swin.edu.au
 */

/**
 *  Preloads rollover images so they are ready to the rollover effect
 */

function function_preloadImages() { 
  var d=document; if(d.images){ if(!d.function_p) d.function_p=new Array();
    var i,j=d.function_p.length,a=function_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.function_p[j]=new Image; d.function_p[j++].src=a[i];}}
}

function rollOver(objImg){
  var regEx = /\.gif/gi;
  var strSource = objImg.src;
  strSource = strSource.replace(regEx, "_over.gif");
  objImg.src = strSource;
}

function rollOut(objImg){
  var regEx = /_over/gi;
  var strSource = objImg.src;
  strSource = strSource.replace(regEx, "");
  objImg.src = strSource;
}

/**
 *  Restores original images after the rollover effect
 */

function function_swapImgRestore() { 
  var i,x,a=document.function_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function function_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=function_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/**
 *  Swaps the image when the mouse is over the image doing a rollover effect
 */

function function_swapImage() { 
  var i,j=0,x,a=function_swapImage.arguments; document.function_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=function_findObj(a[i]))!=null){document.function_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**
 * 	Grab the cookie and the textSize from it
 */

var aCookie = new String(document.cookie);
var textSize = aCookie.substring(aCookie.indexOf('textSize')+9,aCookie.indexOf('textSize')+10);
var firstTime = false; //used to avoid resizing if the user enters for the first time
//set default text size to 1
if(textSize==null || textSize=="" || isNaN(textSize))
{
	firstTime = true;
	textSize = 0;
}
var startSz = textSize*1;//to convert it to a number

/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:

var tgs = new Array( 'div','td','tr','h1','span','h2','a','p');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );

/**
 * Changes the text size receiving two parameters, one is the target (trgt) which is usually the body
 * and the other is the increment (inc) usually -1 or 1
 */

function ts( trgt,inc,domain ) {
	
	if (!document.getElementById) return	
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	if(isNaN(sz))
	{
		sz = 1;
	}
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	//added by david
	createCookie("textSize", sz, 0, domain);
	//end added
	
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


/**
 * Cookie functions
 */

function createCookie(name,value,days,domain) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();	
  }
  else expires = "";
  if (domain) {
	var theDomain = "; domain="+domain;
  }
  else theDomain = "";  
  document.cookie = name+"="+value+expires+"; path=/"+theDomain;
}

