

/*
	
	
	file: 			/js/gallery.js
	description:	gallery functions
	
	author:			sawks
	revision:		1.1.0
	date:			2:28 06/10/03
*/

function launchGallery(url)
{
	//default pos
//	xposition = 20;
//	yposition = 20;

	//default size
	width = 700;
	height = 500;

	/*
	//safari is borked?

	alert(navigator.userAgent.indexOf('Safari') > 0);
	width = 1000;
	height = 1000;
	*/
		
	//center it
	/*
	if ((parseInt(navigator.appVersion) >= 4 ))
	{
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	*/
	
	args = "width=" + (width) + "," 
	+ "height=" + (height) + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "left=" + xposition + ","
	+ "top=" + yposition;
	window.open(url,'sgGallery',args );
}

function displayPhoto(state)
{
	var pic = pics[activePic].split(';');
	var filename = pic[0];
	var imageWidth = parseInt(pic[1]);
	var imageHeight = parseInt(pic[2]);
	var favorite = parseInt(pic[3]);
	var description = pic[4];
	var uploader = pic[5];
	
	if (imageWidth < minWidth)
	{
		imageWidth = minWidth;
	}
	if (imageHeight < minHeight) 
	{
		imageHeight = minHeight;
	}

	pageWidth = theWidth;
	pageHeight = theHeight;
	
	/* resizeTo(pageWidth+50,pageHeight+200); */
	setIdProperty('gallery','width',imageWidth + 'px');
	
	galleryObj = getObject('galleryFooter');
	while(galleryObj.hasChildNodes() == true)
    {
		galleryObj.removeChild(galleryObj.childNodes[0]);
    } 
 
	if (description)
	{
		descriptionLabel = document.createElement("DIV");
		descriptionLabel.setAttribute("id","description");
		descriptionText = document.createTextNode(description);	
		descriptionLabel.appendChild(descriptionText);
		galleryObj.appendChild(descriptionLabel);
	}
	
	
	if(favButtonObj = document.getElementById('favButton'))
	{

		while(favButtonObj.hasChildNodes() == true)
		{
			favButtonObj.removeChild(favButtonObj.childNodes[0]);
		}
		
		if (favorite)
		{
			favText = document.createTextNode('IN FAVORITES');
			favButtonObj.appendChild(favText);    		
		}
		else
		{
			favText = document.createTextNode('ADD TO FAVORITES');
			favButtonObj.appendChild(favText); 	
		}
	}
	

	for (x = 0; x < pics.length; x++)
	{
		getObject('imageTrigger' + x).style.color = '#999999';
	}
	getObject('imageTrigger' + activePic).style.color = '#333333';
	
	switch(state)
	{
		case 'init':
			//nothing
		break;
	
		default:
			getObject('imageHolder').src = filename;
		break;
	}
}

function changePhoto(num)
{
	activePic = num;
	displayPhoto();
}

function setupGallery()
{
	setBrowser();
	displayPhoto('init');
	toggleAutoPlay();
}

function next()
{
	activePic++;
	if (activePic >= pics.length)
	{
		activePic = 0;
	}	
	displayPhoto();
}

function prev()
{
	activePic--;
	if (activePic < 0)
	{
		activePic = pics.length-1;
	}	
	displayPhoto();
}

function toggleAutoPlay()
{
	switch(autoPlayStatus)
	{
		case 'off':
			next();
			autoPlayButton = getObject('autoPlay');
			while(autoPlayButton.hasChildNodes() == true)
			{
				autoPlayButton.removeChild(autoPlayButton.childNodes[0]);
			} 	
			autoPlayButtonText = document.createTextNode(';');
			autoPlayButton.appendChild(autoPlayButtonText);    
			autoPlayStatus = 'on';
			autoPlayTimer = window.setInterval('doAutoPlay()', playTime*1000);
		break;
		case 'on':
			autoPlayButton = getObject('autoPlay');
			while(autoPlayButton.hasChildNodes() == true)
			{
				autoPlayButton.removeChild(autoPlayButton.childNodes[0]);
			} 	
			autoPlayButtonText = document.createTextNode('4');
			autoPlayButton.appendChild(autoPlayButtonText);    
			window.clearInterval(autoPlayTimer);
			autoPlayTimer = null;	
			autoPlayStatus = 'off';
		break;
	}
}

function doAutoPlay()
{
	if (activePic < pics.length)
	{
		next();
	}
}

function addToFavs()
{
	var addPath = '';
	var pic = pics[activePic].split(';');
	
	var filename = pic[0];
	var favorite = parseInt(pic[3]);
	
	
	var imagePath = filename.split('/');
	var girl = imagePath[3];
	var setName = imagePath[5];
	var picName = imagePath[6];
	
	if(!favorite)
	{
		switch(galleryType)
		{
			case 'photoset':
				document.location.href = '/girls/' + girl + '/galleries/' + setName + '/' + (activePic+1) + '/add/' + picName + '/';
			break;
			case 'favPics':
				document.location.href = '/galleries/' + alias + '/' + (activePic+1) + '/' + girl + '/' + setName + '/add/' + picName + '/';
			break;		
		}
	}	
}
