
Dom = YAHOO.util.Dom
Evt = YAHOO.util.Event;
Suscon = {};



issueNav = function() {}


/**
 * DHTML SIDENAV
 */
issueNav.Navigation = function() {
	var Evt = YAHOO.util.Event;
	var Dom = YAHOO.util.Dom;

	return {

		// local variables
		navigation: false,
		navLinks: false,
		linkTimer: false,
		pauseMouseOver: false,

		// INITIALIZE OBJECT
		init: function() {
			// add event listeners
			this.navigation = Dom.get('issueNav');
			Evt.on(this.navigation, 'click', this.handleClick, this, true);

			// get navLinks
			var navLinks = this.getNavLinks(); 
			
			// add 'on' class to navlinks that are on 
			var projects = Dom.getElementsByClassName('projects', 'ul', 'issueNav');
			for (var i=0; i<projects.length; i++) {
				if (projects[i].style.display == 'block') {
					Dom.addClass(projects[i].parentNode, 'on');
				};
			};
		},

		// EVENT HANDLERS
		handleClick: function(ev) {
			// get click target
			targetObj = Evt.getTarget(ev);
			// remove target blur
			targetObj.blur();
			// do what we need to do 
			if (targetObj.className=='programLink') {
				// prevent default action from firing
				if (ev.preventDefault) ev.preventDefault();
				else ev.returnValue = false;
				// make on
				if (Dom.hasClass(targetObj.parentNode, 'on')) {
					this.turnOffSubNav(targetObj.parentNode);
				} else {
					this.turnOnSubNav(targetObj.parentNode);
				};
			};
		},

		// TURN ON/OFF METHODS
		turnOnSubNavFromTimer: function() {
			if (issueNav.Navigation.linkTimer) {
				//var targetObj = Dom.get(targetObjId);
				issueNav.Navigation.turnOnSubNav(issueNav.Navigation.targetObj);
			};
		},

		turnOnSubNav: function(targetObj) {
			// get inner menu obj
			var subNavObj = this.getSubNav(targetObj);
			// get height of new obj
			if (subNavObj) {
				subNavObj.style.position = 'absolute';
				subNavObj.style.left = '-2000px';
				subNavObj.style.display = 'block';
				subNavObj.style.height = 'auto';
				var newHeight = subNavObj.offsetHeight;
				subNavObj.style.position = 'static';
				subNavObj.style.left = '0';
				subNavObj.style.height = '0px';
			};
			var speed = .3;
			// turn 'on'
			Dom.addClass(targetObj, 'on');
			// do slide animation
			var attributes = { height: { from:0, to:newHeight }, opacity: {from:0,to:1} };
			var anim = new YAHOO.util.Anim(subNavObj, attributes, speed);
			anim.animate();
			// disable 'mouseOver' event for a sec, to prevent a new nav from showing because the mouse
			// end up resting on another actuator
			this.pauseMouseOver = true;
			window.setTimeout(function() {issueNav.Navigation.pauseMouseOver=false}, 200);
			
			return;
		},

		turnOffSubNav: function(targetObj) {
			var subNavObj = this.getSubNav(targetObj);

			var attributes = { height: {to:0 }, opacity: {to:0} };
			var anim = new YAHOO.util.Anim(subNavObj, attributes, .15);
			
			anim.onComplete.subscribe(function() { 
				subNavObj.style.display = 'none';
				subNavObj.style.height = 'auto';
				Dom.removeClass(targetObj, 'on');
			});
			
			anim.animate();
		},

		// MISC METHODS
		getSubNav: function(parentObj) {
			var targetId = parentObj.id.substr(10);
			return Dom.get('subnav-list-'+ targetId);
		},

		getNavLinks: function() {
			if (this.navLinks) {
				return this.navLinks;
			} else {
				this.navLinks = Dom.getElementsByClassName('issue', 'li', this.navigation);
				return this.navLinks;
			};
		},



		// END OF FILE
		EOF:null
	};

}();































