// JavaScript Document
var galleryBoxesCurrentPic = new Array();
var galleryBoxesTimer = new Array();
var currentPic;
var timer;
var galleryCurrentPic = 1;
var galleryBrowserTimer;

// ---------------
// NEXT
// ---------------
function next(mls_no,
							nbPics,
							galleryBoxCount,
							killSlideshow,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10){

	//STOP SLIDESHOW
	if(killSlideshow){
		//pause(mls_no, galleryBoxCount);
	}
	
	//GET CURRENT PIC
	currentPic = galleryBoxesCurrentPic[galleryBoxCount] ;
	
	if(!currentPic || currentPic == 0){
		currentPic = 1;	
	}
	//BUILD PIC ARRAY
	picURLs = new Array(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10);

	//GET MINI BROWSER
	var propertyImage = document.getElementById('mls'+mls_no+'pics');
	
	//CHANGE CURRENT PIC COUNT
	if(currentPic < nbPics && currentPic < 10){
		currentPic++;
	}else{
		currentPic = 1;
	}
	//CHANGE IMAGE
	//alert('test');
	propertyImage.src = picURLs[currentPic-1];
	
	//Save the change of picture
	galleryBoxesCurrentPic[galleryBoxCount] = currentPic;
}
// ---------------
// END: NEXT
// ---------------



// ---------------
// PREV
// ---------------
function prev(mls_no, 
							nbPics,
							galleryBoxCount,
							killSlideshow,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10){
	//STOP SLIDESHOW
	if(killSlideshow){
		//pause(mls_no, galleryBoxCount);
	}
	
	//GET CURRENT PIC
	currentPic = galleryBoxesCurrentPic[galleryBoxCount] ;
	if(!currentPic || currentPic == 0){
		currentPic = 1;	
	}

	//BUILD PIC ARRAY
	picURLs = new Array(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10);

	//GET MINI BROWSER
	var propertyImage = document.getElementById('mls'+mls_no+'pics');

	//CHANGE CURRENT PIC COUNT
	if(currentPic == 1){
		currentPic = nbPics;
		if(currentPic > 10){
			currentPic = 10;	
		}
	}else{
		currentPic--;
	}

	//CHANGE IMAGE
	propertyImage.src = picURLs[currentPic-1];
	
	//Save the change of picture
	galleryBoxesCurrentPic[galleryBoxCount] = currentPic;
}
// ---------------
// END: PREV
// ---------------




// ---------------
// PLAY
// ---------------
function play(mls_no,
							nbPics, 
							galleryBoxCount,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10){
	document.getElementById('play'+mls_no).style.display = 'none';
	document.getElementById('pause'+mls_no).style.display = 'block';
	next(mls_no, nbPics, galleryBoxCount, false, pic1, pic2, pic3, pic4, pic5, pic6, pic7, pic8, pic9, pic10);
	galleryBoxesTimer[galleryBoxCount] = setInterval("next("+mls_no+","+nbPics+","+galleryBoxCount+",false,'"+pic1+"','"+pic2+"','"+pic3+"','"+pic4+"','"+pic5+"','"+pic6+"','"+pic7+"','"+pic8+"','"+pic9+"','"+pic10+"')",5000);
}
// ---------------
// END: PLAY
// ---------------



// ---------------
// PAUSE
// ---------------
function pause(mls_no, galleryBoxCount){
	document.getElementById('play'+mls_no).style.display = 'block';
	document.getElementById('pause'+mls_no).style.display = 'none';
	clearTimeout(galleryBoxesTimer[galleryBoxCount]);
	galleryBoxesTimer[galleryBoxCount] = null;
}
// ---------------
// END: PAUSE
// ---------------










// ---------------
// GALLERY NEXT
// ---------------
function galleryNext(nbGalleries,
							killSlideshow,
							id1, 
							id2, 
							id3, 
							id4, 
							id5, 
							id6,
							id7,
							id8,
							id9,
							id10,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10,
							name1,
							name2,
							name3,
							name4,
							name5,
							name6,
							name7,
							name8,
							name9,
							name10){

	//STOP SLIDESHOW
	if(killSlideshow){
		galleryPause();
	}
	
	//BUILD PIC ARRAY
	var picURLs = new Array(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10);
	var titleTexts = new Array(name1,name2,name3,name4,name5,name6,name7,name8,name9,name10);
	var galleryIDs = new Array(id1,id2,id3,id4,id5,id6,id7,id8,id9,id10);

	//GET MINI BROWSER
	var galleryImage = document.getElementById('galleryBrowserPic');
	var galleryTitle = document.getElementById('galleryBrowserTitle');
	
	//CHANGE CURRENT PIC COUNT
	if(galleryCurrentPic < nbGalleries && galleryCurrentPic < 10){
		galleryCurrentPic++;
	}else{
		galleryCurrentPic = 1;
	}
	//CHANGE IMAGE
	galleryImage.src = picURLs[galleryCurrentPic-1];
	galleryTitle.innerHTML = titleTexts[galleryCurrentPic-1];
	
	//CHANGE LINKS
	var imageLink;
	var textLink;
	
	imageLink = document.getElementById('galleryImageLink');
	imageLink.href = "/gallery/?gallery_id="+galleryIDs[galleryCurrentPic-1];
	
	textLink = document.getElementById('galleryBrowserTitle');
	textLink.href = "/gallery/?gallery_id="+galleryIDs[galleryCurrentPic-1];	
	
}
// ---------------
// END: GALLERY NEXT
// ---------------


