
function Rnd( min, max ) {
	if( min > max ) {	return( -1 );	}
	if( min == max ) {	return( min );	}
    return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}
function getVisible() {
	visible = Math.random();
	if (visible>0.9) return true;
	else return false;
}
function changeCell(id,size,rnd) {
	visible = Math.random();
	if (visible>0.2) us = picDir+"/"+size+"/"+purl[Rnd(0,picMax)];
	else us = "test/i/no.png";
	if (rnd==1) us = picDir+"/"+size+"/"+purl[Rnd(0,picMax)];
	$(id).css("background-image", "url("+us+")");  
	$(id).css("background-position", "center center");  
	$(id).css("background-repeat", "no-repeat");  
	$(id).fadeIn("slow");
}

$(document).ready(
function() {
	$('#p_row').oneTime(10, function(i) { 
		$("#pic1").fadeOut(500,function () {changeCell(this,'l');});
		$("#pic12").fadeOut(500,function () {changeCell(this,'',1);});
		$("#pic13").fadeOut(500,function () {changeCell(this,'',1);});									 
		$("#pic20").fadeOut(500,function () {changeCell(this,'m');});
		$("#pic21").fadeOut(500,function () {changeCell(this,'m');});								 
	});
	$('#p_row').everyTime(2000, function(i) {  //everyTime
		
		if (getVisible()) $("#pic1").fadeOut(500,function () {changeCell(this,'l');});
		if (getVisible()) $("#pic2").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic3").fadeOut(500,function () {changeCell(this,'s');});

		if (getVisible()) $("#pic4").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic5").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic6").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic7").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic8").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic9").fadeOut(500,function () {changeCell(this,'l');});
		if (getVisible()) $("#pic10").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic11").fadeOut(500,function () {changeCell(this,'m');});

		if (getVisible()) $("#pic12").fadeOut(500,function () {changeCell(this,'',1);});
		
		if (getVisible()) $("#pic13").fadeOut(500,function () {changeCell(this,'',1);});
		if (getVisible()) $("#pic14").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic15").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic16").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic17").fadeOut(500,function () {changeCell(this,'s');});
		if (getVisible()) $("#pic18").fadeOut(500,function () {changeCell(this,'l');});
		if (getVisible()) $("#pic19").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic20").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic21").fadeOut(500,function () {changeCell(this,'m');});
		if (getVisible()) $("#pic22").fadeOut(500,function () {changeCell(this,'m');});		
		
	});
});	
