$(document).ready(function(){
	/**Search Form**/
	$('#searchForm input#q').css('borderColor','#6DA553'); //Change it back
	$('#searchForm input#q').css('padding','2px'); //Change it back
	$('#searchForm input#q').focus(function() {
		if($(this).val() == 'search') {
			$(this).val('');	
		}
	});
	$('#searchForm input#q').blur(function() {
		if($(this).val() == '') {
			$(this).css('background', '#ffffff'); //Stupid google search thingy
			$(this).val('search');
		}
	});
	/**End search form**/

	/**tabs**/
	$('#container-1').tabs();
	/**End tabs**/

	/**Text resizer**/
	if($.cookie('textSize')){
		$('#container').css('font-size', $.cookie('textSize')+'px');
	}
	$("#textIncrease").click(function(){
		var currentFontSize = $('#container').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum < 16) {
			var newFontSize = currentFontSizeNum+2;
			$('#container').css('font-size', newFontSize+'px');
			$.cookie('textSize', newFontSize, { path: '/'});
		}
		return false;
	});
	$("#textDecrease").click(function(){
		var currentFontSize = $('#container').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum > 10) {
			var newFontSize = currentFontSizeNum-2;
			$('#container').css('font-size', newFontSize);
			$.cookie('textSize', newFontSize, { path: '/'});
		}
		return false;
	});
	/**End text resize**/
	
	/**Striping**/
	$("tbody.striped tr:nth-child(odd)").addClass("odd");
	$("tbody.striped tr:nth-child(even)").addClass("even");

	/**Striping**/
	$("table.striped tbody tr:nth-child(odd)").addClass("odd");
	$("table.striped tbody tr:nth-child(even)").addClass("even");

	$("ul.striped li:nth-child(odd)").addClass("odd");
	$("ul.striped li:nth-child(even)").addClass("even");
	/**End striping**/
	
	/**Lightbox**/
	$('a[rel*=lightbox]').facebox();
	jQuery.each($('a[rel*=lightbox]'),function() {
		var curUrl = $(this).attr('href');
		if(curUrl.indexOf('gif') == -1) {
			if(curUrl.indexOf('?') != -1) {
				$(this).attr('href',curUrl+'&modal=true');
			} else {
				$(this).attr('href',curUrl+'?modal=true');	
			}
		}
	});
	
	/**End lightbox**/
	/**Colorbox**/
	//$(".inline1").colorbox({width:"50%", inline:true, href:".leadership-photos1"});
//	$(".inline2").colorbox({width:"50%", inline:true, href:".leadership-photos2"});
//	$(".inline3").colorbox({width:"50%", inline:true, href:".leadership-photos3"});
//	$(".inline4").colorbox({width:"50%", inline:true, href:".leadership-photos4"});
//	$(".inline5").colorbox({width:"50%", inline:true, href:".leadership-photos5"});
//	$(".inline6").colorbox({width:"50%", inline:true, href:".leadership-photos6"});
//	$(".inline7").colorbox({width:"50%", inline:true, href:".leadership-photos7"});
//	$(".inline8").colorbox({width:"50%", inline:true, href:".leadership-photos8"});
//	$(".inline9").colorbox({width:"50%", inline:true, href:".leadership-photos9"});
//	$(".inline10").colorbox({width:"50%", inline:true, href:".leadership-photos10"});
//	$(".inline11").colorbox({width:"50%", inline:true, href:".leadership-photos11"});
//	$(".inline12").colorbox({width:"50%", inline:true, href:".leadership-photos12"});
//	$(".inline13").colorbox({width:"50%", inline:true, href:".leadership-photos13"});
//	$(".inline14").colorbox({width:"50%", inline:true, href:".leadership-photos14"});
//	$(".inline15").colorbox({width:"50%", inline:true, href:".leadership-photos15"});
//	$(".inline16").colorbox({width:"50%", inline:true, href:".leadership-photos16"});
//	$(".inline17").colorbox({width:"50%", inline:true, href:".leadership-photos17"});
//	$(".inline18").colorbox({width:"50%", inline:true, href:".leadership-photos18"});
//	$(".inline19").colorbox({width:"50%", inline:true, href:".leadership-photos19"});
//	$(".inline20").colorbox({width:"50%", inline:true, href:".leadership-photos20"});
//	$(".inline21").colorbox({width:"50%", inline:true, href:".leadership-photos21"});
//	$(".inline22").colorbox({width:"50%", inline:true, href:".leadership-photos22"});
//	$(".inline23").colorbox({width:"50%", inline:true, href:".leadership-photos23"});
//	$(".inline24").colorbox({width:"50%", inline:true, href:".leadership-photos24"});
	/**End colorbox**/
	
	/**Member login box**/
	$('#memberLoginLink').click(function() {
		$('#utilityLogin').slideToggle();
		return false;
	});
	/**End member login box**/

	/**Detect pdf Links to display download link**/
	if($('a[href$=.pdf]').length > 0) {
		$("div#pdf_module").fadeIn("slow");
	}
	/**end Detect pdf Links to display download link**/
	
	/**State Allocation Charts**/
	$('select#stateAllocationCharts').change(function() {
		if($(this).val() != '') {
			window.location = '/files/advocacy/campaigns/' + $(this).val() + '.pdf';
		}
	});
	/**End state allocation charts**/

	/**State Sample Letters to Congress**/
	$('select#stateSampleLettersCongress').change(function() {
		if($(this).val() != '') {
			window.location = '/files/advocacy/campaigns/' + $(this).val() + '.pdf';
		}
	});
	/**State Sample Letters to Congress**/
	
	/**Member dues contacts**/
	//$('ol.contacts > li:not(:first-child)').hide().addClass('hidden');
	if (document.agencyInfoForm){
		var numberCurrentContacts = (document.agencyInfoForm.numberCurrentContacts.value - 1);
		for (i=numberCurrentContacts;i<4;i++){
			$('ol.contacts > li').eq(i).hide().addClass('hidden');
		}
		
		$('ol.contacts').after('<p class="addContact"><a href="#">Add Another Contact</a></p>');
		$('ol.contacts + p.addContact a').click(function() {
			if($('ol.contacts > li.hidden').length > 0) {
				$('ol.contacts > li.hidden:first').fadeIn('normal').removeClass('hidden');
				if($('ol.contacts > li.hidden').length == 0) {
					$('ol.contacts + p.addContact').hide();
				}
			}
			
			return false;
		});
	}
	if (numberCurrentContacts == 4){
		$('ol.contacts + p.addContact').hide();
	}
	/**End member dues contacts**/

	/**Focus first item that has a class of focus**/
	//$('.focus:first').focus();
	/**End focus first item**/
});