// ---------------
// GALLERY PREV
// ---------------
function galleryPrev(nbGalleries,
							killSlideshow,
							id1, 
							id2, 
							id3, 
							id4, 
							id5, 
							id6,
							id7,
							id8,
							id9,
							id10,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10,
							name1,
							name2,
							name3,
							name4,
							name5,
							name6,
							name7,
							name8,
							name9,
							name10){

	//STOP SLIDESHOW
	if(killSlideshow){
		galleryPause();
	}
	
	//BUILD PIC ARRAY
	var galleryIDs = new Array(id1,id2,id3,id4,id5,id6,id7,id8,id9,id10);
	var picURLs = new Array(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10);
	var titleTexts = new Array(name1,name2,name3,name4,name5,name6,name7,name8,name9,name10);

	//GET MINI BROWSER
	var galleryImage = document.getElementById('galleryBrowserPic');
	var galleryTitle = document.getElementById('galleryBrowserTitle');
	
	//CHANGE CURRENT PIC COUNT
	if(galleryCurrentPic == 1){
		galleryCurrentPic = nbGalleries;
		if(galleryCurrentPic > 10){
			galleryCurrentPic = 10;	
		}
	}else{
		galleryCurrentPic--;
	}
	
	//CHANGE IMAGE
	galleryImage.src = picURLs[galleryCurrentPic-1];
	
	//CHANGE TITLE
	galleryTitle.innerHTML = titleTexts[galleryCurrentPic-1];
	
	//CHANGE LINKS
	var imageLink;
	var textLink;
	
	imageLink = document.getElementById('galleryImageLink');
	imageLink.href = "/gallery/?gallery_id="+galleryIDs[galleryCurrentPic-1];
	
	textLink = document.getElementById('galleryBrowserTitle');
	textLink.href = "/gallery/?gallery_id="+galleryIDs[galleryCurrentPic-1];	
	
	
}
// ---------------
// END: GALLERY PREV
// ---------------




// ---------------
// GALLERY PLAY
// ---------------
function galleryPlay(nbGalleries,
							killSlideshow,
							id1, 
							id2, 
							id3, 
							id4, 
							id5, 
							id6,
							id7,
							id8,
							id9,
							id10,
							pic1, 
							pic2, 
							pic3, 
							pic4, 
							pic5, 
							pic6,
							pic7,
							pic8,
							pic9,
							pic10,
							name1,
							name2,
							name3,
							name4,
							name5,
							name6,
							name7,
							name8,
							name9,
							name10){
	document.getElementById('play').style.display = 'none';
	document.getElementById('pause').style.display = 'block';
	galleryNext(nbGalleries,
								false,
								id1, 
								id2, 
								id3, 
								id4, 
								id5, 
								id6,
								id7,
								id8,
								id9,
								id10,
								pic1, 
								pic2, 
								pic3, 
								pic4, 
								pic5, 
								pic6,
								pic7,
								pic8,
								pic9,
								pic10,
								name1,
								name2,
								name3,
								name4,
								name5,
								name6,
								name7,
								name8,
								name9,
								name10);	
	galleryBrowserTimer = setInterval("galleryNext("+nbGalleries+",false,"+id1+","+id2+","+id3+","+id4+","+id5+","+id6+","+id7+","+id8+","+id9+","+id10+",'"+pic1+"','"+pic2+"','"+pic3+"','"+pic4+"','"+pic5+"','"+pic6+"','"+pic7+"','"+pic8+"','"+pic9+"','"+pic10+"','"+name1+"','"+name2+"','"+name3+"','"+name4+"','"+name5+"','"+name6+"','"+name7+"','"+name8+"','"+name9+"','"+name10+"')",4000);
}
// ---------------
// END: GALLERY PLAY
// ---------------



// ---------------
// PAUSE
// ---------------
function galleryPause(){
	document.getElementById('play').style.display = 'block';
	document.getElementById('pause').style.display = 'none';
	clearTimeout(galleryBrowserTimer);
	galleryBrowserTimer = null;
}
// ---------------
// END: PAUSE
// ---------------



