$(document).ready(function() { 
    $('ul.sf-menu').superfish();
    
    // zaokrąglenia rogów w menu głównym
    $('ul.sf-menu').find('li').each( function() {
        if( $(this).hasClass('first') ) {
            $(this).addClass('roundedTop');
						
        } else if( $(this).hasClass('last') ) {
            $(this).addClass('roundedBottom');
						
        } else {
            $(this).addClass('roundedColor');
        }
    });
				
    $('ul.sf-menu').children().each( function() {
        $(this).removeClass('first last roundedColor roundedTop roundedBottom');
					
        if( $(this).children().length > 1 ) {
						
            $(this).find('span').each( function() {
                if( $(this).parent().parent().parent().get(0).className.indexOf('sf-menu') > -1 ) {
                    $(this).remove();
                }
            })
            
            $(this).hover( function() {
                $(this).addClass('roundedTop');
                $(this).children().each(function() {
                    $(this).addClass('sf-ff-mod');
                });
            }, function() {
                $(this).removeClass('roundedTop');
                $(this).removeClass('sfHover');
            });
						
            $(this).find('li:first').removeClass('roundedTop').addClass('roundedTopLeft');
						
        } else {
            $(this).hover( function() {
                $(this).addClass('roundedAll');
            }, function() {
                $(this).removeClass('roundedAll');
            });
        }
    });
    
    // menu - bottom
    $('.bottom').find('.container').each(function() {
        $(this).hover( function() {
            $(this).addClass('active');  
        }, function() {
            $(this).removeClass('active');  
        })
    });
    
    // wersje językowe - top
    var selectedLang = $('.lang').find('.selected');
    $('.lang').find('.item').each( function() {
        $(this).hover( 
            function() {
                $(this).prev().removeClass('selected');
                $(this).next().removeClass('selected');
                $(this).addClass('selected');
            }, function(){
                $(this).removeClass('selected');
                selectedLang.addClass('selected');
            });
    });
    
    $.preload("arrRight.png", "arrRightSmall.png", "bg.jpg", "bg_content.png", "bg_lang.png", "bg_middleBox.png", "button.png", "cloud_active.png", "cloud_active1.png", "cloud_active2.png", "cloud_active3.png", "cloud_active4.png", "cloud_nonactive.png", "gradient_button.png", "gradient_button_2.png", "gradient_button_w.png", "gradient_button_w2.png", "line_left.png", "line_right.png", "logo.png", "logo_colored.png", "logo_white.png", "menu_arrow.png", "menu_pointer.png", "menu_pointer2.png", "quote.png");
    
    $('.bg_index').animate( {
            backgroundPosition:"-"+(0*946)+"px"
            }, {
                duration:0
            } );
});

function slideSwitch(id) {
    var $active = $('#slideshow_'+id+' img.active');

    if ( $active.length == 0 ) $active = $('#slideshow_'+id+' img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next() : $('#slideshow_'+id+' img:first');

    $active.addClass('last-active');

    $next.css({
        opacity: 0.0
    })
    .addClass('active')
    .animate({
        opacity: 1.0
    }, 1000, function() {
        $active.removeClass('active last-active');
    });
}

jQuery.preload = function() {
    for(var i = 0; i<arguments.length; i++)  {
        jQuery("<img>").attr("src", "./../../images/"+arguments[i]);
    }
}
