// JavaScript Document
var checkboxArray = new Array();
function init () {
	$('.regelVocabulary').tipTip();
	
	$('#regelInfoMenySelectIt').change(function() {
		window.location = $(this).val();
	});
	
	$('#regelsubmit,#regelsmalsubmit').click(function () {
		if (this.id == 'regelsubmit')
			regelSok('bred');
		else
			regelSok('smal');
	});
	
	$('#regelsokText,#regelsokSmalText').keyup(function (e) {
		if (e.which == 13) {
			if (this.id == 'regelsokText')
				regelSok('bred');
			else
				regelSok('smal');
		}
	});
	
	function regelSok (s) {
		if (s == 'bred')
			var ord = $('#regelsokText').val();
		else
			var ord = $('#regelsokSmalText').val();
		
		var pattern = new RegExp(''+ord+'', 'gi');
		$('.regel').each(function () {
			var eacher = $('a',this).html();
			if ((eacher.match(pattern)) == null) {
				if ($(this).is(':visible'))
					$(this).hide();
				$(this).attr('rel','hidden');
			}
			else if ((eacher.match(pattern)) !== null) {
				if ($(this).is(':hidden'))
					$(this).show();
				$(this).attr('rel','visible');
			}
		});
		
		$('.regelWrapper').each(function () {
			var visibleBarn = false;
			$('.regel',this).each(function () {
				if ($(this).attr('rel') == 'visible') {
					visibleBarn = true;
				}
			});
			
			if (visibleBarn == true && $(this).is(':hidden'))
				$(this).show();
			else if (visibleBarn == false && $(this).is(':visible'))
				$(this).hide();
		});
		
		if (ord == '') {
			if ($('#reglerFultsok').is(':visible'))
				$('#reglerFultsok').fadeOut();
		}
		else {
			if ($('#reglerFultsok').is(':hidden'))
				$('#reglerFultsok').fadeIn();
		}
	}
	
	$('#topvalg ul li a.tjSpiller').hoverIntent( showSpiller, hideNav);
	
	$('#sitemap-spiller').mouseleave(function(){
		$('#sitemap-spiller').hide();
	});
	
	$('#topvalg ul li a.tjKlubb').hoverIntent(showKlubb, hideNav);
	
	
	$('#sitemap-klubb').mouseleave(function(){
		$('#sitemap-klubb').hide();
	});
	
	$('#sitemap-klubb a.tjSpiller').mouseover(function(){
		$('#sitemap-klubb').hide();
		$('#sitemap-spiller').show();
	});
	$('#sitemap-spiller a.tjKlubb').mouseover(function(){
		$('#sitemap-spiller').hide();
		$('#sitemap-klubb').show();
	});

	$(".openoverlay").click(function(){
		$("#loginoverlay").show();
	});
	$(".closeoverlay").click(function(){
		$("#loginoverlay").hide();
	});
	$('.openlikefb').click(function(){
		$('#ilikefb').show();
	});
	$('#framefb').click(function(){
		$('#ilikefb').hide();
	});
	
$('#scroll').cycle({

  fx: 'custom',

  cssBefore: { top: 90, opacity:0 },

  animIn:  { top: 0, opacity:1 },

  animOut: { top: -90, opacity:0 }

});

$('#checkboxes input').attr('checked', 'checked').click(checking);
	
}

function checking() {
checkboxArray = [];
	//først finne ut hvem som er valgt av checkboksene
	$('#checkboxes input').each(function () {
		if ($(this).attr('checked')){
			checkboxArray.push($(this).val());
		}
	});
	
	//sette vis-klasse på alle som er checked
	for (var i=0;i<=checkboxArray.length;i++) {
		$('.'+checkboxArray[i]).addClass('vis');
	}
	
	$('.contentitemwrap').each(function () {
		if($(this).hasClass('vis')){
			$(this).show('fast');
			$(this).removeClass('vis');
		}else{
			$(this).hide('fast');
		}
	});
		//$('.' + $(this).val()).slideToggle('fast');
}

function showSpiller(){
	$('#sitemap-spiller').show();
}
function showKlubb(){
	$('#sitemap-klubb').show();
}
function hideNav(){
}

$(document).ready(init);
