Cufon.replace('.slide h2', { fontFamily: 'Gotham HTF' });
Cufon.replace('.slider-navigation ul li a', { fontFamily: 'Gotham HTF' });
Cufon.replace('#navigation ul li a', { fontFamily: 'gotham-medium', hover:true });
Cufon.replace('.promos ul li a', { fontFamily: 'gotham-medium', hover:true });
Cufon.replace('.tabs ul li a', { fontFamily: 'Gotham HTF', hover:true });
Cufon.replace('.date span', { fontFamily: 'Gotham HTF' });
Cufon.replace('.date strong', { fontFamily: 'Gotham HTF' });
Cufon.replace('.entry h2', { hover: true }, { fontFamily: 'Gotham HTF' });
Cufon.replace('#content h1, #sidebar h2', { fontFamily: 'Gotham HTF' });
Cufon.replace('.postTabs_divs h4', { fontFamily: 'Gotham HTF' });

$(document).ready(function(){
	
	// Textbox "text clear" Functionality
	$('.blink').focus(function () {
		if ($(this).val() == $(this).attr('title')) {
			$(this).css('color', '#fff').val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).css('color', '#fff').val($(this).attr('title'));
		}
	});
	
	// Tabs
	$('.tabs ul li a').live('click', function(){
	
		var index = $(this).parent().parent().find('a').index(this);
		$(this).parent().parent().find('a').removeClass('active');
		$(this).addClass('active');
		
		$('.content .tab-content').hide();
		$('.content .tab-content').eq(index).show();
		
		return false;
		
	});
	
	// Slider Functionality
	var sliderNav = $('.slider-navigation a');
	var currentSlide = 0;
	
	sliderNav.click(function(){
		slideID = this.id;
		slideID = slideID.split('-');
		slideID = slideID[1];
		currentSlide = slideID;
		$('#slider-hover').removeClass();
		$('#slider-hover').addClass('slideStyle-'+currentSlide);
		navSlideID = slideID - 1;
		navSlideTo = (navSlideID * 49);
		slideTo = (slideID * 390);
		slideTo = slideTo * -1;
		$('.slider-content ul').animate({'top':slideTo}, 600, "easeInOutExpo");
		$('#slider-hover .hover-block').animate({'top':navSlideTo}, 300, "easeOutExpo");
	});
	
	function move_to_next(){
	
		slideID = parseInt(currentSlide) + 1;
		if (slideID == 6) { slideID = 0; }
		currentSlide = slideID;
		if (slideID == 0) { navSlideID = -10; } else { navSlideID = slideID - 1; }
		$('#slider-hover').removeClass();
		$('#slider-hover').addClass('slideStyle-'+currentSlide);
		navSlideTo = (navSlideID * 49);
		slideTo = (slideID * 390);
		slideTo = slideTo * -1;
		$('.slider-content ul').animate({'top':slideTo}, 600, "easeInOutExpo");
		$('#slider-hover .hover-block').animate({'top':navSlideTo}, 300, "easeOutExpo");
		
	}
	
	// START AUTO-ROTATE CODE
	var timer;
  	var donext = function (x){ move_to_next(); }
  
  	var dotimer = function (){
    	if(timer != null) {
      		clearInterval(timer);
    	}
  
    	timer = setInterval(function() {
      		donext();
    	}, 10000); // Change the time in between rotations here (in milliseconds)   
  	}
  
  	dotimer();
  	
  	$('.slider-navigation').hover(function(){
  		clearInterval(timer);
  	},function(){
  		dotimer();
  	});
  	// END AUTO-ROTATE CODE
  	
  	//logos
	
	_animate_logos();
	
	$('.logos-clip').hover(
		function(){
			is_completed = false;
			$('.logos-holder').stop();
		}, function(){
			_animate_logos();
		}
	);
	
	$('.tip').tooltip();
	
	$("span.sidebar-arrow").click(function(){
		ulToShow = $(this).parent('li').find('ul');
		if ($(ulToShow).is(":visible")) {
			$(ulToShow).slideUp();
		} else {
			$('li.sidebar_block ul li ul').slideUp();
			$(ulToShow).slideDown('fast');
		}
	});
	/* END Sidebar Subpages */
	
	// ---------------------
	// County Dropdown Slider
	// ---------------------
	$("#countyDropdownWindow").hide();
	$("a.countyDropdownActive").hide();
	
	$("a.countyDropdown").click(function(event){  
		$("a.countyDropdownActive").show();
		$("#countyDropdownWindow").slideDown("fast");
		event.stopPropagation();
		$("#statusDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.statusDropdownActive").hide();
		$("#sectorDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.sectorDropdownActive").hide();
		$("#programDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.programDropdownActive").hide();
	});
	
	$("a.countyDropdownActive").click(function(event){
		$("#countyDropdownWindow").slideUp("fast", function() {
			$(this).hide();
		});
		$(this).hide();
	});

	// ---------------------
	// Sector Dropdown Slider
	// ---------------------
	$("#sectorDropdownWindow").hide();
	$("a.sectorDropdownActive").hide();
	
	$("a.sectorDropdown").click(function(event){  
		$("a.sectorDropdownActive").show();
		$("#sectorDropdownWindow").slideDown("fast");
		event.stopPropagation();
		$("#statusDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.statusDropdownActive").hide();
		$("#countyDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.countyDropdownActive").hide();
		$("#programDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.programDropdownActive").hide();

	});
	
	$("a.sectorDropdownActive").click(function(event){
		$("#sectorDropdownWindow").slideUp("fast", function() {
			$(this).hide();
		});
		$(this).hide();
	});
	
	// ---------------------
	// Program Dropdown Slider
	// ---------------------
	$("#programDropdownWindow").hide();
	$("a.programDropdownActive").hide();
	
	$("a.programDropdown").click(function(event){  
		$("a.programDropdownActive").show();
		$("#programDropdownWindow").slideDown("fast");
		event.stopPropagation();
		$("#statusDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.statusDropdownActive").hide();
		$("#sectorDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.sectorDropdownActive").hide();
		$("#countyDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.countyDropdownActive").hide();
	});
	
	$("a.programDropdownActive").click(function(event){
		$("#programDropdownWindow").slideUp("fast", function() {
			$(this).hide();
		});
		$(this).hide();
	});
	
	// ---------------------
	// Program Dropdown Slider
	// ---------------------
	
	$("a.statusDropdown").click(function(event){  
		$("a.statusDropdownActive").show();
		$("#statusDropdownWindow").slideDown("fast");
		event.stopPropagation();
		$("#programDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.programDropdownActive").hide();
		$("#sectorDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.sectorDropdownActive").hide();
		$("#countyDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.countyDropdownActive").hide();
	});
	
	$("a.statusDropdownActive").click(function(event){
		$("#statusDropdownWindow").slideUp("fast", function() {
			$(this).hide();
		});
		$(this).hide();
	});
	
	$('body').click(function() {
		$("#programDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.programDropdownActive").hide();
		$("#sectorDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.sectorDropdownActive").hide();
		$("#countyDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.countyDropdownActive").hide();
		$("#statusDropdownWindow").slideUp("fast", function() { $(this).hide(); }); $("a.statusDropdownActive").hide();
	});
	
});

