jQuery(document).ready(function($) {
	
	// Featured Rotator.
	$( '.tabs' ).tabs( '.slides > div', {
 		effect: 'fade', 
        fadeOutSpeed: "fast",
        rotate: true
	}).slideshow({
		autoplay: true,
		interval: 4000
	});
	
	// Featured Scroller
	$( '.scrollable' ).scrollable({
		size: 1,
		clickable: false,
		api: true,
		items: ".items",
		item: ".page"
	});
	
	var featured_scroller = $( '#featured .scrollable, #recent-videos .scrollable' ).scrollable({
		api: true
	});
	
	if( featured_scroller ) {
		$( '#featured .scrollable-navigation .text' ).html( 'Page ' + ( featured_scroller.getIndex() + 1 ) + ' of ' + featured_scroller.getSize() );
	
		featured_scroller.onStart(function() {
			$( '#featured .scrollable-navigation .text' ).html( 'Page ' + ( this.getIndex() + 1 ) + ' of ' + this.getSize() );
		});
	};
	
	var video_scroller = $( '#recent-videos .scrollable' ).scrollable({
		api: true
	});
	
	if( video_scroller ) {
		$( '#recent-videos .scrollable-navigation .text' ).html( 'Featured ' + ( video_scroller.getIndex() + 1 ) + ' of ' + video_scroller.getSize() );
	
		video_scroller.onStart(function() {
			$( '#recent-videos .scrollable-navigation .text' ).html( 'Featured ' + ( this.getIndex() + 1 ) + ' of ' + this.getSize() );
		});
	};
			
	$( '#featured .scrollable .items .page a' ).tipsy({
		gravity: 's', 
		fade: true
	});
	
	$( '.scrollable-navigation' ).click(function() {
		return false;
	});	  

	// Bottom Tabs
	$("ul.tablist").tabs("#tab-pages > div");
	
	// Wrap Tags
	$( '#hot-tags ul li a, .button-action' ).each(function (i) {
		$( this ).wrapInner( '<span></span>' );
	});
	
	// Comment Form Validation
	$("#commentform").validate({
		success: function(label) {
			label.addClass("success").text("Working Fine");
			label.wrapInner( '<span></span>' );
			label.parent( 'p' ).children('.input').addClass( 'success' );
		},
		rules: {
			name: { required: true },
			email: { required: true, email: true },
			url: { required: false, url: true },
			comment: { required: true }
		},
		messages: {
			name: { required: "<span>Error Please Fix</span>" },
			email: { required: "<span>Error Please Fix</span>", email: "<span>Error Please Fix</span>" },
			url: { required: "<span>Optional</span>", url: "<span>Error Please Fix</span>" },
			comment: { required: "<span>Error Please Fix</span>" }
		},
		onkeyup: true,
		validClass: 'success'
	});
	
	// Hide/Show Gallery Meta
	$( '.gallerymeta a.button-action, .cur-image .info a.close' ).click(function() {
		$( '.cur-image .info' ).toggle();
		return false;
	});
	
	// Remove Border from last navigation child
	$( '#navigation ul li ul li:last-child a' ).css( { border: 0 } );
	
	var currentTallest = 0;
	$( '#latest .post' ).each(function(i){
		if ($(this).height() > currentTallest) { 
			currentTallest = $(this).height(); 
		}
	});
	
	/*$( '#featured' ).css( 'height', ( $( '#more-articles' ).height() + $( '#explorer' ).height() ) + 10 + 'px' );*/
	$( '#latest > .post' ).css( 'height', currentTallest + 'px' );
		
	/**
	 * Decide what the archive view should look like.
	 *
	 * @since 1.0.0
	 */
	$( '.archive-view .list, .archive-view .grid' ).live( 'click', function() {

		var data = {
			action : 'woo_archive_view',
			layout : $( this ).attr( 'rel' ),
			query_string : query_string,
			posted : true,
		};
	
		jQuery.post( load_ajax, data, function( data ) {
			location.reload();
		});
		
		return false;
	});
	
	$( '.sub-menu' ).prepend( '<span class="overlay"></span>' );
	
	$( '.sub-menu .overlay' ).each(function() {
		$( this ).css( {
			width : $( this ).parent().prev().width() + 43
		});
	});
	
});
