$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};

$.ifixpng('/img/blank.gif');

$(document).ready(function(){
    $('li.selected').hover(function(){
        $(this).addClass('hover');
        if(!window.ie6)
            return ;
        $(this).find('.sub').width($(this).width()+45);
        if ($(this).width() + 45 < 180) {
            $(this).find('.bl').width('180px');
            $(this).find('.ml').width('180px');
            $(this).find('.ml').height($(this).find('.sub2').height()-20);
        }
        else {
            $(this).find('.bl').width($(this).width()+45);
            $(this).find('.ml').width($(this).width()+45);
            $(this).find('.ml').height($(this).find('.sub2').height()-20);
        }
    },function(){
        $(this).removeClass('hover');
    });
    
    $('*').ifixpng();
    
    //$('.select-option').show();
    //$('.select-option').ifixpng();
    
    /*$('.red ul li a').pngfix();*/
    
    $('form.test .run').click(
        function() {
            var self = this;
            var form = this.form;
            $(self).css({'cursor':'progress'});
            setTimeout(function() {
                var q = parseInt($(form).attr('q')) || 0;
                var s = 0;
                var i = 0;
                $(form).find('*:radio:checked').each(
                    function() {
                        i += 1;
                        s += parseInt($(this).val()) || 0;
                    }
                );
                $(form).find('.result').show();
                $(form).find('.result p').hide();
                if (i == q) {
                    if (s >= 5 && s <= 15) {
                        $(form).find('.result p:eq(3)').show();
                    }
                    else if (s > 15) {
                        $(form).find('.result p:eq(2)').show();
                    }
                    else {
                        $(form).find('.result p:eq(1)').show();
                    }
                }
                else {
                    $(form).find('.result p:eq(0)').show();
                }
                $(self).css({'cursor':'auto'});
            }, Math.floor(Math.random() * 1000 + 1000));
        }
    );
    
    $(document).click(function(e) {
        $('.select-option').hide();
    });
    
    $('.select').click(function(e) {
        $('.select-option').hide();
        $(this).find('.select-option').show();
        return false;
    });
    
    $('.select .select-option a').click(function(e) {
        e.stopPropagation();
        e.cancelBubble = true;
    });
    
    /*var selectTimeout = 0;
    
    $('.select').hover(function() {
        $(this).find('.select-option').show();
        clearTimeout(selectTimeout);
    }, function() {
        var select = this;
        selectTimeout = setTimeout(function() {
            $(select).find('.select-option').hide();
        }, 5000);
    });*/
    
    /*$('a[popup]').mouseover(function(e) {
        var o = $(this).offset();
        $('#popup-i').html($(this).attr('popup'));
        $('#popup').css({'top':o.top,'left':o.left}).show();
        return false;
    });*/
    
    /*$('a[popup]').each(function(e) {
        var a = this;
        $.ajax({
            'url':$(a).attr('popup'),
            'method':'get',
            'complete':function(data) {
                $(a).attr('popup', $(data.responseText).find('#content').html());
                $(a).mouseover(function(e) {
                    var o = $(a).offset();
                    $('#popup-i').html($(a).attr('popup'));
                    $('#popup').css({'top':o.top,'left':o.left}).show();
                    return false;
                });
            }
        });
    });*/
    
    /*$('#popup').mouseover(function(e) {
        $(this).show();
    });
    
    $('#popup').mouseout(function(e) {
        $(this).hide();
    });*/
    
    $('a[tab]').mouseover(function(e) {
        //$('.tabs > .tab-rows > .tab[name='+$(this).attr('tab')+']').trigger('click');
        $('#'+$(this).attr('tab')).trigger('click');
        return false;
    });
    
    $('.tabs').each(function() {
        var tabs = this;
        //$('> .tab-rows', tabs).show();
        //$('> .content-rows > div', tabs).hide();
        //$('> .content-rows > div:eq(0)', tabs).show();
        $('> .tab-rows > .tab', tabs).each(function() {
            var n = $('> .tab-rows > .tab', tabs).index(this);
            if (!$(this).hasClass('c')) {
                $('> .content-rows > div:eq('+n+')', tabs).hide();
            }
            $(this).click(function() {
                $(this).addClass('c').siblings().removeClass('c');
                $('> .content-rows > div', tabs).hide();
                $('> .content-rows > div:eq('+n+')', tabs).show();
                return false;
            });
        });
    });
    
});
