jQuery(function($) {
	
	
	// Initialize hover over dropdown navigation menus
	$("ul.nav").superfish({
	  delay: 200,
	  animation: {
		opacity: 'show',
		height: 'show'
		},
	  speed: 'fast',
	  autoArrows: false
	});
	
	
	// Initialize javascript tabs for toggling
	$("ul.tabs").tabs("div.pane", {
		effect: 'fade'
	});
	
	
	//Comments/Trackbacks switch
	var comment_list_now = 'comments';
	$('.comment-controls a').click(function() {
		var type = this.href.split('#')[1];
		if(comment_list_now != type) {
			comment_list_now = type;
			$(this).parent().find('a').toggleClass('button');
			jQuery('.commentlist').toggle();
		}
		return false;
	});
	
	
	// Add Classes
	$("#main-nav ul.nav li:last-child").addClass("last");
	$("#featured .post:nth-child(3)").addClass("last");
	$("#main div.one_third:nth-child(3n+0)").addClass("last");
	$("#main .posts .half:nth-child(2n+0)").addClass("even");
	$("body.single-post #main .post-section:last-child").addClass("last");
	$("#comments ol.commentlist li:last-child").addClass("last");
	$("#related-posts .posts .post:odd").addClass("even");
	$("#sidebar .widget:last-child").addClass("last");
	$("#sidebar .widget-video h3").addClass("fl");
	$("#subfooter .widget:nth-child(3n+0)").addClass("last");
	$(".flickr_badge_image:nth-child(3n+4)").addClass("last");
	$("#pagination div > a").addClass("button");
	jQuery('#sidebar .widget-ads .square .ad-image:odd').addClass('odd');
	
	// Insert Clearing Div
	$("#subfooter .widget:nth-child(4n+0)").before("<div class=\"divider_padding\">");

	
	//Featured Slider
	var opn_slider_length = Math.ceil($('#featured .post').length / 3), opn_slider_current = 0;

	$('#featured-controls a').click(function() {
		var rel = $(this).attr('rel');
		if(rel == 'prev') {
			opn_slider_current--;
		} else if(rel == 'next') {
			opn_slider_current++;
		} else {
			opn_slider_current = parseInt(rel) - 1;
		}

		if(opn_slider_current < 0) {
			opn_slider_current = opn_slider_length - 1;
		} else if(opn_slider_current >= opn_slider_length) {
			opn_slider_current = 0;
		}

		$(this).siblings('a').removeClass('active');
		$(this).parent().find('a.featured-dot').eq(opn_slider_current).addClass('active');

		$('#featured-inner').animate({
			left: -915 * opn_slider_current
		});

		return false;
	});


});

