// functions definitions

// counter of chars
function counterChars(object, maxChars, info) {
    var count = jQuery(object).val().length;
    var total = maxChars - count;

    if(total < 0) {
            total = 0;
            jQuery(object).val(jQuery(object).val().truncate(maxChars, ''));
    } // eof if

    jQuery(info).html(total);
}; // eof function counterChars

jQuery(document).ready(function() {	
    // top menu animation
    jQuery('#top-menu ul li a').hover(function() {
        jQuery(this).parent().stop().animate({backgroundPosition:"right -175px"}, 700);
    }, function() {
        jQuery(this).parent().stop().animate({backgroundPosition:"right 175px"}, 200);
    });
    
    // hot news animation
    jQuery('.hot-news-content').hide();
    jQuery('#hot-news li a.header_news').bind('click', function() {
        jQuery('#hot-news li a').removeClass('active');
        jQuery(this).addClass('active');
        var hotnewsContent = jQuery(this).next();

        if( hotnewsContent.is(':hidden') ) {
            jQuery('.hot-news-content').slideUp();
            hotnewsContent.slideDown();
        } else {            
            hotnewsContent.slideUp();
            jQuery(this).removeClass('active');
        } // eof if            

        jQuery(this).blur();
        return false;
    });
    
    // faq
    jQuery('.faq .faq-entry p').hide();
    jQuery('.faq .faq-entry h4 a').bind('click', function() {
        jQuery(this).blur();
        var answerContent = jQuery(this).parent().next();
        
        if(answerContent.is(':hidden')) {
            answerContent.slideDown();
        } else {
            answerContent.slideUp();
        }
                
        return false;
    });	

    // (+pz) lightbox:
   jQuery('a[rel=lightbox]').lightBox();

	// shoutbox
    jQuery('#ShoutboxContent').bind('keyup', function(e) {
        counterChars('#ShoutboxContent', 255, '#shoutboxChars');
    });

    // comment content
    jQuery('#CommentContent').bind('keyup', function(e) {
        counterChars('#CommentContent', 2000, '#chars');
    });

    // photo comment content
    jQuery('#PhotoCommentContent').bind('keyup', function(e) {
        counterChars('#PhotoCommentContent', 2000, '#chars');
    });
});

//// polls in box animate
//function animatePollsInBox() {
//    jQuery('#ankiety .wynik .wskaznik').each(function(k,v) {
//        var width = jQuery(v).children().width();
//        jQuery(v).children().width(0).animate({'width':width}, 500);
//    });
//} // eof function animatePollsInBox
//
//// polls on page animate
//function animatePollsOnPage() {
//    jQuery('#ankieta .wynik .wskaznik').each(function(k,v) {
//        var width = jQuery(v).children().width();
//        jQuery(v).children().width(0).animate({'width':width}, 1000);
//    });
//} // eof function animatePollsOnPage



