jQuery(function($) {
	$('#sitemap .sitemap-item h4 a').click(function() {
		$(this).parent().parent().find('ul:eq(0)').slideToggle("fast");
		return false;
	});
	$('.fix-last > *:last-child').addClass('last');
	$('.fix-last.ilast > *:last-child').addClass('last-item');
	
	if ($('#blog-slider').length) {
		var slider_index = 0;
		var num_slides = $('.blog-slide').length - 1;
		
		function move_blog_slider() {
			var new_left = -1 * slider_index * 740;
		    $('.blog-slider-dock').animate({left: new_left + 'px'});
		}
		
		$('.text-prev, .text-next').click(function () {
		    if (slider_index==0 && $(this).hasClass('text-prev')) {
		    	slider_index = num_slides;
		    } else if (slider_index==num_slides && $(this).hasClass('text-next')) {
		    	slider_index = 0;
		    } else if ($(this).hasClass('text-prev')) {
		    	slider_index--;
		    } else if ($(this).hasClass('text-next')) {
		    	slider_index++;
		    } else {
		    	throw "shouldn't happen";
		    }
		    move_blog_slider();
		    return false;
		});
		
		// That's actually last
		$('.notext-prev').click(function () {
			slider_index = num_slides;
		    move_blog_slider();
		});
		
		// That's actually first
		$('.notext-next').click(function () {
			slider_index = 0;
		    move_blog_slider();
		});
	}
	
	/*----*/
	
	$('.arrow').click(function () {
	  $(this).parents('.cat-selector').find('.cats').slideToggle('fast');
          var z = $(this).parents('.cat-selector').css('z-index') == '1' ? '2' : '1';
          $(this).parents('.cat-selector').css('z-index', z);
	});
	
	$('.send-tell-a-friend.active').live('click', function () {
		var site_url = $(this).attr('url');
		var get_url = $(this).attr('get-url') + '?mailto=' + $('.taf-mailto').val() + "&body=" + $('.taf-body').val() + '&subject=' + $('.taf-subject').val() + '&url=' + site_url;
		$(this).removeClass('active');
		$(this).val('Sending ...');
		var me = this;
		$.get(get_url, [], function (data, textStatus) {
			if (data.toString().indexOf('success-') != -1) {
				alert(data.toString().replace('success-', ''));
				tb_remove();
			} else {
				alert(data.toString());
			}
			
			$(me).addClass('active');
			$(me).val('Tell a friend!');
		});
		
		return false;
	});
	
	$('.blink').focus(function () {
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	});
	$('.blink').blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	
	$('.swap-video').click(function () {
		$(this).hide();
		$(this).parent().find('.video-object').show();
	});
});
