// onClick
function swap(id){
	if(!working) return;	pix_id = id;

	bigpic = document.getElementById('bigPic');
	bigpic2 = document.getElementById('bigPic2');
	lowpic2 = document.getElementById('p'+id);

	if(bigpic.getAttribute('act')==1){		bigpic2.src = "pix/thumbs/"+$(lowpic2).attr("name");		}else{			bigpic.src = "pix/thumbs/"+$(lowpic2).attr("name");		}

	//setTimeout('slide('+id+')', 500);
    return false;}

//slideshow
function slide(id){
	bigpic = document.getElementById('bigPic');
	bigpic2 = document.getElementById('bigPic2');	lowpic2 = document.getElementById('p'+id);

	if(!working) return;

	//active nubmer under picture
	$('.acts').attr('class','');
	if( id == 1){
		$('#p'+(tot_pix)).attr('class','acts');
		}else{			$('#p'+(id-1)).attr('class','acts');		}

	//hide bigPic, show bigPic2
	if(bigpic.getAttribute('act')==1){
		$('#bigPic2').animate({
			  "opacity": "0"
			},100
		);
		$('#bigPic').animate({
			  "opacity": "0"
			},4000
		);

		$('#bigPic2').animate({
			  "opacity": "1"
			},4000, function(){				bigpic.setAttribute('act','0');
				bigpic2.setAttribute('act','1');

				bigpic.src = "pix/thumbs/"+$(lowpic2).attr("name");

				//margins
			    shift_left = Math.round(( max_w - $(lowpic2).attr("wdth"))/2);
			    shift_top = Math.round(( max_h - $(lowpic2).attr("hght"))/2);

				bigpic.style.left = shift_left;
				bigpic.style.top = shift_top;

                setTimeout(next, 3000);
				return false;			}
		);


	//show bigPic, hide bigPic2		}else{
		    $('#bigPic').animate({
			  "opacity": "1"
				},4000, function(){
					bigpic.setAttribute('act','1');
					bigpic2.setAttribute('act','0');

					bigpic2.src = "pix/thumbs/"+$(lowpic2).attr("name");

					//margins
				  	shift_left = Math.round(( max_w - $(lowpic2).attr("wdth"))/2);
				    shift_top = Math.round(( max_h - $(lowpic2).attr("hght"))/2);

				    bigpic2.style.top = shift_top;
	   				bigpic2.style.left = shift_left;

                    setTimeout(next, 3000);
					return false;
				}
			);

			$('#bigPic2').animate({
				  "opacity": "0"
				},4000
			);
		}

    return false;
}

//change pics
function swapImg(){	bigpic = document.getElementById('bigPic');
	bigpic2 = document.getElementById('bigPic2');	bigpic.src = bigpic2.src;

	$('#bigPic').animate({
			  "opacity": "1"
		},4000,function(){			next();		});}

function	next(){
        next_id = pix_id*1+1*1;

        if (next_id==tot_pix*1+1*1){
        	pix_id=1;
        	slide(1);
          	return false;
        }

		if(!working) return;

        pix_id++;
        slide(next_id);

		return false;
	}

function prev_inst(){	working = false;
	prev_id = pix_id*1-1*1;

	change_img(prev_id);

 	pix_id--;
	setTimeout(start_slide, 3000);}

function next_inst(){	working = false;
	next_id = pix_id*1+1*1;

	change_img(next_id);

 	pix_id++;
	setTimeout(start_slide, 3000);}

function start_slide(){	next();
	working = true;}

function	change_img(id){

	bigpic = document.getElementById('bigPic');
	bigpic2 = document.getElementById('bigPic2');
	lowpic2 = '';

	if (id==tot_pix*1+2*1){
		pix_id=1;
	}

	if (id == -1 ){		pix_id = tot_pix*1;	}

	lowpic2 = document.getElementById('p'+pix_id);
	shift_left = Math.round(( max_w - $(lowpic2).attr("wdth"))/2);
	shift_top = Math.round(( max_h - $(lowpic2).attr("hght"))/2);

	if(bigpic.getAttribute('act')==1){
		//margins
	    bigpic.style.top = shift_top;
 			bigpic.style.left = shift_left;

		bigpic.src = "pix/thumbs/"+$(lowpic2).attr("name");
		}else{
			//margins
		    bigpic2.style.top = shift_top;
  				bigpic2.style.left = shift_left;
			bigpic2.src = "pix/thumbs/"+$(lowpic2).attr("name");		}
 		//active nubmer under picture
	$('.acts').attr('class','');
	$('#p'+(pix_id)).attr('class','acts');

	return false;
}

function	prev(){
		prev_id=pix_id*1-1*1;

		if (prev_id==0){
			pix_id=tot_pix;
        	swap(tot_pix);
        	return false;
        }

		pix_id--;
        swap(prev_id);

		return false;
	}
