// JavaScript Document


$(document).ready(function() {

/*--Vertical news tabs--*/
var $items = $('#vtab>ul>li');
	
$items.click(function() {
    $items.removeClass('selected');
    $(this).addClass('selected');

    var index = $items.index($(this));
    $('#vtab>div').hide().eq(index).show();
    clearInterval(timerId);
});


/* Rotate through the tabs */
var tabs = $items.length;
var currentTab = 0;

$items.eq(currentTab).addClass('selected');

function loopTabs() {
	if(currentTab<tabs-1) {
		currentTab++;
	} else {
		currentTab = 0;
	}
    $('#vtab>div').hide().eq(currentTab).show();
    
    $items.removeClass('selected');
    $items.eq(currentTab).addClass('selected');
};

var timerId = window.setInterval(loopTabs, 3000);

/*--Splash Rotators--*/

	/*--Fade--*/
	
	$('#rotator-splash-text').cycle({ 
		fx:     'fade', 
		delay:  -2000,
		speed: 1000,
		timeout: 8000,
		next: '#splash-pager'
	});
	
	/*--Slide--*/
	
	$('#rotator-splash').cycle({ 
		fx:     'scrollLeft', 
		easing: 'easeOutQuad', 
		delay:  -2000,
		speed: 1000,
		timeout: 8000,
		next: '#splash-pager'
	});	

	
/*--Module Hovers--*/

	/*--DCS--*/
	
		$(".module-consulting").hover(
		  function () {
			$(".module-consulting .description").animate({"top": "0px"}, "slow");
		  }, 
		  function () {
			$(".module-consulting  .description").animate({"top": "150px"}, "fast");
		  }
		);

		$(".module-law").hover(
		  function () {
			$(".module-law .description").animate({"top": "0px"}, "slow");
		  }, 
		  function () {
			$(".module-law  .description").animate({"top": "150px"}, "fast");
		  }
		);

		$(".module-research").hover(
		  function () {
			$(".module-research .description").animate({"top": "0px"}, "slow");
		  }, 
		  function () {
			$(".module-research  .description").animate({"top": "150px"}, "fast");
		  }
		);

	/*--Clients--*/
	
		$("#carousel li").hover(
			function () {
				$(this).find('.client-logo').fadeIn('slow');
			}, 
			function () {
				$(".client-logo").fadeOut('slow');
			}
		);
		
		jQuery('#carousel').jcarousel({
			wrap: 'circular',
			scroll: 1,
			easing:'easeOutQuad',
			auto: '6'
		});
		
	/*--Search popup--*/

		$("#search-button").toggle(
			function () {
				$('#search-panel').fadeIn('slow');
			}, 
			function () {
				$("#search-panel").fadeOut('slow');
			}
		);

	/*--Blog Scroll--*/

		$("#frame-blog li").hover(
			function () {
				$(this).find('.blog-title').animate({"width": "230px"}, "slow");
			}, 
			function () {
				$(".blog-title").animate({"width": "0px"}, "fast");
			}
		);


	/*--Fonts--*/

	/*-- Cufon.replace('#frame-splash h1, #frame-splash-subpage h1', { fontFamily: 'helvetica-bold' }); --*/
	Cufon.replace('#frame-splash h1,.front-titles div,.got-a-question h2,.blog-title-test h2,#frame-splash-subpage h1,#site-navigation li, #modules li h2', { fontFamily: 'helvetica-medium',hover:true });
	Cufon.replace('#news-title h2, #frame-media h2, #frame-specialist-areas h2, #frame-newsletter h2, #frame-subcategories h2, #mc_embed_signup h2', { fontFamily: 'helvetica-thin' });
	Cufon.replace('#frame-content-subpage .right-column-subpage h1,.featured-videos h2, .full-column-subpage h1, #frame-content-subpage .right-column-subpage h2 ,.full-column-subpage h2', { fontFamily: 'helvetica-light' });
	
	
	

	/*--Pagination--*/
	
	$(function(){
		itemsPerPage = 6;
		paginatorStyle = 4;
		paginatorPosition = 'top';
		$("#frame-specialist-areas ul").pagination();
	});
	
	/*--Newsletter Tabs--*/
	
	
	$(".tab-quarterly").click(
		function () {
			$('#newsletter-legal').css("display","none");
			$('#newsletter-quarterly').fadeIn('fast');
			$('.tab-quarterly').addClass('active');
			$('.tab-quarterly').removeClass('inactive');
			$('.tab-legal').removeClass('active');
			$('.tab-legal').addClass('inactive');
		} 
	);
	
	$(".tab-legal").click(
		function () {
			$('#newsletter-quarterly').css("display","none");
			$('#newsletter-legal').fadeIn('fast');
			$('.tab-legal').addClass('active');
			$('.tab-legal').removeClass('inactive');
			$('.tab-quarterly').removeClass('active');
			$('.tab-quarterly').addClass('inactive');
		} 
	);
	
	
	//*--Specialist Area--*/
	
	$("#frame-specialist-areas li:nth-child(2n)").addClass("second");
	$("#frame-content-subpage #search-results li:last").addClass("end");
	$(".category li:last").addClass("end");
	
});


/*--Quicksand------------------------------------------------------------*/

(function($) {
	$.fn.sorted = function(customOptions) {
		var options = {
			reversed: false,
			by: function(a) { return a.text(); }
		};
	$.extend(options, customOptions);
	$data = $(this);
	arr = $data.get();
	arr.sort(function(a, b) {
		var valA = options.by($(a));
		var valB = options.by($(b));
		if (options.reversed) {
			return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
		} else {		
			return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
		}
	});
	return $(arr);
	};
})(jQuery);

$(function() {

	var $filterType = $('.media-select');
	var $filterSort = $('.media-select');
	var $applications = $('#media-centre-list');
	var $data = $applications.clone();
	
	$filterType.add($filterSort).change(function(e) {
		if ($($filterType).val() == 'all') {
			var $filteredData = $data.find('li.parent');
		} else {
			var $filteredData = $data.find('li.parent[data-type=' + $($filterType).val() + ']');
		}
	
		
		if ($('#filter select').val() == "size") {
			var $filteredData = $filteredData.sorted({
				by: function(v) {
				return parseFloat($(v).find('span[data-type=size]').text());
			}
		});
		} else {
			var $filteredData = $filteredData.sorted({
			by: function(v) {
			return $(v).find('strong').text().toLowerCase();
		}
		});
		}   
	
		$applications.quicksand($filteredData, {
			duration: 100
		});
	
	});
	
});



