// JavaScript Document
function mod_akt(id,sc) {
	window.open(sc+"h/mod_akt.php?id="+id,"aktualnosci","status=no,toolbar=no,scrollbars=yes,width=750,height=600,left=0,top=50");
}


function zmien_stan_akt(id){
	var pole=$("#"+id);
	if(pole.attr('stan')==1){
		$("#"+id).slideUp('slow');
		pole.attr('stan',0);
	}else {
		$("#"+id).slideDown("slow");
		pole.attr('stan',1);
	}
}


function zaladuj_akt(){
	$.ajax({
		url: 'panel/a/aWypiszAkt.php', //wzgledna sciezka do skryptu php
		dataType: 'json', //typ transferu xml/json/javascript/html
		async : false,
		success: function(data){
			$('#main').data('aktualnosci',data);
			animacja_akt();
		}
		   
	})
}

function animacja_akt(){
	var i=1;
	$.each($('#main').data('aktualnosci'),function(){
		var div=$(document.createElement('div'));
		var akt=this;
		
		//div.addClass('kwadrat');
		div.html(i);
		div.attr('aktualnosc',this['id']);
		
		div.click(function(){
			$(".magic-box-bar-right-active").removeClass('magic-box-bar-right-active');
			
			$(this).addClass('magic-box-bar-right-active');
			
			var old_img=$('#magic-box-foto').find('img');
			var zIndex=old_img.css('zIndex');
			if(typeof(zIndex) == 'undefined'){
				zIndex=1;
			}
			
			var old_tresc=$('#magic-box-text').find('div');
			var old_title=$('#magic-box-bar-left').find('div');
						
			old_img.animate({
				opacity : 0
			},700,function(){
				old_img.remove();	
			});
			
			old_tresc.animate({
				opacity : 0
			},700,function(){
				old_tresc.remove();	
			});
			
			old_title.animate({
				opacity : 0
			},700,function(){
				old_title.remove();	
			});
			
			
			var zdj=$(document.createElement('img'));
			zdj.attr('src','zdj'+akt['zdj']);
			zdj.css({
				'position' : 'absolute',
				'top' : 0,
				'left' : 0,
				'width' : 300,
				'height' : 'auto',
				'max-height' : 246,
				'opacity' : 0,
				'z-index' : (parseInt(zIndex)+1),
				'display' : 'block'
			});
			
			var tresc=$(document.createElement('div'));
			tresc.html(akt['tresc']);
			tresc.css({
				'position' : 'absolute',
				'top' : 0,
				'left' : 10,
				'width' : 280,
				'height' : 'auto',
				'max-height' : 220,
				'opacity' : 0,
				'text-align' : 'justify',
				'z-index' : (parseInt(zIndex)+1)
				
			});						
			
			var title=$(document.createElement('div'));
			title.html(akt['tytul']);
			title.css({
				'position' : 'absolute',
				'top' : 0,
				'left' : 0,
				'width' : 400,
				'height' : 'auto',
				'max-height' : 25,
				'opacity' : 0,
				'z-index' : (parseInt(zIndex)+1)
				
			});			
			
			$('#magic-box-foto').append(zdj);
			$('#magic-box-text').append(tresc);
			$('#magic-box-bar-left').append(title);
			
			setTimeout(function(){
				zdj.animate({
					opacity : 1
				},1000);
				tresc.animate({
					opacity : 1
				},1000);
				title.animate({
					opacity : 1
				},1000);
				
			},400);
			
		});
		
		$('#magic-box-bar-right').append(div);
		
	i++;
	})
}


function przejscie_akt(){
	var ile_akt=$('#magic-box-bar-right > div').length;
	var index=$('#magic-box-bar-right').find('.magic-box-bar-right-active').index();
	if(index==-1){
		$('#magic-box-bar-right > div').eq(0).click();	
	}else if((index+1) == ile_akt){
		$('#magic-box-bar-right > div').eq(0).click();	
	}else{
		$('#magic-box-bar-right > div').eq(index+1).click();		
	}
	
}
