$(document).ready(function() {
	// Enable smooth scrolling of in-page links.
	$('a[href*=#]').each(function() {
		if ((this.host == location.host || this.host == location.hostname) &&
			this.pathname == location.pathname &&
			this.hash.replace(/#/,'').length) {
			var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
			var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top - 15;
				$(this).click(function() {
					$('html, body').animate({scrollTop: targetOffset}, 400);
					return false;
				});
			}
		}
	});
	
	// Color two_color tables
	$('.two_colors.auto tr:odd').addClass('dark');
	
	// Fix YouTube-links
	$('.social_network.youtube a').hover(function(){
	    $(this).find('.youtube_tube').css('text-decoration', 'underline');
	}, function(){
        $(this).find('.youtube_tube').css('text-decoration', 'none');
	});
	// Fix LunarStorm-links
	$('.social_network.lunarstorm a').hover(function(){
	    $(this).find('.lunarstorm_storm').css('text-decoration', 'underline');
	}, function(){
        $(this).find('.lunarstorm_storm').css('text-decoration', 'none');
	});});

function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; }

function show_event(id){
	$('tr#event_' + id).show();
	a_tag = $('a#event_link_' + id);
	a_tag.text("Dölj");
	a_tag.attr({href: "javascript: hide_event('" + id + "');"});
}
function hide_event(id){
	$('tr#event_' + id).hide();
	a_tag = $('a#event_link_' + id);
	a_tag.text("Mer info");
	a_tag.attr({href: "javascript: show_event('" + id + "');"});
}

function show_attachments(id){
	$('tr#attachments_' + id).show();
	a_tag = $('a#attachments_link_' + id);
	a_tag.text("Dölj");
	a_tag.attr({href: "javascript: hide_attachments('" + id + "');"});
}
function hide_attachments(id){
	$('tr#attachments_' + id).hide();
	a_tag = $('a#attachments_link_' + id);
	a_tag.text("Bilagor");
	a_tag.attr({href: "javascript: show_attachments('" + id + "');"});
}

function show_fileinfo(id){
	$('tr#fileinfo_' + id).show();
	a_tag = $('a#fileinfo_link_' + id);
	a_tag.text("Dölj");
	a_tag.attr({href: "javascript: hide_fileinfo('" + id + "');"});
}
function hide_fileinfo(id){
	$('tr#fileinfo_' + id).hide();
	a_tag = $('a#fileinfo_link_' + id);
	a_tag.text("Mer info");
	a_tag.attr({href: "javascript: show_fileinfo('" + id + "');"});
}

function display_region(region, onoff){
	$('#sverigekarta #' + region).css('display', onoff);
}

function deobfuscate(str){
	letter_shifter = '8vjEOQ.f05I P3m2:bNoHc9Cdq"k-ypY<gxS7uZFVzaeL_RhnM6rDUXtKGJ1l4wi@BAsT>';
	str_out = "";
	for(i = 0; i < str.length; i++){
		pos = letter_shifter.indexOf(str.charAt(i));
		if(pos == -1)
			str_out += str.charAt(i);
		else {
			pos = pos - i - 7;
			while(pos < 0) pos += letter_shifter.length;
			str_out += letter_shifter[pos];
		}
	}
	return str_out;
}
