// JavaScript Document

 



 


var CollapsingMenu = {};
	
CollapsingMenu.init = function(){

//add .toggleMenu as event handlers to clicks associated with "ul"s with class collapsable.
	PageUpdate.activateLinks(document,"collapsable","a","click",CollapsingMenu.toggleMenu);
	PageUpdate.activateLinks(document,"sibling_collapse","a","click",CollapsingMenu.collapseSiblings);
	
};

CollapsingMenu.apply = function(){
		//same as init above, but to be used in case when you do not need this to run right 
		//upon loading of XHTML- CAN I ELIIMINATE THIS ONE- PROBABLY... **ATTEN TO**
	
	PageUpdate.activateLinks(document,"collapsable1","a","click",CollapsingMenu.toggleMenu);
};

	
CollapsingMenu.collapse = function(block){
	Core.removeClass(block,"expanded");
	Core.addClass(block,"collapsed");
};

CollapsingMenu.expand= function(block){	
	Core.removeClass(block,"collapsed");
	Core.addClass(block,"expanded");
};

CollapsingMenu.toggleBlock = function(block){
	if (block.className == "collapsed"){
			CollapsingMenu.expand(block);
		}
	else{
			CollapsingMenu.collapse(block);
		}
};

CollapsingMenu.getBlockForLink = function(myLink){
/*As what is expanded or collapsed in a nested list is the block
defined by the ul element, we must have a way to get to that element from
the link associated with it that the user clicks. This is the purpose of this
method. Get LI that is parent of link, the go through all children of this parent
until you find the UL element (there will only ever be one) that you want. 
*/

var myBlock = null;
		/* ATTEND TO: CHANGE CODE HERE TO [0] TYPE */
	var myParentNode = myLink.parentNode;
	var myLinkSiblings = myParentNode.childNodes;
	for (var i=0;i<myLinkSiblings.length;i++){
		if (myLinkSiblings[i].tagName == "UL" || myLinkSiblings[i].tagName == "ul"){
		 myBlock = myLinkSiblings[i];
		}
	}
			return myBlock;

};
			

CollapsingMenu.toggleMenu = function(event){
/*This is the fucnction that "does" the collapsing or expanding
when a link is clicked. Not only must you collapse or expand
(Depending on its current state) the link but you must 
also collapse any other expanded links except for the "parent"
link. 
*/
	var myBlock = CollapsingMenu.getBlockForLink(this);
		if (Core.hasClass(myBlock,"collapsed")){
			CollapsingMenu.collapseSiblingLinks(this);
			CollapsingMenu.expand(myBlock);	
					}
		
	else{
			CollapsingMenu.collapse(myBlock);
		}
		Core.preventDefault(event);
		Core.stopPropagation(event);
};
		

CollapsingMenu.collapseDescendantBlocks = function(myAncestorUL){
//This function will collapse all first descendants "ul" blocks of parent "ul" block.
	var myChildrenULNodes = myAncestorUL.getElementsByTagName("UL");

	for (var i =0;i <myChildrenULNodes.length;i++){
		CollapsingMenu.collapse(myChildrenULNodes[i]);
	}
};


CollapsingMenu.collapseSiblings = function(event){

CollapsingMenu.collapseSiblingLinks(this);

Core.stopPropagation(event);
Core.preventDefault(event);
	
};


CollapsingMenu.collapseSiblingLinks = function(myLink){
/* The "sibling" links referred to in the method name or those that need
to be collapsed when a given link is clicked. These are all the links that are on the "same level"
as the clicked link. 
*/
	var myUlAncestor = myLink.parentNode.parentNode;
	//This gets the ul "ancestor" node of the link. 
	CollapsingMenu.collapseDescendantBlocks(myUlAncestor);
};


/* In this file create an object with methods that assigns to links handlers that will then be used to generate inner menus 
from click on links in the main navigation.
*/



var InnerNavigation ={};
/* This object with its associated methods deals with the behaviour of the inner menus. e.g. when you click COACHES, a method from 
this object will bring up a the inner age sub-menu as well as the inner image of a coach. Clicking on "DRILLS AND PRACTICES" will cause
a method from this object to bring up the DRILLS AND PRACTICES INNER MENU. */

InnerNavigation.init = function(){
PageUpdate.activateLinks(document,"to_thumbnails","a","click",InnerNavigation.getThumbnails);
};

