jQuery(function($){
	
	// Adprice select box
	$('#adprice-descriptions').change(function(){
		$('.adprice-description').hide();
		var index = $(this).find('option:selected').index()-1;
		if (index >= 0) $('.adprice-description').eq(index).show();
	});
	
	// jQuery Uniform
	// $('select, input[type=checkbox], input[type=radio], input[type=file], input[type=submit], a.button, button').uniform();
	
	// Category list accordion
	$('#category-list h5').click(function(e) {
		e.preventDefault();
		$(this).next('ul').slideToggle('fast');
		window.location.hash = $(this).attr('id');
	});
	
	// Front pages magazine quiz light box
	$('#magasintest').click(function(e){
		e.preventDefault();
		$('#quiz-content').lightbox_me({
			centered: true,
			onLoad: function() {
				// If you want anything to happen on load, put it here
			}
		});
	});
	
	// Filtering publications 
	var $filterType = $('#filterOptions li.active a').attr('class'); 
	var $holder = $('ul.ourHolder'); 
	var $data = $holder.clone(); 
	$('#filterOptions li a').click(function(e) { 
		$('#filterOptions li').removeClass('active'); 
		var $filterType = $(this).attr('class'); 
		$(this).parent().addClass('active'); 
		if ($filterType == 'all') { 
			window.location.hash = ''; 
			var $filteredData = $data.find('li'); 
		} else { 
			window.location.hash = $filterType; 
			var $filteredData = $data.find('li[data-type=' + $filterType + ']'); 
		} 
		$holder.quicksand($filteredData, { 
			duration: 400, 
			easing: 'easeInOutQuad' 
		});
		return false; 
	});
	// Filter if hash is available
	if (window.location.hash) {
		$('#filter-' + window.location.hash.replace('#', '')).trigger('click');
		$('#' + window.location.hash.replace('#', '')).trigger('click');
	}
	
	/* Beregn høyeste element i gruppe */
	function equalHeight(group) {
		var tallest = 0;
		group.each(function(){
			var thisHeight = $(this).height();
			if (thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	
	equalHeight($('.publication'));
	
	// Frontpage carousel
	var sliderSwitched = false;
	$('#slider').cycle({
		fx: 'fade',
		// delay: 10000,
		delay: 5000,
		before: function(elem){
			$('#publications-category li').removeClass('active');
			if (sliderSwitched) {
				var activeIndex = $('#slider .slide').index(elem) + 1;
				$('#publications-category li:nth-child(' + activeIndex + ')').addClass('active');
			}
			sliderSwitched = true;
		}
	});
	$('#publications-category a').click(function(e){
		/*
		e.preventDefault();
		var index = $(this).index('#publications-category a');
		console.log(index+1);
		*/
	});
	
	// Front page news list slider
	$('#frontpage-news ul').jcarousel();
	
});
