corefunctions = {
  externallinks: function () 
  {
    if ( document.getElementsByTagName ) {
       var links = document.getElementsByTagName ( 'a' );
       for (var i = 0; i < links.length; i++ ) {
		 	if(links[i].getAttribute("rel") && links[i].getAttribute("href")) {
				var theREL = links[i].getAttribute("rel");
				var relArr = theREL.split('|');
				if (relArr[0] == 'popup'){
					extendOnClick(links[i], function(evt,el) {
						var that = typeof(el)=='object'?el:this;
						var url = that.getAttribute("href");
						var rel = that.getAttribute("rel");
						return corefunctions.popup(url,rel);
					});
				}

				if(theREL=='externaloverlay'){
					extendOnClick(links[i], function(evt,el) {
						var that = typeof(el)=='object'?el:this;
						var baseURL = 'http://www.sonywonder.com/parents/external.php?' + encodeURIComponent(that.getAttribute("href"));
						window.open(baseURL);
						return false;
					});
				}
			}
       }
	   
       var links = document.getElementsByTagName ( 'area' );
       for (var i = 0; i < links.length; i++ ) {
         var link = links[i];
         if ( ( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'external' ) ) {
           link.target = '_blank';
         }
       }
	   
    }//end outer if to get tag name
  }
  
  ,popup: function(theURL,theREL){
				var totalNumProps = 11;
				var reqNumProps = 4;
				var relArr = theREL.split(" ");
				
				//Check for syntax of REL string value and determine value for position. If syntax is incorrect, do not open a window.
				if(relArr.length > 2){
					if(typeof(console)!='undefined') console.log('INCORRECT! Too many spaces in REL tag associated with this link: '+ relArr);
					return true;
				}else{
					var position = "default";	
				}
			
				//Check for syntax of remaining REL string values and set properties. If syntax is incorrect, do not open a window. 
				relArr = relArr[0];
				relArr = relArr.split("|");
				if( (relArr.length == 2) && (relArr[1] != "") ){	
					var position = relArr[1];
				}else if ( (relArr.length < reqNumProps) || (relArr[relArr.length-1] == "") || (this.myParseInt(relArr[2], 0) == 0) || (this.myParseInt(relArr[3], 0) == 0) ){
					if(typeof(console)!='undefined') console.log('INCORRECT! Must have at least 4 initial values or there is an extra | separator or width/height is not a number!');
					return true;
				}
				
				var newArr = new Array(totalNumProps-relArr.length);
				for ( var i=0; i < newArr.length; i++) {
						newArr[i] = "0";
				}
				relArr = relArr.concat(newArr);
				var func = relArr[0]; 
				var target = relArr[1];
				var width = relArr[2];
				var height = relArr[3];			
				var toolbar = relArr[4];
				var scrollbars = relArr[5];
				var menubar = relArr[6];
				var resizable = relArr[7];
				var status = relArr[8];
				var location = relArr[9];
				var directory = relArr[10];
				
				for(var i=0; i < relArr.length; i++){
					var currProp = relArr[i];
					switch (currProp){
						case "t":
							toolbar = "1";
							break;
						case "s":
							scrollbars = "1";
							break;
						case "m":
							menubar = "1";
							break;
						case "r":
							resizable = "1";
							break;
						case "st":
							status = "1"
							break;
						case "l":
							location = "1"
							break;
						case "d":
							directory = "1";
							break;
						default: 
							break;
					}	
				}
				
				//Debug info for total number of REL tag properties
				/*var arrOutput = "There are "+relArr.length+" properties:\n";
				for ( var i=0; i < totalNumProps; i++) {
					arrOutput += relArr[i] + "\n"; 
				}
				if(typeof(console)!='undefined') console.log(arrOutput);*/
				
				if(position != "default"){
					var commaArr = position.split(",");
					
					if((commaArr.length > 2) || ((commaArr.length == 2) && ( (this.myParseInt(commaArr[0], 0) == 0) || (this.myParseInt(commaArr[1], 0) == 0)))) {	
						if(typeof(console)!='undefined') console.log('To many commas or coordinate values are not numbers for position value: '+commaArr);
						return true;
					}else if (commaArr.length == 2){	
						var left = commaArr[0];
						var top = commaArr[1];
						if(typeof(console)!='undefined') console.log('Popup is being placed at coordinate: '+left+','+top);
					}else{
						if(position == "center"){
							//Center the popup window
							var winLeft = (screen.width - width) / 2;
     						var winTop = (screen.height - height) / 2;
							var left = winLeft.toString();
							var top = winTop.toString();
							if(typeof(console)!='undefined') console.log('Popup is centered at '+left+','+top);
						}
						if(position == "full"){
							//Calculate fullscreen of popup window
							var width = screen.width;
     						var height = screen.height;
							var left = "0";
							var top = "0";
							if(typeof(console)!='undefined') console.log('Popup is full size with a w='+width+' height='+height);
						}
					}
				}else{
					var left = "0";
					var top = "0";
					if(typeof(console)!='undefined') console.log('Popup is full size at w='+width+' height='+height+' at coordinate '+left+','+top)
				}
				
				window.open(theURL,name,"width="+width+",height="+height+",toolbar="+toolbar+",scrollbars="+scrollbars+",menubar="+menubar+",resizable="+resizable+",status="+status+",location="+location+",directory="+directory+",left="+left+",top="+top+"'");
				return false;	
}

,myParseInt: function(str,defaultValue){
    var retValue = defaultValue;
    if(str!=null){
        if(str.length>0){
            if (!isNaN(str)){
                retValue = parseInt(str);
            }
        }
    }
    return retValue;
}//end myParseInt

}//end corefunctions

addLoadEvent(corefunctions.externallinks);