InnerNavigation.getThumbnails = function(event){
	/*This method obtains the thumbanils to be be displayed through an XMLHttpRequest*/
var InnerDisplayer = document.getElementById("inner_displayer");
var WrapContent = document.getElementById("wrap_content");
WrapContent.removeChild(InnerDisplayer);

PageUpdate.addXML(this,"div",WrapContent);

		ScrollBars.activateScrollBar("thumbnail_container","thumbnail_content","thumbnail_scroll_area","thumbnail_scroller","thumbnail_up_arrow_link","thumbnail_down_arrow_link");


Core.preventDefault(event);	
Core.stopPropagation(event);
	
};


var Tree1 = {};


Tree1.transferTree = function(XMLNode,XHTMLParentNode){
/*This recursive method takes an XML node, translates it into an XHTML node and append into to a "parent" XHTML node*/
var XHTMLNode = Tree1.translate(XMLNode);

if (XHTMLNode != null) {
	XHTMLParentNode.appendChild(XHTMLNode);
}


if (XMLNode.childNodes != null){
	for (var i = 0; i < XMLNode.childNodes.length;i++){
	
	Tree1.transferTree(XMLNode.childNodes[i],XHTMLNode);
		
	}
	
	
	}

};

Tree1.translate = function(XMLNode){
/*This function translates an XML node into and XHTML node*/
var regex_text = /\S/;
var XHTMLNode = null;
	//debugger;
	if (XMLNode.nodeType == 1){
	
	 XHTMLNode = document.createElement(XMLNode.nodeName);
			//translate non-text nodes
		XHTMLNode = Tree1.translateAttribute(XMLNode,XHTMLNode,"class");
		XHTMLNode = Tree1.translateAttribute(XMLNode,XHTMLNode,"href");	
		XHTMLNode = Tree1.translateAttribute(XMLNode,XHTMLNode,"id");
		XHTMLNode = Tree1.translateAttribute(XMLNode,XHTMLNode,"src");
		XHTMLNode = Tree1.translateAttribute(XMLNode,XHTMLNode,"alt");
		
	
	}
if (XMLNode.nodeType ==3)
	{
		//Create this text node only if it is not a whitespace node. 
		if (regex_text.test(XMLNode.nodeValue)){
			
			XHTMLNode = document.createTextNode(XMLNode.nodeValue);
		}
	
	}
	
return XHTMLNode;

};




Tree1.translateAttribute = function(XMLnode,XHTMLnode,attribute){
		/*Make this code more efficient*/
		/*In XML class, href, src and id are all treated as attributes. Translate into the appropriate XHTML categories.*/
	var myAttributeValue = XMLnode.getAttribute(attribute);
	
	if (myAttributeValue != null){
			
			if (attribute == "class"){
					Core.addClass(XHTMLnode,myAttributeValue);
			}
			
			if (attribute == "href"){
					XHTMLnode.setAttribute(attribute,myAttributeValue);
			}
			
			if (attribute == "id"){
					XHTMLnode.id= myAttributeValue;
			}
			
			if (attribute == "src"){
					XHTMLnode.setAttribute(attribute,myAttributeValue);
			}
			
			if (attribute == "alt"){
					XHTMLnode.setAttribute(attribute,myAttributeValue);
			}
				 
			
	}

return XHTMLnode;
};

var ToExternalSite = {};

ToExternalSite.init = function(){
	
PageUpdate.activateLinks(document,"to_outside","a","click",ToExternalSite.externalLink);
	
	
};
	
ToExternalSite.externalLink = function(event){

confirm("You are about to leave Inside Soccer. Are you sure?");

Core.stopPropagation(event);
};

var DomUtilities = {};

DomUtilities.removeChildren = function(parent){
//This fucntion removes alll children from a parent node	

var AllChildren = parent.childNodes; 
var InitialLength = AllChildren.length;
var myLength = AllChildren.length;

if (myLength != 0){
	
	var i = 0;
	
	while ( i < InitialLength){
		
			parent.removeChild(AllChildren[InitialLength - 1 - i]);		
			i++;
			
	AllChildren = parent.childNodes;
			myLength = AllChildren.length;

		}
	
	
	}


};


var PageUpdate = {};

