﻿$(document).ready(function () {
    //preload mixer panel
    var image = new Image();
    image.src = '/images/mixer/main/panel.png';

    CalcDimensions();

    $('#mixer_container').show('slow');
});

function ToggleMixerPanel() {
    var width = 0, height = 0;
    if ($('#mixer_button').visible()) {
        $('#mixer_button').hide('slow');
        $('#mixer_panel').show('fast');
        width = 282;
        height = 12; /*206*/
    }
    else {
        $('#mixer_button').show('slow');
        $('#mixer_panel').hide('fast');
        width = 47;
        height = 0; /*172*/
    }

    CalcDimensions(width, height);
}

function CloseMixer() {
    $.unblockUI();
    ShowMixerContainerElement('#mixer_button');
}

function CalcDimensions(elementWidth, elementHeight) {    
    var currentElementWidth = 0, currentElementHeight = 0;
    if ($('#mixer_button').visible()) {
        currentElementWidth = 47;
        currentElementHeight = 0; /*172*/
    }
    else if ($('#mixer_panel').visible()) {
        currentElementWidth = 282;
        currentElementHeight = 12; /*206*/
    }
    //currentElementWidth = elementWidth || currentElementWidth;
    currentElementHeight = elementHeight || currentElementHeight;

    //var left = $(window).width() - currentElementWidth;
    var top = $('.menu').offset().top + $('.menu').height() - currentElementHeight;

    $('#mixer_container').css({ 'top': top + 'px' });

    if ($.browser.msie && $.browser.version <= 6) {
        $('#mixer_container').css({ 'top': top + 'px', 'position': 'absolute' });
    }
}

$.fn.visible = function () {
    var display = $(this).css('display');
    return display == 'block' || display != 'none';
};

function LoadMixer(id) {
    HideMixerContainerElement('#mixer_panel');
    $.blockUI({ message: '<h2>Секундочку...</h2>' });
    $.get('/home/mixer/' + id, function (data) {
        $.unblockUI();
        var left = ($(window).width() / 2) - (1100/*MIXER WIDTH*// 2)  + 'px';
        $.blockUI({ message: data, css: { cursor: 'default', width: 'auto', top: '1%', left: left, height: '95%', overflow: 'auto'} });
        $('.blockOverlay').click($.unblockUI);
    });
}

function ShowMixerContainerElement(id) {
    $(id).show('slow');
    CalcDimensions(47, 0/*172*/);
}

function HideMixerContainerElement(id) {
    $(id).hide('slow');
}
