﻿var size = 'small';

$('#main').ready(function () {
    //$('#main').css({ opacity: 0, 'z-index': 999 });
});

$('body').ready(function () {
    //$('#main').css({ opacity: 0 });
    //if($.browser.msie) return;
    if ($('body').width() > 1460) {
        $('body').removeClass('small').addClass('large');
        size = 'large';
        return;
    }
});

$(document).ready(function () {
    //if ($.browser.msie) {
    if ($('body').width() > 1460) {
        $('body').removeClass('small').addClass('large');
        size = 'large';
    }
    //}
    $('#lang-bar').css({ visibility: 'visible' });

    var changeImgSize = function () {
        if ($('body').hasClass('large')) {
            $('img.large').each(function () {
                // check if small img already in the DOM
                var smallImg = $(this).parent().children('img.small');
                if (!smallImg.length > 0) { // create the small img node
                    smallImg = $(this).clone(true);
                    smallImg.unbind('load');
                    smallImg.attr('src', $(this).attr('src').replace('_l.', '_s.'));
                    smallImg.id = this.id.replace('_l.', '_s.');
                    smallImg.removeClass('large').addClass('small');
                    smallImg.insertBefore($(this).parent().children('div.popable'));
                }
            });
        } else {
            $('img.small').each(function () {
                // check if large img already in the DOM
                var largeImg = $(this).parent().children('img.large');
                if (!largeImg.length > 0) { // create the small img node
                    largeImg = $(this).clone(true);
                    largeImg.unbind('load');
                    largeImg.attr('src', $(this).attr('src').replace('_s.', '_l.'));
                    largeImg.id = this.id.replace('_s.', '_l.');
                    largeImg.removeClass('small').addClass('large');
                    largeImg.insertBefore($(this).parent().children('div.popable'));
                }
            });
        }

    };

    window.changeSize = function () {
        if ($('body').width() > 1460) {
            changeImgSize();
            $('body').removeClass('small').addClass('large');
        } else {
            changeImgSize();
            $('body').removeClass('large').addClass('small');
        }
    }

    if (size != 'small') {
        $('img.resizable').each(function () {
            $(this).attr('src', $(this).attr('src').replace('_s.', '_l.'));
            $(this).removeClass('small').addClass('large');
        });
    } else {
        $('img.resizable').each(function () {
            $(this).attr('src', $(this).attr('src').replace('_l.', '_s.'));
            $(this).removeClass('large').addClass('small');
        });
    }

    window.changeSize();

    $(window).resize(window.changeSize);
    var date = new Date();
    date.setYear(date.getYear + 1);
    if (!$.cookie('Essence_UserSize'))
        $.cookie("Essence_UserSize", size.substr(0, 1), { expires: date });
    else
        $.cookie("Essence_UserSize", size.substr(0, 1));
});
