/*
Copyright (c) 2007-2009, AOL LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the AOL LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Keyboard Capture
// http://dev.aol.com/axs
// Version 1.2
// March 10, 2009
// C. Blouch

axs.debug=1;

var test={
	//Initialize things after the page is fully loaded
	init:function(){
		axs.id("box1").onclick=function(){test.gothere.apply(this,["c1.html"])};
		axs.id("box2").onclick=function(){test.gothere.apply(this,["c2.html"])};
		axs.id("box3").onclick=function(){test.gothere.apply(this,["c3.html"])};
		axs.id("box4").onclick=function(){test.gothere.apply(this,["c4.html"])};
		
		axs.keyreg("control+alt+l",test.gothere,{args:["c1.html"],node:axs.id("box1"),des:"Load content in the box that currently has focus"});
		axs.keyreg("control+alt+l",test.gothere,{args:["c2.html"],node:axs.id("box2")});
		axs.keyreg("control+alt+l",test.gothere,{args:["c3.html"],node:axs.id("box3")});
		axs.keyreg("control+alt+l",test.gothere,{args:["c4.html"],node:axs.id("box4")});
		axs.keyreg("control+alt+7",test.jump,{args:["box1"],des:"Move focus to Box 1"});
		axs.keyreg("control+alt+8",test.jump,{args:["box2"],des:"Move focus to Box 2"});
		axs.keyreg("control+alt+9",test.jump,{args:["box3"],des:"Move focus to Box 3"});
		axs.keyreg("control+alt+0",test.jump,{args:["box4"],des:"Move focus to Box 4"});
		axs.keyreg("control+alt+g",test.loadall,{des:"Load content in all boxes"});
		axs.keychart.l10n.help="<span id='bob'>For more help see our <a href='keycap_help.html'>Help page</a></span>";
		axs.keychart();
	},
	//Ajax in the new content
	gothere:function(file){
		axs.gdoc(file,{cb:test.gothere_cb,p:{obj:this}});
	},
	gothere_cb:function(re,p){
		//Check to see if the ajax completed correctly
		if(re.status==200){
			//Move focus away from the object we want to update so Jaws won't get confused
			p.obj.blur();
			//Stuff the object given us in p with the content returned by the ajax request
			axs.r(p.obj,re.responseText);
			//Move focus to the h6 header in the new content inside the object
			//If this is a loadall, only move when box 1 is done
			if(p.la && p.obj.id=="box1" || !p.la){
				axs.focus(p.obj.getElementsByTagName("h6")[0]);
			}
		}
	},
	//Load up all the boxes
	loadall:function(){
		//Walk through all the IDs and call gdoc on each one
		//URL is 'c1.html' for the content going into box 1
		//ID is 'box1' for the DIV that makes up box 1
		for(var i=1;i<5;i++){
			axs.gdoc("c"+i+".html",{cb:test.gothere_cb,p:{obj:axs.id("box"+i),la:1}});
		}
	},
	//Move focus to one of the boxes
	jump:function(box){
		axs.focus(axs.id(box));
	}
}
//When the window fires an onload event, call the function init()
axs.ae(window,'load',test.init);