function toppbildeStart () {
	toppbildeIntervall = setTimeout('toppbildeFerdig()', toppbildeTid);
}
function toppbildeFerdig () {
	var id = toppbildeAktiv == toppbildeTotal ? 1 : toppbildeAktiv + 1;
	toppbildeBytt(id);
}
function toppbildeBytt (id) {
	if (toppbildeTotal > 1) {
		clearTimeout(toppbildeIntervall);
		$('#toppbilde_' + toppbildeAktiv).fadeOut(toppbildeFart);
		$('#toppbildeknapp_' + toppbildeAktiv).removeClass('aktiv');
		$('#toppbilde_' + id).fadeIn(toppbildeFart);
		$('#toppbildeknapp_' + id).addClass('aktiv');
		$('#toppbildenummer').text(id);
		toppbildeAktiv = id;
		toppbildeStart();
	}
}
function smallpopup () {
	$(this).css({'z-index': 1000});
	$(this).find('.smallpopup').show();
}
function smallpopup_gone () {
	$(this).css('z-index', 2);
	$(this).find('.smallpopup').hide();
	
}
function searchBox (e) {
	var pos = e.type == 'focus' ? 'bottom' : 'top';
	if ($(this).val() == '') $(this).css('background-position', 'left ' + pos);
}
function bar () {
	$(this).css('background-position', 'left top');
}
function init () {
	$('#toppbilde img').hide();
	$('#toppbilde_' + toppbildeAktiv).show();
	toppbildeTotal = $('#toppbilde img').length;
	$('#toppbildenummer').text(toppbildeAktiv);
	$('#toppbildetotal').text(toppbildeTotal);
	$('#toppbildeknapp_' + toppbildeAktiv).addClass('aktiv');
	if (toppbildeTotal > 1) toppbildeStart();
	
	$('.photo').hover(smallpopup, smallpopup_gone);
	$('a.lightbox').lightBox();
	
	$('#ajaxSearch_input').focus(searchBox).blur(searchBox).val('');
	$('#tipFormButton').click(function () { $('#tipForm').parent().toggleClass('show'); });
	$('#tipForm input[type=text]').focus(searchBox).blur(searchBox).val('');
	$('#tipForm').bind({
		'submit': function () {
			$.post($(this).attr('action'), $(this).serialize(), function () { $('#tipForm').parent().removeClass('show'); }, 'text');
			return false;
		},
		'reset': function () {
			$('#tipForm').parent().removeClass('show');
			return false;
		}
	});
}

var toppbildeTid = 10000;
var toppbildeIntervall;
var toppbildeFart = 500;
var toppbildeAktiv = 1;
var toppbildeTotal;

$(document).ready(init);
