//Faux-columns
$.fn.fauxColumns = function(){

	var maxHeight = 0;

	this.each(function(){
		if (this.offsetHeight > maxHeight) maxHeight = this.offsetHeight;
	});

	this.each(function(){
		this.style.height = maxHeight + 'px';
		if (this.offsetHeight > maxHeight) {
			this.style.height = (maxHeight - (this.offsetHeight - maxHeight)) + 'px';
		}
	});

};

//Roterende header
var newsitems;
var curritem=0;
var iPause=0;

function ticknews() {
  if (iPause==0){
	$("#header_bilde li:eq("+curritem+")").fadeOut("slow",function(){$(this).hide();});
	curritem = ++curritem%newsitems;
	$("#header_bilde li:eq("+curritem+")").fadeIn("slow");
	}
}

$(document).ready( function(){

	//Navigasjon
	$("ul.nav_list_1 ul").hide();
	$("a.nav_children").toggle(function() {
			$(this).next("ul").slideDown("slow");
			$(this).addClass('nav_open');
		},function() {
			$(this).removeClass('nav_open');
			$(this).next("ul").slideUp("slow");
	});

	//Roterende header
	$('ul#header_bilde').innerfade({
		speed: 'slow',
		timeout: 10000,
		type: 'sequence',
		containerheight: '167px'
	});


	//De-obfuscate emails
	$('a.obfuscated').each(function(){
		var to_replace = '[at-no-spam]';
		$(this).html($(this).html().replace(to_replace, '@')).attr('href', $(this).attr('href').replace(to_replace, '@'));
	});

	//Sett linker til target="_blank"
	$('a.external').each( function() {
		$(this).attr("target", "_blank");
	});

	//First and last childs, lists
	$('ul li:first-child').addClass('fli');
	$('ul li:last-child').addClass('lli');

	//Zebra-striped tables
	$('table.zebra tr:even').addClass('even');

	//Alternating list-items
	$('ul.zebra li:even').addClass('even');

	//Label-switcher for forms
	$('form.labelswitch .swl').each( function(){
		
		$(this).prev().hide();
		if($(this).val() == ''){
			$(this).val($(this).prev().text().slice(0, -1));
			if($(this).attr('type') == 'password'){
				$(this).attr('type', 'text');
			}
		}

	});
	
	$('form.labelswitch .swl').click( function(){
		$(this).val('');
		if($(this).prev().text() == 'Passord:'){
			$(this).attr('type', 'password');
		}
	});

});

