﻿function SelectTopTab(object) {
    $(document).ready(function () {
        $(object).attr("className", "Selected");
    });
}

function SetAutoScrollable(ScrollObject) {
    $(document).ready(function () {
        $(ScrollObject).scrollable({ loop: true, size: 1 }).autoscroll({ autoplay: true });
    });
}

function SetSameHeight(object1, object2) {
    var obj1 = $(object1);
    var obj2 = $(object2);

    if (obj1.height() >= obj2.height()) {
        obj2.height(obj1.height());
    }
    else {
        obj1.height(obj2.height());
    }
}

function SetSameHeightDefault(object1) {
    var obj1 = $(object1);
    obj1.height($("#ContentColumn").height() - 6);
}

function GetUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function UrlDecode(url) {
    var o = url;
    var binVal, t, b;
    var r = /(%[^%]{2}|\+)/;
    while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
        if (m[1] == '+') {
            t = ' ';
        } else {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b);
        }
        o = o.replace(m[1], t);
    }
    return o;
}

function CenterPosition(ObjectClass) {
    $(ObjectClass).css('position', 'absolute');
    $(ObjectClass).css('top', (($(window).height() - $(ObjectClass).height()) / 2) + 'px');
    $(ObjectClass).css('left', ($(window).width() - $(ObjectClass).width()) / 2 + 'px');

    $(window).resize(function () {
        $(ObjectClass).css('position', 'absolute');
        $(ObjectClass).css('top', (($(window).height() - $(ObjectClass).height()) / 2) + 'px');
        $(ObjectClass).css('left', ($(window).width() - $(ObjectClass).width()) / 2 + 'px');
    });
}

function SetSubMenu(Parent, Child) {
    $(document).ready(function () {
        $(Child).css('display', 'none');
        $(Parent).hover(function () {
            $(Child).css('display', 'block');
            $(Child).css('top', $(Parent).position().top + $(Parent).height() + "px");
            $(Child).css('left', $(Parent).position().left - ($(Child).width() - 13 - $(Parent).width()) + "px");
        },
        function () {
            $(Child).css('display', 'none');
        });
    });
}

function LoadFlash(Area, Path, Height, Width) {
    $(Area).flash({ src: Path, height: Height, width: Width });
}

function setScrollable(object) {
    var Previous = $(object).children('.Previous');
    var Next = $(object).children('.Next');
    var Window = $(object).children('.Window');
    var Items = $(object).find('.Items');

    var FirstChild = $(Items).children(':first');
    var LastChild = $(Items).children(':last');

    Previous.click(function () {
        var Left = Items.position().left + Window.width();
        if (Items.position().left < 0)
            Items.animate({ 'left': (Left + 'px') }, 'slow');
        else
            Items.animate({ 'left': (0 + 'px') }, 'slow');
    });

    Next.click(function () {
        var Left = Items.position().left - Window.width();
        var LastChildPos = LastChild.position().left;
        if (Left > parseInt('-' + LastChildPos))
            Items.animate({ 'left': (Left + 'px') }, 'slow');
        else
            Items.animate({ 'left': (0 + 'px') }, 'slow');
    });
}

function setMarquee(object) {
    $(document).ready(function () {
        var Wrapper = $(object);
        var List = Wrapper.children('ul');
        var ListTop = List.position().top;
        Wrapper.css('position', 'relative');
        List.css('position', 'absolute');
        List.width = Wrapper.width;
        List.css('left', '0px');

        var Run = true;

        List.hover(function () { Run = false; }, function () { Run = true; })

        setInterval(function () {
            ListTop = ListTop - Wrapper.height();
            if (Run) {
                if (ListTop >= parseInt('-' + List.height() - 100)) {
                    List.animate({ 'top': (ListTop + 'px') }, 'slow');
                }
                else {
                    ListTop = 0;
                    List.animate({ 'top': (ListTop + 'px') }, 'slow');
                }
            }
        }, 5000);

    });
}

//Page Init
window.onload = function () {
    $(document).ready(function () {
        SetSameHeight(".ShadowContent700", ".ShadowContent300");
        $(".ShadowContent700").resize(function () { SetSameHeight(".ShadowContent700", ".ShadowContent300"); });

        $(".Search .Input").click(function () {
            this.value = "";
        });

        CenterPosition(".OrderOption");

        SetSameHeightDefault(".LeftColumn .ShadowContent250");
    });
}