//function scrollToId(objectId) {
//    var scrollTopValue = jQuery('#'+objectId).position().top;
//    var elements = 'html';
//
////    window.document.body.scrollTop = scrollTop;
////    window.document.documentElement.scrollTop = scrollTop;
//    if( jQuery.browser.safari == true ) {
//        elements = 'html,body';
//    } // eof if
//    
//    jQuery(elements).animate({scrollTop: scrollTopValue}, 250);
////    window.scrollTo(0, scrollTop);
//} // eof function scrollToId
//
//// jQuery initialize
//jQuery(document).ready(function() {
//    
//    // animate messages
//    jQuery('.message').hide().fadeIn(1000);
//    
//    // short news in mainpage
//    jQuery('.news_content').hide();
//    jQuery('#news li div a').bind('click', function() {
//        var newsContent = jQuery(this).parent().next();
//        
//        if( newsContent.is(':hidden') ) {
//            jQuery('.news_content').slideUp();
//            newsContent.slideDown();
//        } else {
//            newsContent.slideUp();
//        } // eof if
//        
//        // old code with arrows
////        if( jQuery(this).attr('class').indexOf('strzalka_down') > -1 ) {
////            jQuery('.news_content').slideUp();
////            jQuery('#news li div a').removeClass('strzalka_up').addClass('strzalka_down');
////            jQuery(this).removeClass('strzalka_down').addClass('strzalka_up').parent().next().slideDown();
////        } else {
////            jQuery(this).removeClass('strzalka_up').addClass('strzalka_down').parent().next().slideUp();
////        } // eof if        
//        
//        jQuery(this).blur();
//        return false;
//    });
//    
//    // main menu animate
//    jQuery('#main_menu ul li').not('.separator').hover(function(event) {
//            jQuery(this).addClass('active');
//            jQuery(this).children('ul').fadeIn('fast');
//        }, function() {
//            jQuery(this).removeClass('active');
//            jQuery(this).children('ul').fadeOut('slow');
//    });
//    
//    jQuery('.submenu li, .submenu2 li').hover(function(event) {
//            jQuery(this).addClass('hover');
//        }, function() {
//            jQuery(this).removeClass('hover');
//    });
//    
////    jQuery('#main_menu ul li').not('.separator').bind('mouseover', function() {
////        jQuery(this).has('ul').show();
////    });
//    
////    jQuery('#main_menu ul li').not('.separator').hover(function() {
////        jQuery(this).addClass('active');
////        if( jQuery(this).children().is('ul') ) {
////            jQuery(this).children().fadeIn('fast');
////            
////            jQuery('#main_menu .submenu li').hover(function() { 
////                jQuery(this).addClass('hover');
////                if( jQuery(this).children().is('ul') ) {
////                    jQuery(this).children().fadeIn('fast');
////                } // eof if
////            }, function() {
////                jQuery(this).removeClass('hover');
////                if( jQuery(this).children().is('ul') ) {
////                    jQuery(this).children().fadeOut('normal');
////                } // eof if
////            });
////        } // eof if
////    }, function() {
////        jQuery(this).removeClass('active');
////        if( jQuery(this).children().is('ul') ) {
////            jQuery(this).children('ul').fadeOut('normal');
////        } // eof if
////    });        
//    
//    // box: komentarze, ankiety, archiwum
//    jQuery('#pkomentarze, #pankiety, #parchiwum').hover(function() {
//            jQuery(this).parent().addClass('hover');
//        }, function() {
//            jQuery(this).parent().removeClass('hover');
//    });        
//    
//    jQuery('#pkomentarze, #pankiety, #parchiwum').bind('click', function(e, returnValue) {
//        window.location.hash = e.target.hash;
//        jQuery('#komentarze, #ankiety, #archiwum').hide();
//        jQuery('#pkomentarze, #pankiety, #parchiwum').parent().removeClass('active');
//        jQuery(this).parent().addClass('active');
//        
//        switch( e.target.hash ) {
//            case '#komentarze' :
//            case '#archiwum' : { jQuery(e.target.hash).fadeIn(); break; }
//            case '#ankiety' : { jQuery(e.target.hash).fadeIn(); animatePollsInBox(); break; }
//            default : { jQuery('#komentarze').fadeIn(); break; }
//        } // eof switch                
//        
//        jQuery(this).blur();
//        
//        if( returnValue != undefined ) {
//            window.scrollTo(0, jQuery('.box .ankieta').position().top-10);            
//            return returnValue;
//        } else {
//            return false;
//        }
//    });
//    
//    // if page is loading with hash in URL
//    if( window.location.hash != undefined ) {
//        var vhash = window.location.hash;
//        vhash = vhash.substr(1,vhash.length);
//                
//        switch( '#'+vhash ) {
//            case '#komentarze' :
//            case '#ankiety' :
//            case '#archiwum' : {
//                jQuery('#p' + vhash).trigger('click', true);
//                break;
//            }
//            default : {}
//        } // eof switch
//    } // eof if        
//    

//    
//    // guest book
//    jQuery('#GuestbookContent').bind('keyup', function(e) {
//        counterChars('#GuestbookContent', 1000, '#guestbookChars');
//    });
//    

