// JavaScript Document
// Copyright Christopher Donnelly T&C Web Concepts 2006/2007

//Page Variables for Bio Pages
var currentPage=0;
var totalPages=1;
var pageCount=1;
var itemCount=1;
var page=new Array();
var entering=true;
//Navigation Variables
var totalNav=0;
var navItems=new Array();
//Shadow Variables
var shadowDepth=6; //In Pixels
var shadowColor='#000000'; //Shadow Color
var addShadows=new Function(); //Function variable for addLoadEvents
var shadowContainer='contentLayer'; //Container Layer for shadows
var searchClass='shadow'; //Search for this Class
var shadowClass='shadow2'; //Shadow Class
//Mouse Move Variables
var mouseX, mouseY;
//Browser Variables
var	agent=navigator.userAgent;
var	dom=document.getElementById?true:false;
var docAll=document.all?true:false;
var	firefox=(agent.indexOf("Firefox")>-1)?true:false;
var	ie=(agent.indexOf("MSIE")>-1)?true:false;

//if(firefox) ie=false;

if(window.Event && document.captureEvents)
	document.captureEvents(Event.MOUSEMOVE);

document.onmousemove=getMousePos;

function getMousePos(e){
	if (!e)
		var e=window.event||window.Event;

	if('undefined'!=typeof e.pageX){
		mouseX=e.pageX;
		mouseY=e.pageY;
	}else{
		mouseX=e.clientX+document.body.scrollLeft;
		mouseY=e.clientY+document.body.scrollTop;
	}

}

