﻿
function fbs_click() {
    u = location.href;
    t = '...';
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}


var addthis_config = {
    ui_cobrand: "Skånemejerier",
    ui_delay: 200,
    services_compact: "facebook,twitter,email,favorites",
    ui_language: "sv"
    //services_exclude: "print"
}


function toggle_search_text(input, mode, def) {
    if (mode == 'click') {
        if (input.value == def)
            input.value = '';
    }
    if (mode == 'blur') {
        if (input.value == '')
            input.value = def;
    }
}


/*
    directions: top / bottom
*/
var crop_config = {
    direction: 'top'
};

function bg_crop() {
    var img = $("#background-image");
    if (img) {
        var window_width = $(window).width();
        var window_height = $(window).height();
        ratio_window = window_height / window_width;
        ratio_img = bg_img_attr.natural_height / bg_img_attr.natural_width;

        if (ratio_window > ratio_img) {
            new_width = window_height / ratio_img;
            img.css("height", window_height + "px");
            img.css("width", "auto");
            img.css("left", "-" + parseInt((new_width - window_width) / 2) + "px");
            if (crop_config.direction == 'bottom') {
                if (img.height() < bg_img_attr.natural_height) {
                    img.css("top", "-" + parseInt(img.height() - window_height) + "px");
                }
            }
        }
        else {
            img.css("width", "100%");
            img.css("height", "auto");
            img.css("left", "0");
            if (crop_config.direction == 'bottom') {
                if (img.height() < bg_img_attr.natural_height) {
                    img.css("top", "-" + parseInt(img.height() - window_height) + "px");
                }
            }
        }
    }
}

$(document).ready(function() {
    bg_img_attr = {
        natural_width: 1900,
        natural_height: 1150
    };

    $(window).resize(bg_crop);
    bg_crop();
});