
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(activateMembersLink);
addLoadEvent(insertSiteLinks);

function activateMembersLink() {
	var container = document.getElementById("xg_layout_column_1");
        if (!container) return false;
	var titles = container.getElementsByTagName("h2");
	for (var i=0; i < titles.length; i++) {
		if (titles[i].innerHTML == "Members") {
			titles[i].innerHTML = '<a style="color:#fff" href="/profiles/members/">members</a>';
		}
	}
}



function insertSiteLinks() {
	var elAccount = document.getElementById('xg_module_account');
	if (!elAccount) return false;
	var elContainer = elAccount.parentNode;
	if (!elContainer) return false;
var strLinks = '<p><a style="font-size:12px;" href="/groups">Groups</a>  |  <a style="font-size:12px;" href="/profiles">My Profile</a>  |  <a style="font-size:12px;" href="http://boards.atlanticrecords.com/artists/staind/forums?mod=4691056" target="_blank">Old Forums</a></p>\n';
strLinks = strLinks + '<div id="rightlinks"><table cellpadding="0" cellspacing="0" border="0" align="center" width="183"><tr><td><a href="http://www.facebook.com/pages/Staind/28175172673" target="_blank"><img src="http://flash.atlrec.com/staind/ning/logo_face.gif"  /></a></td>\n';
strLinks = strLinks + '<td><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewArtist?id=613161" target="_blank"><img src="http://flash.atlrec.com/staind/ning/logo_itunes.gif"  /></a></td></tr>\n';
strLinks = strLinks + '<tr><td><a href="http://www.myspace.com/staind" target="_blank"><img src="http://flash.atlrec.com/staind/ning/logo_myspace.gif"  /></a></td>\n';
strLinks = strLinks + '<td><a href="http://www.youtube.com/user/StaindVideos" target="_blank"><img src="http://flash.atlrec.com/staind/ning/logo_youtube.gif"  /></a></td></tr>\n';
strLinks = strLinks + '<tr><td colspan="2"><a href="http://www.imeem.com/staind" target="_blank"><img src="http://flash.atlrec.com/staind/ning/logo_imeem.gif"  /></a></td></tr></table></div>';
var elLinks = document.createElement("div");
elLinks.setAttribute("style", "font-size:12px;text-align:center;padding-bottom:10px;");
elLinks.innerHTML = strLinks;
elContainer.insertBefore(elLinks, elAccount);


}

var tourstab = document.createElement('li');
tourstab.id='xg_tab_tour';
tourstab.innerHTML = '<a href="/events">Tour</a>';

var newstab = document.createElement('li');
newstab.id='xg_tab_news';
newstab.innerHTML = '<a href="/notes/index/allNotes">News</a>';

var blogtab = document.createElement('li');
blogtab.id='xg_tab_blog';
blogtab.innerHTML = '<a href="/profiles/blog/list">Blog</a>';

var musictab = document.createElement('li');
musictab.id='xg_tab_music';
musictab.innerHTML = '<a href="/discography">Music</a>';

var photostab = document.createElement('li');
photostab.id='xg_tab_photos';
photostab.innerHTML = '<a href="/photo">Photos</a>';

var biotab = document.createElement('li');
biotab.id='xg_tab_bio';
biotab.innerHTML = '<a href="/page/page/show?id=2223627%3APage%3A45">Bio</a>';

var fanclubtab = document.createElement('li');
fanclubtab.id='xg_tab_fanclub';
fanclubtab.innerHTML = '<a href="http://www.dysfunctionalstaind.com" target="_blank">Fanclub</a>';

var storetab = document.createElement('li');
storetab.id='xg_tab_store';
storetab.innerHTML = '<a href="http://www.fanfire.com/cgi-bin/WebObjects/fanfire.woa/wa/artist?artistName=Staind&sourceCode=STAWEB" target="_blank">Store</a>';

var ringtonestab = document.createElement('li');
ringtonestab.id='xg_tab_ringtones';
ringtonestab.innerHTML = '<a href="http://www.atlanticrecords.com/mobile/artist/?artistId=Staind" target="_blank">Ringtones</a>';

// add the new menu items at their right spot

var referencetab = document.getElementById('xg_tab_video');
if(referencetab) {
	referencetab.parentNode.insertBefore(newstab,referencetab);
	referencetab.parentNode.insertBefore(blogtab,referencetab);
	referencetab.parentNode.insertBefore(tourstab,referencetab);
	referencetab.parentNode.insertBefore(musictab,referencetab);
}

var referencetab = document.getElementById('xg_tab_forum');
if(referencetab) {
	referencetab.parentNode.insertBefore(photostab,referencetab);
	referencetab.parentNode.insertBefore(biotab,referencetab);
}

var referencetab = document.getElementById('xg_tab_forum');
if(referencetab) {
	referencetab.parentNode.appendChild(fanclubtab,referencetab);
	referencetab.parentNode.appendChild(storetab,referencetab);
	referencetab.parentNode.appendChild(ringtonestab,referencetab);
}



//The order we want the tabs to be in.
// - elements are stated here in the form of their tab's HTML ID attribute without the xg_tab_
// - all items not in this list will be removed
// - all items in this list that aren't tabs will be ignored


var newTabOrder = new Array("main", "news", "blog", "tour", "photo", "video", "music", "bio", "forum", "fanclub", "store", "ringtones", "manage");



//get the current nav bar
var currentNavBar = document.getElementById("xg_navigation");
//where we'll put the tabs
var currentTabs = Array();
var tabList = null;

//only update the nav bar if it's on this page
if(currentNavBar) {
    //grab all of the nav items now
    for(var x=0; x < currentNavBar.childNodes.length; x++) {
        if(currentNavBar.childNodes[x].nodeName && 
            currentNavBar.childNodes[x].nodeName.match("UL")) {
            //we've found the list of nodes, now extract
            tabList = currentNavBar.childNodes[x];
            for(var y=0; y < tabList.childNodes.length; y++) {
                //finally, grab the tabs
                if(tabList.childNodes[y].nodeName && 
                    tabList.childNodes[y].nodeName.match("LI")) {
                    currentTabs.push(tabList.childNodes[y]);
                }
            }
            //remove the current navigation links
            if ( tabList.hasChildNodes() ) {
                while ( tabList.childNodes.length >= 1 ) {
                    tabList.removeChild( tabList.firstChild );       
                } 
            }
            break;
        }
    }

    //now that it's empty, add the tabs back in the desired order
    //yes this is O(n^2), but if that's a problem you have too many tabs
    for(var x=0; x < newTabOrder.length; x++) {
        for(var y=0; y < currentTabs.length; y++) {
            if(currentTabs[y].id && 
                currentTabs[y].id.match(newTabOrder[x])) {
                //we found the tab for this position, add it
                tabList.appendChild(currentTabs[y]);
                break;
            }
        }
    }
}

/****************************************************
     Author: Eric King
     Url: http://redrival.com/eak/index.shtml
     This script is free to use as long as this info is left in
     Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}

// JavaScript Document
/*
	Copyright Robert Nyman, http://www.robertnyman.com
	Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}