PageUpdate.addXML = function(myLink, XMLParentElement, targetHTMLNode){
/* This function retrieves XML file associated with a link, converts in XHTML DOM elements and appends ito to 
the target node, after first clearing the parent node of all its children*/	
var XMLFile = myLink.href;
var xhr = 	MyXMLHttp.getXHR();
	if (xhr != null){
		var XMLObj = MyXMLHttp.basicRequest(xhr,XMLFile,false);	
	if (XMLObj != null){
		var ParentNode = XMLObj.getElementsByTagName(XMLParentElement)[0];
		Tree1.transferTree(ParentNode,targetHTMLNode);
		}
	}	
};


PageUpdate.activateLinks = function(targetNode,className,tagName,eventType,eventFunction){

/*This fucntion applies the <eventFunction> to event of  <evenType> to all elements in the targetNode that have tage <tagName> and are of 
class <className>.*/

var myLinks = targetNode.getElementsByTagName(tagName);
if (className == "none"){
		for (var i = 0; i < myLinks.length;i++){
			Core.addEventListener(myLinks[i],eventType,eventFunction);					
			}
	
	
	}
	else
	{
		for (var i = 0; i < myLinks.length;i++){
				if (Core.hasClass(myLinks[i],className)){
					Core.addEventListener(myLinks[i],eventType,eventFunction);					
				}										 
		}
		
	}
	

};




var Rollover = {};

Rollover.init = function(){
	/* et all images for which you want to have a rollover behaviuor and assign this beahvior to them*/	
	Rollover.assignRolloversToPage("rollover",".png");
	
	};

Rollover.assignRolloversToPage = function(rollover_class,image_ext){
	
	var myImages = Core.getElementsByClass(rollover_class);
	for (var i = 0; i < myImages.length;i++){
		Rollover.activateRollover(myImages[i],image_ext);		
		}
	};
/*
Rollover.activateRollover = function(thisImage,image_ext){
	 
	 thisImage.outImage = new Image();
	 thisImage.outImage.src = thisImage.src;
	 Core.addEventListener(thisImage,"mouseout",Rollover.rollOut);
	 
	 var src = thisImage.src;
	 var i = src.lastIndexOf("/");
	 var image_dir = src.substring(0,i);
	 
	thisImage.overImage = new Image();
	 thisImage.overImage.src = image_dir + "\/" + thisImage.id + "_on" + image_ext;
	 Core.addEventListener(thisImage,"mouseover",Rollover.rollOver);
	 
	};
*/
Rollover.activateRollover = function(thisImage,image_dir,image_ext){
 
thisImage.outImage = new Image();
thisImage.outImage.src = thisImage.src;
Core.addEventListener(thisImage,"mouseout",Rollover.rollOut);
 
         var src   = thisImage.src;
         var i     = src.lastIndexOf ("/");
         var j     = src.lastIndexOf (".");
         image_dir = src.substring(0, i);
         image_ext = src.substring(j);
         
thisImage.overImage = new Image();         
thisImage.overImage.src = image_dir + "\/" + thisImage.id + "_on" + image_ext;
Core.addEventListener(thisImage,"mouseover",Rollover.rollOver);
 
};

Rollover.rollOut = function(){
	this.src = this.outImage.src; 
		
	};
	
Rollover.rollOver = function(){
	this.src = this.overImage.src; 
		
	};

var InnerNavigation ={};
/* This object with its associated methods deals with the behaviour of the inner menus. e.g. when you click COACHES, a method from 
this object will bring up a the inner age sub-menu as well as the inner image of a coach. Clicking on "DRILLS AND PRACTICES" will cause
a method from this object to bring up the DRILLS AND PRACTICES INNER MENU. */

InnerNavigation.init = function(){
PageUpdate.activateLinks(document,"to_thumbnails","a","click",InnerNavigation.getThumbnails);
};

InnerNavigation.getThumbnails = function(event){
	/*This method obtains the thumbanils to be be displayed through an XMLHttpRequest*/
var InnerDisplayer = document.getElementById("inner_displayer");
var WrapContent = document.getElementById("wrap_content");
WrapContent.removeChild(InnerDisplayer);

PageUpdate.addXML(this,"div",WrapContent);

		ScrollBars.activateScrollBar("thumbnail_container","thumbnail_content","thumbnail_scroll_area","thumbnail_scroller","thumbnail_up_arrow_link","thumbnail_down_arrow_link");


Core.preventDefault(event);	
Core.stopPropagation(event);
	
};