Suscon.Homepage = function() {
	return {

		imageDiv: false,
		timer: false,
		queue: false,
		counter: false,
	
		init: function() {
			
			this.imageDiv = Dom.get('homeImage');
			
			//  preload the next three images
			this.queue = [];
			this.addImage('/images/homeClimateChange.jpg');
			this.addImage('/images/homeCleanAir.jpg');
			this.addImage('/images/homeCleanWater.jpg');
			this.addImage('/images/homeBiodiversity.jpg');
			
			//start a counter at zero
			this.counter = Math.floor(Math.random() * this.queue.length);
			//this.counter = 0;
			
			// set initial image
			this.imageDiv.appendChild(this.queue[this.counter]);
			this.incrementCounter();
			
			// set a timer (window.setTimeout) that calls rotate()
			this.timer = window.setInterval(Suscon.Homepage.fadeOut, 8000);
		},
		
		addImage: function(source) {
			if (source) {
				var tmp = new Image();
				tmp.src = source;
				this.queue.push(tmp);
			};
		},
		
		incrementCounter: function() {
			this.counter++;
			if (this.counter == this.queue.length) {
				this.counter = 0;
			};
		},
		
		fadeOut: function() {			
			// fade out
			var myAnimation = new YAHOO.util.Anim('homeImage', {
				opacity: {
					from: 1.0,
					to: 0.0
				}
			}, 0.3);
			myAnimation.onComplete.subscribe(Suscon.Homepage.fadeIn); 
			myAnimation.animate();
		},
		
		fadeIn: function() {
			// clear existing image
			Suscon.Homepage.imageDiv.innerHTML = '';
			
			//place new image
			Suscon.Homepage.imageDiv.appendChild(Suscon.Homepage.queue[Suscon.Homepage.counter]);
			
			//increment a counter so you know where you are in the queue
			Suscon.Homepage.incrementCounter();
			
			// fade in
			var myAnimation = new YAHOO.util.Anim('homeImage', {
				opacity: {
					from: 0.0,
					to: 1.0
				}
			}, 0.3);
			myAnimation.animate();
		},
		
		

		EOF: null
	};
}();






/*
Rotating image or text(You can use for changing banners)
Author: Narayan Chand Thakur
Source: http://ncthakur.itgo.com/
This may be used freely as long as this message is intact.

<!--

//you may add your image file or text below
var item=new Array()
item[0]="<a href='#'><img src='ballon2.gif' border='0'></a>"
item[1]="<a href='#'><img src='ballon3.gif' border='0'></a>"
item[2]="<a href='#'><img src='ballon4.gif' border='0'></a>"
item[3]="<strong><font face='arial' size='4' color='red'>Text without a Link!</font></strong>"
item[4]="<a href='#'><font face='arial' size='4' color='darkgreen'><B>This text has Link</B></font></a>"
item[5]="<a href='#'><font face='arial' size='4' color='darkgreen'><B>How do you like that?</B></font></a>"
var current=0

var ns6=document.getElementById&&!document.all
function changeItem(){
if(document.layers){
document.layer1.document.write(item[current])
document.layer1.document.close()
}
if(ns6)document.getElementById("div1").innerHTML=item[current]
{
if(document.all){
div1.innerHTML=item[current]
}
}
if (current==5) current=0
else current++
setTimeout("changeItem()",2000)
}
window.onload=changeItem
//-->
*/






/*

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace
	(" over", "");
   }
   }
  }
 }
}
window.onload=startList;

*/

function popUp(thisURL) {
	var day = new Date();
	var id = day.getTime();
	window.open(
		thisURL,
		'thisWindow', 
		'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=405,height=300'
	);
}

function popupWindow(url,name,w,h) {
	var features = "'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width="+ w +",height="+ h +"'";
	var newWin = window.open(url,name,features);
}
