// Start jQuery

$(document).ready(function() {

// BLOG SCRIPTS //

/* Input field clearance on blog **********************************************/
	
	var searchLabel = $('#searchbox label').remove().text();
	$('#search').addClass('placeholder').val(searchLabel).focus(function() {
		if (this.value == searchLabel) {
			$(this).removeClass('placeholder').val('');
		};
	}).blur(function() {
		if (this.value == '') {
			$(this).addClass('placeholder').val(searchLabel);
		};
	});
	$('#searchbox').submit(function() {
		if ($('#search-text').val() == searchLabel) {
			$('search-text').val('');
		}
	});
	
/* Dynamically add a class to the blog layout *********************************/
	
	// Top 4 posts
	$("div#topposts div.post:nth-child(1)").addClass('top-first-post');
    $("div#topposts div.post:nth-child(2)").addClass('top-second-post');
    $("div#topposts div.post:nth-child(3)").addClass('top-third-post');
    $("div#topposts div.post:nth-child(4)").addClass('top-fourth-post');
    
    // Middle 4 posts
    $("div#middleposts div.post:nth-child(1)").addClass('mid-first-post');
    $("div#middleposts div.post:nth-child(2)").addClass('mid-second-post');
    $("div#middleposts div.post:nth-child(3)").addClass('mid-third-post');
    $("div#middleposts div.post:nth-child(4)").addClass('mid-fourth-post');
    
    // Bottom 4 posts
    $("div#bottomposts div.post:nth-child(1)").addClass('btm-first-post');
    $("div#bottomposts div.post:nth-child(2)").addClass('btm-second-post');
    $("div#bottomposts div.post:nth-child(3)").addClass('btm-third-post');
    $("div#bottomposts div.post:nth-child(4)").addClass('btm-fourth-post');
    
/* Dynamically adds a class to the calendar layout in Categories & Archives ***/
	
	// Fifth post in every row
	$("div.calendar div.archivedpost:nth-child(5)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(6)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(10)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(11)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(15)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(16)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(20)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(21)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(25)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(26)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(30)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(31)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(35)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(36)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(40)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(41)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(45)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(46)").addClass("first");
	$("div.calendar div.archivedpost:nth-child(50)").addClass("last");
	$("div.calendar div.archivedpost:nth-child(51)").addClass("first");
	
	$("div.archivedpost").click(function(){
    	window.location=$(this).find("a").attr("href");
    	return false;
	});


/* Search Results *************************************************************/

	$("div.searchpost:nth-child(4)").addClass("last");
	$("div.searchpost:nth-child(5)").addClass("first");
	$("div.searchpost:nth-child(8)").addClass("last");
	$("div.searchpost:nth-child(9)").addClass("first");
	$("div.searchpost:nth-child(12)").addClass("last");
	$("div.searchpost:nth-child(13)").addClass("first");
	$("div.searchpost:nth-child(16)").addClass("last");
	$("div.searchpost:nth-child(17)").addClass("first");
	$("div.searchpost:nth-child(20)").addClass("last");
	$("div.searchpost:nth-child(21)").addClass("first");
	$("div.searchpost:nth-child(24)").addClass("last");
	$("div.searchpost:nth-child(25)").addClass("first");
	$("div.searchpost:nth-child(28)").addClass("last");
	$("div.searchpost:nth-child(29)").addClass("first");
	$("div.searchpost:nth-child(32)").addClass("last");
	$("div.searchpost:nth-child(33)").addClass("first");
	$("div.searchpost:nth-child(36)").addClass("last");
	$("div.searchpost:nth-child(37)").addClass("first");
	$("div.searchpost:nth-child(40)").addClass("last");
	$("div.searchpost:nth-child(41)").addClass("first");
	$("div.searchpost:nth-child(44)").addClass("last");
	$("div.searchpost:nth-child(45)").addClass("first");
	$("div.searchpost:nth-child(48)").addClass("last");
	$("div.searchpost:nth-child(49)").addClass("first");
	$("div.searchpost:nth-child(52)").addClass("last");
	$("div.searchpost:nth-child(53)").addClass("first");
	$("div.searchpost:nth-child(56)").addClass("last");
	$("div.searchpost:nth-child(57)").addClass("first");
	$("div.searchpost:nth-child(60)").addClass("last");
	$("div.searchpost:nth-child(61)").addClass("first");
	$("div.searchpost:nth-child(64)").addClass("last");
	$("div.searchpost:nth-child(65)").addClass("first");
	$("div.searchpost:nth-child(68)").addClass("last");
	$("div.searchpost:nth-child(69)").addClass("first");
	$("div.searchpost:nth-child(72)").addClass("last");
	$("div.searchpost:nth-child(73)").addClass("first");
	$("div.searchpost:nth-child(76)").addClass("last");
	$("div.searchpost:nth-child(77)").addClass("first");
	$("div.searchpost:nth-child(80)").addClass("last");
	$("div.searchpost:nth-child(81)").addClass("first");
	$("div.searchpost:nth-child(84)").addClass("last");
	$("div.searchpost:nth-child(85)").addClass("first");
	$("div.searchpost:nth-child(88)").addClass("last");
	$("div.searchpost:nth-child(89)").addClass("first");
	$("div.searchpost:nth-child(92)").addClass("last");
	$("div.searchpost:nth-child(93)").addClass("first");
	$("div.searchpost:nth-child(96)").addClass("last");
	$("div.searchpost:nth-child(97)").addClass("first");
	$("div.searchpost:nth-child(100)").addClass("last")
	$("div.searchpost:nth-child(101)").addClass("first");
	$("div.searchpost:nth-child(104)").addClass("last")
	$("div.searchpost:nth-child(105)").addClass("first");
	$("div.searchpost:nth-child(110)").addClass("last")
	$("div.searchpost:nth-child(111)").addClass("first");
	$("div.searchpost:nth-child(114)").addClass("last")
	$("div.searchpost:nth-child(115)").addClass("first");
	$("div.searchpost:nth-child(120)").addClass("last")
	$("div.searchpost:nth-child(121)").addClass("first");
	$("div.searchpost:nth-child(124)").addClass("last");
	$("div.searchpost:nth-child(125)").addClass("first");
	$("div.searchpost:nth-child(128)").addClass("last");
	$("div.searchpost:nth-child(129)").addClass("first");
	$("div.searchpost:nth-child(132)").addClass("last");
	$("div.searchpost:nth-child(133)").addClass("first");
	$("div.searchpost:nth-child(136)").addClass("last");
	$("div.searchpost:nth-child(137)").addClass("first");
	$("div.searchpost:nth-child(140)").addClass("last");
	
	$("div.searchpost").click(function(){
    	window.location=$(this).find("a").attr("href");
    	return false;
	});
	
	
/* Filter posts ***************************************************************/
	
	$('a#filtered').toggle(
		function(){
			$('#filteroptions').animate({ "height": "show"}, { "duration": "fast", "easing": "easein" });
			$('a#filtered img').attr('src','http://www.45royale.com/wp-content/themes/45v6_1/images/bg_filter_open.png');
		}, function() {
			$('#filteroptions').animate({ "height": "hide"}, { "duration": "fast", "easing": "easein" });
			$('a#filtered img').attr('src','http://www.45royale.com/wp-content/themes/45v6_1/images/bg_filter.png');
	});

	$('a#filteredsidebar').toggle(
		function(){
			$('#filteroptions_sidebar').animate({ "height": "show"}, { "duration": "fast", "easing": "easein" });
			$('a#filteredsidebar img').attr('src','http://www.45royale.com/wp-content/themes/45v6_1/images/bg_filter_sidebar_open.png');
		}, function() {
			$('#filteroptions_sidebar').animate({ "height": "hide"}, { "duration": "fast", "easing": "easein" });
			$('a#filteredsidebar img').attr('src','http://www.45royale.com/wp-content/themes/45v6_1/images/bg_filter_sidebar.png');
	});

/* Search Results *************************************************************/

	$("div.post.all:nth-child(4)").addClass("last");
	$("div.post.all:nth-child(5)").addClass("first");
	$("div.post.all:nth-child(8)").addClass("last");
	$("div.post.all:nth-child(9)").addClass("first");
	$("div.post.all:nth-child(12)").addClass("last");
	$("div.post.all:nth-child(13)").addClass("first");
	$("div.post.all:nth-child(16)").addClass("last");
	$("div.post.all:nth-child(17)").addClass("first");
	$("div.post.all:nth-child(20)").addClass("last");
	$("div.post.all:nth-child(21)").addClass("first");
	$("div.post.all:nth-child(24)").addClass("last");
	$("div.post.all:nth-child(25)").addClass("first");
	$("div.post.all:nth-child(28)").addClass("last");
	$("div.post.all:nth-child(29)").addClass("first");
	$("div.post.all:nth-child(32)").addClass("last");
	$("div.post.all:nth-child(33)").addClass("first");
	$("div.post.all:nth-child(36)").addClass("last");
	$("div.post.all:nth-child(37)").addClass("first");
	$("div.post.all:nth-child(40)").addClass("last");
	$("div.post.all:nth-child(41)").addClass("first");
	$("div.post.all:nth-child(44)").addClass("last");
	$("div.post.all:nth-child(45)").addClass("first");
	$("div.post.all:nth-child(48)").addClass("last");
	$("div.post.all:nth-child(49)").addClass("first");
	$("div.post.all:nth-child(52)").addClass("last");
	$("div.post.all:nth-child(53)").addClass("first");
	$("div.post.all:nth-child(56)").addClass("last");
	$("div.post.all:nth-child(57)").addClass("first");
	$("div.post.all:nth-child(60)").addClass("last");
	$("div.post.all:nth-child(61)").addClass("first");

	
/* Archives *******************************************************************/

	// Archive containers
	
	var tabContainers = $('div#archiveyear > div');
	tabContainers.hide().filter(':first').show();
	
	$('ul.yearswitch a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).fadeIn(400);
		$('ul.yearswitch a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	});

/* Dynamic comment paragraphs *************************************************/

	$("ol.commentlist div.commenttext p:last-child").addClass("last");
    
/* Image post - Hover qualities ***********************************************/
    
    $('div.image').hover(function(){
    	$(this).find('img').animate({ left:'217px' },{ queue: false, duration: 300 });
		}, function(){
		$(this).find('img').animate({ left:'0' },{ queue: false, duration: 300 });
	});
	
/* Flickr images **************************************************************/
	
	$("div#blogfooter div.blogflickr a:nth-child(6)").addClass('flickr-image-six');
	$("div#blogfooter div.blogflickr a:nth-child(12)").addClass('flickr-image-twelve');

/* Related media posts ********************************************************/

	$("ul.relatedthumbs li:nth-child(5)").addClass("last");

/* More recent author posts ***************************************************/
	
	$('div#moreposts .authorpost:nth-child(2)').hide();
	$('div#moreposts').cycle({ 
    	fx: 'scrollHorz', 
    	prev: '#morecontrols #prev', 
    	next: '#morecontrols #next',
    	speed: 250,
    	timeout: 0 
	});
	
}); // End jQuery