$(document).ready(function(){
	setTopPanel();
	setVoteList();
	setLocationsOverview();
	setMenuTrail();
	$('.tabs').tabs();
	$('#tabs').tabs({selected:3});
	$('div#content_header.carousel').carousel({ autoSlide: true, autoSlideInterval: 4000, effect: 'fade', animSpeed: 5000, loop: true});
	$('div#main_content .carousel').carousel({ autoSlide: true, effect: 'fade', autoSlideInterval: 8000, animSpeed: 250, loop: true, pagination: true});
	$('div.nominees').carousel({ autoSlide: true, dispItems: 3, effect: 'fade', autoSlideInterval: 8000, animSpeed: 1000, loop: true});
	$('.obfuscated').each(deObfuscateEmail);
	
});

function deObfuscateEmail(i)
{
    var content = $(this).text().replace(/ AT /g, '@').replace(/ DOT /g, '.');
    $(this).replaceWith($('<a href="mailto:'+content+'?subject=Best of Swiss Gastro" title="Via E-Mail kontaktieren">'+content+'</a>'));
} 

function setTopPanel(){
	$(".folded").hide();
	$(".toggle").click(function(){
		$(".toggle").removeClass('activated').addClass('deactivated');
		var target = $(this).attr('href');
		if($(target).hasClass('shown')){
			$(target).slideUp("fast").removeClass('shown');
			$(".toggle").removeClass('activated').removeClass('deactivated');
			$("#top").removeClass('open');
		}else{
			$(this).toggleClass('activated').toggleClass('deactivated');
			$("#top").addClass('open');
			$(".folded").not(target).removeClass('shown').slideUp("fast", function(){
				$(target).slideDown("fast").addClass('shown');
			});
		}
		return false;
	});
	
	if(window.location.hash == '#login_form'){
		$('#login_link a').trigger('click')
	}
	
}
function setVoteList(){
	$('.voteform').hide();
	$('.location_overview li ul li').mouseover(function(){
		$(this).addClass('hover');
	});
	$('.location_overview li ul li').mouseout(function(){
		$(this).removeClass('hover');
	});
}
function setMenuTrail(){
	$('li.active').parents('li').addClass('trail');
	for(var i=0; i <gTrails.length; i++){
		$('#menu-item-' + gTrails[i]).addClass('trail');
	}
}
function setLocationsOverview(){
	$('.location_overview li ul').hide();
	$('.location_overview h3').click(function() {
		$(this).toggleClass('activated');
		$(this).next().toggle('normal');
		return false;
	}).next().hide();
	var cat = window.location.toString();
	cat = cat.substring(cat.lastIndexOf('#'));
	if (cat != ""){
		var URLselect = parseInt(window.location.search.substring(10));
		$(cat+' ul').show();
		$(cat+' h3').toggleClass('activated');
	}else{
		$('.category_nominees:first').show();
		$('.location_overview h3:first').toggleClass('activated');
	}
}