function returnObjById(id){
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function navObj(arg1,arg2,arg3){
	this.name=arg1;
	this.value=arg2;
	this.page=arg3;
}

function addNavItem(navItem,navValue,navPage){
	navItems[totalNav]=new navObj(navItem,navValue,navPage);
	totalNav++;
}

function initNav(){
	addNavItem('home','Home','index.htm');
	/*addNavItem('about','About SBBS','about.htm');
	addNavItem('birds','Sanctuary Birds','birds.htm');
	addNavItem('success','Successful Adoptions','stories.htm');
	addNavItem('rescue','Rescue\'s Song','rescue.htm');
	addNavItem('education','Educational Information','education.htm');
	addNavItem('contribute','Contribution Information','contribute.htm');
	addNavItem('info','Additional Information','info.htm');
	addNavItem('founder','SBBS Founder','founder.htm');
	addNavItem('contact','Contact','contact.htm');
	addNavItem('links','Links','links.htm');*/
}

function addBio(imgLoc,name,bio){
	if(itemCount>6){
		itemCount=1;
		pageCount++;
	}
	initPages(pageCount,6);
	
	page[pageCount].image[itemCount]=imgLoc;
	page[pageCount].name[itemCount]=name;
	page[pageCount].bio[itemCount]=bio;
	
	itemCount++;
}

function writeEmails(){
	document.write('<p class="contentAddy" style="padding-left:25px;"><a href="mailto:JMENAGERIE@aol.com?subject=E-Mail%20Treasurer" title="E-Mail Treasurer">Treasurer</a></p>');
	document.write('<p class="contentAddy" style="padding-left:25px;"><a href="mailto:JMENAGERIE@aol.com?subject=E-Mail%20President" title="E-Mail President">President</a></p>');
	document.write('<p class="contentAddy" style="padding-left:25px;"><a href="mailto:JMENAGERIE@aol.com?subject=E-Mail%20Vice%20President" title="E-Mail Vice President">Vice President</a></p>');
	document.write('<p class="contentAddy" style="padding-left:25px;"><a href="mailto:JMENAGERIE@aol.com?subject=E-Mail%20Secretary" title="E-Mail Secretary">Secretary</a></p>');
	document.write('<p class="contentAddy" style="padding-left:25px;"><a href="mailto:JMENAGERIE@aol.com?subject=E-Mail%20Information" title=Information>Info</a></p>');
}

function writeImage(arg,width,height){
	if(firefox)
		document.write('<img src="images/'+arg+'.png" name="'+arg+'" id="'+arg+'" width="'+width+'" height="'+height+'">');
	else
		document.write('<img src="images/trans.gif" name="'+arg+'" id="'+arg+'" width="'+width+'" height="'+height+'" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src=\'images/'+arg+'.png\');">');
}

function writeBio(arg){
	if(firefox){
		document.write('<td align="center" valign="top" width="33%">')
		document.write('<img src="birds/imgLoading.png" name="birdImg'+arg+'" id="birdImg'+arg+'" width="175" height="247" class="'+searchClass+'"></td>');
	}else{
		document.write('<td align="center" valign="top" width="33%">')
		document.write('<img src="birds/trans.gif" name="birdImg'+arg+'" id="birdImg'+arg+'" width="175" height="247" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src=\'birds/imgLoading.png\');" class="'+searchClass+'"></td>');
	}
}

function writeInfo(arg){
	document.write('<td align="left" valign="top">');
	document.write('<p class="contentAddy" name="birdName'+arg+'" id="birdName'+arg+'">"Loading Name '+arg+'" Bird Age: ?</p>');
	document.write('<p class="content" name="birdBio'+arg+'" id="birdBio'+arg+'">Birdie Bio is Loading...</p></td>');
}

function writeNavBar(arg){
	document.write('<table width="100" border="0" cellpadding="0" cellspacing="7">');
	for(var i=0;i<totalNav;i++){
		var curPage=navItems[i].page;
		document.write('<tr><td style="padding-left:4px;">');
		if(document.location.href.indexOf(curPage)==-1)
			document.write('<a href="'+navItems[i].page+'" name="'+navItems[i].name+'" target="_self">'+navItems[i].value+'</a>');
		else
			document.write('<p class="content"><strong>'+navItems[i].value+'</strong></p>');
		document.write('</td></tr>');
	}
	document.write('</table>');
}

function pageObj(arg){
	this.image=new Array();
	this.name=new Array();
	this.bio=new Array();
	for(var j=1;j<=arg;j++){
		this.image[j]='birds/trans.gif';
		this.name[j]='&nbsp;';
		this.bio[j]='&nbsp;';
	}
}

function initPages(arg1,arg2){
	totalPages=arg1;
	for(var i=1;i<=arg1;i++){
		if(page[i]==null)
			page[i]=new pageObj(arg2);
	}
}

function changePage(arg){
	hideStory();
	var pageLinks;
	
	if(isNaN(arg)){
		if(arg=='next')
			currentPage++;
		else
			currentPage--;
	}else currentPage=parseInt(arg);

	if(totalPages>1){
		pageLinks=(currentPage>1)?"<a href='#' class='contentAddy' onClick='changePage(\"back\")'>&lt;-- Prev Birds</a>&nbsp;&nbsp;":"<img src='images/trans.gif' width='96' height='5'>&nbsp;&nbsp;";
		for(var i=1;i<=totalPages;i++){
			if(i!=currentPage)
				pageLinks+="<a href='#' class='contentAddy' onClick='changePage("+i+")'>"+i+"</a>&nbsp;&nbsp;"
			else
				pageLinks+="<span class='contentAddy'>"+i+"</span>&nbsp;&nbsp;"
		}
		pageLinks+=(currentPage<totalPages)?"<a href='#' class='contentAddy' onClick='changePage(\"next\")'>More Birds --&gt;</a>":"<img src='images/trans.gif' width='100' height='5'>";
	}else pageLinks='&nbsp;';

	var topNav=returnObjById('topNav');
	var bottomNav=returnObjById('bottomNav');
	topNav.innerHTML=pageLinks;
	bottomNav.innerHTML=pageLinks;
	
	for(var j=1;j<=6;j++){
		//alert(page[currentPage].name[j])
		var birdName=returnObjById('birdName'+j);
		var birdBio=returnObjById('birdBio'+j);
		if(page[currentPage].image[j]=='birds/trans.gif') returnObjById('birdImg'+j).className='';
		else returnObjById('birdImg'+j).className=searchClass;
		
		if(firefox){
			document.images['birdImg'+j].src=page[currentPage].image[j];
		}else{
			document.images['birdImg'+j].src=page[currentPage].image[j];
			document.all['birdImg'+j].style.filter="none";
		}
		birdName.innerHTML=page[currentPage].name[j];
		if(page[currentPage].bio[j].length>375){
			var synops="";
			for(var i=0;i<375;i++)
				synops+=page[currentPage].bio[j].charAt(i);
			birdBio.innerHTML=synops+"... <a href='#' class='content' onMouseOver='showStory(\""+page[currentPage].bio[j]+"\")'>[Full Story]</a>";
		}else 
			birdBio.innerHTML=page[currentPage].bio[j];
	}
	if(!entering){
		removeShodows();
		addShadows();
	}
	entering=false;
}

function hideStory(){
	var divLayer=returnObjById('moreBio');
	divLayer.style.visibility='hidden';
	divLayer.innerHTML="";
}

function showStory(arg){
	if (parseInt(navigator.appVersion)>3){
		if (navigator.appName=="Netscape"){
			winW=window.innerWidth;
			winH=window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1){
			winW=document.body.offsetWidth;
			winH=document.body.offsetHeight;
		}
	}
	if(document.documentElement&&document.documentElement.scrollTop){
		theTop=document.documentElement.scrollTop;
		theLeft=document.documentElement.scrollLeft;
	}else if(document.body){
		theTop=document.body.scrollTop;
		theLeft=document.body.scrollLeft;
	}
		
	var divLayer=returnObjById('moreBio');
	divLayer.style.visibility='visible';
	
	var height=grabComputedHeight(divLayer);
	var width=grabComputedWidth(divLayer);

	divLayer.innerHTML="<div style='position:absolute; right:2px; top:2px; width:15px; height:15px; text-align:center;' class='tableBorder'><a href='#' onClick='hideStory();'><span class='content'><strong>&nbsp;X&nbsp;</strong><span></a></div><span class='content'>"+arg+"</span>";
	
	var leftPos=(winW/2)-(width/2)-theLeft;
	divLayer.style.left=leftPos;
	
	var topPos=(winH/2)-(height/2)+theTop;
	divLayer.style.top=topPos;
}

function grabComputedStyle(elementObject){
    if(document.defaultView&&document.defaultView.getComputedStyle)
        return document.defaultView.getComputedStyle(elementObject, null);
    else if(elementObject.currentStyle)
        return elementObject.currentStyle;
    else
        return null;
}

function grabComputedHeight(elementObject){
    var height=grabComputedStyle(elementObject).height;
    if(height!=null){
        if(height.indexOf('px')!=-1)
            height=height.substring(0, height.indexOf('px'));
        if(height=='auto'){
            if(elementObject.offsetHeight)
                height=elementObject.offsetHeight;
        }
    }
    return height;
}

function grabComputedWidth(elementObject){
    var width=grabComputedStyle(elementObject).width;
    if(width!=null){
        if(width.indexOf('px')!=-1)
            width=width.substring(0, width.indexOf('px'));
        if(width=='auto'){
            if(elementObject.offsetWidth)
                width=elementObject.offsetWidth;
        }
    }
    return width;
}

function custWindowLink(arg1,width,height){
	var left=(screen.width/2)-width/2;
	var top=(screen.height/2)-height/2;
	var features='width='+width+',height='+height+',left='+left+',top='+top;
	window.open(arg1,'sbbsPopup',features);
}

// addLoadEvent created by: Simon Willison 
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// Modified by Christopher Donnelly 01/28/2007 to save the passed 
// function into a variable for use after moving or resizing images.
function addLoadEvent(arg){
	addShadows=arg;
	var oldonload=window.onload;
	if(typeof window.onload!='function') window.onload=addShadows;
	else{
		window.onload=function(){
			if(oldonload) oldonload();
			addShadows();
		}
	}
}

addLoadEvent(
	function() {
		// Created by: Michael Burt
		// http://galaxydefense.ga.funpic.org/
		// Modified by : Christopher Donnelly 01/28/2007 to append Child objects within container objects 
		var a=document.all?document.all:document.getElementsByTagName('*');
		var b=returnObjById(shadowContainer);
		for(var i=0;i<a.length;i++){
			if (a[i].className==searchClass){
				for (x=0;x<shadowDepth;x++){
					var newSd=document.createElement('DIV');
					newSd.className=shadowClass;
					newSd.style.background=shadowColor;
					newSd.style.width=a[i].offsetWidth+'px';
					newSd.style.height=a[i].offsetHeight+'px';
					newSd.style.left=a[i].offsetLeft+x+'px';
					newSd.style.top=a[i].offsetTop+x+'px';
					b.appendChild(newSd);
				}
			}
		}
	}
);

function removeShodows(){
	var b = returnObjById(shadowContainer);
	var i=b.childNodes.length;
	for(var i=b.childNodes.length;i>=0;i--){
		if(b.childNodes[i]!=null){
			if(b.childNodes[i].className==shadowClass) b.removeChild(b.childNodes[i]);
		}
	}
}