//ADJUST VALUES TO REFLECT NUMBER OF NAV ITEMS IN EACH MENU
var menu1_navItems = 8;
var menu2_navItems = 4;
var menu3_navItems = 5;
var menu4_navItems = 8;
var menu5_navItems = 2;


//START - PROTOTYPE FUNCTIONS

function floatY(speed,endy) {
	
	if(document.all){
		this.yFinal = this.obj.style.pixelTop;
		this.yPos = this.obj.style.pixelTop;
	} else if(document.getElementById){
		this.yFinal =  parseInt(this.obj.style.top);
		this.yPos = parseInt(this.obj.style.top);
	}

	this.speed = "."+speed;
	this.endy = endy;
	this.dist_y = Math.round(endy - this.yPos);
	this.vel_y = this.dist_y*this.speed;
	this.yFinal += this.vel_y;

	if(document.all) this.obj.style.pixelTop = this.yFinal;
	else if(document.getElementById) this.obj.style.top = this.yFinal + 'px';

}

function posX(endx) {
	if(document.all) this.obj.style.pixelLeft = endx;
	else if(document.getElementById) this.obj.style.left = endx + 'px';
}

function posY(endy) {
	if(document.all) this.obj.style.pixelTop = endy;
	else if(document.getElementById) this.obj.style.top = endy + 'px';
}

function vis(v) {
	this.obj.style.visibility = v;
}

function myObject(value) {
    if(document.all) this.obj = document.all(value);
	else if(document.getElementById) this.obj = document.getElementById(value);

}

myObject.prototype.floatY = floatY;
myObject.prototype.posX = posX;
myObject.prototype.posY = posY;
myObject.prototype.vis = vis;

//END - PROTOTYPE FUNCTIONS

//START - TOEIC FUNCTIONS
var flashObj;

function makeObj(){
	flashObj = new myObject('flash');
	toggle("none");
}

function toggle(state){
	var flash = ['flashHeader','flashHolder'];
	for(var i=0; i< flash.length;i++){
		var obj = (document.getElementById) ? document.getElementById(flash[i]) : document.all(flash[i]);
		obj.style.display = state;
	}
}

function setXYflash(x,y,file){
	flashObj.posX(x);
	flashObj.posY(y);
	flashObj.vis('visible');

	if(document.all){
		document.all('flash').innerHTML = buildFlash(file);
		}
	else if (document.getElementById){
		document.getElementById('flash').innerHTML = buildFlash(file);
	}
}


function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}


function setFlash(file,t){

	toggle("block");

	flashObj.vis('visible');


	var string = Get_Cookie("domain");

	if(string == null){
		domain = '';
		}
	else{
		domain = 'http://' + string;
		}

	var items = t.split("/*");

	if(document.all){
		document.all('flash').innerHTML = buildFlash(domain + file);
		document.all('title').innerHTML = items[0];
		document.all('useage').innerHTML = items[1];
		document.all('definition').innerHTML = items[2];
		}
	else if (document.getElementById){
		document.getElementById('flash').innerHTML = buildFlash(domain + file);
		document.getElementById('title').innerHTML = items[0];
		document.getElementById('useage').innerHTML = items[1];
		document.getElementById('definition').innerHTML = items[2];
	}
}

function buildFlash(file){

	var string = Get_Cookie("domain");

	if(string == null){
		domain = '';
		}
	else{
		domain = 'http://' + string;
		}


	var f = '<object ' +
		'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'width="152" ' +
		'height="60" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"> ' +
		'<param name="movie" value="' + domain + '/TOEICBD/audio/loader_toeic_small.swf?file1=' + file + '"> ' +
		'<param name="play" value="true"> ' +
		'<param name="loop" value="false"> ' +
		'<param name="quality" value="high"> ' +
		'<param name="menu" value="false"> ' +
		'<param name="bgcolor" value="#ffffff"> ' +
		'<embed ' +
		'	src="'+ domain + '/TOEICBD/audio/loader_toeic_small.swf?file1=' + file + '" ' +
		'	width="152" ' +
		'	height="60" ' +
		'	bgcolor="#ffffff" ' +
		'	play="true" ' +
		'	loop="false" ' +
		'	quality="high" ' +
		'	menu="false" ' +
		'	type="application/x-shockwave-flash" ' +
		'	pluginspage="http://www.macromedia.com/go/flashplayer/"> ' +
		'</embed> ' +
		'</object>';

	return f;
}
//END- TOEIC FUNCTIONS

