$(function() {

	///////////////////////// CHRONICLES/////////////////////////
	// We get the full wrapper
	var chronicleWrapper = $('.chronicleslist');
	// We get all the chronicles
	var allChronicle = chronicleWrapper.find('> ul li');
	// We get the current selected chronicle
	var currentChronicle = allChronicle.filter('.current');
	// We get the main title
	var mainTitle = chronicleWrapper.find('> h2');
	// Fading speed
	var fadingSpeed = 200;

	// We style the whole thing
	chronicleWrapper.addClass('enabled');

	var menuList = $('<ul class="menu">');
	// We get the list of thumbnail and create a menu with them
	allChronicle.find('.thumbnailcontent').each(function() {
		// We create a <li> with this content
		var newLi = $('<li>').html($(this).html())
			// We will also add a span that will represent the arrow
			.prepend('<span class="arrow"></span>')
			// We save the parent
			.data('parentChronicle', $(this).closest('li'))
			// We set hover and click events
			.click(selectChronicle).hover(hoverChronicleOn, hoverChronicleOff)
			// We add it to the menu
			.appendTo(menuList);

		// If this chronicle is selected, we set the corresponding class
		if ($(this).closest('li').is('.current')) {
			newLi.addClass('selected');
		}
	});
	// We add the menu to the wrapper
	chronicleWrapper.append(menuList);
	// We set the title the current title
	mainTitle.html(currentChronicle.find('h2').html());

	// What to do when clicking on a chronicle
	function selectChronicle() {
		// Keeping reference to the var
		var thumbnail = $(this);
		// Hiding the current chronicle with a fadeout
		currentChronicle.fadeOut(fadingSpeed, function() {
			// We remove the current attribute to the current chronicle
			$(this).removeClass('current');
			// We set the parent of the thumbnail as the current one
			currentChronicle = thumbnail.data('parentChronicle').addClass('current').css('display', 'none').fadeIn(fadingSpeed);

			// We change the title
			mainTitle.html(currentChronicle.find('h2').html());
			// We select this thumbnail
			menuList.find('li').removeClass('selected');
			thumbnail.addClass('selected');
		});
	}

	//Adding class when hovering
	function hoverChronicleOn() {
		$(this).addClass("hover");
	}
	function hoverChronicleOff() {
		$(this).removeClass("hover");
	}


	///////////////////////////////////// STRIPS////////////////////////////////
	$('.strips').each(function() {
		// We get all the inner strips
		var strips = $(this).find('.img');
		// We save them in the parent data
		$(this).data('stripList', strips);
		$(this).data('maxStrips', strips.length-1);
		$(this).data('actualStrip', 0);

		// We add a hover mechanism on them
		strips.hover(function() {
			$(this).find('div.legend').animate({'bottom': '0px'});
		}, function() {
			$(this).find('div.legend').animate({'bottom': '-30px'});
		});

		// We hide them all
		strips.hide();
		// We show the first one
		$(strips.get(0)).show();

		// We now add navigation to the nav
		$(this).find('.nav a.previous').click(function() {
			// reference to the parent
			var stripParent = $(this).closest('.strips');
			var actualStrip = stripParent.data('actualStrip');
			var maxStrips = stripParent.data('maxStrips');
			var stripList = stripParent.data('stripList');

			// We get the previous strip
			var previousStripIndex = actualStrip-1;
			if (previousStripIndex<0) previousStripIndex = maxStrips;
			stripParent.data('actualStrip', previousStripIndex);

			// We hide the current one
			stripParent.find('.img:visible').fadeOut(200, function() {
				$(stripList.get(previousStripIndex)).fadeIn(200);
			});

			return false;
		});

		// We now add navigation to the nav
		$(this).find('.nav a.next').click(function() {
			// reference to the parent
			var stripParent = $(this).closest('.strips');
			var actualStrip = stripParent.data('actualStrip');
			var maxStrips = stripParent.data('maxStrips');
			var stripList = stripParent.data('stripList');

			// We get the previous strip
			var nextStripIndex = actualStrip+1;
			if (nextStripIndex>maxStrips) nextStripIndex = 0;
			stripParent.data('actualStrip', nextStripIndex);

			// We hide the current one
			stripParent.find('.img:visible').fadeOut(200, function() {
				$(stripList.get(nextStripIndex)).fadeIn(200);
			});

			return false;
		})

	});


	////////////////////// TRANSACTIONS/////////////////////
	/*
	$('.transactionlist ul').jcarousel({
		vertical: true,
		scroll: 3,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		initCallback: function(carousel) {
			// Getting the navigation menu
			var navMenu = carousel.container.closest('.transactionlist').find('.nav');
			// Previous
			navMenu.find('a.previous').click(function() {
				carousel.prev();
				return false;
			});
			// Next
			navMenu.find('a.next').click(function() {
				carousel.next();
				return false;
			});
		}

    });
	*/



	///////////////////// BD BLOGS ////////////////////////////////
	$('.guestbdblogs .otherblogs a').tipsy();

	
	var tab = $('#listabdtab');
function testanim(size, callback){
var f= function(){tab.animate({fontSize:size},250, callback)}
return f;
}


testanim('1.3em', testanim('1.1em',testanim('1.4em', testanim('1.1em',testanim('1.5em', testanim('1.1em'))))))();
	
});
