// $( function () {

// });
$(function () {
    var $tabMenuItems = $('.pro_list span');
    $tabMenuItems.click( function (){
        $(this).addClass('active').siblings().removeClass('active');
        var $contentItem = $(".act div").eq($(this).index());
        $contentItem.show().siblings().hide();
    });
    $tabMenuItems.first().click();
    (function (){
        $('body').append('<div id="bigImg"><img src=""/></div>');
        $('.r_pics li').click(function (){
            $('.r_zoom img').attr({
                src: $(this).find('img').attr('src')
            });
            $(this).parent().find('li').removeClass('hot');
            $(this).addClass('hot');
        });
        $('.r_pics li').each(function () {
            $(this).data('p_l', $(this).position().left);
        }).bind('switch',function (){
            var l = $(this).parent().position().left - $(this).data('p_l');
            $(this).parent().stop().animate({
                marginLeft: l
            },200);
        });

        var now = $('.r_pics li:first');

        $('.r_control_l').click( function () {
            var next = now.prev();
            if(next.length > 0){
                now = next;
                next.trigger('switch');
            }
            return false;
        });

        $('.r_control_r').click( function () {
            var next = now.next();
            if(next.length > 0){
                now = next;
                next.trigger('switch');
            }
            return false;
        });

        $('.r_zoom').mousemove(function (e) {
            var b_w = ($(this).outerWidth(true) - $(this).width())/2;
            var p_x = e.pageX - $(this).position().left;

            var b_h = ($(this).outerHeight(true) - $(this).height())/2;
            var p_y = e.pageY - $(this).position().top;

            var on = p_x >= b_w && p_x <= b_w + $(this).height();
            on = on && p_y >= b_h && p_y <= b_h + $(this).height();

            var glass = $('.r_zoom_glass');
            if(on){
                var x = p_x - b_w;
                var y = p_y - b_h;
                glass.css({display: 'block'});


                var g_t = y - glass.height()/2;
                g_t = g_t < 0 ? 0 : g_t ;
                g_t = g_t > $(this).height() - glass.height()? $(this).height() - glass.height() : g_t ;

                var g_l = x - glass.width()/2;
                g_l = g_l < 0 ? 0 : g_l ;
                g_l = g_l > $(this).width() - glass.width()? $(this).width() - glass.width() : g_l ;


                $('.r_zoom_glass').css({
                    top: g_t,
                    left: g_l
                });

                var p_h =  $('#bigImg').height() / glass.height();
                var p_w = $('#bigImg').width() / glass.width();
                $('#bigImg img').attr({
                    src: $(this).find('img').attr('src')
                }).css({
                    height:  p_h * $(this).find('img').height(),
                    width:  p_w * $(this).find('img').width(),
                    marginTop: - p_h * g_t,
                    marginLeft: - p_w * g_l
                });
                $('#bigImg').css({
                    display: 'block',
                    top: $(this).position().top,
                    left: $(this).position().left + $(this).outerWidth(true) + 10
                });
            } else {
                glass.css({display: 'none'});
                $('#bigImg').css({display: 'none'});
            }
        }).mouseout(function (){
            $('.r_zoom_glass').css({display: 'none'});
            $('#bigImg').css({display: 'none'});
        });

    })();
});
$(document).ready(function(){
    $('li.mainlevel').mousemove(function(){
        $(this).find('ul').slideDown();//you can give it a speed
    });
    $('li.mainlevel').mouseleave(function(){
        $(this).find('ul').slideUp("fast");
    });

});
