var fluid = {
Ajax : function(){
	$("#loading").hide();
	var content = $("#ajax-content").hide();
	$("#toggle-ajax").bind("click", function(e) {
        if ( $(this).is(".hidden") ) {
            $("#ajax-content").empty();

            $("#loading").show();
            $("#ajax-content").load("/fluid960gs/data/ajax-response.html", function() {
            	$("#loading").hide();
            	content.slideDown();
            });
        }
        else {
            content.slideUp();
        }
        if ($(this).hasClass('hidden')){
            $(this).removeClass('hidden').addClass('visible');
        }
        else {
            $(this).removeClass('visible').addClass('hidden');
        }
        e.preventDefault();
    });
},
Toggle : function(){
	var default_hide = {"download": false };
	$.each(
		["download", "grid", "paragraphs", "blockquote", "list-items", "section-menu", "tables", "forms", "login-forms", "search", "articles", "accordion"],
		function() {
			var el = $("#" + (this == 'accordon' ? 'accordion-block' : this) );
			if (default_hide[this]) {
				$("[id='toggle-"+this+"']").addClass("hidden");
				el.slideUp(2000);
			}
			$("[id='toggle-"+this+"']")
			.bind("click", function(e) {
				if ($(this).hasClass('hidden')){
					$(this).removeClass('hidden').addClass('visible');
					el.slideDown();
				} else {
					$(this).removeClass('visible').addClass('hidden');
					el.slideUp();
				}
				e.preventDefault();
			});
		}
	);
	var default_show_news = {"news11": true };
	$.each(
		["news1", "news2", "news3", "news4", "news5", "news6", "news7", "news8", "news9", "news10", "news11", "news12", "news13", "news14", "news15"],
		function() {
			var part1 = $("#" + this + "-part1");
			var part2 = $("#" + this + "-part2");
			if (default_show_news[this]) {
				part1.hide();
			}
			else {
				part2.hide();
				$("[id='toggle-"+this+"']").addClass("hidden");
			}
			$("[id='toggle-" + this + "']")
			.bind("click", function(e) {
				if ($(this).hasClass('hidden')){
					$(this).removeClass('hidden').addClass('visible');
					part1.slideUp();
					part2.slideDown();
				} else {
					$(this).removeClass('visible').addClass('hidden');
					part1.slideDown();
					part2.slideUp();
				}
				e.preventDefault();
			});
		}
	);
},
/*Kwicks : function(){
	var animating = false;
    $("#kwick .kwick")
        .bind("mouseenter", function(e) {
            if (animating) return false;
            animating == true;
            $("#kwick .kwick").not(this).animate({ "width": 125 }, 200);
            $(this).animate({ "width": 485 }, 200, function() {
                animating = false;
            });
        });
    $("#kwick").bind("mouseleave", function(e) {
        $(".kwick", this).animate({ "width": 215 }, 200);
    });
},*/
Kwicks : function(){
	/* Total kwick w780xh520. Init each kwick width: 175 + 20 margin left+right*/
	/* Start (incl 20 px margin): Nyheder width: 384, rest width 132*/
	/* Roll over: Selected width: 408, rest width: 124*/
	$(".kwick.one").animate({ "width": 364 }, 800);
	$(".kwick.two").animate({ "width": 112 }, 250);
	$(".kwick.three").animate({ "width": 112 }, 250);
	$(".kwick.four").animate({ "width": 112 }, 250);
	var animating = false;
    $("#kwick .kwick")
        .bind("mouseenter", function(e) {
            if (animating) return false;
            animating == true;
            $("#kwick .kwick").not(this).animate({ "width": 100 }, 100);
            $(this).animate({ "width": 388 }, 100, function() {
                animating = false;
            });
        });
    $("#kwick").bind("mouseleave", function(e) {
        $(".one", this).animate({ "width": 364 }, 400);
        $(".two", this).animate({ "width": 112 }, 400);
        $(".three", this).animate({ "width": 112 }, 400);
        $(".four", this).animate({ "width": 112 }, 500);
    });
},
SectionMenu : function(){
	$("#section-menu")
        .accordion({
            "header": "a.menuitem"
        })
        .bind("accordionchangestart", function(e, data) {
            data.newHeader.next().andSelf().addClass("current");
            data.oldHeader.next().andSelf().removeClass("current");
        })
        .find("a.menuitem:first").addClass("current")
        .next().addClass("current");
},
Accordion: function(){
	$("#accordion").accordion({
        'header': "h3.atStart"
    }).bind("accordionchangestart", function(e, data) {
        data.newHeader.css({
            "font-weight": "bold",
            "background": "#fff"
        });

        data.oldHeader.css({
            "font-weight": "normal",
            "background": "#eee"
        });
    }).find("h3.atStart:first").css({
        "font-weight": "bold",
        "background": "#fff"
    });
},
Breadcrumbs: function(){
    $("#breadcrumbs li a")
        .bind("mouseenter", function(e) {
			if ($(this).hasClass('breadcrumb-bkg')){
				$(this).removeClass("breadcrumb-bkg").addClass("breadcrumb-bkg-hover");
				$(this).parent().prev().find(".breadcrumb-bkg").removeClass("breadcrumb-bkg").addClass("breadcrumb-bkg-hover-prev");
			}
			if ($(this).hasClass('breadcrumb-bkg-last')){
				$(this).removeClass("breadcrumb-bkg-last").addClass("breadcrumb-bkg-hover-last");
				$(this).parent().prev().find(".breadcrumb-bkg").removeClass("breadcrumb-bkg").addClass("breadcrumb-bkg-hover-prev");
			}
        });
    $("#breadcrumbs li a")
        .bind("mouseleave", function(e) {
			if ($(this).hasClass('breadcrumb-bkg-hover')){
				$(this).removeClass("breadcrumb-bkg-hover").addClass("breadcrumb-bkg");
				$(this).parent().prev().find(".breadcrumb-bkg-hover-prev").removeClass("breadcrumb-bkg-hover-prev").addClass("breadcrumb-bkg");
			}
			if ($(this).hasClass('breadcrumb-bkg-hover-last')){
				$(this).removeClass("breadcrumb-bkg-hover-last").addClass("breadcrumb-bkg-last");
				$(this).parent().prev().find(".breadcrumb-bkg-hover-prev").removeClass("breadcrumb-bkg-hover-prev").addClass("breadcrumb-bkg");
			}
        });
}
}
jQuery(function ($) {
	if($("#accordion").length){fluid.Accordion();}
	if($("[id$='ajax']").length){fluid.Ajax();}
	if($("[id^='toggle']").length){fluid.Toggle();}
	if($("#kwick .kwick").length){fluid.Kwicks();}
	if($("#section-menu").length){fluid.SectionMenu();}
	if($("#breadcrumbs").length){fluid.Breadcrumbs();}
});
