$(document).ready(function() {
	$("#menu1").change(function() {
		if($("#menu1").val() != '') {
			$("#form1").submit();
		}
	});

	$("#menu2").change(function() {
//		if($("#menu2").val() != '') {
			$("#form2").submit();
//		}
	});

	$("#menu3").change(function() {
		$("#form3").submit();
	});

	$("#form1 > input:submit").hide();
	$("#form2 > input:submit").hide();
	$("#form3 > input:submit").hide();

	$(".karusell").jCarouselLite({
		btnPrev: ".arrow_left",
		btnNext: ".arrow_right",
		scroll: 3
	});

	$(".button_search").click(function() {
		doSearch($(this).parent().children(".input").val());
	});

	$(".search .input").keypress(function(e) {
		if(e.keyCode == 13) {
			doSearch($(this).val());
		}
	});

	$(".search .input").focus(function() {
		if($(this).val() == "Søk oppskrifter") $(this).val("");
	});

	$(".set h6 a").click(function() {
		$(this).parents(".set").find("h6 a").removeClass("selected");
		$(this).addClass("selected");
		ul = $(this).parent().siblings("ul").attr("id");
		otherul = $(this).closest("div").siblings("div").children("ul").attr("id");
		$("#" + ul + " > li").tsort();
		$("#" + otherul + " > li").tsort({attr: "title"});
		return false;
	});

});

$(".imagelistcontainer").live("mouseover", function(e) {
	$(".desc", this).show();
});

$(".imagelistcontainer").live("mouseout", function(e) {
	$(".desc", this).hide();
});

$(".desc").live("mouseover", function(e) {
	$(this).hide();
});

function doSearch(term) {
	location.href = "/oppskrifter/oppskriftssok?search=" + term;
	return false;
}
