// JavaScript Document
// shared scripts for handling NNIRR rollovers

// path to images folder, change to match server
var imagePath = "/images/";	
var rootPath  = "/";
// var imagePath = "/nnirr/www/images/";
// var rootPath = "/nnirr/www/";
// var imagePath = "/nnirr/images/";
// var rootPath = "/nnirr/";

// default language (1=english, 2=spanish)
var language = 1;	

// returns the path to the root folder of the web site
var hasCustomRootPath = 0;
function getRootPath()
{
	// pages can override the computed value by specifying a value for
	// global var customRootPath and setting hasCustomRootPath to 1.
	if (hasCustomRootPath)
		return customRootPath;

    return rootPath;
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = imagePath + arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = imagePath + changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		campaign_over = newImage("campaign-over.gif");
		toolkit_over = newImage("toolkit-over.gif");
		donate_over = newImage("donate-over.gif");
		home_over = newImage("home-over.gif");
		about_over = newImage("about-over.gif");
		immvote_over = newImage("immvote-over.gif");
		campaigns_over = newImage("campaigns-over.gif");
		resources_over = newImage("resources-over.gif");
		news_over = newImage("news-over.gif");
		press_over = newImage("press-over.gif");
		preloadFlag = true;
	}
}


// function to hide mailto links from spam bots
function writeMailtoText(address, domain, txt)
{
	emailE=(address + '@' + domain);
	document.write('<a href="mailto:' + emailE + '">' + txt + '</a>');
}

// function to hide mailto links from spam bots
/*
 	usage: <script language="javascript" type="text/javascript">writeMailto("user", "nnirr.org");</script>
 */
function writeMailto(address, domain)
{
	emailE=(address + '@' + domain);
	document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>');
}

// just print the current date to the page
function nnirrWriteDate()
{
	var now=new Date();
	var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
	document.write(weekday[now.getDay()] + ", ")
	document.write(monthname[now.getMonth()] + " ")
	document.write(now.getDate() + ", ")
	document.write(now.getFullYear())
}

// initializes dropdown menus from nav bar
function nnirrLoadMenus() {
  var path = "location='" + getRootPath();
  var font = "Verdana, Helvetica, sans-serif";
  var fs = 11;
  if (window.fw_menu_0) return;
  window.fw_menu_0 = new Menu("root",148,16,font,fs,1);
  fw_menu_0.addMenuItem("Mission and Overview",path+"about/index.php'");
  fw_menu_0.addMenuItem("Programs",path+"about/programs.php'");
  fw_menu_0.addMenuItem("History",path+"construction.php'");
  fw_menu_0.addMenuItem("Accomplishments",path+"about/accomplishments.php'");
  fw_menu_0.addMenuItem("Contact Us",path+"about/contact.php'");
  fw_menu_0.addMenuItem("Join NNIRR",path+"about/join.php'");
  fw_menu_0.addMenuItem("Support NNIRR",path+"about/support.php'");
  fw_menu_0.addMenuItem("FAQ",path+"about/faq.php'");
  fw_menu_0.addMenuItem("Board of Directors",path+"about/board.php'");
  fw_menu_0.hideOnMouseOut=true;
  
  window.fw_menu_1 = new Menu("root",120,16,font,fs,1);
  fw_menu_1.addMenuItem("Action Alerts",path+"action/index.php'");
  fw_menu_1.addMenuItem("Alerts Archive",path+"action/index.php?op=list&time=past'");
  fw_menu_1.hideOnMouseOut=true;
   
  window.fw_menu_2 = new Menu("root",256,16,font,fs,1);
  fw_menu_2.addMenuItem("How to Get Involved",path+"getinvolved/index.php'");
  fw_menu_2.addMenuItem("Census 2010",path+"census2010/index.php'");
  fw_menu_2.addMenuItem("National Community Dialogue for Border Justice",path+"construction.php'");
  fw_menu_2.addMenuItem("Campaign for Fair and Just Immigration Reform",path+"construction.php'");
  fw_menu_2.addMenuItem("HURRICANE",path+"hurricane/index.php'");
  fw_menu_2.addMenuItem("BRIDGE",path+"shop/curricula.php'");
  fw_menu_2.addMenuItem("Immigrant and Refugee Rights Training Institute",path+"construction.php'");
  fw_menu_2.addMenuItem("Celebrate International Migrants Day",path+"december18'");
  fw_menu_2.hideOnMouseOut=true;
   
  window.fw_menu_3 = new Menu("root",120,16,font,fs,1);
  fw_menu_3.addMenuItem("Newest Resources",path+"resources/index.php?language="+language+"'");
  fw_menu_3.addMenuItem("Services",path+"construction.php'");
  fw_menu_3.addMenuItem("Affiliates",path+"construction.php'");
  fw_menu_3.addMenuItem("Links",path+"resources/index.php?op=list&type=6'");
  fw_menu_3.addMenuItem("Reports",path+"resources/index.php?op=list&type=10'");
  fw_menu_3.addMenuItem("Fact Sheets",path+"resources/index.php?op=list&type=3'");
  fw_menu_3.addMenuItem("Activist Tool Kits",path+"construction.php'");
  fw_menu_3.addMenuItem("Archive",path+"resources/index.php?op=list&priority=0'");
  fw_menu_3.hideOnMouseOut=true;
   
  window.fw_menu_4 = new Menu("root",120,16,font,fs,1);
  fw_menu_4.addMenuItem("Latest News",path+"news/index.php'");
  fw_menu_4.addMenuItem("Network News",path+"news/index.php?op=list&type=7'");
  fw_menu_4.addMenuItem("Immigrant Rights News",path+"news/index.php?op=list&type=2'");
  fw_menu_4.addMenuItem("Press Releases",path+"news/index.php?op=list&type=8'");
  fw_menu_4.addMenuItem("NNIRR in the News",path+"news/index.php?op=list&type=5'");
  fw_menu_4.hideOnMouseOut=true;
   
  window.fw_menu_5 = new Menu("root",108,16,font,fs,1);
  fw_menu_5.addMenuItem("NNIRR Events",path+"events/index.php'");
  fw_menu_5.addMenuItem("Other Events",path+"events/index.php?type=2'");
  fw_menu_5.addMenuItem("Past Events",path+"events/index.php?time=2'");
  fw_menu_5.addMenuItem("Find an Event",path+"events/index.php?op=findform'");
  fw_menu_5.hideOnMouseOut=true;
   
  window.fw_menu_6 = new Menu("root",108,16,font,fs,1);
  fw_menu_6.addMenuItem("New",path+"shop/index.php'");
  fw_menu_6.addMenuItem("Curricula",path+"shop/curricula.php'");
  fw_menu_6.addMenuItem("Video",path+"shop/video.php'");
  fw_menu_6.addMenuItem("Reports",path+"shop/reports.php'");
  fw_menu_6.addMenuItem("Posters",path+"shop/posters.php'");
  fw_menu_6.addMenuItem("T-Shirts",path+"shop/posters.php'");
  fw_menu_6.addMenuItem("Membership",path+"shop/membership.php'");
  fw_menu_6.addMenuItem("Subscriptions",path+"shop/subscriptions.php'");
  fw_menu_6.hideOnMouseOut=true;
   
  fw_menu_6.writeMenus();
} // nnirrLoadMenus()

// Google Analytics
 var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-17555284-1']);
 _gaq.push(['_trackPageview']);

 (function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
