var DROP_DOWN_MENU_TOP = 129;











function DNode(title, text, img){

	this.title = title;

	this.text = text;

	this.img = img;

	this.next = null;

	this.previous = null;

}





function DLList(){

	this.root = null;

	this.title="";

	this.insert = function(title, text, img){

		var new_node = new DNode(title, text, img)

		if(this.root == null){//if first element

			this.root = new_node;

			this.root.next = this.root;

			this.root.previous = this.root;

		}else{

			new_node.next = this.root;

			new_node.previous = this.root.previous;

			this.root.previous.next = new_node;

			this.root.previous = new_node;

			this.root = new_node;

		}

	}

	this.next = function(){ this.root = this.root.next;}

	this.previous = function(){ this.root = this.root.previous;}

	

	this.get_img = function(){ return this.root.img;}

	this.get_title = function(){ return this.root.title;}

	this.get_text = function(){ return this.root.text;}

}



function News_Ticker(tick_rate, title_div, text_div){

	this.tick_rate = tick_rate;

	this.title_div = title_div;

	this.text_div = text_div;

	this.stories = new DLList();

	this.tick_index = 1;//on



	this.add_story = function(title, text, img_div){ 

		this.stories.insert(title, text, img_div);

		this.draw();

	}	

	this.next = function(){

		this.hide_background();

		this.stories.next();

		this.draw();

		this.show_background();

	}

	this.previous = function(){

		this.hide_background();

		this.stories.previous();

		this.draw();

		this.show_background();

	}

	this.hide_background = function(){

		document.getElementById(this.stories.get_img()).style.visibility = "hidden";		

	}

	this.show_background = function(){

		document.getElementById(this.stories.get_img()).style.visibility = "visible";		

	}

	this.draw = function(){

		var current;

		var new_image = document.createElement('img');

		new_image.src = this.stories.root.img;

		

		current = document.getElementById(this.title_div);

		current.innerHTML = this.stories.get_title();

		current = document.getElementById(this.text_div);

		current.innerHTML = this.stories.get_text();

	};

	this.tick = function(self){

		if(ticker.tick_index > 0){

			self.next();

			var p = window.setTimeout("ticker.tick(ticker)", self.tick_rate);		

		}else

			var p = window.setTimeout("ticker.tick(ticker)", self.tick_rate);		

	};

	this.pause = function(){

		if(this.tick_index<0){

			//play

			this.tick_index = 20;

			document.getElementById('play_img').style.visibility="hidden";			

			document.getElementById('pause_img').style.visibility="visible";



		}else{

			//pause

			this.tick_index= -1;

			document.getElementById('pause_img').style.visibility="hidden";			

			document.getElementById('play_img').style.visibility="visible";



		}

	};

}







function sleep(Us){

	var waitFlag = true;

	var p = window.setTimeout("waitFlag=false", Us);

	while(waitFlag){;}

}









function all_off(){

	document.getElementById('nav3_menu').style.visibility = "hidden";

	document.getElementById('nav4_menu').style.visibility = "hidden";

	document.getElementById('nav5_menu').style.visibility = "hidden";

	document.getElementById('nav6_menu').style.visibility = "hidden";

}



function draw_menu(div_id){

	///DRAW MENU DOES NOT MAKE THE MENU VISIBLE

	var parent=document.getElementById(div_id);

	var menu=document.getElementById(div_id + "_menu");

	var winW=0;

	var winCenter=0;

	var left=0;





	//find winCenter

	if (parseInt(navigator.appVersion)>3) {

		if (navigator.appName=="Netscape") { winW = window.innerWidth;}

		if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth;}

	}

	winCenter = winW / 2;



	//calculate respective nav_bar locations	

	if(div_id.toString() == 'nav3') left = winCenter - 225;	//site selectors

	if(div_id == 'nav4') left = winCenter - 150; 			//learning

	if(div_id == 'nav5') left = winCenter - 100;			//living

	if(div_id == 'nav6') left = winCenter - 40;				//working



	document.getElementById(div_id + "_menu").style.top = DROP_DOWN_MENU_TOP + "px";

	document.getElementById(div_id + "_menu").style.left = left + "px";

}



function mouse_over(div_id){

	all_off();

	if(div_id.toString() != "kill"){

		draw_menu(div_id);

		document.getElementById(div_id + "_menu").style.visibility = "visible";

	}

}





function mouse_out(){}



function resize_handler(){

	draw_menu('nav3');

	draw_menu('nav4');

	draw_menu('nav5');

	draw_menu('nav6');

}



function Set_Cookie( name, value, expires, path, domain, secure ) 

{

	// set time, it's in milliseconds

	var today = new Date();

	today.setTime( today.getTime() );

	

	/*

	if the expires variable is set, make the correct 

	expires time, the current script below will set 

	it for x number of days, to make it for hours, 

	delete * 24, for minutes, delete * 60 * 24

	*/

	if ( expires )

	{

	expires = expires * 1000 * 60 * 60 * 24;

	}

	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" : "" );

}



function set_section_cookie(section){

	Set_Cookie( 'section', section, new Date().getFullYear() + 60) ;

}