var isEcom;
var top_1;
var top_2;
var top_3;
var top_4;
var top_5;
var bottom;

var currOpen = false;
var once = false;

function routine(id){

	if(currOpen && (currOpen != id)){
		document['m'+ currOpen].src = "images/m" + currOpen + ".gif";
		if(currOpen == 1) runOne(top_1,true);
		if(currOpen == 2) runTwo(top_2,true);
		if(currOpen == 3) runThree(top_3,true);
		if(currOpen == 4) runFour(top_4,true);
		if(currOpen == 5) runFive(top_5,true);
	}

	if(id){
		document['m'+ id].src = "images/m" + id + "_over.gif";
		if(id != currOpen){
			if(id == 1) runOne(bottom,true);
			if(id == 2) runTwo(bottom,true);
			if(id == 3) runThree(bottom,true);
			if(id == 4) runFour(bottom,true);
			if(id == 5) runFive(bottom,true);
		}

		if(!once){
			//TURN VISIBILITY OF LAYERS TO VISIBLE
			nav1.vis('visible');
			nav2.vis('visible');
			nav3.vis('visible');
			nav4.vis('visible');
			nav5.vis('visible');
			//ONLY NEED TO RUN THIS CODE ONCE 
			once = true;
		}
	}

	currOpen = id;
}


function makeObjects(){

	nav1 = new myObject('menu1');
	nav2 = new myObject('menu2');
	nav3 = new myObject('menu3');
	nav4 = new myObject('menu4');
	nav5 = new myObject('menu5');

	nav1.posX(getLeft(1));
	nav2.posX(getLeft(2));
	nav3.posX(getLeft(3));
	nav4.posX(getLeft(4));
	nav5.posX(getLeft(5));

	if(isEcom == "yes"){
		bottom = 169;
	} else{
		bottom = 248;
	}

	top_1 = bottom - parseInt(menu1_navItems * 20);
	top_2 = bottom - parseInt(menu2_navItems * 20);
	top_3 = bottom - parseInt(menu3_navItems * 20);
	top_4 = bottom - parseInt(menu4_navItems * 20);
	top_5 = bottom - parseInt(menu5_navItems * 20);

	nav1.posY(top_1);
	nav2.posY(top_2);
	nav3.posY(top_3);
	nav4.posY(top_4);
	nav5.posY(top_5);

}

var float1 = false;
var float2 = false;
var float3 = false;
var float4 = false;
var float5 = false;

function runOne(yPos,clear){
	if(clear) clearTimeout(float1);
	nav1.floatY(3,yPos);
	float1 = setTimeout('runOne(' + yPos +')',100);
}

function runTwo(yPos,clear){
	if(clear) clearTimeout(float2);
	nav2.floatY(3,yPos);
	float2 = setTimeout('runTwo(' + yPos +')',100);
}

function runThree(yPos,clear){
	if(clear) clearTimeout(float3);
	nav3.floatY(3,yPos);
	float3 = setTimeout('runThree(' + yPos +')',100);
}

function runFour(yPos,clear){
	if(clear) clearTimeout(float4);
	nav4.floatY(3,yPos);
	float4 = setTimeout('runFour(' + yPos +')',100);
}

function runFive(yPos,clear){
	if(clear) clearTimeout(float5);
	nav5.floatY(3,yPos);
	float5 = setTimeout('runFive(' + yPos +')',100);
}

function getLeft(id){
	if(document.images['m' + id]){
		var holdingImage = document.images['m' + id];
		return holdingImage.offsetLeft;
	}
}

function getTop(id){
	if(document.images['m' + id]){
		var holdingImage = document.images['m' + id];
		return holdingImage.offsetTop;
	}
}

function roll(id,over){
	if(over) document[id].src = "images/" + id + "_over.jpg";
	else document[id].src = "images/" + id + ".jpg";
}

function rollGif(id,over){
	if(over) document[id].src = "images/" + id + "_over.gif";
	else document[id].src = "images/" + id + ".gif";
}

function bGeneric(id,over,img){
	if(over) id.src = "images/" + img + "_over.gif";
	else id.src = "images/" + img + ".gif";
}

