jQuery(function($) {
	$('#navigation > ul > li > ul').each(function() {
		$(this).css('left', (($(this).parent().width() - $(this).width()) / 2) + 'px');
	});
	
	$('#navigation ul li li').append('<div class="cl" />');
	
	$('#navigation ul ul').each(function() {
		var max_width = $(this).find('li:first').width();
		$(this).find('> li').each(function() {
			if ($(this).width() > max_width) {
				max_width = $(this).width();
			}
		}).width(max_width);
		$(this).width(max_width);
	});
	
	$('#navigation ul ul ul').each(function() {
		$(this).css('left', $(this).parent().parent().width() + 'px');
	});
	
	$('#slider ul').jcarousel({
		scroll: 1,
		auto: 4,
		visible: 5,
		wrap:"circular"
	});
	
	// User Rounded Corners only in IE (<=8)
	if($.browser.msie && $.browser.version.substr(0,1) == 6) {
		DD_belatedPNG.fix('h1#logo a, #header, #navigation .active, .dd-t, .dd-holder, .dd-b,  #slider li, #slider .placeholder, .jcarousel-prev, .jcarousel-next, .download-more-info a, .bug-report a, div, a, img');
	}

	/*$('.takeActionHeader #select_county_form').addClass('select_county_form').removeAttr('id');
	$('.takeActionHeader .select_county_form input[type="submit"]').hide();
	$('.takeActionHeader .select_county_form select').selectbox().change(function() {
		window.location = $(this).val();
	});*/
	
	$('#select_county_form input[type="submit"]').hide();
	$('#select_county_form select').selectbox().change(function() {
		window.location = $(this).val();
	});
	
	//var selectCounty = $('#content .select_county_container').clone();
	//$('.takeActionHeader .selectCountyHeader').html(selectCounty);
	//$('.takeActionHeader #select_county_form').addClass('select_county_form_header').removeAttr('id');
	$('#select_county_form_header input[type="submit"]').hide();
	$('#select_county_form_header select').selectbox().change(function() {
		window.location = $(this).val();
	});
	//$('.takeActionHeader').show();
	
	$('form.grantsUpload input').uniform();
	
	$('.jcarousel-container').prepend('<span class="hider notext">&nbsp;</span>');
	
	function _animate_horizontal() {
		var clip = $('#partners');
		var ul = clip.find('> ul');
		var li = ul.find('> li');
		
		if (li.length <= 4) return;
		
		var direction = 'right';
		
		var clip_w = clip.width();
		var clip_x = clip.position().left;
		var clip_offset_x = clip.offset().left;
		
		// set width to 2000 for Chrome/Safari
		ul.css({ 'width': '2000px' });
		
		var time = li.length * 500;
		
		var $t = this;
		var animated = false;
		var direct;
		
		clip.mousemove(function(e){
			var x = e.pageX - clip_offset_x;
			var left_x = clip_w / 2 - 150;
			var right_x = clip_w / 2 + 150;
			
			if( x > clip_w / 2 ) {
				direct = 'right';
			} else {
				direct = 'left';
			}
			
			if( direction != direct || !animated ){
				direction = direct;
				$t._animate();
			}
			
			if( x > left_x && x < right_x ) {
				$t._stop();
			}
			
		});
		
		
		clip.hover(function(){}, function(){
			$t._stop();
		});
		
		_stop = function(){
			ul.stop();
			animated = false;
		}
		
		_animate = function(){
			var ul_w = 0;
			li.each(function(){ ul_w += $(this).outerWidth(true); });
			ul.css({ 'width': ul_w + 'px' });
			
			if( direction == 'left' ) {
				left_position = 0;
			}else {
				left_position = clip_w - ul_w;
			}
			
			var space_left = Math.abs( left_position - ul.position().left )
			time = Math.ceil(space_left / ul_w * 10000);
			
			ul.stop();
			ul.animate({ 'left' : left_position + 'px' }, time, 'linear');
			animated = true;
		}
		
	}
	
	_animate_horizontal();
});

// Cufon.replace('.image h2, .image h3, .widgettitle, .home_subpage h2, .post h2, .hentry h2, body.error404 h2.center, h2.pagetitle, #sidebar .widget .video strong a, .kids-slider h2, h1:not(#logo), h2, h3, h4, h5, h6', { hover: true });
// Cufon.replace('#slider h3, .heading_container .inner-page-title', { textShadow:'3px 3px #092E04' });
