history.navigationMode = 'compatible';
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_91','.pushedsource_49','.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());
	
		
	/* 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*/
	

	// :: 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(isHome){
		$.getScript("common/js/jquery.tools.js",function(){
			$.getScript("common/js/jquery.jRotator.js", function(){
				var crotator = new contentRotator("newsControl", contentRSS, rotatorWidth, slideHeight, false, 8000);	
			});	
		});
		$.each(tabs,function(i,section){
			$(section).css('display','none'); //hide tab pushes
		});
		$('<div class="loadingtabs" style="float:left;padding:30px 0 0 100px;" align=center>Loading...<br /><img src="common/images/ajax.gif" alt=""/></div> </div>').insertBefore(tabs[0]); //create loader
		
		var x = readCookie('lipinskynewsdialog');
		if (!x) { 
			$('body').append('<div id="dialog" style="display:none;"><div class="enewsdialog">'+$('.enews').html()+'</div></div>');
			$('.enewsdialog form').before('<p>Get updates on important issues sent to your email</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('lipinskynewsdialog','enewsdialog',5);
		}
		
	} //ishome
	
	
	
	// :: JQUERY-UI CORE
	if(isHome){
	$.getScript("common/js/jquery-ui.widget.tabs.js",function(){
		
			$.each(tabs,function(i,section){
				$(section).css('display','block'); //show tab pushes
				$('.loadingtabs').remove(); //destroy loader
			});
															   
			var maintabs = new uiTabs({ tabs: tabs, id: 'maintabs', animated: true});
			$('#maintabs .tab-1').click(function() { 
				if($('.resultsBox_gsvb').length ==0){								 
					$.getScript("images/gsvideobar.js",function(){
						$.getScript("images/loadVideoBar_b.js");	
					});
				 }
				
			 });
			/*
			$('#maintabs .tab-3').click(function() { 
				$.getScript("common/js/jquery.pager.js",function(){
					$.getScript("common/js/ajaxFeed_byyear.js",function(){
						new rssdisplayer("newsletters",2009,"http://lipinski.congressnewsletter.net//common/mailings/?rss",1000);
					});
				});
			});*/
			
			//$('.tab-0 span').html('Press Release');
			//$('.tab-1 span').html('News');
			
																	
	});
	}

	
	// 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
	});



	
	// ROOT SECTIONS
	if(!isHome){
			var currentPage = document.location.href,
				sectionId = "";
			if(currentPage.indexOf('sectiontree') >-1){
				if(currentPage.substr((currentPage.indexOf('sectiontree')+12))!= "" && currentPage.substring(currentPage.indexOf('sectiontree')+12,currentPage.indexOf('sectiontree')+13) !='&')
					sectionId = parseInt(/sectiontree=(\d+)/.exec(currentPage)[1], 10);
			} else
				sectionId = parseInt(/sectionid=(\d+)/.exec(currentPage)[1], 10);
		
			$('.menu_'+sectionId).addClass('activeroot');
		
	}
	// ::: 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;
}
/*:::::::::: 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";
    }
}


