$(document).ready(function() { // wykonaj po załadowaniu strony
  $('#newsletter input.text').focus(function() {
    if (this.value == this.defaultValue) {
      	this.value = '';
  	}
    if(this.value != this.defaultValue) {
    	this.select();
    }
  });
  $('#newsletter input.text').blur(function() {
    if ($.trim(this.value == '')) {
      this.value = (this.defaultValue ? this.defaultValue : '');
  	}
  });
  
  var imagesRotationImage = 1;
  var imagesRotationAmount = $('#rotation div.item').size();
  imagesRotationInterval = setInterval(function() { changeImageRotation() }, 7000);
  function changeImageRotation( id ) {
		$("#rotation #item"+imagesRotationImage).fadeOut("slow");
		$("#navigator a.item"+imagesRotationImage).removeClass("active");
		
		if( id ) {
			//alert("imagesRotationImage: "+imagesRotationImage+" id: "+id);
			imagesRotationImage = id;
			clearInterval(imagesRotationInterval);
      imagesRotationInterval = setInterval(function() { changeImageRotation() }, 7000);
		} else {
			if( imagesRotationImage < imagesRotationAmount) {
        imagesRotationImage++;
			} else {
        imagesRotationImage = 1;
      }
		}
		
		$("#rotation #item"+imagesRotationImage).fadeIn("slow");
		$("#navigator a.item"+imagesRotationImage).addClass("active");
  }
  
  $('#navigator li a[title]').click(function(){
    changeImageRotation( $(this).attr('title') );
  });
  
	$('.accordionButton').click(function() {
		$('.accordionButton').removeClass('on');
	 	$('.accordionContent').slideUp('normal');
		if($(this).next().is(':hidden') == true) {
			$(this).addClass('on');
			$(this).next().slideDown('normal');
		} 
	});
	  
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
	}).mouseout(function() {
		$(this).removeClass('over');										
	});

	$('.accordionContent').hide();
	$('.accordionButton:first').addClass('on');
	$('.accordionContent:first').show();
	$('.news-item:last').addClass('news-item-last');


	
	$("#catalogs a").fancybox({
		'width'				: 1050,
		'height'			: 800,
    'autoScale'     	: false,
    'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity' : 0.8,
		'overlayColor'		:	'#000'
		});

	$(".fancybox[rel=group], .fancybox").fancybox({
		'titleShow'     : false,
		'autoScale'     : false
		});
		
  $("a.fancybox-youtube").click(function() {
    $.fancybox({
      'autoScale'           : false,
      'transitionIn'        : 'none',
      'transitionOut'       : 'none',
      'width'               : 640,
      'height'              : 360,
      'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
      'type'                : 'swf',
      'swf'                 : {'allowfullscreen':'true'} // <-- flashvars here
    });
    return false;
  }); 

  $(".shop-details").fancybox({
  	'width'				: 300,
  	'height'			: 150,
    'autoScale'     	: false,
    'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity' : 0.8,
		'overlayColor' : '#000'
		
  });
		
		$('ul.team li div.name').hide();
		
  	$('ul.team li').hover(function() {
  		$(this).children().next().fadeIn('medium');
  	}, function() {
  		$(this).children().next().fadeOut('fast');									
  	});
} );

