$(document).ready(function() {
    $('ul.menu>li>a').each( function(){
        $(this).css('font-weight', 'bold');
        var w = $(this).attr('offsetWidth');
        $(this).css('width', w + "px");
        $(this).css('font-weight', 'normal');
    });
    $('.pages a').each( function(){
        $(this).css('font-weight', 'bold');
        var w = $(this).attr('offsetWidth');
        $(this).css('width', w + "px");
        $(this).css('font-weight', 'normal');
    });

    // menu rozwijane
    $('ul.menu>li').mouseover( function(){
        $(this).children('ul').show();
        $(this).children('a').addClass('act');
    });
    $('ul.menu>li>a').mouseover( function(){
        $(this).show();
    });
    $('ul.menu>li').mouseout( function(){
        $(this).children('ul').hide();
        $(this).children('a').removeClass('act');
    });

	// scrollbar
    $('.scroll-pane').jScrollPane({scrollbarWidth: 4, dragMinHeight: 10, scrollbarMargin: 20});

    // aktuanosci
    $(".newsZajawka a.more").click().toggle(function(){
        $(this).parent().next("div.newsTresc").show("fast", function(){
            // reinicjacja scrollbarów
            $('.scroll-pane').jScrollPane({scrollbarWidth: 4, dragMinHeight: 10, scrollbarMargin: 20});
        });
        $(this).children(".m").hide();
        $(this).children(".l").show();
        //$(this).text('« zwiń');
    }, function(){
        $(this).parent().next("div.newsTresc").hide("fast", function(){
            // reinicjacja scrollbarów
            $('.scroll-pane').jScrollPane({scrollbarWidth: 4, dragMinHeight: 10, scrollbarMargin: 20});
        });
        $(this).children(".l").hide();
        $(this).children(".m").show();
        //$(this).text('więcej »');
    });
	
    $('.projMaska2').mouseover( function(){
        $(this).parent().children('.projMaska').fadeTo("fast", '0');
        $(this).children('span').fadeOut("fast");
    });
    $('.projMaska2').mouseout( function(){
        $(this).parent().children('.projMaska').fadeTo("fast", '0.8');
        $(this).children('span').fadeIn("fast");
    });

    // animacje obrazka na stronie projektu
    $('.pages a').click( function(){
        $(this).parent().children('a').removeClass('act');
        $(this).addClass('act');

        var index = $('.pages a').index($(this));
		//alert(index);
		$('#img div.show').fadeTo(500, 0);
		$('#img div.show').removeClass('show');
		$('#img div').eq(index).fadeTo(500, 1);
		$('#img div').eq(index).addClass('show');
    });

    // przewijanie fotek
    $('#przewin').click( function(){
		var ile = $('#img div').not('#przewin').length;

		// jeśli ostatnia, to wracamy do 1.
		if($('#img div').index($('#img .show')) == ile - 1){
			$('#img div.show').fadeTo("slow", 0);
			$('#img div.show').removeClass('show');
			$('#img div').eq(0).fadeTo("slow", 1);
			$('#img div').eq(0).addClass('show');
			$('.pages a').removeClass('act');
			$('.pages a').eq(0).addClass('act');
		}

		// jeśli nie ostatnia, to odsłaniamy kolejną
        else{
			$('#img div.show').fadeTo("slow", 0);
			$('#img .show').next('div').fadeTo("slow", 1);
			var index = $('#img div').index($('#img .show'));
			$('#img div.show').removeClass('show');
			$('#img div').eq(index + 1).addClass('show');
			$('.pages a').removeClass('act');
			$('.pages a').eq(index + 1).addClass('act');
        }
    });

	// IE hack
	if(isIe()){
		$('#img div').not('.show').not('#przewin').fadeTo(0, 0.1);
		$('#img div').not('.show').not('#przewin').fadeTo(0, 0);
	}
});

function isIe(){
	return navigator.userAgent.toLowerCase().indexOf('msie') > -1;
}

