history.navigationMode = 'compatible'; //fire jQuery ready function on back button
jQuery(function($){
	/*SETTINGS*/
	var rotatorWidth = 825,
		slideHeight = 365,
		slideMaxWidth = 872, //while open
		slideMinWidth = 48, //while closed
		gallerySlideHeight = 382,
		videosOn = true,
		contentRSS = 'rss=46',
		videosRSS = 'rss=59',
		gallerySource = 'gateway', //flickr or gateway
		galleryRSS = 'rss=60', //if source from gateway
		flickrUser = 'iconstituent',
		flickrApiKey = 'e3941b69c3d06957430e01307a711414',
		tabsOn = true,
		tabs = ['.pushedsource_61','.pushedsource_65','.pushedsource_64']; //for tabed section
	
	//$.ajaxSetup({ cache: false });
	//DETECT HOMEPAGE
	var isHome = false;
	if($('#sectionid_1').length > 0) 
		isHome = true;
		
	/* IMPORT STYLESHEETS*/
	var CSS = [
			   'css/jquery.Rotator.css',
			   'common/css/prettyPhoto.css',
			   'common/css/ui-lightness/jquery-ui.css'
			   ];
	$.each(CSS, function(i){
		$('head').append('<link rel="stylesheet" href="'+CSS[i]+'" type="text/css" />');
	});
	/* LOAD SCRIPTS*/
	

	$.getScript("common/js/jquery.prettyPhoto.js"); // lightbox
	//$.getScript("common/js/jquery.pager.js"); // plugin for ppLightbox
	

	// :: TOPNAV SUPERFISH
	$.getScript("common/js/hoverIntent.js",function(){
		$.getScript("common/js/superfish.js",function(){ 
			$("#topnav ul").superfish({ 
				delay: 200, 
				animation: {height:'show'}, 
				speed: 'fast'
			});	
		});
	
	
	//
	
	
		if ($('.item').length >0){
	var itemid = $('.item').attr('id') || 'none';
	if (itemid.indexOf("itemid") != -1) {
		$('#centerbox table:first').addClass('itemtools').find('a').addClass('printicon');
		$('#addthisdiv').insertAfter('.printicon');
	}
	}


	});
	if(isHome){
		//SET UP STAGE FOR ACCORDIAN AND SET CONTENT ROTATOR
		$('.haccordian').insertBefore('#rightbox');//append before #rightbox
		$.getScript("common/js/jquery.tools.js",function(){
			$.getScript("common/js/jquery.jRotator.js", function(){
		
					var crotator = new contentRotator("newsControl", contentRSS, rotatorWidth, slideHeight, false, 6000);	
			});		
		});
		// :: ACCORDIAN OBJECT*/
		$.getScript("common/js/jquery.jAccordion.js", function(){											   
		 var accordion = new jAccordion({
			slideHeight: slideHeight,
			slideMaxWidth: slideMaxWidth,
			slideMinWidth: slideMinWidth,
			gallerySlideHeight: gallerySlideHeight,
			videosOn: videosOn,
			videosRSS: videosRSS,
			gallerySource: gallerySource,
			galleryRSS: galleryRSS,
			flickrUser: flickrUser,
			flickrApiKey: flickrApiKey
		});
	
		});
		
		$.getScript("common/js/jquery-ui.widget.tabs.js",function(){
			//if(isHome)												   
			var maintabs = new uiTabs({ tabs: tabs, id: 'maintabs', animated: true});
			/*var addrtabs = $("#addresses").tabs({ fx: { opacity: 'show', duration : 'fast' } });
				INTERACTION FOR DISTRICT POINTS
				$('#tab3').click(function() { 
					addrtabs.tabs('select', 2);return false;
				});*/
		});
		
	} //ishome

	// some html formating
	$('.pushedsource_61 li:odd').addClass('alternate');
	$('.pushedsource_49 li:odd').addClass('alternate');
	$('.pushedsource_25 li:odd').addClass('alternate');
	$('.pushedsection .sectiondate').each(function(){
		$(this).html(formatdateCal($(this).text())); //reformat section date for news section
	});


	// ::: END JQUERY CALLS
});
	
function formatdateCal(datestr) {
	
        var d = new Date(datestr)
        var month = new Array(12);
        month[0] = "Jan";
        month[1] = "Feb";
        month[2] = "Mar";
        month[3] = "Apr";
        month[4] = "May";
        month[5] = "Jun";
        month[6] = "Jul";
        month[7] = "Aug";
        month[8] = "Sep";
        month[9] = "Oct";
        month[10] = "Nov";
        month[11] = "Dec";
        var itemdate = "<span class=mo>"+month[d.getMonth()] + "</span> <span class=day>" + d.getDate() + "</span>";
		if(month[d.getMonth()])
        return "<span class=cal>" + itemdate + "</span>";
		
    }	
var textsize = 12;
function changetextsize(up){
	if(up){
		textsize = parseFloat(textsize)+2;
	}else{
		textsize =parseFloat(textsize)-2;
	}
}
function fsize(size,unit,id){
	var vfontsize = document.getElementById(id);
	if(vfontsize){
		vfontsize.style.fontSize = size + unit;
		createCookie("textsizestyle", textsize, 365);
	}
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/*:::::::::: END FONT SIZE CONTROL :::::::::: */

function iFocus(e) {
    if (e.value == e.defaultValue) {
        e.value = "";
        e.style.color = "#000";
    }
}
function iBlur(e) {
    if (e.value == "") {
        e.value = e.defaultValue;
        e.style.color = "#999";
    }
}

