function animateStars(obj){
	obj.animate(
		{'opacity': '0.2'}, 4000, 'swing',
		obj.animate( {'opacity': '1'}, 1000, 'swing',
			function(){ animateStars(obj); }
		)
	);
}

function animateMenu(obj){
	obj.children('span').css('display','none');
	obj.hover(
		function(){
			$(this).stop().css('backgroundPosition', '50% 0').animate({'backgroundPosition': '(50% 6px)'}, 300, 'swing',
				function(){
					$(this).animate({'backgroundPosition': '(50% 0)'}, 200, 'swing'
					);
				}
			).children('span').stop(true, true).fadeIn('slow');
		},
		function(){
			$(this).stop().css('backgroundPosition', '50% 0').children('span').stop(true, true).fadeOut();
		}
	);
}

function animateHeader(obj){
	obj.hover(
		function(){
			$(this).stop().css('backgroundPosition', 'right 0px').animate({'backgroundPosition': '(right -86px)'}, 600, 'swing');
		},
		function(){
			$(this).stop().animate({'backgroundPosition': '(right 0px)'}, 500, 'swing');
		}
	);
}
//offer

function loadPicZoom(){
var links = $("div.block.right div.images a");
	links.click(function(){
		$('div.block.center').html('<img src="czapki/285/'+$(this).attr('rel')+'" alt="'+$(this).children('img').attr('alt')+'" />');
		links.removeClass('active');
		$(this).addClass('active').blur();
		return false;
	});
}

function offerEffects(){
	$('body').addClass('js');
	var links = $("div.block.left div.images a");
	$('#navContainer .prev').css('opacity', '0.5');
	var linkPages = links.size()/9;
	links.click(
		function() {
			$("div.block.center").html('');
			$.ajax({
				type: "POST",
				url: "oferta-ajax.php",
				data: "ajax=true&p="+$(this).attr('rel'),
				success: function(msg){
					$("div.block.right").hide().html(msg).fadeIn(600);
				}
			});
			links.removeClass('active');
			$(this).addClass('active').blur();
			return false;
		}
	);
	var position = 0;
	///alert(linkNumber);
	$('#navContainer .next').click(
		function() {
			if((position/285) < linkPages-1){
				//alert('go '+position+' '+linkPages);
				$("div.block.left div.images").animate({'left': '-=285px'}, 500, 'linear');
				position += 285;
			}
			if((position/285) >= linkPages-1){
				$(this).css('opacity', '0.5');
			}
			if(position > 280){
				$('#navContainer .prev').css('opacity', '1');
			}
			return false;
		}
	);
	$('#navContainer .prev').click(
		function() {
			if(position > 280){
				//alert('go '+position+' '+linkPages);
				$("div.block.left div.images").animate({'left': '+=285px'}, 500, 'linear');
				position -= 285;
			}
			if(position <= 280){
				$(this).css('opacity', '0.5');
			}
			if((position/285) < linkPages-1){
				$('#navContainer .next').css('opacity', '1');
			}
			return false;
		}
	);

	$('div.b00lock.left .images a').hover(
		function(){
			$(this).children('img').stop().animate({'width': '91px', 'height': '91px',  'top': '-=5px',  'left': '-=5px'}, 200, 'linear');
		},
		function() {
			$(this).children('img').stop().animate({'width': '81px', 'height': '81px',  'top': '+=5px',  'left': '+=5px'}, 200, 'linear');
		}
	);
}

$(document).ready(function(){
	animateStars($('#stars'));
	animateMenu($('#menu li a'));
	animateHeader($('#header h1 a'));
	if ( $.browser.msie && $.browser.version < 7 ){
		$('body.offer div.block.left .images a').hover(
		 function(){ $(this).children("img").css( {'width':'89px', 'height':'89px', 'top':'0' } ) },
		 function(){
		 	if( $(this).hasClass('active') == false )
		 		$(this).children("img").css( {'width':'81px', 'height':'81px', 'top':'4px' } )
		  }
		 );
	}
});
