function mailt(str1,str2,el) {
	el.href = 'mailto:' + str1 + '@' + str2;
}

jQuery.exists = function(selector) {return ($(selector).length > 0);}


var activeFront;
var showFront = function (id) {
	if (activeFront == id) return;

	var prev_content = $('#' + activeFront),
		next_content = $('#' + id);

	next_content.hide()
	prev_content.fadeOut('100')
	next_content.fadeIn('100')

	$('#fb-' + activeFront).removeClass('active')
	$('#fb-' + id).addClass('active').find('a').before($('#front-arrow')).blur()

	activeFront = id
}


var frontCycle;
var startFrontCycle = function () {
	var frontContents = $('.front-content-holder .front-content').toArray();
	if (frontContents.length > 0) activeFront = parseInt(frontContents[0].id)
	if (frontContents.length < 2) return;
	frontCycle = setInterval(function(){
		var el = frontContents.shift();
		frontContents.push(el)
		showFront(parseInt(el.id))
	}, 7000);
}
var stopFrontCycle = function () {
	if (frontCycle) clearInterval(frontCycle);
}


function toggleLangOptions() {
	if ($('#langoptions').is(':visible')) {
		$('#langoptions').slideUp(150);
	} else {
		$('#langoptions').slideDown(150);
	}

}

function cycleNews() {
	var first = $('.top .lastnews').children('a:first');
	var fader = function(el) {
		var next = (el.next().length > 0)?el.next():first;
		el.delay(7500).fadeOut('slow',function(){
			next.fadeIn('slow',function(){
				fader(next);
			});
		});
	}
	fader(first);
}


function openVideo() {
	var cont = $('<div class="front-video-container"></div>');
	var bg = $('<div class="bg"></div>').click(function(){cont.remove()}).appendTo(cont);
	var embed = $('<div class="object"><iframe width="640" height="385" src="http://www.youtube.com/embed/0JFNOAue9Gk?hd=1&autoplay=1" frameborder="0" allowfullscreen></iframe></div>').appendTo(cont);
	embed.css({
		'left':(Math.round(($(window).width()-640)/2)) + 'px',
		'top':(Math.round(($(window).height()-385)/2)) + 'px'
	});
	cont.appendTo($('body'));
}


function _bgFix() {
	$('body').css('background-position', ($('body').innerWidth() - 2000)/2 + 'px 160px');
}
$(window).resize(function(){
	_bgFix();
});
$(document).ready(function(){
	_bgFix();

	$('.slide_list').find('p.title').click(function(){
		$.each($('.slide_list').find('p.title'), function (k,v) {
			if (!$(v).hasClass('thumbnail')) $(v).css('background-image','url(' + root_path + '/gfx/arrow-1.png)');
		});
		var self = $(this);
		var data = $(this).next();
		if (data.is(':visible')) {
			data.slideUp('fast');
		} else {
			var opened = self.closest('ul').find('div.data:visible');
			if (opened.length > 0) {
				opened.slideUp('fast',function(){
					if (!self.hasClass('thumbnail')) self.css('background-image','url(' + root_path + '/gfx/arrow-1f.png)');
					data.slideDown('fast');
				});
			} else {
				if (!self.hasClass('thumbnail')) self.css('background-image','url(' + root_path + '/gfx/arrow-1f.png)');
				data.slideDown('fast');
			}
		}
	});

});
