


jQuery.fn.corner = function(o) {
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
            var v = jQuery.css(node,'backgroundColor');
            if ( v.indexOf('rgb') >= 0 ) {
                rgb = v.match(/\d+/g);
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };
    function getW(i) {
        switch(fx) {
        case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
        case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
        case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
        case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
        case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
        case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
        case 'curl':   return Math.round(width*(Math.atan(i)));
        case 'tear':   return Math.round(width*(Math.cos(i)));
        case 'wicked': return Math.round(width*(Math.tan(i)));
        case 'long':   return Math.round(width*(Math.sqrt(i)));
        case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
        case 'dog':    return (i&1) ? (i+1) : width;
        case 'dog2':   return (i&2) ? (i+1) : width;
        case 'dog3':   return (i&3) ? (i+1) : width;
        case 'fray':   return (i%2)*width;
        case 'notch':  return width;
        case 'bevel':  return i+1;
        }
    };
    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
            B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
        };

        if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = jQuery.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
            var d = document.createElement('div');
            var ds = d.style;

            bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

            if (bot && cssHeight != 'auto') {
                if (jQuery.css(this,'position') == 'static')
                    this.style.position = 'relative';
                ds.position = 'absolute';
                ds.bottom = ds.left = ds.padding = ds.margin = '0';
                if (jQuery.browser.msie)
                    ds.setExpression('width', 'this.parentNode.offsetWidth');
                else
                    ds.width = '100%';
            }
            else {
                ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' :
                                    (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';
            }

            for (var i=0; i < width; i++) {
                var w = Math.max(0,getW(i));
                var e = strip.cloneNode(false);
                e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
            }
        }
    });
};

//---------------------------------------------------------------------------------------------
function getAbsoluteLeft(objectId) {
        // Get an object left position from the upper left viewport corner
        o = document.getElementById(objectId)
        oLeft = o.offsetLeft            // Get left position from the parent object
        while(o.offsetParent!=null && o.getAttribute("id") != 'image_line') {   // Parse the parent hierarchy up to the document element
                oParent = o.offsetParent    // Get parent object reference
                oLeft += oParent.offsetLeft // Add parent left position
                o = oParent
        }
        return oLeft
}

function getAbsoluteTop(objectId) {
        // Get an object top position from the upper left viewport corner
        o = document.getElementById(objectId)
        oTop = o.offsetTop            // Get top position from the parent object
        while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
                oParent = o.offsetParent  // Get parent object reference
                oTop += oParent.offsetTop // Add parent top position
                o = oParent
        }
        return oTop
}

function shovBox(x,y,src){
        src = 'products_pictures/alt_picture/'+src;
        $("#boxed").css({"display":"block","top":(y-60),"left":(x+500)}).find("td").html('<img align="center"  src="'+src+'">')
}
var anim_l = '<img src="loadingAnimation.gif" style="margin:180px 0 0 225px">';
var anim_2 = '<img src="loadingAnimation.gif" style="margin:130px 0 0 145px">';

