$(document).ready(function() {

    $("#nav ul").hide();
    $("#nav li.selected ul").show();

    $("#nav > li > a").click(function() {
        if($(this).html() != "Sklep") {
        if($(this).parent().attr('class') != 'selected') {
            $("#nav li").removeClass('selected');
            $("#nav ul").hide();
            $(this).parent().addClass('selected');
            $(this).parent().find('ul').show(300);
        }
        if($(this).parent().find('ul').html() != null) {
            return false;
        }
        }
    });


    $("input[type='radio']")
        .wrap($("<span />")
            .addClass('radio_wrapper'))
    $(".radio_wrapper")
            .append($("<span />").addClass('replace'))

    $(".radio_wrapper .replace").click(function() {
        $(this).parent().parent().parent().find(".radio_wrapper .replace").removeClass('checked')
        $(this).addClass('checked')
        $(this).parent().parent().find("input[type='radio']").click();
    });

    $("label").click(function() {
        $(this).parent().parent().find(".radio_wrapper .replace").removeClass('checked')
        $(this).parent().find(".radio_wrapper .replace").addClass('checked')
        $(this).parent().find("input[type='radio']").click();
    });
    
    $(".box")
        .click(function() {
            if($(this).find('h3 a').attr('href') == undefined) {
                href = $(this).find('h4 a').attr('href');
            } else {
                href = $(this).find('h3 a').attr('href');        
            }
            window.location = href;
            return false;
        })
        .mouseover(function() {
            $(this).find('.description').css({
//                 'text-decoration': 'underline',
                'cursor': 'pointer'
            })
            $(this).find('h3 a').css({
                'color': '#e3446a'
            })
            $(this).find('h4 a').css({
                'color': '#e3446a'
            })
        })
        .mouseout(function() {
            $(this).find('.description').css({
//                 'text-decoration': 'none',
                'cursor': 'pointer'
            })
            $(this).find('h3 a').css({
                'color': '#8f8f8f'
            })
            $(this).find('h4 a').css({
                'color': '#8f8f8f'
            })
        })

    if($("#search input[type='text']").val() == '') {
        $("#search input[type='text']").val('Szukaj...');
    }
    var search_value = $("#search input[type='text']").attr('value');

    $("#search input[type='text']").focus(function() {
        if($(this).attr('value') == search_value) {
            $(this).attr({'value':''});
        }
    }).blur(function() {
        if($(this).attr('value') == '') {
            $(this).attr({'value': search_value});
        }
    });

            
    if($("#newsletter input[type='text']").val() == '') {
        $("#newsletter input[type='text']").val('Podaj adres e-mail...');
    }
    var newsletter_value = $("#newsletter input[type='text']").attr('value');

    $("#newsletter input[type='text']").focus(function() {
        if($(this).attr('value') == newsletter_value) {
            $(this).attr({'value':''});
        }
    }).blur(function() {
        if($(this).attr('value') == '') {
            $(this).attr({'value': newsletter_value});
        }
    });
    

    $(".box h4 a:visited, .box h3 a:visited").parent().parent().css({
        'opacity': 0.7
    });
            
    $("#down_link").click(function() {
        $("html, body").animate({ 'scrollTop': $("#bottom").offset().top}, 500);
        return false;
    });
            
    $("#top_link").click(function() {
        $("html, body").animate({ 'scrollTop': $("#top").offset().top}, 500);
        return false;
    });
            
    $("a.ajax-film").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'	    : false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		    : 680,
            'height'		: 495,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'		    : 'swf',
            'swf'			: {
                 'wmode'	: 'transparent',
                 'allowfullscreen': 'true'
            }
    })
        return false;
    });


            
});

