// add wrapping iframe - ie only
function add_iframe(elm)
{
        if ($.browser.msie && $.browser.version <= 6 && $(".pre_ie_iframe", elm).length == 0)
        {
                var elm_w = elm.width();
                var elm_h = elm.height();
                var elm_z = (elm.css("z-index") != 0)? elm.css("z-index") - 1: 0;
                elm.wrapInner('<div class="pre_ie_iframe"></div>');
                $(".pre_ie_iframe", elm).css({height: elm_h, left: 0, position: "absolute", top: 0, width: elm_w, zIndex: elm_z + 1});
                $("").attr({className: "ie_iframe"}).css({border: 0, height: elm_h, left: 0, opacity: 0, position: "absolute", top: 0, width: elm_w, zIndex: elm_z}).appendTo(elm);
                $(elm).bind("resize", function()
                        {
                                var elm_w = elm.width();
                                var elm_h = elm.height();
                                $(".pre_ie_iframe", elm).css({height: elm_h, width: elm_w});
                                $(".ie_iframe", elm).css({height: elm_h, width: elm_w});
                        }
                );
        }
        return;
}
// blck_b - only for ie6
function correct_blck_b()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var h = $(".blck_b").height();
                $(".blck_b .b_m").css({top: h});
        }
        return;
}
// blck_m - only for ie6
function correct_blck_m()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                $(".blck_m .b").css({bottom: -10});
        }
        return;
}
// setting left, right column height #ww_info - only for ie6
function correct_btns_w()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var w = $(".years").width();
                $(".years .t, .years .b").width(w);
        }
        return;
}
// setting footer to bottom - only for ie6
function correct_footer_pos()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var doc_h = $(body).height();
                var f_h = $("#footer").height();
                $("#footer").css({top: doc_h - f_h});
        }
        return;
}
// setting des light to bottom - only for ie6
function correct_lights_pos()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var doc_h = $(body).height();
                var h1 = $("#des_light_1").height();
                var h2 = $("#des_light_3").height();
                $("#des_light_1").css({top: doc_h - h1});
                $("#des_light_3").css({top: doc_h - h2});
        }
        return;
}
// correct menu top last item
function correct_m_top_last()
{
        var w = $("#m_top .menu").width();
        lis_w = 0;
        $("#m_top .menu > li").each(function()
                {
                        lis_w += $(this).width();
                }
        );
        var correct = w - lis_w - 3;
        var last = $("#m_top .menu > li:last");
        last.width(last.width() + correct);
        return;
}
// setting left, right column height #ww_colors - only for ie6
function correct_ww_colors()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var h = $("#ww_colors").height();
                $("#ww_colors .lm, #ww_colors .rm").height(h + 10);
        }
        return;
}
// setting left, right column height #ww_info - only for ie6
function correct_ww_info()
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var h = $("#ww_info").height();
                $("#ww_info .lm, #ww_info .rm").height(h);
        }
        return;
}
// setting background layer height
function set_bg_height(bg, parent)
{
        if ($.browser.msie && $.browser.version <= 6)
        {
                var h = parent.height();
                bg.height(h);
        }
        return;
}
// center teasers by setting width
function center_teasers()
{
        teasers_w = 0;
        var lis = $("#footer .teasers .list li").length;
        var correct = (lis > 1) ? -50 : 0;
        $("#footer .teasers .list li").each(function()
                {
                        teasers_w += $(this).width() + 50;
                }
        );
        $("#footer .teasers .list").width(teasers_w + correct);
        return;
}
// center mini blocks by setting width
function center_mini()
{
        mini_w = 0;
        $(".mini").each(function()
                {
                        mini_w = 0;
                        //var lis = $(".li", $(this)).length;
                        //var correct = (lis > 1) ? -22 : 0;
                        var correct = 0;
                        $(".li", $(this)).each(function()
                                {
                                        mini_w += $(this).width() + 22;
                                }
                        );
                        $(this).width(mini_w + correct);
                }
        );
        return;
}
// colors images roller
function display_h_roller()
{
        $('#product .product .colors .images').css({overflow: "hidden"});
        var total_elms = $('#product .product .colors .images .list li').length;
        var cont_width = $('#product .product .colors').width();
        var elm_w = 134 + 20;
        var gal_width = total_elms * elm_w - 20;
        var elms_w = Math.floor(cont_width / elm_w) * elm_w;
        var cus_scroll = $("#product .product .colors .scroll").width();
        var scroll_coef = 1;
        $("#product .product .colors .images").scrollLeft(0);
        $("#product .product .colors .scroll .bar").css({left: 0});
        if (cont_width - elms_w > 20 && cont_width - elms_w < 134)
        {
                $('#product .product .colors .images').width(elms_w - 20);
                $("#product .product .colors .scroll").width(elms_w - 20);
                cont_width = elms_w - 20;
                cus_scroll = elms_w - 20;
        }
        else if (cont_width - elms_w >= 134)
        {
                elms_w = Math.ceil(cont_width / elm_w) * elm_w;
                $('#product .product .colors .images').width(elms_w - 20);
                $("#product .product .colors .scroll").width(elms_w - 20);
                cont_width = elms_w - 20;
                cus_scroll = elms_w - 20;
        }
        $('#product .product .colors .images .list').css({width: gal_width});
        // slider
        var scoll_val = elm_w;
        var show_elms = Math.floor(elms_w / elm_w);
        $("#product .product .colors .nav_prev a").bind("click", function(e)
                {
                        e.preventDefault();
                        cont_width = $('#product .product .colors .images').width();
                        cus_scroll = $("#product .product .colors .scroll").width();
                        scroll_coef = 1 / ((gal_width - cont_width) / cus_scroll + ((gal_width - cont_width) * .025 / cus_scroll));
                        var cur_scr = cont_width + 20 + $('#product .product .colors .images').scrollLeft();
                        var show = (Math.floor(cur_scr / elm_w) - (cur_scr / elm_w) == 0) ? Math.floor(cur_scr / elm_w) - 1 : Math.floor(cur_scr / elm_w);
                        var scroll_val = show * elm_w - cont_width - 20;
                        $('#product .product .colors .images').animate({scrollLeft: scroll_val}, 300);
                        if (scroll_val >= 0)
                        {
                                var sc_left = (scroll_val * scroll_coef + 18 <= cont_width) ? scroll_val * scroll_coef : cont_width - 18;
                                $("#product .product .colors .scroll .bar").animate({left: sc_left}, 300);
                        }
                }
        );
        $("#product .product .colors .nav_next a").bind("click", function(e)
                {
                        e.preventDefault();
                        cont_width = $('#product .product .colors .images').width();
                        cus_scroll = $("#product .product .colors .scroll").width();
                        scroll_coef = 1 / ((gal_width - cont_width) / cus_scroll + ((gal_width - cont_width) * .025 / cus_scroll));
                        var cur_scr = cont_width + 20 + $('#product .product .colors .images').scrollLeft();
                        var show = (Math.ceil(cur_scr / elm_w) - (cur_scr / elm_w) == 0) ? Math.ceil(cur_scr / elm_w) + 1 : Math.ceil(cur_scr / elm_w);
                        var scroll_val = show * elm_w - cont_width - 20;
                        $('#product .product .colors .images').animate({scrollLeft: scroll_val}, 300);
                        if (scroll_val <= gal_width - cont_width)
                        {
                                var sc_left = (scroll_val * scroll_coef + 18 <= cont_width) ? scroll_val * scroll_coef : cont_width - 18;
                                $("#product .product .colors .scroll .bar").animate({left: sc_left}, 300);
                        }
                }
        );
        // scroll
        if ($("#product .product .colors .scroll .bar").length == 1 && gal_width - cont_width > 0)
        {
                var gap = ($('#product .product .colors').width() - $('#product .product .colors .images').width()) / 2;
                $("#product .product .colors .scroll").show();
                $("#product .product .colors .scroll .bar img").ifixpng();
                $("#product .product .colors .nav_prev").css({left: gap - 20}).show();
                $("#product .product .colors .nav_prev img").ifixpng();
                $("#product .product .colors .nav_next").css({right: gap - 20}).show().ifixpng();
                $("#product .product .colors .nav_next img").ifixpng();
        }
        else
        {
                $("#product .product .colors .scroll").hide();
                $("#product .product .colors .scroll li").width("100%");
                $("#product .product .colors .nav_prev").hide();
                $("#product .product .colors .nav_next").hide();
        }
        $("#product .product .colors .scroll .bar").draggable({axis: 'x', containment: '#product .product .colors .scroll', snap: '#product .product .colors .scroll', snapMode: 'inner'});
        $("#product .product .colors .scroll .bar").bind("drag", function(e, ui)
                {
                        cont_width = $('#product .product .colors .images').width();
                        cus_scroll = $("#product .product .colors .scroll").width();
                        scroll_coef = (gal_width - cont_width) / cus_scroll + ((gal_width - cont_width) * .025 / cus_scroll);
                        $("#product .product .colors .images").scrollLeft(Math.ceil(ui.position.left * scroll_coef));
                }
        );
        return;
}
// popup roller
function display_h_roller_2()
{
        $('#ww_colors .colors .images').css({overflow: "hidden"});
        var total_elms = $('#ww_colors .colors .images .list li').length;
        var cont_width = $('#ww_colors .colors').width();
        var elm_w = 95 + 13;
        var gal_width = total_elms * elm_w - 13;
        var cus_scroll = $("#ww_colors .colors .scroll").width();
        var scroll_coef2 = 1;
        $("#ww_colors .colors .images").scrollLeft(0);
        $("#ww_colors .colors .scroll .bar").css({left: 0});

        $('#ww_colors .colors .images .list').css({width: gal_width});
        // scroll
        if ($("#ww_colors .colors .scroll .bar").length == 1 && gal_width - cont_width > 0)
        {
                $("#ww_colors .colors .scroll").show();
                if ($.browser.msie && /6.0/.test(navigator.userAgent))
                {
                        $("#ww_colors .colors .scroll .bar img").attr({src: "/images/dot.gif"});
                        $("#ww_colors .colors .scroll .bar img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='/images/des_dot_20x21.png')"});
                        $("#ww_colors .submit button img").attr({src: "/images/dot.gif"});
                        $("#ww_colors .submit button img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='/images/icon_rarr_11x16.png')"});
                }
                //$("#ww_colors .colors .scroll .bar img").ifixpng();
        }
        else
        {
                $("#ww_colors .colors .scroll").hide();
                $("#ww_colors .colors .scroll li").width("100%");
        }
        $("#ww_colors .colors .scroll .bar").draggable({axis: 'x', containment: '#ww_colors .colors .scroll', snap: '#ww_colors .colors .scroll', snapMode: 'inner'});
        $("#ww_colors .colors .scroll .bar").bind("drag", function(e, ui)
                {
                        cont_width = $('#ww_colors .colors .images').width();
                        cus_scroll = $("#ww_colors .colors .scroll").width();
                        scroll_coef2 = (gal_width - cont_width) / cus_scroll + ((gal_width - cont_width) * .025 / cus_scroll);
                        $("#ww_colors .colors .images").scrollLeft(Math.ceil(ui.position.left * scroll_coef2));
                }
        );
        return;
}
function display_h_roller_3(id)
{
        $('.ww_colors_' + id + ' .colors .images').css({overflow: "hidden"});
        var total_elms = $('.ww_colors_' + id + ' .colors .images .list li').length;
        var cont_width = $('.ww_colors_' + id + ' .colors').width();
        var elm_w = 95 + 13;
        var gal_width = total_elms * elm_w - 13;
        var cus_scroll = $(".ww_colors_" + id + " .colors .scroll").width();
        var scroll_coef2 = 1;
        $(".ww_colors_" + id + " .colors .images").scrollLeft(0);
        $(".ww_colors_" + id + " .colors .scroll .bar").css({left: 0});

        $('.ww_colors_' + id + ' .colors .images .list').css({width: gal_width});
        // scroll
        if ($(".ww_colors_" + id + " .colors .scroll .bar").length == 1 && gal_width - cont_width > 0)
        {
                $(".ww_colors_" + id + " .colors .scroll").show();
                if ($.browser.msie && /6.0/.test(navigator.userAgent))
                {
                        $(".ww_colors_" + id + " .colors .scroll .bar img").attr({src: "/images/dot.gif"});
                        $(".ww_colors_" + id + " .colors .scroll .bar img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='/images/des_dot_20x21.png')"});
                        $(".ww_colors_" + id + " .submit button img").attr({src: "/images/dot.gif"});
                        $(".ww_colors_" + id + " .submit button img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='/images/icon_rarr_11x16.png')"});
                }
                //$("#ww_colors .colors .scroll .bar img").ifixpng();
        }
        else
        {
                $(".ww_colors_" + id + " .colors .scroll").hide();
                $(".ww_colors_" + id + " .colors .scroll li").width("100%");
        }
        $(".ww_colors_" + id + " .colors .scroll .bar").draggable({axis: 'x', containment: '.ww_colors_' + id + ' .colors .scroll', snap: '.ww_colors_' + id + ' .colors .scroll', snapMode: 'inner'});
        $(".ww_colors_" + id + " .colors .scroll .bar").bind("drag", function(e, ui)
                {
                        cont_width = $('.ww_colors_' + id + ' .colors .images').width();
                        cus_scroll = $(".ww_colors_" + id + " .colors .scroll").width();
                        scroll_coef2 = (gal_width - cont_width) / cus_scroll + ((gal_width - cont_width) * .025 / cus_scroll);
                        $(".ww_colors_" + id + " .colors .images").scrollLeft(Math.ceil(ui.position.left * scroll_coef2));
                }
        );
        return;
}
// photos images roller
function display_v_roller()
{
        $('#product .product .photos .images').css({overflow: "hidden"});
        var cont_height = $('#product .product .photos .images').height();
        var cont_width = $('#product .product .photos .images').width();
        var total_elms = $('#product .product .photos .images .list li').length;
        var elm_w = 130 + 15;
        var elm_h = 130 + 15;
        var line_lis = Math.floor(cont_width / elm_w);
        var col_lis = Math.ceil(total_elms / line_lis);
        var gal_height = col_lis * elm_h;
        var scroll_coef1 = 1;
        var cus_scroll = $("#product .product .photos .scroll").height();
        $("#product .product .photos .images").scrollTop(0);
        $("#product .product .photos .scroll .bar").css({top: 0});
        // slider
        var scoll_val = elm_h;
        $("#product .product .photos .nav_down a").bind("click", function(e)
                {
                        e.preventDefault();
                        cont_width = $('#product .product .photos .images').width();
                        line_lis = Math.floor(cont_width / elm_w);
                        col_lis = Math.ceil(total_elms / line_lis);
                        gal_height = col_lis * elm_h;
                        cus_scroll = $("#product .product .photos .scroll").height();
                        scroll_coef1 = 1 / ((gal_height - cont_height) / cus_scroll);
                        var cur_scr = cont_height + 15 + $('#product .product .photos .images').scrollTop();
                        var show = (Math.ceil(cur_scr / elm_h) - (cur_scr / elm_h) == 0) ? Math.ceil(cur_scr / elm_h) + 1 : Math.ceil(cur_scr / elm_h);
                        var scroll_val = show * elm_h - cont_height - 15;
                        $('#product .product .photos .images').animate({scrollTop: scroll_val}, 300);
                        if (scroll_val <= gal_height - cont_height)
                        {
                                var sc_top = (scroll_val * scroll_coef1 + 18 <= cont_height) ? scroll_val * scroll_coef1 : cont_height - 18;
                                $("#product .product .photos .scroll .bar").animate({top: sc_top}, 300);
                        }
                }
        );
        $("#product .product .photos .nav_up a").bind("click", function(e)
                {
                        e.preventDefault();
                        cont_width = $('#product .product .photos .images').width();
                        line_lis = Math.floor(cont_width / elm_w);
                        col_lis = Math.ceil(total_elms / line_lis);
                        gal_height = col_lis * elm_h;
                        cus_scroll = $("#product .product .photos .scroll").height();
                        scroll_coef1 = 1 / ((gal_height - cont_height) / cus_scroll);
                        var cur_scr = cont_height + 15 + $('#product .product .photos .images').scrollTop();
                        var show = (Math.floor(cur_scr / elm_h) - (cur_scr / elm_h) == 0) ? Math.floor(cur_scr / elm_h) - 1 : Math.floor(cur_scr / elm_h);
                        var scroll_val = show * elm_h - cont_height - 15;
                        $('#product .product .photos .images').animate({scrollTop: scroll_val}, 300);
                        if (scroll_val >= 0)
                        {
                                var sc_top = (scroll_val * scroll_coef1 + 18 <= cont_height) ? scroll_val * scroll_coef1 : cont_height - 18;
                                $("#product .product .photos .scroll .bar").animate({top: sc_top}, 300);
                        }
                }
        );
        // scroll
        if ($("#product .product .photos .scroll .bar").length == 1 && gal_height - cont_height > 15)
        {
                $("#product .product .photos .scroll").show();
                $("#product .product .photos .scroll .bar img").ifixpng();
                $("#product .product .photos .nav_down").show();
                $("#product .product .photos .nav_down img").ifixpng();
                $("#product .product .photos .nav_up").show();
                $("#product .product .photos .nav_up img").ifixpng();
        }
        else
        {
                $("#product .product .photos .scroll").hide();
                $("#product .product .photos .nav_down").hide();
                $("#product .product .photos .nav_up").hide();
        }
        $("#product .product .photos .scroll .bar").draggable({axis: 'y', containment: '#product .product .photos .scroll', snap: '#product .product .photos .scroll', snapMode: 'inner'});
        $("#product .product .photos .scroll .bar").bind("drag", function(e, ui)
                {
                        cont_width = $('#product .product .photos .images').width();
                        line_lis = Math.floor(cont_width / elm_w);
                        col_lis = Math.ceil(total_elms / line_lis);
                        gal_height = col_lis * elm_h;
                        cus_scroll = $("#product .product .photos .scroll").height();
                        scroll_coef1 = (gal_height - cont_height) / cus_scroll + ((gal_height - cont_height) * .035 / cus_scroll);
                        $("#product .product .photos .images").scrollTop(ui.position.top * scroll_coef1);
                }
        );
        return;
}
// positioning popup
function position_popup(popup)
{
        var view_width = $(window).width();
        var view_height = $(window).height();
        var popup_width = popup.width();
        var popup_height = popup.height();
        var popup_loading_left = Math.ceil((view_width - popup_width) / 2) + $(document).scrollLeft();
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
        if (view_width - popup_width < 0)
        {
                popup_loading_left = $(document).scrollLeft() + 10;
        }
        if (view_height - popup_height < 0)
        {
                popup_loading_top = $(document).scrollTop() + 10;
        }
        popup.css({left: popup_loading_left, top: popup_loading_top});
        return;
}
function GetRealPos(el)
{
        if(!el || !el.offsetParent)
                return false;

        var res = Array();
        res["left"] = el.offsetLeft;
        res["top"] = el.offsetTop;
        var objParent = el.offsetParent;

        while(objParent && objParent.tagName != "BODY")
        {
                res["left"] += objParent.offsetLeft;
                res["top"] += objParent.offsetTop;
                objParent = objParent.offsetParent;
        }
        res["right"] = res["left"] + el.offsetWidth;
        res["bottom"] = res["top"] + el.offsetHeight;

        return res;
}

