﻿function DrawImage(_this) {
    var width = parseInt(_this.attr("_width"));
    var image = new Image();
    image.src = _this.attr("src");

    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= width / width) {
            if (image.width > width) {
                _this.width(width);
                _this.height((image.height * width) / image.width);
            }
            else {
                _this.width(image.width);
                _this.width(image.height);
            }
        }
        else {
            if (image.height > width) {
                _this.width(width);
                _this.width((image.width * width) / image.height);
            } else {
                _this.width(image.width);
                _this.width(image.height);
            }
        }
    }
}

$(document).ready(function() {
    $("#menu li").each(function() {
        $(this).mousemove(function() {
            $(this).parent().find("div").each(function() { $(this).hide() });

            var _liThis = $(this);
            var _this = $(this).find("div");
            _this.show();
            var width = 0;
            var leftValue = 0;
            _this.find("a").each(function() { width += $(this).width() });
            _this.find("span").each(function() { width += $(this).width() + 30 });
            _this.width(_liThis.parent().width());
            _liThis.parent().find("li").each(function() {
                if ($(this).html() == _liThis.html()) {
                    return false;
                }
                leftValue = leftValue + $(this).width();
            });
            if (width > _liThis.parent().width() - leftValue) {
                _this.css("margin-left", "-" + (_liThis.parent().width() - leftValue - 0) + "px");
            }
        });

        $(this).mouseleave(function() {
            $("#menu li:eq(" + menuIndex + ")").mousemove();
        });
    });
    $("#menu li:eq(" + menuIndex + ")").mousemove();

    $("[_width]").each(function() {
        $(this).load(function() {
            DrawImage($(this));
        });
    });
});

/*Ajax Begin*/
function AjaxAPI(requestURL, requestData, successFun, errorFun) {
    $.ajax({
        url: requestURL,
        cache: false,
        type: "POST",
        data: requestData,
        dataType: "json",
        success: function(json) {
            if (json.result != undefined && json.result.state == false) {
                if (errorFun != undefined) {
                    errorFun(json);
                }
            }
            else {
                if (successFun != undefined) {
                    successFun(json);
                }
            }
        }
    });
}
/*Ajax End*/

