﻿/* Author: 
Meed AB - David Gustafsson
*/

ALL.Utils = {
    init: function () {

        $('#slider').galleryView({
            panel_width: 785,
            panel_height: 490,
            frame_width: 130,
            frame_height: 80,
            filmstrip_size: 5,
            frame_gap: 10,
            show_overlays: true,
            transition_interval: 10000,
            //frame_scale: 'nocrop',
            panel_scale: 'nocrop',
            pointer_size: 0,
            easing: 'swing'
        });

        ALL.Utils.AddCufonFonts();
        ALL.Utils.FixPlaceHolders();
        ALL.Utils.AddValidation();

        if ($('#job-list, #news-list, #company-list').length) {
            $('#job-list, #news-list, #company-list').delegate('li', 'hover', function () {
                $(this).toggleClass('hover');
            });
            $('#job-list li, #news-list li, #company-list li').click(function () {
                $(location).attr('href', $(this).children('a').attr('href'));
            });
        }

        $('.puff, #post-it').click(function () {
            $(location).attr('href', $(this).children('a').attr('href'));
        });

        $('.puff, .puff-wide').mouseover(function () {
            $(this).addClass('hover');
        }).mouseout(function () {
            $(this).removeClass('hover');
        });

        $('#main').delegate('#post-it', 'hover', function () {
            $(this).toggleClass('hover');
        });
    },
    AddCufonFonts: function () {
        Cufon.replace('#post-it .heading', { fontFamily: 'agbook' });
        Cufon.replace('.teaser-read-more .intro-text', { fontFamily: 'agbook' });
        Cufon.replace('h1', { fontFamily: 'agbook' });
        Cufon.replace('h2', { fontFamily: 'agbook' });
        Cufon.replace('h3', { fontFamily: 'agbook' });
        Cufon.replace('.heading', { fontFamily: 'agbook' });
        Cufon.replace('.intro', { fontFamily: 'agbook' });
        Cufon.replace('.top-heading', { fontFamily: 'agbook' });
        Cufon.replace('.top-note', { fontFamily: 'handsean' });
        Cufon.replace('.note-text', { fontFamily: 'handsean' });
        Cufon.replace('#main .intro-text .heading', { fontFamily: 'agbook' });
        Cufon.replace('.small-button', { fontFamily: 'agbook' });
    },
    FixPlaceHolders: function () {
        $("input.name").placeHolder({
            "text": "DITT NAMN"
        });
        $("textarea.text").placeHolder({
            "text": "SKRIV DITT ÄRENDE HÄR"
        });
        $("input.phone").placeHolder({
            "text": "DITT TELEFONNUMMER"
        });
        $("input.email").placeHolder({
            "text": "DIN EPOST-ADRESS"
        });
    },
    AddValidation: function () {
        $("#mainForm").validate({
            rules: {
                mail: {
                    required: true,
                    email: true
                },
                text: {
                    required: true
                }
            },
            messages: {
                mail: {
                    required: "Du måste fylla i en mejladress",
                    email: "Du måste fylla i en korrekt mejladress"
                },
                text: "Du måste fylla i ett meddelande"
            },
            invalidHandler: function (form, validator) {
                var message = 'Formuläret är inte korrekt ifyllt';
                ALL.Flash.message(message, false, true);
            }
        });
    }
}

ALL.Flash = {
    timer: 0,
    timeout: 8000,
    message: function (text, success, autoHide) {
        var flashDiv = jQuery('#flash-notice').hide();
        clearTimeout(ALL.Flash.timer);
        var statusClass = ALL.Flash.getStatus(success);
        flashDiv.find('div.feedback').removeClass().addClass(statusClass).addClass('feedback');
        flashDiv.find('div.content').html(text).end().show();
        if (autoHide) {
            ALL.Flash.timer = setTimeout(function () {
                ALL.Flash.hide();
            }, ALL.Flash.timeout);
        }
    },
    hide: function () {
        var flashDiv = jQuery('div#flash-notice').fadeOut('slow');
    },
    getStatus: function (success) {
        return (success) ? 'success' : 'error';
    }
};

ALL.Ajax = {
    onComplete: function (content) {
        var json = content.get_response().get_object();
        if (json !== null) {
            if (json.status == "error") {
                ALL.Flash.message("Ops, nu blev det fel!", false, true);
            } else {
                ALL.Flash.message("Meddelande skickat!", true, true);
            }
        }
    },
    onBegin: function () {
        ALL.Flash.message('<img src="/Content/images/ajax-loader-trans.gif" alt="" />', true, false);
        return $('#mainForm').validate().form();
    }
};

ALL.init = function () {
    ALL.Utils.init();
};

jQuery(document).ready(function () {
    ALL.init();
});
















