    var oak = {
        init: function() {
        	this.topRotator()
            this.logoRotator()
        },
        
        topRotator: function() {
            var $promo = $('#promo-dls'),
                visibleDl = $('dl', $promo).attr('class'),
                visibIndex = parseInt(visibleDl.substr(6));
                
            $promo.after('<div id="promo-temp" />').next('#promo-temp').hide()
            
            $('#promo-temp').load($('base').attr('href')+$('html').attr('lang')+'/_promos dl:not(.' + visibleDl + ')', function() {
                $('#promo-temp dl').appendTo('#promo-dls');
                $('#promo-temp').remove();
                
                var prevIndex = visibIndex-1;
                $('#promo-dls dl.promo-' + visibIndex).insertAfter('#promo-dls dl.promo-' + prevIndex)
            
                $promo.cycle({
                    fx: 'fade',
                    speed: 750,
                    timeout:  4000,
                    pager: '#promo-pager',
                    cleartype: 'true',
                    startingSlide: prevIndex // 0-based
                })
                .parent().hover(
                    function(){ $('#promo-dls').cycle('pause'); },
                    function(){ $('#promo-dls').cycle('resume'); }
                );
            })
        },
        
        logoRotator: function() {
            var $logos = $('#logos-wrap'),
                visibleLogos = $('ul', $logos).attr('class'),
                visibIndex = parseInt(visibleLogos.substr(5));
                
            $logos.after('<div id="logos-temp" />').next('#logos-temp').hide();
            
            $('#logos-temp').load($('base').attr('href')+$('html').attr('lang')+'/_logos ul:not(.' + visibleLogos + ')', function() {
                $('#logos-temp ul').appendTo('#logos-wrap')
                $('#logos-temp').remove()
                
                var prevIndex = visibIndex - 1;
                $('#logos-wrap ul.logo-' + visibIndex).insertAfter('#logos-wrap ul.logo-' + prevIndex)
                
            	$logos.cycle({
                    fx: 'fade',
                    speed: 1500,
                    timeout:  4000,
                    pager: '#logos-pager',
                    startingSlide: prevIndex
                }).parent().hover(
                    function(){ $('#logos-wrap').cycle('pause'); }, 
                    function(){ $('#logos-wrap').cycle('resume'); }
                )
                .find('li')
                    .animate({'opacity': 0.7}, 100)
                    .hover(
                        function(){ $(this).animate({'opacity': 1}, 200) }, 
                        function(){ $(this).animate({'opacity': 0.7}, 200) }
                    );
            })
        },
        
        messages: {
            mailSend: "wiadomość wysłana!",
            sendNewMessage: "wyślij nową",
            goToCategories: "przejdź do kategorii",
            addNewMail: "dodaj kolejny"
        }
    }
    