function position_popup2(popup, id)
{
        var view_width = $(document).width();
        if ($.browser.msie && $.browser.version <= 6 && ($(window).height() - $(document).height() < 0))
        {
                view_width -= 17;
        }

        var view_height = $(window).height();
        var all_height = $(document).height();
        var popup_width = popup.width();
        var popup_height = popup.height();
        var obLi = document.getElementById('product_li_' + id);
        var arPos = GetRealPos(obLi);


        if($.browser.msie && $.browser.version <= 6 && obLi)
        {
                arPos["left"] = $(obLi).offset().left;
                arPos["left"] += 6;
        }

        var popup_loading_left = Math.ceil((view_width - popup_width) / 2 - arPos["left"]) + $(document).scrollLeft();
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2 - arPos["top"]) + $(document).scrollTop();

        $('#need_z_index').css('z-index', '10');
        $('#footer').css('z-index', '1');

        /*var field = document.createElement('div');
        field.id = 'ww_overlay_div';
        document.getElementById('product_li_' + id).appendChild(field);
        $('#ww_overlay_div').css({'top' : '-' + arPos["top"] + 'px', 'left' : '-' + arPos["left"] + 'px', 'width' : view_width + 'px', 'height' : all_height + 'px', 'background-color': '#333', 'position': 'absolute', 'z-index': '99', 'opacity' : '0.5'});*/

        $("<div></div>").attr({id: "ww_overlay_div"}).css({'top' : '-' + arPos["top"] + 'px', 'left' : '-' + arPos["left"] + 'px', 'width' : view_width + 'px', 'height' : all_height + 'px', 'background-color': '#fff', 'position': 'absolute', 'z-index': '99', 'opacity' : '0.5'}).appendTo($('#product_li_' + id));

        if (view_width - popup_width < 0)
        {
                popup_loading_left = $(document).scrollLeft() + 10;
        }
        if (view_height - popup_height < 0)
        {
                popup_loading_top = $(document).scrollTop() + 10;
        }
        if($.browser.msie && $.browser.version == 7)
                popup_loading_left = Math.ceil((view_width - popup_width - arPos["left"])/2) + $(document).scrollLeft();

        $('#product_li_' + id).css('z-index', '1000');
        popup.css({left: popup_loading_left, top: popup_loading_top});

        return;
}
function position_popup_elem(popup, id)
{
        var view_width = $(document).width();
        if ($.browser.msie && $.browser.version <= 6 && ($(window).height() - $(document).height() < 0))
        {
                view_width -= 17;
        }

        var view_height = $(window).height();
        var all_height = $(document).height();
        var popup_width = popup.width();
        var popup_height = popup.height();
        var arPos = {};
        arPos["top"] = $('#product').offset().top;
        arPos["left"] = $('#product').offset().left;

        if($.browser.msie && $.browser.version <= 6)
                arPos["left"] += 6;

        var popup_loading_left = Math.ceil((view_width - popup_width) / 2 - arPos["left"]) + $(document).scrollLeft();
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2 - arPos["top"]) + $(document).scrollTop();

        $('#need_z_index').css('z-index', '10');
        $('#footer').css('z-index', '1');

        $("<div></div>").attr({id: "ww_overlay_div"}).css({'top' : '-' + arPos["top"] + 'px', 'left' : '-' + arPos["left"] + 'px', 'width' : view_width + 'px', 'height' : all_height + 'px', 'background-color': '#fff', 'position': 'absolute', 'z-index': '599', 'opacity' : '0.5'}).appendTo($('#product'));

        if (view_width - popup_width < 0)
        {
                popup_loading_left = $(document).scrollLeft() + 10;
        }
        if (view_height - popup_height < 0)
        {
                popup_loading_top = $(document).scrollTop() + 10;
        }
        /*if($.browser.msie && $.browser.version == 7)
                popup_loading_left = Math.ceil((view_width - popup_width - arPos["left"])/2) + $(document).scrollLeft();*/

        popup.css({left: popup_loading_left, top: popup_loading_top});

        return;
}
function position_popup_color(popup)
{
        var view_width = $(window).width();
        var view_height = $(window).height();
        var popup_width = popup.width();
        var popup_height = popup.height();
        var popup_loading_left = Math.ceil((view_width - popup_width) / 2) + $(document).scrollLeft();
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
        if (view_width - popup_width < 0)
        {
                popup_loading_left = $(document).scrollLeft() + 10;
        }
        if (view_height - popup_height < 0)
        {
                popup_loading_top = $(document).scrollTop() + 10;
        }
        popup.css({left: popup_loading_left-250, top: popup_loading_top-250});
        return;
}
function position_popup_color2(popup)
{
        var view_width = $('#products').width();
        var view_height = $('#products').height();
        var popup_width = popup.width();
        var popup_height = popup.height();
        var correct_left =$(window).width() - view_width;
        //alert(correct_left);

        var popup_loading_left = Math.ceil((view_width - popup_width - correct_left) / 2)+ $(document).scrollLeft();
        var popup_loading_top = Math.ceil((view_height - popup_height) / 2) + $(document).scrollTop();
        //alert(popup_loading_left + ' ' + popup_loading_top);
        if (view_width - popup_width < 0)
        {
                popup_loading_left = $(document).scrollLeft() + 10;
        }
        if (view_height - popup_height < 0)
        {
                popup_loading_top = $(document).scrollTop() + 10;
        }
        popup.css({left: '0px', top: '0px'});
        return;
}
// sorting
function sort_num(arg_1, arg_2)
{
        if (arg_1 > arg_2)
        {
                return -1;
        }
        else
        {
                return 1;
        }
}
// setting equal height
function set_eq_height(parent, elm)
{
        if (parent.length > 0)
        {
                parent.each(function()
                        {
                                var li_num = $(elm, $(this)).length;
                                if (li_num > 0)
                                {
                                        var li_heights = new Array();
                                        var i = 0;
                                        $(elm, $(this)).each(function()
                                                {
                                                        li_heights[i] = $(this).height();
                                                        ++i;
                                                }
                                        );
                                        li_heights.sort(sort_num);
                                        $(elm, $(this)).height(li_heights[0]);
                                }
                        }
                );
        }
        return;
}
$(document).ready(function()
{
        $(".iepng").ifixpng();
        // auth block showup
        $(".auth a").bind("click", function(e)
                {
                        e.preventDefault();
                        add_iframe($("#ww_auth"));
                        $("#ww_auth").show();
                }
        );
        $("#ww_auth .close a").bind("click", function(e)
                {
                        e.preventDefault();
                        $("#ww_auth").hide();
                }
        );
        set_bg_height($(".blck_b .bg_m"), $(".blck_b"));
        $(".blck_b").bind("resize", function()
                {
                        set_bg_height($(".blck_b .bg_m"), $(".blck_b"));
                        $(".blck_b .b_m").css({top: $(".blck_b").height()});
                }
        );
        /*$("#m_top .menu li .sub").each(function()
                {
                        set_bg_height($(".bg", $(this)), $(this));
                }
        );*/
        // top menu corners showup
        if ($("#m_top .menu > li:first").hasClass ("a"))
                                {
                                                //var left = ($(this).hasClass("ind")) ? 4 : 5;
                                                //$(".sub", $(this)).css({left: -left, width: $(".sub", $(this)).width() + left});
                                                //$(".sub", $(this)).css({left: -left, width: $("#m_top .menu > li:first").width() + left});
                                                $("#m_top .l_a").removeClass("hide");
                                }

        $("#m_top .menu > li:first")._hover(


                function()
                {
                         if ($("#m_top .menu > li:first").hasClass ("a"))
                                {
                                        var left = ($(this).hasClass("ind")) ? 4 : 5;
                                        //$(".sub", $(this)).css({left: -left, width: $(".sub", $(this)).width() + left});
                                        $(".sub", $(this)).css({left: -left, width: $("#m_top .menu > li:first").width() + left});
                                        $("#m_top .l_a").removeClass("hide");
                                }
                            else{
                        var left = ($(this).hasClass("ind")) ? 4 : 5;
                        //$(".sub", $(this)).css({left: -left, width: $(".sub", $(this)).width() + left});
                        //$("#m_top .menu > li:first .sub").css({left: -left, width: $("#m_top .menu > li:first").width() + left});
                        $("#m_top .l_a").removeClass("hide");
                        }
                },
                function()
                {
                        if ($("#m_top .menu > li:first").hasClass ("a"))
                                {
                                        var left = ($(this).hasClass("ind")) ? 4 : 5;
                                                //$(".sub", $(this)).css({left: -left, width: $(".sub", $(this)).width() + left});
                                                $(".sub", $(this)).css({left: -left, width: $("#m_top .menu > li:first").width() + left});
                                                $("#m_top .l_a").removeClass("hide");
                                }
                            else{
                        var left = ($(this).hasClass("ind")) ? 4 : 5;
                        /*$(".sub", $(this)).css({left: 0, width: $(".sub", $(this)).width() - left});*/
                        $("#m_top .l_a").addClass("hide");
                        }
                }
        );
        if ($("#m_top .menu > li:last").hasClass ("a"))
        {
                var w = ($(this).hasClass("ind")) ? 6 : 7;
                //$(".sub", $(this)).css({width: $(".sub", $(this)).width() + w});
                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width() + w});
                $("#m_top .r_a").removeClass("hide");
        }
        $("#m_top .menu > li:last")._hover(
                function()
                {
                        if ($("#m_top .menu > li:last").hasClass ("a"))
                        {
                                var w = ($(this).hasClass("ind")) ? 6 : 7;
                                //$(".sub", $(this)).css({width: $(".sub", $(this)).width() + w});
                                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width() + w});
                                $("#m_top .r_a").removeClass("hide");
                        }
                        else
                        {
                                var w = ($(this).hasClass("ind")) ? 6 : 7;
                                //$(".sub", $(this)).css({width: $(".sub", $(this)).width() + w});
                                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width() + w});
                                $("#m_top .r_a").removeClass("hide");
                        }
                },
                function()
                {
                        if ($("#m_top .menu > li:last").hasClass ("a"))
                        {
                                var w = ($(this).hasClass("ind")) ? 6 : 7;
                                //$(".sub", $(this)).css({width: $(".sub", $(this)).width() + w});
                                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width() + w});
                                $("#m_top .r_a").removeClass("hide");
                        }
                        else
                        {
                                var w = ($(this).hasClass("ind")) ? 6 : 7;
                                //$(".sub", $(this)).css({width: $(".sub", $(this)).width() - w});
                                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width() - w});
                                $("#m_top .r_a").addClass("hide");
                        }
                }
        );
        // top sub menu showup
        /*$("#m_top .menu li")._hover(
                function()
                {
                        $(".sub", $(this)).show();
                        $(this).parents("li").addClass("over");
                },
                function()
                {
                        $(".sub", $(this)).hide();
                        $(this).removeClass("over");
                }
        );*/
        $("#m_top .menu li")._hover(
                function()
                {
                        if($(this).hasClass("fst"))
                        {
                                 var left = ($(this).hasClass("ind")) ? 4 : 5;
                                //alert( $("#m_top .menu > li:first").width() + ' ' + $("#m_top .menu > li:first .sub").width());
                                $("#m_top .menu > li:first .sub").css({left: -left, width: $("#m_top .menu > li:first").width() + left});
                                $("#m_top .l_a").removeClass("hide");
                                $(this).parents("li").addClass("over");
                                $(".sub", $(this)).show();
                        }
                        else
                        {
                                $(".sub", $(this)).show();
                                $(this).parents("li").addClass("over");
                                var w = ($(this).hasClass("ind")) ? 6 : 7;
                                $(".sub", $(this)).css({width: $("#m_top .menu > li:first").width()});
                        }
                },
                function()
                {
                        $(".sub", $(this)).hide();
                        $(this).removeClass("over");
                }
        );
        // teasers center
        center_teasers();
        // mini blocks center
        center_mini();
        // actions slide down/up
        $("#actions .list .preface a").bind("click", function(e)
                {
                        e.preventDefault();
                        var parent = $(this).parents("li");
                        if (parent.hasClass("closed"))
                        {
                                $(".descr", parent).slideDown(300);
                                parent.removeClass("closed");
                                parent.addClass("opened");
                        }
                        else
                        {
                                $(".descr", parent).slideUp(300);
                                parent.removeClass("opened");
                                parent.addClass("closed");
                        }
                }
        );
        // lightbox
        $("#gallery .img a").lightBox();
        $("#gallery .title a").lightBox();
        $("#gallery .zoom a").lightBox();
        $("#product .colors .list a").lightBox({overlayOpacity:        0.1, viewAll: false});
        $("#product .product .photos .img a").lightBox({viewAll: false});
        $("#pos .photo a").lightBox({viewAll: false});
        $("#order table .photo a").lightBox({viewAll: false});
        $("#products .li .img a").lightBox({viewAll: false});
        $(".content .img_l a, .content .img_r a").lightBox({viewAll: false});
        // product colors images hover
        $("#product .product .colors li a").bind("mouseover", function()
                {
                        $(this).parents("li").addClass("a");
                }
        );
        $("#product .product .colors li a").bind("mouseout", function()
                {
                        $(this).parents("li").removeClass("a");
                }
        );
        // product qa functionality
        $("#product .qa .question a, #faq .qa .question a").bind("click", function(e)
                {
                        e.preventDefault();
                        var parent = $(this).parents("li");
                        if (parent.hasClass("a"))
                        {
                                parent.removeClass("a");
                                $(".answer", parent).slideUp(200);
                        }
                        else
                        {
                                parent.addClass("a");
                                $(".answer", parent).slideDown(400);
                        }
                }
        );
        // product images
        $("#product .product .photos .images .list li a").bind("click", function(e)
                {
                        e.preventDefault();
                        var parent = $(this).parents("li");
                        var img = $(this).attr("href");
                        var thumb = $(".thumb img", parent).attr("src");
                        $("#product .product .photos .img").css({backgroundImage: "url("+thumb+")"});
                        $("#product .product .photos .img a").attr({href: img});
                }
        );
        // colors images roller
        display_h_roller();
        // photos images roller
        display_v_roller();
        // pos total
        $("#pos .col input").bind("change, blur", function()
                {
                        var total = 0;
                        $("#pos .col input").each(function()
                                {
                                        var num = (!isNaN(parseInt($(this).val()))) ? parseInt($(this).val()) : 0;
                                        total += num;
                                }
                        );
                        $("#pos .total strong").text(total);
                }
        );
        // catalog hover effect
        $("#catalog .list li .img a")._hover(
                function()
                {
                        $(this).parents("li").addClass("a");
                },
                function()
                {
                        $(this).parents("li").removeClass("a");
                }
        );
        // btn2 button highlight
        $(".btn2 button")._hover(
                function()
                {
                        $(this).addClass("a");
                },
                function()
                {
                        $(this).removeClass("a");
                }
        );
        // btn3 button highlight
        $(".btn3 button")._hover(
                function()
                {
                        $(this).addClass("a");
                },
                function()
                {
                        $(this).removeClass("a");
                }
        );
        // btn hover class
        $("button")._hover(
                function()
                {
                        $(this).addClass("a");
                },
                function()
                {
                        $(this).removeClass("a");
                }
        );
        // submit hover class
        $(".submit input")._hover(
                function()
                {
                        $(this).addClass("a");
                },
                function()
                {
                        $(this).removeClass("a");
                }
        );
        // test window showup
        /*$("#test .submit").find("input").bind("click", function(e)
                {
                        e.preventDefault();
                        position_popup($("#ww_info"));
                        $("#ww_info").show();
                        $(window).bind("resize", function()
                                {
                                        position_popup($("#ww_info"));
                                }
                        );
                }
        );*/
        // product colors showup
        /*$("#product .rinfo .btn4 button, #product .rinfo .btn4 a").bind("click", function(e)
                {
                        e.preventDefault();
                        position_popup($("#ww_colors"));
                        $("#ww_colors").show();
                        $(window).bind("resize", function()
                                {
                                        position_popup($("#ww_colors"));
                                }
                        );

                }
        );*/
        display_h_roller_2();
        // popup roller

        /*$("#ww_colors .submit button").bind("click", function(e)
                {
                        e.preventDefault();
                        $("#ww_colors").hide();
                }
        );*/
        // ww_colors check
        /*$("#ww_colors .colors .list a").bind("click", function(e)
                {
                        e.preventDefault();
                        var parent = $(this).parents("li");
                        $('#ww_colors .check :checkbox').removeAttr('checked');
                        $(".check input", parent).attr({checked: true});
                }
        );*/

        // products colors popup
        /*$("#products .li .btn4 button, #products .li .btn4 a").bind("click",
function(e)
                {
                        var parent = $(this).parents(".li");
                        if ($(".x_colors_html", parent).length == 1)
                        {
                                e.preventDefault();
                                var title = $("h2 a", parent).text();
                                $("#ww_colors .h .for").text(title);
                                $("#ww_colors .form_placeholder").html($(".x_colors_html", parent).html());
                                position_popup2($("#ww_colors"));
                                $("#ww_colors").show();
                                $(window).bind("resize", function()
                                        {
                                                position_popup2($("#ww_colors"));
                                        }
                                );
                                // popup roller
                                display_h_roller_2();
                        }
                }
        );*/

        // scroller arrows change
        $("#product .colors .nav_prev a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_larr_12x16_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_larr_12x16.png"}).ifixpng();
                }
        );
        $("#product .colors .nav_next a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_rarr_12x16_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_rarr_12x16.png"}).ifixpng();
                }
        );
        $("#product .photos .nav_up a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_uarr_16x12_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_uarr_16x12.png"}).ifixpng();
                }
        );
        $("#product .photos .nav_down a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_darr_16x12_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_darr_16x12.png"}).ifixpng();
                }
        );
        // pages nav img change
        $(".pages .prev a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_larr_12x16_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_larr_12x16.png"}).ifixpng();
                }
        );
        $(".pages .next a")._hover(
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_rarr_12x16_a.png"}).ifixpng();
                },
                function()
                {
                        $("img", $(this)).attr({src: "/images/icon_rarr_12x16.png"}).ifixpng();
                }
        );
        // top menu last item width correct
        correct_m_top_last();
        // further links at line
        set_eq_height($("#info_ins .list"), "li");
        //set_eq_height($("#galleries .list"), ".blck_m");
        //set_eq_height($("#gallery .list"), ".blck_w1");
        set_eq_height($("#catalog .list"), ".blck_m");
        set_eq_height($("#catalog_1 .list"), ".wrap_b");
        correct_blck_b();
        correct_blck_m();
        correct_ww_info();
        correct_ww_colors();
        correct_btns_w();
        correct_footer_pos();
        correct_lights_pos();
        $(window).bind("resize", function()
                {
                        correct_m_top_last();
                        correct_blck_b();
                        correct_blck_m();
                        set_eq_height($("#info_ins .list"), "li");
                        //set_eq_height($("#galleries .list"), ".blck_m");
                        //set_eq_height($("#gallery .list"), ".blck_w1");
                        set_eq_height($("#catalog .list"), ".blck_m");
                        set_eq_height($("#catalog_1 .list"), ".wrap_b");
                        display_h_roller();
                        display_v_roller();
                        correct_footer_pos();
                        correct_lights_pos();
                }
        );
        /* Sub Menu catalog
        $("#promo_menus ul.menu li").bind("mouseover", function()
        {

             if($(this).find('.sub_shop').css('display')=='none')
             {
                $(this).find('a.isparent').addClass('parent');

                //$(this).find('a').ifixpng();
                $('.sub_shop').hide();
                $(this).find('.sub_shop').show();
             }
        }
        );
        $("#promo_menus ul.menu li").bind("mouseout", function()
        {
             $(this).find('a.isparent').removeClass('parent');
             $('.sub_shop').hide();
        }
        );*/
        $("#promo_menus .menu>li")._hover(
                function()
                {
                        $('a.isparent', $(this)).addClass('parent');
                        $('a', $(this)).ifixpng();
                        $('.sub_shop').hide();
                        $('.sub_shop', $(this)).show();
                },
                function()
                {
                        $(this).find('a.isparent').removeClass('parent');
                        $('.sub_shop').hide();
                }
        );

        $("#promo_menus div").ifixpng();
        $("a").ifixpng();
        $("#m_left ul.menu li a.is_parent").bind("click", function()
        {
             if($(this).parent().find('.sub_shop').css('display')=='none')
             {
                $('a.is_parent').css({color:'#020202'});
                $('a.is_parent').hover(
                    function () {
                      $(this).css({color:'#760023'});
                    },
                    function () {
                      $(this).css({color:'#020202'});
                    }
                  );
                $('.sub_shop').hide(300);
                $(this).css({color:'#760023'});
                $("#m_left .txt a").css({color:'#ffffff'});
                $(this).parent().find('.sub_shop').show(300);

             }
             else if($(this).parents('.txt').parent().find('.sub_shop').css('display')=='none')
             {
                $('a.is_parent').css({color:'#020202'});
                $('a.is_parent').hover(
                    function () {
                      $(this).css({color:'#760023'});
                    },
                    function () {
                      $(this).css({color:'#020202'});
                    }
                  );
                $('.sub_shop').hide(300);
                $(this).css({color:'#760023'});
                $("#m_left .txt a").css({color:'#ffffff'});
                $(this).parent().parent().find('.sub_shop').show(300);

             }
             else
             {
                $(this).css({color:'#020202'});
                $("#m_left .txt a").css({color:'#ffffff'});
                $('.sub_shop').hide(300);
             }
             return false;
        }
        );

        $("#m_left ul.menu li.a").parents('li').find('.is_parent').css({color:'#760023'});
        $("#m_left ul.menu li.a").parents('li').find('.sub_shop').show(300);
});

