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=140',
		//videosRSS = 'rss=381',
		//gallerySource = 'gateway', //flickr or gateway
		//galleryRSS = 'rss=381', //if source from gateway
		//flickrUser = 'iconstituent',
		//flickrApiKey = 'e3941b69c3d06957430e01307a711414',
		tabsOn = true,
		tabs = ['.pushedsource_52','.pushedsource_152','.pushedsource_143','.pushedsource_144']; //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/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.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'
			});	
			
			
		});
	});
	
	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 xx = readCookie('kindnewsdialog');
			if (!xx) { 
				$.getScript("common/js/jquery.pager.js",function(){
					$.getScript("common/js/jquery.prettyPhoto.js",function(){
						//$('body').append('<div id="mydialog" />');
						//$('#mydialog').html('<div class=enewsdialog>'+$('#dialog').html()+'</div>');
						
						fireDialog("dialog", "mytrigger", 550, 0);
						//jQuery("a[rel*=prettyPhoto]").prettyPhoto({theme:"light_rounded"});
					});
				});
				createCookie('kindnewsdialog','kenewsdialog',5);
			}
	
	} //ishome
	
	
	
	// :: JQUERY-UI CORE
	 $.getScript("common/js/jquery-ui.widget.tabs.js",function(){
		
		//if(tabsOn)
		//$.getScript("common/js/jquery-ui.tabs.min.js",function(){
			$.each(tabs,function(i,section){
				$(section).css('display','block'); //show tab pushes
				$('.loadingtabs').remove(); //destroy loader
			});
			if(isHome)												   
			var maintabs = new uiTabs({ tabs: tabs, id: 'maintabs', animated: true});
			//var addrtabs = $("#addresses").tabs({ fx: { opacity: 'show', duration : 'fast' } });
				
				$('#maintabs .tab-2').click(function() { 
					$.getScript("images/gsvideobar.js",function(){
						$.getScript("images/loadVideoBar_b.js");	
					});
				 });
				$('#maintabs .tab-3').click(function() { 
					$('.photoscontainer').html('<object width="375" height="280"> <param name="flashvars" value="offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fronkind%2Fshow%2F&page_show_back_url=%2Fphotos%2F49556675@N04%2F&user_id=49556675@N04&jump_to="></param> <param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&lang=en-us&page_show_url=%2Fphotos%2F49556675@N04%2Fshow%2F&page_show_back_url=%2Fphotos%2Fronkind%2F&user_id=49556675@N04&jump_to=" width="375" height="280"></embed></object>');
				});
				
	/*ROLL CALL VOTES*/
	if($('#vrollcall').length > 0){
		$.getScript("/common/js/jquery.prettyPhoto.js",function(){
			$.getScript("/common/js/vRollcall.js",function(){
				var rollcall = new vRollcall({
					containerID: "vrollcall",
					feedLocation: "http://www.opencongress.org/people/atom/400218_Ronald_Kind",
					maxEntries: 0
				});								
			});
		});											
	}
				
			/*right column height*/
			//$('#rightbox').height($('#centerbox').height());
		//});
	});

	
	// 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";
    }
}


