﻿$(document).ready(function () {

    $("A.Fancybox").fancybox({
        'width': '80%',
        'height': '95%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });


    $("FORM").validate({
        messages: {
            Namn: "Ange namn",
            Epost: {
                required: "Ange e-postadress",
                email: "Giltigt format är namn@domän.se"
            }
        },
        submitHandler: function (form) {
            var options = {
                resetForm: true,
                beforeSubmit: function () {
                    var overlay = jQuery("<div id=\"FormOverlay\"><h2>Skickar formulär</h2></div>");
                    overlay.appendTo(document.body);
                },
                success: function () {
                    $("#FormOverlay").remove();
                    var status = jQuery("<div id=\"FormStatus\"><h2>Ditt meddelande har skickats. Vi kommer kontakta dig inom kort.</h2></div>");
                    status.appendTo(document.body);
                    $("HTML, BODY").animate({ scrollTop: 0 }, 500);
                    setTimeout("$('#FormStatus').slideUp('slow', function() { $('#FormStatus').remove() })", 3000);
                }
            };
            $(form).ajaxSubmit(options);
        }
    })

    $(".StyleSelect").selectmenu({
        style: 'dropdown',
        width: 175,
        menuWidth: 173
    });
    $(".StyleSelectContact").selectmenu({
        style: 'dropdown',
        width: 242,
        menuWidth: 240
    });

    $("#PlaceholderFaq > h2")
            .each(function () {
                $(this).attr("class", "Plus");
            })
            .click(function () {
                if ($(this).attr("class") == "Minus")
                    $(this).attr("class", "Plus");
                else
                    $(this).attr("class", "Minus");
                $(this).nextUntil("h2").toggle(100);
                return false;
            }).nextUntil("h2").hide();
});

// Cufon Replace
Cufon.replace("h1");
Cufon.replace("h2");

function keypressed(e) {
    var key = e.charCode || e.keyCode || e.which || 0;
    if (key == 13) {
        search();
        return false;
    }
    else
        return true;
}

function search() {
    var keyword = escape($("#q").val());
    if ($("#SearchChoices option:selected").val() == "webbutik")
        document.location = "http://webshop.leifarvidsson.se/SE/Catalog/search.html?searchtext=" + keyword + "&search=S%F6k";
    else 
        document.location = "http://www.leifarvidsson.se/Sok/?q=" + document.getElementById("q").value;

    return false;
}