var Forms = {};

Forms.init = function(){
PageUpdate.activateLinks(document,"to_my_teams","a","click",Forms.getMyTeamsFormElements);

}

Forms.getMyTeamsFormElements = function(event){
//debugger;
if (!Core.hasClass(this,"doneXML")){
		
	var Li = document.getElementById("teams_anchor")
	PageUpdate.addXML(this,"ol",Li);
	Core.addClass(this,"doneXML");
	}
	
	Core.preventDefault(event);	
	Core.stopPropagation(event);
};

Forms.getMyTeamsInfo = function(myTeamCB,liCbId){

var teamXMLFile = 
PageUpdate.addXML(this,"div",WrapContent);


};




var MyXMLHttp = {};



MyXMLHttp.getXHR_old = function(){


try 
	{
		var xhr = new XMLHttpRequest();
	}
	catch (error)
	{
			try
			{
				var xhr = new ActivexObjext("Microsoft.XMLHTTP");
			}
			catch (error)
			{
					var xhr = null;
			}
	}
	
	if (xhr == null) {
		alert("Not Ajax enabled!");
		}

return xhr;
};

MyXMLHttp.getXHR = function(){
  var xmlhttp=false;
   /* running locally on IE5.5, IE6, IE7 */                                             
     if(location.protocol=="file:"){
      if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
      if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
     }                                                                               
   /* IE7, Firefox, Safari, Opera...  */
     if(!xmlhttp)try{ xmlhttp=new XMLHttpRequest(); }catch(e){xmlhttp=false;}
   /* IE6 */
     if(typeof ActiveXObject != "undefined"){
      if(!xmlhttp)try{ xmlhttp=new ActiveXObject("MSXML2.XMLHTTP"); }catch(e){xmlhttp=false;}
      if(!xmlhttp)try{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){xmlhttp=false;}
     }
   /* IceBrowser */
     if(!xmlhttp)try{ xmlhttp=createRequest(); }catch(e){xmlhttp=false;}


	if (!xmlhttp) {
		alert("Not Ajax enabled!");
		}

return xmlhttp;
};


MyXMLHttp.basicRequest_old = function(xhr,filename,is_asynchronous){

var XMLObj = null;
//debugger;
xhr.open("GET",filename,is_asynchronous);
xhr.send(null);		
var XMLObj = xhr.responseXML;
	
return XMLObj;
};

MyXMLHttp.basicRequest = function(xhr,filename,is_asynchronous){
//debugger;
var XMLObj = null;
//debugger;
xhr.open("GET",filename,is_asynchronous);
xhr.send(null);		

var isLocal = (xhr.status == Statuscode.mydefault); 
if (xhr.readyState == Readystate.complete &&  
   (xhr.status == Statuscode.ok || isLocal)) {  
   
   XMLObj = xhr.responseXML;
   
   if (XMLObj == null){
	  
	   //return XMLObj;
   }
   else if (XMLObj.documentElement==null){
	   	if (!isLocal){
			//there is no xml in this request 
			//return XMLObj;
		}
		else {
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = false;
			xmlDoc.loadXML(xhr.responseText);
			
			if (xmlDoc.documentElement != null){
				XMLObj = xmlDoc;
				//return XMLObj;
			}
			else{
				//return XMLObj;	
			}
		}		
 	  }
	}
return XMLObj; 
};




MyXMLHttp.textFromXMLNode = function(tagname,parentnode){
	
	var myNode = parentnode.getElementsByTagName(tagname)[0];
	var myTextNode = myNode.firstChild;
	var myText = myTextNode.nodeValue;
	

return myText;
	
};

var Readystate = {};
	
Readystate.uninitialized =0;
Readystate.loading = 1;
Readystate.loaded = 2;
Readystate.interactive = 3;
Readystate.complete = 4;
	


var Statuscode ={};
	
Statuscode.ok= 200;
Statuscode.mydefault = 0;

	

Core.start(CollapsingMenu);	
Core.start(InnerNavigation);
/*Core.start(LandingLinks);*/
/*Core.start(Players);*/
Core.start(ToExternalSite);
Core.start(Rollover);
Core.start(Forms);