var interval;
var is_completed = true;
function _animate_logos(){
	var clip_left = parseInt($('.logos-holder').css('left'));
	
	var w = $('.logos-clip a:eq(0)').width() + 20;
	var l =  -1 * w;
	
	if(is_completed)
		$('.logos-clip a:eq(0)').clone().appendTo('.logos-holder');
	
	var speed = w / $('.logos-clip').width();
	if( clip_left != 0 ) 
		speed = (w+clip_left) / $('.logos-clip').width();
	
	var speed = parseInt(speed * 10000) * 2;
	
	$('.logos-holder').animate({ 'left' : l + 'px' }, speed, 'linear', function(){
		$('.logos-clip a:eq(0)').hide().remove();//.appendTo('.logos-holder').fadeIn();
		$('.logos-holder').css('left', 0);
		is_completed = true;
		_animate_logos();
	});
	
}

(function($) {
	$.fn.tooltip = function(settings){
		
		var tip = $('<div class="tooltip"></div>').appendTo('body');
		
		var text, l, t;
		
		$(this)
			.live('mouseover', function(){
				text = $(this).attr('title');
				
				tip.html( text );
				
				l = $(this).offset().left + ( $(this).outerWidth() / 2) - (tip.outerWidth()/2);
				t = $(this).offset().top - 60;
				
				if($.browser.msie){
					t += 35;
				}
				
				tip.css('top', t + 'px').css('left', l + 'px').fadeIn('fast');
				
				$(this).attr('_title', text);
				$(this).attr('title', '');
			})
			.live('mouseout', function(){
				tip.hide();
				$(this).attr('title', $(this).attr('_title'));
			}
		);
	}
})(jQuery);

function pageLoaded() {
	
	$('#navigation li:last').addClass('last');
	
	/* Sidebar Subpages */
    $("li.sidebar_block ul li").each(function(){
	
		var childID = '';
		var grandchildrenPages = '';
		grandchildrenPages = $(this).find('ul');

		if ($(this).children('ul').size() > 0) {
			$(grandchildrenPages).hide();
			$(this).prepend('<span class="sidebar-arrow"></span>');
		}
		
		$('li.sidebar_block ul li ul li .sidebar-arrow').hide();
		$('li.current_page_item ul').show();
		$('li ul li ul li.current_page_item').parent('ul').parent('li').find('ul').show();
		$('li ul li ul li ul li.current_page_item').parent('ul').parent('li').parent('ul').parent('li').find('ul').show();
	});
	
	$("#statusDropdownWindow").hide();
	$("a.statusDropdownActive").hide();
	
	Cufon.now();
}