$(document).ready(function(){
    
    oak.init();

    jQuery.fn.extend({
        // msie7 ClearType problem
        removeFilter: function() {
            return this.each(function(){
                if(this.style.filter && this.style.removeAttribute){
                    this.style.removeAttribute('filter');
                }
            });
        },
        // highlight categories (home)
        hoverCategories: function() {
        	return this.each(function(){
                $(this).hover(function(){
                	$(this).animate({'opacity': 0.5}, 150)
                }, function(){
                	$(this).animate({'opacity': 1}, 150, function() {
                		if ($.browser.msie && $.browser.version == '7.0') { $(this).removeFilter(); }
                	})
                });
        	});
        }
    })
    
    $('#catalog a').hoverCategories();

    // newsletter input[type=text]:focus
    $('form .itext-wrap input').animate({'opacity': 0.7}, 100);
    $('form .itext-wrap input').focus(function() {
        $(this).parent().animate({'opacity': 1}, 150)
    }).blur(function(){
        $(this).parent().animate({'opacity': 0.7}, 150)
    })
    
    // input.submit:hover
    $('form input.submit').hover(
        function(){ $(this).css('backgroundPosition', '0 -30px') }, 
        function(){ $(this).css('backgroundPosition', '0 0') }
    );
  
    // ie :focus
    if ($.browser.msie) {
        $('#contact-form textarea, #contact-form :text').focus(function(){
            $(this).addClass('form-focus')
        }).blur(function(){
            $(this).removeClass('form-focus')
        })
        
        $('#contact-form :submit').focus(function(){
            $(this).css('backgroundPosition', '0 -30px')
        }).blur(function(){
            $(this).css('backgroundPosition', '0 0')
        })
    }
    
    /*
        porftolio gallery
    */
	
	var oakGallery = function() {
		var opacity = 0.6;
		
		$('ul.gallery li')
			.filter(':first').addClass('active').end()
			.filter(':not(.active)').fadeTo(200, opacity).end()
			
		$('ul.gallery').galleria({
			isert: '#main-img',
			history: true,
			
			onImage: function(image, caption, thumb) {
				image.hide().fadeIn(500);
			
				var $ul = $(thumb).parents('ul'),
					$li = thumb.parent(),
					imgWidth = 760,
					thumbLeft = parseInt($li.css('left'));
	                    
				$('body').is('#c-wydruki-wielkoformatowe') ? imgHeight = 400 : imgHeight = 500;
				
				$li.fadeTo(200, 1).siblings().fadeTo(200, opacity)

				caption.text( $(thumb).parent().data('index').split('-')[1] )
				
				// img description
				if ($('div.desc', $li).length) {
					$('div.galleria_wrapper').append('<div class="description"></div>');

					$('div.galleria_wrapper').css({'width': imgWidth + 'px', 'height': imgHeight + 'px'});
					$('div.desc', $li).clone()
						.appendTo('div.description')
						.css({
							'position': 'absolute',
							'bottom': 0,
							'left': 0
						});
					
					var descHeight = '47px';
					$('div.description').prepend('<div class="desc-bg" />').find('.desc-bg').css('height', descHeight)	

					// negative margin = descriptionHeight is necessary for ie6
					if ($.browser.msie && $.browser.version == 6) { $('div.description').css('marginTop', '-47px') }
					
					$('div.galleria_wrapper div.description').show();
					if ($('div.galleria_wrapper span.desc-link').length) {
						$('div.galleria_wrapper span.desc-link').each(function() {
							// No. target="_blank" is not-my-idea.
							var link = $('<a href="http://' + $(this).text() + '" target="_blank">' + $(this).text() + '</a>');
							$(this).html(link);
						});
					}
				}
				
				/* prev / next image arrows */
				image.parent()
					.append('<div id="prev-img" /><div id="next-img" />')
					.find('#prev-img, #next-img').css({'height': imgHeight, 'backgroundPosition': '-1000px'});
					
				if ($.browser.msie && $.browser.version == '6.0') {
					image.parent().find('#prev-img div').hide();
					$('#prev-img, #next-img').wrapAll('<div id="prevnext" />');
					
					$('div#prevnext').css({ 'width': '760px', 'marginTop': -imgHeight })
				};
				
				if (!$('ul.galleria :first-child').is('.active')) {
					$('#prev-img').css('cursor', 'pointer');
					
					$('#prev-img').hover(
						function(){ $(this).css('backgroundPosition', '0 50%') }, 
						function(){ $(this).css('backgroundPosition', '-1000px 50%') }
					).click(function(){ $.galleria.prev() });
				} else { $('#prev-img').css('cursor', 'auto') }
				
				if (!$('ul.galleria :last-child').is('.active')) {
					$('#next-img').css('cursor', 'pointer');
					
					$('#next-img').hover(
						function(){ $(this).css('backgroundPosition', '100% 50%') }, 
						function(){ $(this).css('backgroundPosition', '-1000px 50%') }
					).click(function(){ $.galleria.next(); });
				} else { $('#next-img').css('cursor', 'default') }			
				
				$('#main-img').trigger('image-change')
			},
			
			onThumb : function(thumb) {
				var $li = thumb.parents('li');
				var fade = $li.is('.active') ? '1' : '0.6';
				
				$li.hover(
					function() { $li.fadeTo(200, 1); },
					function() { $li.not('.active').fadeTo(200, opacity); }
				)
			}
		})
		
		$('ul.gallery li img')
			.css('opacity', '0')
			.each(function(){
				if (this.complete || this.readyState == 'complete') { $(this).animate({'opacity': 1}, 300) } 
				else { $(this).load(function() { $(this).animate({'opacity': 1}, 300) }); }
			});
		
		
		var jc = $('ul.gallery').jcarousel({
			scroll: 5,
			initCallback: initCallbackFunction
		})
		
		$('ul.gallery li').each(function(index) {
			$(this).data('index','li-' + (++index));
			
		});
		
		
	    function initCallbackFunction(carousel) {
			if ($.browser.msie && $.browser.version == '6.0') {
				$('.jcarousel-skin-tango .jcarousel-prev-horizontal, .jcarousel-skin-tango .jcarousel-next-horizontal ').css({
				    'position': 'absolute', 'top': '43px'
				})
			}
			
			jQuery(document).bind('keydown', 'left', function (evt){ $.galleria.prev() });
			jQuery(document).bind('keydown', 'right', function (evt){ $.galleria.next() });
		
		    $('#main-img').bind('image-change',function() {
			    var idx = parseInt($('.caption').text())-3;
				
		        carousel.scroll(idx);
		        return false;
		    });
		};
	}

	if ($('#main-img').length) { oakGallery() }
});

