$(function(){
    if($.browser.msie)
    {
        $('div#menu li.dropdown:hover').hover(function(){
            $(this).addClass('hover');
        }, function(){
            $(this).removeClass('hover');
        });
    }
    
    $('div#content div.category-list div.choose-platform form').each(function(){
        $form = $(this);
        $select = $('select#choose_platform', $form);
        var init_val = $select.val();
        
        $select.change(function(){
            $('option:selected', $select).each(function(){
                new_val = $(this).val();
                if(new_val != init_val)
                {
                    var base = $($('base').get(0)).attr('href');
                    document.location.href = base+'pliki-'+new_val+'.html';
                }
            });
        });
    });
    
    $('div#content div.file-list div.options form select').each(function(){
        $select = $(this);
        var init_val = $select.val();

        $select.change(function(){
            option = $('option:selected', $select).get(0);
            new_val = $(option).val();
            if(new_val != init_val)
            {
                $(this).parent().parent().submit();
            }
        });
    });
    $('div#content div.file-list div.options form :checkbox').each(function(){
        $checkbox = $(this);
        var init_val = $checkbox.is(':checked');
        
        $checkbox.change(function(){
            new_val = $(this).is(':checked');
            
            if(new_val != init_val)
            {
                $(this).parent().parent().submit();
            }
        });
    });
    $('div#sidebar div.box-newsletter form').each(function(){
        $form = $(this);
        $action = $('input[name="action"]', $form);
        $email = $('input[name="email"]', $form);
        
        $form.submit(function(){
            $.post($form.attr('action'), { action: $action.val(), email: $email.val() }, function(data){
                $form.before('<p>'+data+'</p>');
            }, 'html');
            return false;
        });

        $('a.signin', $form).click(function(){
            $action.val('in');
            $form.submit();
            return false;
        });
        $('a.signout', $form).click(function(){
            $action.val('out');
            $form.submit();
            return false;
        });
    });
    $('div#content div.file-details div.infobox div.thumb a').each(function(){
        $a = $(this);
        $img = $('img', $a);
        var title = $img.attr('title');
        var match = /([0-9]+)x([0-9]+)/.exec(title);
        $a.click(function(){
            window.open($a.attr('href'), '', 'toolbar=no,menubar=no,scrollbars=no,resizable=no,height='+match[2]+',width='+match[1]);
            return false;
        });
    });
    $('div#content div.article form div.captcha').each(function(){
        $img = $('img', $(this));
        $a = $('label a', $(this));
        var captcha_src = $img.attr('src');
        $a.click(function(){
            $img.attr('src', captcha_src+'?c='+Math.random());
            return false;
        });
    });
    $('div.site-columns div#sidebar div.box-poll').each(function(){
        $form = $('form', this);
        $a = $('p.vote a.vote', this);
        $a.click(function(){
            $form.submit();
            return false;
        });
    });
});
