//====================================================================
// Purpose: This routine randomizes images
// Author: Ed Donohue 
// Date: September 24, 2008
//====================================================================
var randomPicture = function()  { 
	// specify the target image tag
	var targetImgID = "targetImage";
	// get a handle to it
	var targetImg = document.getElementById(targetImgID);
	// load up the various graphic reference paths
	var picture = [ "/images/banner1.jpg", "/images/banner2.jpg", "/images/banner3.jpg", "/images/banner4.jpg", "/images/banner5.jpg", "/images/banner6.jpg" ];
	// get the number of graphics
	var range = picture.length;
	// randomize
	if (Math.random) {
		picIndex = Math.round(Math.random() * (range-1)); 
	} else { 
		var now  = new Date(); 
		picIndex = (now.getTime() / 1000) % range; 
	} 
	// safety net
	if (picIndex > range) {
		picIndex = 0;
	}
	// update the image src with the random graphic
	targetImg.src = picture[picIndex];
} 
//====================================================================
// Purpose: These variables and routines relate to the font sizing, printing and emailing functions
// Author: Ed Donohue 
// Date: October 1, 2008
//====================================================================
// Establish default settings
var minimumFontSize = 90;
var maximumFontSize = 180;
var currentFontSize = 100;
var fontFactor = 10;

// Increase font size for selected document elements
var setFontSize = function() {
	var el = document.getElementById( 'bodyContent' );
	if ( el ) el.style.fontSize = currentFontSize + '%';
		
	var el3 = document.getElementById( 'bodyLeftContent' );
	if ( el3 ) el3.style.fontSize = currentFontSize + '%';
		
	var el2 = document.getElementById( 'bodyRightContent' );
	if ( el2 ) el2.style.fontSize = currentFontSize + '%';				
}

// Increase font size
var increaseFontSize = function() {
	currentFontSize += fontFactor;
	if ( currentFontSize > maximumFontSize )
		currentFontSize = maximumFontSize;
	setFontSize();
}

// Decrease font size
var decreaseFontSize = function() {
	currentFontSize -= fontFactor;
	if ( currentFontSize < minimumFontSize )
		currentFontSize = minimumFontSize;
	setFontSize();
}

// Print page
var printPage = function() { window.print(); }

// Replaces email graphic with mailto link around the graphic
var createEmailLink = function() {
	var mailTo = "";
	var eMail = document.getElementById("emailLink");
	if (eMail) {
		var html = '<a href="mailto:' + mailTo + "?body=I found the following on NYSTRS' Web site and thought you would be interested: %0D%0A%0D%0A" + document.title + '%0D%0A%0D%0A' + location.href + '&subject=NYSTRS Online: Note of Interest">' + eMail.innerHTML + '</a>';	
		eMail.innerHTML = html;
	}
}

//====================================================================
// Purpose: Ajax routines to load up the executive note with any content found in the notes file
// Author: Ed Donohue 
// Date: September 24, 2008
//====================================================================
var targetDivBorderId = "execNoteBorder"
var targetDivID = "execNote"; // use this as the id for the div that should be loaded with the note
var sourceNote = "./execnote/note.htm" // this is where the note content will come from - this is what the ftp will allow updating too by execs
	
// status codes
var HTTP_STATUS_OK = 200;
var READYSTATE_COMPLETED = 4;
	
// ajax request object
var ajaxReq = null;
	
// create the request object
var createRequest = function() {
	if (window.XMLHttpRequest) { 
		try {
			ajaxReq = new XMLHttpRequest();
		} catch(e) {
			ajaxReq = null;
		}
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) { 
		try {
			ajaxReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {		
				ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {		
				ajaxReq = null;
			}
		}
	}
	// Return request success status
	if (ajaxReq == null) {
		return false;
	} else {
		return true;
	}
}
	
// this is fired after ajax returns with  a completed state - this takes the returning content and floods the note div
var processNote = function() {
	if (ajaxReq.readyState == READYSTATE_COMPLETED) {
		var targetDiv = document.getElementById(targetDivID);
		var targetBorder = document.getElementById(targetDivBorderId);
		targetDiv.innerHTML =  ajaxReq.responseText;
		if (ajaxReq.responseText.length > 0) {
			targetBorder.style.visibility = 'visible';
			targetBorder.style.display = 'block';
		}
	}
}
	
// this is to be called by the onload event
var executiveNote = function() {
	if (createRequest()) {
		ajaxReq.open("GET",sourceNote + '?id=' + Math.floor(Math.random()*1000000), true);
		ajaxReq.onreadystatechange = processNote;	
		ajaxReq.send(null);		
	} else {
		alert("Error creating request object for executive note");
	}
}
	
var addBookmark = function(title, url){
	var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1);
	var buttonStr=isMac?'Command/Cmd':'CTRL';
	 
	if( window.sidebar ){ // Firefox
    	window.sidebar.addPanel(title, url,''); } 
	else if(document.all){ //IE
		window.external.AddFavorite(url, title); }
	else { //others
    	alert('Press '+buttonStr+' + D to bookmark this page.'); } 
}

var doBookmark = function() {
	addBookmark( document.title, location.href );	
}

//====================================================================