//
//
//
//
//
function loadcenter(hi){
        hi.empty().html("идет загрузка...");
        $.get("catalog.asp", { ajaxt: par[1]},
                  function(data){
                        hi.empty().html(data);
                                $(hi+" td div").mouseover(function(){
                                        var id = $(this).attr("id");
                                        var x = getAbsoluteLeft(id)
                                        var y = getAbsoluteTop(id)
                                        var src = $(this).find("img").attr("rel")
                                        shovBox(x,y,src)
                                        }
                                )
                                $(hi+" div.smallkard").mouseout(function(){
                                        $("#boxed").css({"display":"none"})
                                        }
                                )

                  }
        )
}
//
//
//
//
//
var naw = '';
var timerID = null;
$(document).ready(function(){
// подменю
//alert($.browser.version)




        // мастер подбора

        $("#mainimage").css('cursor','pointer').click(function(){tb_show('', $('#dop_z2').attr('href'), 'gallery0')})
        $("#dop_z2").css('cursor','pointer').click(function(){tb_show('', $('#dop_z2').attr('href'), 'gallery0');return false;})

        $("#mainp h4.news, #mainp h4.blog, #mainp h4.clouds ").corner("5px");



        $("#type2 div.smallkard").click(function(){
                document.location.href = $(this).find("a").attr("href");
                }
        )
        $("#type2 td div").mouseover(function(){
                        var id = $(this).attr("id");
                        var x = getAbsoluteLeft(id)
                        var y = getAbsoluteTop(id)
                        var src = $(this).find("img").attr("rel")
                        shovBox(x,y,src)
                }
        )
        $("#type2 div.smallkard").mouseout(function(){
                $("#boxed").css({"display":"none"})
                }
        )


        // для каталога навигация справа
        var obj;
        $("#right_naw a").one("click", function(){
                obj = $(this)
                var url = (obj.attr("href"))
                var arr = url.split("?")
                var par = arr[1].split("=")
                //
                $.get("ligen.asp", { grp: par[1]},
                          function(data){
                                obj.parent().after(data);

////


                                obj.click(function(){
                                        var subb = $(this).parent().next()
                                        subb.toggle()
                                        return false;
                                })
                          }
                )
                return false;
        })

        var str = '0';


        if(str != 'null' && url_1!='' &&  url_2!=''){
                $.get("ligen.asp", { grp: url_1},
                        function(data){
                                // вставил подпунты первого уровня
                                var query1 = "a[href*='"+ url_1+"']";
                                $("#right_naw").find(query1).parent().after(data);
                                //с этим работать - подпункты
                                var work_sub = $("#right_naw").find(query1).parent().next();



                                work_sub.find('a').unbind( "click" )
                                work_sub.find("a").one("click", function(){

                                        obj = $(this)
                                        var url = (obj.attr("href"))
                                        var arr = url.split("?")
                                        var par = arr[1].split("=")

                                        var hi = $('#type2')
                                        if(hi.html() == null){hi = $('#type3')}
                                        hi.empty().html("идет загрузка...");
                                        loadcenter(hi)


                                        //
                                        $.get("ligen.asp", { grp: par[1]},
                                                  function(data){
                                                        obj.parent().after(data);
                                                        var fgt = obj.parent().next();
                                                        fgt.find('a').click(function(){
                                                                var subd1 = $(this).parent().parent().parent().prev().find("a").attr('href');
                                                                var a1 = subd1.split(".asp");
                                                                var subd1 = a1[1];

                                                                var subd2 = $(this).parent().parent().prev().find("a").attr('href');

                                                                $.cookie('LNK', subd1+'#'+subd2, { path: '/', expires: 10 });
                                                        })

                                ////
                                                        obj.click(function(){
                                                                var subb = $(this).parent().next()
                                                                subb.toggle()
                                                                return false;
                                                        })
                                                  }
                                        )
                                        return false;
                                })

                                // >>>>>

                                $.get("ligen.asp", { grp: url_2},
                                        function(data){
                                                // вставил подпунты первого уровня
                                                var query2 = "a[href*='"+ url_2+"']";
                                                work_sub.find(query2).parent().after(data);

                                                work_sub.find(query2).parent().next().find('a').unbind( "click" )
                                                work_sub.find(query2).parent().next().find('a').click(function(){
                                                                var subd1 = $(this).parent().parent().parent().prev().find("a").attr('href');
                                                                var a1 = subd1.split(".asp");
                                                                var subd1 = a1[1];

                                                                var subd2 = $(this).parent().parent().prev().find("a").attr('href');

                                                        $.cookie('LNK', subd1+'#'+subd2, { path: '/', expires: 10 });
                                                })

                                                //

                                                work_sub.find(query2).unbind( "click" )
                                                work_sub.find(query2).click(function(){
                                                        var subb = $(this).parent().next()
                                                        subb.toggle()
                                                        return false;
                                                })



                                        }
                                )
                        }
                )
        }

})
