﻿var imgDir = "/_repository/_gui/default/";


//common functions

function reset(cntx, selector, imgArr) {
    cntx.each(function() {
        if(imgArr)
            setImg($(selector, $(this)), imgArr[$(this).attr("id")][0]);
        else
            $(selector, $(this)).removeClass("select");
    });

    if (imgArr) {
        cntx.hover(function() {
            setImg($(selector, $(this)), imgArr[$(this).attr("id")][1]);
        },
        function() {
            setImg($(selector, $(this)), imgArr[$(this).attr("id")][0]);
        }
        );
    }
}

function select(cntx, selector, imgArr) {

    cntx.each(function() {
        if (imgArr) {
            cntx.each(function() {
                setImg($(selector, $(this)), imgArr[$(this).attr("id")][1]);
            });

            cntx.hover(function() {
                setImg($(selector, $(this)), imgArr[$(this).attr("id")][1]);
            },
            function() {
                setImg($(selector, $(this)), imgArr[$(this).attr("id")][1]);
            });
        }
        else
            $(selector, $(this)).addClass("select");
    });

}

function setOver(img, src, over) {
    img.hover(function() {
        setImg(img, over);
    },
    function() {
        setImg(img, src);
    }
    );
    
}

function setImg(img, src) {
    //imgDir set in codebehind
    img.attr("src", imgDir + src);
}

function preloadImg(imgArr) {

    for (property in imgArr) {
        var img0 = new Image();
        img0.src = imgDir + imgArr[property][0];
        var img1 = new Image();
        img1.src = imgDir + imgArr[property][1];
    }
}

/* RESIZE */
function onLoadBG() {
    if ($("div#wrap-outer").height() != null) {
        if (($(window).height() < $(document).height())) {
            if (($(document).height() > $("div#wrap-outer").height())) {
                $("body").height($(window).height());
            }
            else {
                $("body").height($(document).height());
            }
        } else {
            $("body").height($(window).height());
        }
    }
}

function onResizeBG() {
    if ($("div#wrap-outer").height() != null) {
        if (!($(window).height() < $(document).height())) {
            if (($(document).height() > $("div#wrap-outer").height())) {
                $("body").height($(window).height());
            }
            else {
                $("body").height($(document).height());
            }
        }
    }
}

$(window).load(function() {
    onLoadBG();
});


$(window).resize(function() {
    onResizeBG();
});

/* END RESIZE */
