/*
 *resize
 */
$( function() {

    if( $('#programForm').get().length > 0 ) {
        $('#programForm input[name=form[od]], #programForm input[name=form[do]]').datepicker({
            dateFormat: 'dd/mm/yy',
            firstDay : 1,
            monthNames: [
            'Styczeń','Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'
            ],
            dayNamesMin: [
            'N', 'Pon', 'Wt', 'Śr', 'Cz', 'Pt', 'Sob'
            ]
        });
    }
} );


/*lightbox */
$( function() {
    $('[rel=lightbox], .fullNews .min, [rel=lightbox[gallery]]').prettyPhoto( {
        theme: 'dark_square',
        showTitle: false
    } );
} );


/*news */
$(function() {
    $( '#menu td' ).click( function() {
        window.location = $(this).find( '> a' ).attr('href');
        
    } );
/*$('.newsBox .more').click( function() {
        if( $(this).parent().parent().attr('id')=='leftNews' ) {
            return true;
        }
        if($('.productBox, .product').get().length > 0) {
            return true;
        }
        if($('#homeNews').get().length>0) {
            return true;
        }
        $(this).parent().parent().find('.full').slideDown();
        $(this).css('display', 'none');
        $('.newsBox .back').css('display', 'block');
        return false;
    } );
    $('.newsBox .img a').click(function() {
        if($('.productBox, .product').get().length > 0) {
            return true;
        }
        $(this).parent().parent().find('.more').click();
        return false;
    });
    $('.newsBox .back').each(function() {
        if($(this).parent().parent().hasClass('fullNews')) {
            return;
        }
        $(this).click( function() {
            $(this).hide();
            $(this).parent().parent().find('.more').css('display', 'block');
            $(this).parent().slideUp();
            return false;
        }  ) }  );*/
});

/*
 * Contact Form
 */
$( function() {
    $('.txtinput, #searchForm .text, #newsletter .text').each( function() {
        $(this).attr('defaultText', ( $(this).hasClass('mess') ? $(this).text() : $(this).attr('value') )).focus( txtinputFocus ).blur( txtinputBlur );
    } );
} );
function txtinputFocus() {
    if($(this).hasClass('mess')) {
        if($(this).attr('defaultText') == $(this).text())
            $(this).text('');
    } else {
        if($(this).hasClass('pass_fake')) {
            $(this).hide();
            $('.txtinput.pass').show().focus();
            return;
        }
        if($(this).attr('defaultText') == $(this).attr('value'))
            $(this).attr('value','');

    }
}

function txtinputBlur() {
    if($(this).hasClass('mess')) {
        if($(this).attr('value') == '')
            $(this).text($(this).attr('defaultText'));
    } else {
        if($(this).attr('value') == '') {
            if($(this).hasClass('pass')) {
                $(this).hide();
                $('.pass_fake').show();
            } else
                $(this).attr('value', $(this).attr('defaultText') );
        }

    }
}

$(  function() {
    $('#top .logo, #top .text1, #top .text2, #images .active').css( 'opacity', 0 );
    setTimeout( function() {
        $( '#top .logo, #images .active' ).animate({
            opacity: 1
        }, 1000);
        $( '#top .text1' ).animate({
            opacity: 1
        }, 1200, function() {
            $('#top .text2').animate( {
                opacity: 1
            }, 1200 );
        });
    }, 600 );
    

} );

$(function() {
    $('.polecamy .title').toggle( function() {
        var up = $(this).parent();
        up.find('.all').slideDown();
        up.stop().animate( {
            height: '193px'
        } ).addClass('polecamyActive');
        return false;
    }, function() {
        var up = $(this).parent();
        up.find('.all').slideUp();
        up.stop().animate( {
            height: '25px'
        }, 'normal', function() {
            $(this).removeClass('polecamyActive');
        } );
        return false;
    } );
});



var siteLoaded = false;

function photoInterval() {
    $('#photo .active').show().fadeOut('slow').removeClass('active');
    actPhoto++;
    if(actPhoto == topPhoto)
        actPhoto=0;
    $( $('#photo img').get(actPhoto) ).fadeIn('slow').addClass('active');

    
}
var actPhoto = 0;
var topPhoto = 0;
$(function() {
    topPhoto = $('#photo img').get().length;
    $('#photo .active').hide().fadeIn('slow');
    if( topPhoto > 1 ) {
        setInterval(photoInterval, 10000);
    }
});



/*
 * hooks
 */
$(function() {
    //footmenu
    var width =  ( $('#footLinks ul').width()-($('#footLinks img').get().length * 3) );
    var length = $('#footLinks a').css('padding', '0px').each(function() {
        width -= $(this).width();
    }).get().length;

    $('#footLinks a').css('padding', '0px ' + ( Math.floor(width/length/2) ) + 'px');
});

/**
 * menu
 */
$( function() {

    $('#menu li, #menu td').hover( function() {
        var submenu = $('> div', this);
        if(submenu.get().length == 0) {
            //$(this).find('>a').addClass('hoverEmpty');
            return;
        }
        if(submenu.hasClass('toOver')) {
            submenu.stop().removeClass('toOver');
        } else {
            submenu.stop().attr('style', '').removeAttr('style');
        
            $(this).find('>a').addClass('hover');
        
            if($(this).attr("tag") == 'TD')
                submenu.slideDown('fast');
            else
                submenu.show('fast');
        }
    }, overMenu );
    
} );
var toOver;
function overMenu() {

    var submenu = $('> div', this);
    if(submenu.get().length == 0) {
        //$(this).find('>a').removeClass('hoverEmpty');
        return;
    }
    if(submenu.get().length == 0)
        return;

    

    submenu.addClass('toOver').stop().animate({
        'display': 'block'
    }, 500, function() {
        if($(this).parent().attr("tag") == 'TD')
            $(this).slideDown('fast');
        else
            $(this).hide('fast');
        $(this).parent().find('>a').removeClass('hover');
        $(this).removeClass('toOver');
    });
        
    
}

