var url, target, delay=1000;

function doAHAH(htmlPage,containingDiv,loadImg) {
	url = htmlPage;
	target = containingDiv;
	jah(url,target,loadImg);
}	

function init() {
	doAHAH('/fishing/stories/index.html','fishStory',0);
}

// AHAH Code from: http://microformats.org/wiki/rest/ahah

function jah(url,target,loadImg) {
    // native XMLHttpRequest object
		var loadImgArray = new Array();
		loadImgArray[0] = "<img src='/images/fishing/crew/loading_group.gif' alt='Loading' width='475' height='73' border='0' style='margin: 35px 0px 25px 20px;'>";
		loadImgArray[1] = "<img src='/images/fishing/crew/loading_full.gif' alt='Loading' width='475' height='353' border='0' style='margin-top: -6px;'>";
		loadImgArray[2] = "<img src='/images/fishing/crew/loading_content.gif' alt='Loading' width='70' height='70' border='0' style='margin: 75px 0px 25px 185px;'>";
		loadImgArray[3] = "<img src='/images/fishing/crew/loading_content.gif' alt='Loading' width='70' height='70' border='0' style='border: none;margin: 95px 200px 95px 185px;'>";

    document.getElementById(target).innerHTML = loadImgArray[loadImg];
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
}    

function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
            execJS(document.getElementById(target));
        } else {
            document.getElementById(target).innerHTML="jah error:\n" +
                req.statusText;
        }
    }
}
var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
var bMoz = (navigator.appName == 'Netscape');
function execJS(node) {
  var st = node.getElementsByTagName('SCRIPT');
  var strExec;
  for(var i=0;i<st.length; i++) {     
    if (bSaf) {
      strExec = st[i].innerHTML;
    }
    else if (bOpera) {
      strExec = st[i].text;
    }
    else if (bMoz) {
      strExec = st[i].textContent;
    }
    else {
      strExec = st[i].text;
    }
    try {
      eval(strExec);
    } catch(e) {
      alert(e);
    }
  }
}

// END base AHAH code
var currentGroup = 'florida', currentMember, currentSection, currentPicture;

function setGroup(newGroup) {
	var oldGroupLink = document.getElementById(currentGroup);
	var newGroupLink = document.getElementById(newGroup);

	oldGroupLink.className='offGroup';
	newGroupLink.className='current';

	doAHAH('/fishing/crew/'+newGroup+'.html','fishingCrew',0);	
	
	currentGroup = newGroup;
	currentMember = '';
	currentSection = '';
}

function setMember(newMember) {
	if (newMember != currentMember) {
		var newMemberLink = document.getElementById(newMember);
		newMemberLink.className='crewLink activeCrew';
	
		if (currentMember) {
			var oldMemberLink = document.getElementById(currentMember);
			oldMemberLink.className='crewLink';
		}
		
		doAHAH('/fishing/stories/'+newMember+'.html','crewMemberBox',1);	
		currentMember = newMember;
		currentSection = 'bio';
		currentPicture = 'one';
	}
}

function setSection(whichSection) {
	if (whichSection != currentSection) {
		var newSectionLink = document.getElementById(whichSection);
		newSectionLink.className='on';
	
		if (currentSection) {
			var oldSectionLink = document.getElementById(currentSection);
			oldSectionLink.className='off';
		}
		
		doAHAH('/fishing/crew/'+currentMember+'/'+whichSection+'.html','crewContentContain',2);	
		currentSection = whichSection;
	}
}
/*
function setPicture(whichPicture) {
	if (setPicture.arguments.length > 1)
		currentPicture = 'one';
	
	if (whichPicture != currentPicture) {
		var newPictureLink = document.getElementById(whichPicture+'Link')
		var newPictureDiv = document.getElementById(whichPicture);
		
		var currentPictureLink = document.getElementById(currentPicture+'Link')
		var currentPictureDiv = document.getElementById(currentPicture);
		
		currentPictureLink.className = 'off';
		currentPictureDiv.style.display = 'none';		
		
		newPictureLink.className = 'on';
		newPictureDiv.style.display = 'inline';		

		currentPicture = whichPicture;
	}
}
*/
function setRig(newRig) {
	if (newRig != currentRig) {
		var newRigLink = document.getElementById("rigLink" + newRig);
		newRigLink.className='crewLink activeCrew';
	
		if (currentRig) {
			var oldRigLink = document.getElementById("rigLink" + currentRig);
			oldRigLink.className='crewLink';
		}
		doAHAH('/fishing/outfitting/rig'+newRig+'/rig.html','rigBox',1);	
		currentRig = newRig;
		currentView = 1;
	}
}

function setRigShot(whichPicture) {
	if (whichPicture != currentView) {
		var oldRigShotLink = document.getElementById("rigShotLink" + currentView);
		var newRigShotLink = document.getElementById("rigShotLink" + whichPicture);
		oldRigShotLink.className="";
		newRigShotLink.className="currentShot";
		
		doAHAH('/fishing/outfitting/rig'+currentRig+'/rigShot_'+whichPicture+'.html','rigShot',3);	
		
		currentView = whichPicture;
	}
}