// JavaScript Document

function promoSwitch() {
    
	// pobranie active
	var $activePromo = $('#promo a.active');
    if ( $activePromo.length == 0 ) $activePromo = $('#promo a:last');
	
	// pobranie następnego
    var $nextPromo =  $activePromo.next().length ? $activePromo.next()
        : $('#promo a:first');
	
	// 
    $activePromo.addClass('last-active');
	// wysunięcie zawartości poza widok
	$('.last-active p.line2').animate({right:552}, 300, function(){
							$('.last-active p.line1').animate({right:552}, 300, function(){
								$('.last-active img.promoPhoto').animate({opacity:0}, 300, function(){
									// zmiana active na następny element
									$nextPromo.addClass('active');
									$activePromo.removeClass('active last-active');
									
									// wsunięcie kolejnych elementów
									$('.active img.promoPhoto').animate({opacity:1}, 500, function(){
										$('.active p.line1').animate({right:126}, 300, function(){
											$('.active p.line2').animate({right:150}, 300, function(){
											});
										});
									});
									
									
								});
							});
						});
	
		
	
    
	
}
	

$(document).ready(function(){
	$(function() {
		
		// usunięcie z widoku zawartości promo
		// paragrafy line1 i line2 poza widok
		$("div#promo p").css('right', 552);
		// obrazek poza widok
		$("div#promo img.promoPhoto").css('opacity', 0);		
		// wsunięcie kolejnych elementów  #promo a.active
		$('.active img.promoPhoto').animate({opacity:1}, 500, function(){
			$('.active p.line1').animate({right:126}, 300, function(){
				$('.active p.line2').animate({right:150}, 600, function(){
				});
			});
		});
		
		// zmiana czasowa
		setInterval( "promoSwitch()", 5000 );
	});
});
