/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************/
var Drag = {
	obj : null,
	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper){
		if (parseInt(navigator.appVersion)>3) {
 			if (navigator.appName=="Netscape") {
  				winW = window.innerWidth-16;
  				winH = window.innerHeight-16;
 			}
 			if (navigator.appName.indexOf("Microsoft")!=-1) {
  				winW = document.body.offsetWidth-20;
  				winH = document.body.offsetHeight-20;
 			}
		}
		offset=(winW-500)/2;
		o.onmousedown	= Drag.start;
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = offset+"px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},
	start : function(e){
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},
	drag : function(e){
		e = Drag.fixE(e);
		var o = Drag.obj;
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;
		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)
		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;
		Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	end : function(){
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},
	fixE : function(e){
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};







function toggleBlogs(obj){
	var details=dojo.dom.getNextSiblingElement(dojo.dom.getNextSiblingElement(obj));
	if(obj.innerHTML=='Show Details'){
		obj.innerHTML='Hide Details';
		obj.className='hide_details';
		details.className='';
	}else{
		obj.innerHTML='Show Details';
		obj.className='show_details';
		details.className='hidden';
	}
}


//////////////
// search() //
///////////////////////////////////////////////////
// Performs a site search on the term entered    //
// into the search box using aolsearch.aol.com.  //
//                                               //
// ARGUMENTS:                                    //
// (none)                                        //
///////////////////////////////////////////////////
function search(){
	var queryUrl = 'http://aolsearch.aol.com/aol/search?query=site:beta.aol.com%20';
	window.location=queryUrl+encodeURI(dojo.byId('search_input').value);
}
///////////////
// subMenu() //
///////////////////////////////////////////////////
// Toggle the sub menus and buttons for the top  //
// navigation menu. If the corresponding menu    //
// for the button that was clicked is already    //
// displayed, close that menu.                   //
//                                               //
// ARGUMENTS:                                    //
// i -- Number of sub menu to be opened.         //
// obj -- The button that was clicked.           //
///////////////////////////////////////////////////
function subMenu(i,obj){
	// If button is clicked a second time, set obj and i to
	// false to close the sub menu
	if(i && dojo.byId('sub'+i).style.display=='block'){
		obj=false;
		i=false;
	}
	// Retrieve the buttons and sub menus
	var subs = dojo.dom.getFirstChildElement(dojo.byId('sub_bar'));
	var buttons = dojo.dom.getFirstChildElement(dojo.byId('nav_bar'));
	// Hide all sub menus
	while(subs){
		subs.style.display='none';
		subs = dojo.dom.getNextSiblingElement(subs);
	}
	// Display the sub menu that corresponds to the button clicked
	if(i){
		dojo.byId('sub'+i).style.display='block';
	}
	// Reset all the buttons
	while(buttons){
		dojo.dom.getFirstChildElement(buttons).className='';
		dojo.dom.getLastChildElement(buttons).style.display='block';
		buttons = dojo.dom.getNextSiblingElement(buttons);
	}
	// Set the clicked button to the selected state
	if(obj){
		obj.className='nav_selected';
		dojo.dom.getLastChildElement(obj.parentNode).style.display='none';
	}
}
////////////////
// testInfo() //
///////////////////////////////////////////////////
// Show test information that corresponds to the //
// test button clicked. If clicked a second time //
// or cancel button is clicked, hide the test    //
// information.                                  //
//                                               //
// ARGUMENTS:                                    //
// id -- ID of test information to be toggled.   //
// obj -- The button that was clicked.           //
///////////////////////////////////////////////////
function testInfo(id,obj){
	if(id && dojo.byId(id).style.display=='block'){
		id=false;
	}
	var list = dojo.dom.getFirstChildElement(dojo.byId('project_info'));
	while(list){
		list.style.display='none';
		list = dojo.dom.getNextSiblingElement(list);
	}
	if(dojo.byId('int_tests')){
		var projList = dojo.dom.getFirstChildElement(dojo.byId('int_tests'));
		while(projList){
			projList.className='';
			if(dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).className=='new'){
				dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).src='resources/graphics/new-information.gif';
				dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).alt='Recently Updated - View Test Information';
			}else{
				dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).src='resources/graphics/information.gif';
				dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).alt='View Test Information';
			}
			projList = dojo.dom.getNextSiblingElement(projList);
		}
	}
	var projList = dojo.dom.getFirstChildElement(dojo.byId('pub_tests'));
	while(projList){
		projList.className='';
		if(dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).className=='new'){
			dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).src='resources/graphics/new-information.gif';
			dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).alt='Recently Updated - View Test Information';
		}else{
			dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).src='resources/graphics/information.gif';
			dojo.dom.getFirstChildElement(dojo.dom.getFirstChildElement(projList)).alt='View Test Information';
		}
		projList = dojo.dom.getNextSiblingElement(projList);
	}
	if(id){
		dojo.byId('intro_text').style.display='none';
		dojo.byId(id).style.display='block';
		obj.parentNode.className='select';
		dojo.dom.getFirstChildElement(obj).src='resources/graphics/cancel.gif';
		dojo.dom.getFirstChildElement(obj).alt='Close Test Information';
	}else{
		dojo.byId('intro_text').style.display='block';
	}
}
///////////////
// setSkin() //
///////////////////////////////////////////////////
// Sets a cookie with the name of a color_*.css  //
// to be used as the skin and reloads the page.  //
//                                               //
// ARGUMENTS:                                    //
// file -- Name of the CSS file to be used.      //
///////////////////////////////////////////////////
function setSkin(file){
	document.cookie = 'skin=' + file + '; expires=Fri, 12 Mar 2010 20:47:11 UTC;';
	window.location.reload();
}
//////////////////
// displayBox() //
///////////////////////////////////////////////////
// Brings a UI box out of the panel and to the   //
// top center of the page. The rest of the page  //
// is darkened and disabled. See HTML source for //
// the format of the UI box.                     //
//                                               //
// ARGUMENTS:                                    //
// id -- ID of the UI Box to be presented.       //
///////////////////////////////////////////////////
function openBox(id){
	var box = dojo.byId(id);
	box.style.left=(screen.width/2)-100+'px';
	box.className='display_box';
	var handle = dojo.dom.getFirstChildElement(box);
	var root = box;
	Drag.init(handle, root);
	disablePage(true);
}
////////////////
// closeBox() //
///////////////////////////////////////////////////
// Closes the UI box that contains the button    //
// that was clicked and places is back into the  //
// panel.                                        //
//                                               //
// ARGUMENTS:                                    //
// obj -- The close link of the box to be closed.//
///////////////////////////////////////////////////
function closeBox(obj){
	var link = dojo.dom.getFirstChildElement(obj.parentNode);
	var box = obj.parentNode.parentNode;
	box.className='box';
	link.style.display='inline';
	disablePage(false);
}
///////////////
// hideBox() //
///////////////////////////////////////////////////
// Closes the UI box that contains the button    //
// that was clicked.                             //
//                                               //
// ARGUMENTS:                                    //
// obj -- The close link of the box to be closed.//
///////////////////////////////////////////////////
function hideBox(obj){
	var box = obj.parentNode.parentNode;
	box.className='hidden';
	disablePage(false);
}
///////////////
// showBox() //
///////////////////////////////////////////////////
// Renders a box that is not on the button panel.//
//                                               //
// ARGUMENTS:                                    //
// id -- ID of the box to be displayed.          //
///////////////////////////////////////////////////
function showBox(id){
	var box = dojo.byId(id);
	box.style.left=(screen.width/2)-100+'px';
	box.className='display_box';
	var handle = dojo.dom.getFirstChildElement(box);
	var root = box;
	Drag.init(handle, root);
	disablePage(true);
}
///////////////////
// disablePage() //
///////////////////////////////////////////////////
// Disables the page by rendering a              //
// semi-transparent layer with a z-index of 100. //
//                                               //
// ARGUMENTS:                                    //
// disable -- Boolean. True to disable the page, //
// false to re-enable the page.                  //
///////////////////////////////////////////////////
function disablePage(disable){
	var cover=dojo.byId('cover');
	if(disable){
		cover.style.display='block';
		var coverHeight=dojo.byId('page').offsetHeight;
		cover.style.height=coverHeight+'px';
	}else{
		cover.style.display='none';
	}
}
//////////////
// toggle() //
///////////////////////////////////////////////////
// Toggle UI boxes between the open and closed   //
// states. See HTML source for format of the UI  //
// boxes.                                        //
//                                               //
// ARGUMENTS:                                    //
// obj -- The expand/contract button that was    //
// clicked.                                      //
///////////////////////////////////////////////////
function toggle(obj){
	var text = dojo.dom.getNextSiblingElement(obj.parentNode);
	var button = dojo.dom.getFirstChildElement(obj);
	if(button.alt=='Minimize'){
		text.style.display='none';
		button.src='resources/graphics/page_right.gif';
		button.alt='Expand';
	}else{
		text.style.display='block';
		button.src='resources/graphics/page_down.gif';
		button.alt='Minimize';
	}
}
