﻿var settings = { gap: 16, width: 260, easing: 'easeInOutQuart', duration: 500, speed: 1 };

//var base = "http://letskiosk.com/";
$(document).ready(function () {
    //    if (location.href == base) {
    /*        tn = true;
    var hash = "just-b-productions";
    oldhit = "#c-" + hash;
    pressed = hash;
    tempclass = $(oldhit).attr('class');
    pageload(pressed, tn);*/
    //$("#boxes").grid(settings);
    //    }
    //resizeTimer = setTimeout(function () {
    //  $("#boxes").grid(settings, '', false, true);
    //}, 100);

    if ($('.background').attr('src') == '') {
        $('.background').hide();
    }

});


$(function () {

    $('#area_left').hide();
    $('#area_right').hide();

    /*$('#topMask, #topWrapper').css('width', '1000px');
    $('#topMask, #topWrapper').css('height', '150px');*/


    // on window resize, call again
    var resizeTimer = null;
    $(window).bind('resize', function () {


        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function () {
            if ($('#boxes > div').length > 0) {
                $('#boxes').grid(settings, '', false, true);
            }
            $('#debug span').html($(window).width());
            setContactInfoMargin();
        }, 100);

    });
    if ($('#boxes > div').length > 0) {
        $('#boxes').grid(settings);
        setContactInfoMargin();
    }
    /*
    $('#link_clients').click(function () {
    $('#boxes').fadeOut(500, function () {
    $('#boxes > div').empty();

    jQuery.get("/base/orangeriet/GetClients.aspx", function (data) {
    $('#boxes').html(data);
    $('#boxes').fadeIn(500);
    $('#boxes').grid(settings);
    setContactInfoMargin();
    });

    });
    //return false;
    });

    $('#link_projects').click(function () {
    $('#boxes').fadeOut(500, function () {
    $('#boxes > div').empty();

    jQuery.get("/base/orangeriet/GetProjects.aspx", function (data) {
    $('#boxes').html(data);
    $('#boxes').fadeIn(500);
    $('#boxes').grid(settings);
    setContactInfoMargin();
    });
    });
    //return false;
    });*/
    setContactInfoMargin();
    //window.location.hash = "#sdfsdf";
});

function setContactInfoMargin() {
    var _marginLeft = 0;
    if ($(window).width() < 1136) {
        _marginLeft = 0;
    } else if ($(window).width() < 1412) {
        _marginLeft = 276;
    } else if ($(window).width() < 1688) {
        _marginLeft = 552;
    } else if ($(window).width() < 1964) {
        _marginLeft = 828;
    } else {
        _marginLeft = 1104;
    }

    // Hvis det er få bokser, må kontaktinfo plasseres deretter.
    if (getTotalWidthOfBoxes() < 4) {
        _marginLeft = 0;
    } else if (getTotalWidthOfBoxes() < 5) {
        _marginLeft = 276;
    } else if (getTotalWidthOfBoxes() < 6) {
        _marginLeft = 552;
    } else if (getTotalWidthOfBoxes() < 7) {
        _marginLeft = 828;
    } else if (getTotalWidthOfBoxes() < 8) {
        _marginLeft = 1104;
    }
    _marginLeft2 = _marginLeft + 552 + 32;
    _marginLeft2 = _marginLeft2 + "px";

    //alert($("#contactInfo").css('marginLeft'));
    //alert($("#contactInfo").css('marginLeft') + " " + _marginLeft + "px");
    if ($("#contactInfo").css('marginLeft') != _marginLeft2) {

        $("#contactInfo").animate({ marginLeft: _marginLeft2 }, 500, 'swing');
    }

}

function getTotalWidthOfBoxes() {
    var size = 0;
    $('#boxes > div').each(function (key, value) {
        if ($(value).hasClass('postwide')) {
            size += 2;
        } else if ($(value).hasClass('post')) {
            size += 1;
        }
    });
    return size;
}

(function ($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)


// append hashtag to fb share button

$(function () {
    var hash = window.location.hash;
    if (hash !== undefined && hash !== '') {
        var src = $('ul#share a.fbShare').attr("href");
        if (src !== undefined && src !== '') {
            $('ul#share a.fbShare').attr("href", src + hash);
        }
    }
});
