history.navigationMode = 'compatible'; //fire jQuery ready function on back button
jQuery(function($){
	/*SETTINGS*/
	var rotatorWidth = 663,
		slideHeight = 	280,
		//slideMaxWidth = 872, //while open
		//slideMinWidth = 48, //while closed
		//gallerySlideHeight = 382,
		//videosOn = true,
		contentRSS = 'rss=46',
		//videosRSS = 'rss=381',
		//gallerySource = 'gateway', //flickr or gateway
		//galleryRSS = 'rss=381', //if source from gateway
		//flickrUser = 'iconstituent',
		//flickrApiKey = 'e3941b69c3d06957430e01307a711414',
		tabsOn = true,
		tabs = ['.pushedsource_63','.pushedsource_55','.pushedsource_43']; //for tabed section
	
	//$.ajaxSetup({ cache: false });
	//DETECT HOMEPAGE
	var isHome = false;
	if($('#sectionid_1').length > 0) 
		isHome = true;
	
	//if (!isHome)
	//$('#rightbox').height($('#centerbox').height());
	
	var pool = 4; 
	function pickRandom(range) { 
		if (Math.random) 
			return Math.round(Math.random() * (range-1)); 
		else { 
			var now = new Date(); 
			return (now.getTime() / 1000) % range; 
			} 
	} 
	var choice = pickRandom(pool);
	var x = readCookie('toggleheader_'+choice);
	if(x){
		if(choice == pool){
			choice = choice-1;
		} else { choice = choice+1; }
	}
	for(var i =0; i<9; i++){
		eraseCookie('toggleheader_'+i);
	}
	$('#siteheader').addClass('toggleheader_'+choice);
	createCookie('toggleheader_'+choice,'toggleheaderimage',0);

		
	/* IMPORT STYLESHEETS*/
	var CSS = [
			   'common/css/galleria.classic.css',
			   'css/jquery.Rotator.css',
			   'common/css/PPLbx_light_round.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.PPLightbox.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'
			});	
		});
	});



		//MODAL DIALOG
		var x = readCookie('walshmodaldialog');
		if (!x) { 
			$('body').append('<div id="dialog" style="display:none;"><div class="enewsdialog">'+$('.enews').html()+'</div></div>');
		//	$('.enewsdialog form').before('<p>tes</p>');
			$.getScript("common/js/jquery.pager.js",function(){
				$.getScript("common/js/jquery.PPLightbox.js",function(){
					
					function delayEvt(){
						function startEvt(){
							fireDialog("dialog", "trigger", 550, 0);
						}
						t = setTimeout(startEvt, 1000);
					}
					delayEvt();

				
				});
			});
			createCookie('walshmodaldialog','enewsdialog',0);
		}
		




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, 8000);	
			});		
		});
		
		
	} //ishome
	
	// :: JQUERY-UI CORE
	$.getScript("images/jquery.ui.core.min.js",function(){
			$.getScript("images/jquery.ui.widget.min.js",function(){
			if(tabsOn)
			$.getScript("common/js/jquery-ui.tabs.min.js",function(){
				if(isHome)												   
				var maintabs = new uiTabs({ tabs: tabs, id: 'sidetabs', animated: true});
				var addrtabs = $("#addresses").tabs({ fx: { opacity: 'show', duration : 'fast' } });
				
				var fbframe = '<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FRepJoeWalsh&amp;width=240&amp;colorscheme=light&amp;show_faces=false&amp;stream=true&amp;header=false&amp;height=245" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:240px; height:245px;" allowTransparency="true"></iframe>';
				
				$('.fbframe').html(fbframe);
				
				
					/*INTERACTION FOR DISTRICT POINTS*/
					$('#sidetabs .tab-1').click(function() { 
						
						$.getScript("images/twitterFeed.js",function(){
							new TWTR.Widget({
								version: 2,
								id: 'myTweets',
								type: "profile",
								rpp: 5,
								interval: 6000,
								width: 370,
								height: 190,
								features: {
									scrollbar: false,
									loop: false,
									live: true,
									hashtags: true,
									timestamp: true,
									avatars: true,
									behavior: "all"
								}
							}).render().setUser("RepJoeWalsh").start();
						});
						
					});
				
			});
		});
	});	 
	
	
	// some html formating
	$('.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
	});


	
	/* :: TOOLBAR ::*/
	if($('#icToolbar').length !=0){
		$('body').append('<div class="toolbar"><div class="inner"><div class="hide" /></div></div>');
		$('.toolbar .inner').append($('.toolbaritems'));
		$('.toolbaritems').appendTo('.toolbar .inner');
		/*search bill actions*/
		$('.bykeyword_open').click(function(){
			$('.radio').removeClass('selected');
			$(this).addClass('selected');
			$('.bykeyword').show();
			$('.bynumber').hide();
		});
		$('.bynumber_open').click(function(){
			$('.radio').removeClass('selected');
			$(this).addClass('selected');
			$('.bynumber').show();
			$('.bykeyword').hide();
		});
		$('.toolbar .hide').click(function(){
			if($(this).hasClass('show')){
				$(this).removeClass('show');
				$(this).parent().parent().animate({'height':'42px'});
				eraseCookie('toolbarishidden');
			} else{
				$(this).parent().parent().animate({'height':'10px'})//.delay().find('.hide').addClass('show');
				$(this).fadeOut('fast').fadeIn('fast').addClass('show');
				
				if($('.searchBill').hasClass('sbOpen')){
					$('.searchBill').removeClass('sbOpen').css({'top':'10px'}).find('.sbhideshow').removeClass('show');
				}
				createCookie('toolbarishidden','mytoolbar',0);
			}
		});
		$('.sbhideshow').click(function(){
			if($(this).hasClass('show')){
				$(this).removeClass('show');
				$(this).parent().animate({'top':'10px'}).removeClass('sbOpen');
			} else{
				$(this).parent().animate({'top':'-80px'}).addClass('sbOpen');
				$(this).addClass('show');
			}
		});
		
		var x = readCookie('toolbarishidden') 
		if (x) { 
			$('.toolbar .hide').click();
		}
	}
	// ::: 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>"
        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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
/*:::::::::: 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 = "#777";
    }
}