//    
//    // animate pools results on page
//    if( jQuery('#ankieta').is('div') ) {
//        animatePollsOnPage();
//    } // eof if
//    
//    // forms validation
//    jQuery('form#formLogin').bind('submit', function() {
//        if(jQuery('input#UserUsernameLogin').val() == '') {
//            alert('Pole "Użytkownik" nie może być puste');
//            jQuery('input#UserUsernameLogin').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserPasswordLogin').val() == '') {
//            alert('Pole "Hasło" nie może być puste');
//            jQuery('input#UserPasswordLogin').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formSearch').bind('submit', function() {
//        if(jQuery('input#NewsSearch').val() == '') {
//            alert('Proszę wpisać frazę do wyszukania');
//            jQuery('input#NewsSearch').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formGuestbook').bind('submit', function() {
//        if(jQuery('input#GuestbookUsername').val() == '') {
//            alert('Pole "Użytkownik" nie może być puste');
//            jQuery('input#GuestbookUsername').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#GuestbookEmail').val() == '') {
//            alert('Pole "Email" nie może być puste');
//            jQuery('input#GuestbookEmail').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#GuestbookSite').val() == '') {
//            alert('Pole "Strona" nie może być puste');
//            jQuery('input#GuestbookSite').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('textarea#GuestbookContent').val() == '') {
//            alert('Pole "Treść wpisu" nie może być puste');
//            jQuery('textarea#GuestbookContent').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formRegister').bind('submit', function() {
//        if(jQuery('input#UserUsername').val() == '') {
//            alert('Pole "Użytkownik" nie może być puste');
//            jQuery('input#UserUsername').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserEmail').val() == '') {
//            alert('Pole "Email" nie może być puste');
//            jQuery('input#UserEmail').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserPassword').val() == '') {
//            alert('Pole "Hasło" nie może być puste');
//            jQuery('input#UserPassword').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserPasswordConfirm').val() == '') {
//            alert('Pole "Powtórz hasło" nie może być puste');
//            jQuery('input#UserPasswordConfirm').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserName').val() == '') {
//            alert('Pole "Imię i nazwisko" nie może być puste');
//            jQuery('input#UserName').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formResetPassword').bind('submit', function() {
//        if(jQuery('input#UserEmail').val() == '') {
//            alert('Proszę wpisać swój adres poczty elektronicznej');
//            jQuery('input#UserEmail').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formShoutbox').bind('submit', function() {
//        if(jQuery('textarea#ShoutboxContent').val() == '') {
//            alert('Proszę wpisać swój wypowiedź');
//            jQuery('textarea#ShoutboxContent').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formChangePassword').bind('submit', function() {
//        if(jQuery('input#UserPasswordOld').val() == '') {
//            alert('Pole "Stare hasło" nie może być puste');
//            jQuery('input#UserPasswordOld').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserPasswordNew').val() == '') {
//            alert('Pole "Nowe hasło" nie może być puste');
//            jQuery('input#UserPasswordNew').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('input#UserPasswordConfirm').val() == '') {
//            alert('Pole "Powtórz nowe hasło" nie może być puste');
//            jQuery('input#UserPasswordConfirm').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formAddNews').bind('submit', function() {
//        if(jQuery('input#NewsTitle').val() == '') {
//            alert('Pole "Tytuł" nie może być puste');
//            jQuery('input#UserPasswordOld').focus();
//            return false;
//        } // eof if
//        
//        if(jQuery('textarea#NewsContent').val() == '') {
//            alert('Pole "Treść" nie może być puste');
//            jQuery('input#NewsContent').focus();
//            return false;
//        } // eof if
//    });
//    
//    jQuery('form#formPoll').bind('submit', function() {
//        var checked = false;
//        jQuery('input[name="data[Poll][answer]"]').each(function(k,v) {
//            if(jQuery(v).is(':checked')) {
//                checked = true;
//            } // eof if
//        });
//        
//        if(checked === false) {
//            alert('Musisz zaznaczyć swoją odpowiedź');
//            return false;
//        } // eof if
//    });
//    
//});

