/*****************************************************************************
 *
 * File     : gallery.js
 * 
 * Project  : Whistler
 * 
 * Contents : Manager of panels (thumbs, albums, etc)
 *
 * Author: 
 *
 * Copyright 2007 Whistler Info
 * http://www.whistlerinfo.ca
 * All rights reserved.
 * 
 ***|***************************|***********************|*******************|*/



/************************************************************************
*
*	function:	startHResize
*
*	purpose:	
*
*************************************************************************/
function startHResize(event)
{
	// firefox disabling drag
	if (event.preventDefault) event.preventDefault();
	
	document.onmousemove = hResize;
	document.onmouseup = endResize;
	document.body.style.cursor = "w-resize";

	// set the width only first time
	if (_albumPanel.style.width == "") _albumPanel.style.width = _albumPanel.offsetWidth + "px";
	if (_thumbPanel.style.width == "") _thumbPanel.style.width = _thumbPanel.offsetWidth - 4 + "px";

	_lastX = event.screenX;
}

/************************************************************************
*
*	function:	startVResize
*
*	purpose:	
*
*************************************************************************/
function startVResize(evt)
{
	// firefox disabling drag
	if (evt.preventDefault) evt.preventDefault();
	
	document.onmousemove = vResize;
	document.onmouseup = endResize;
	document.body.style.cursor = "n-resize";
	
	// set the height only first time
	if (_selector.style.height == "") _selector.style.height = _selector.offsetHeight + "px";
	if (_albumView.style.height == "") _albumView.style.height = _albumView.offsetHeight + "px";
	if (_thumbView.style.height == "") _thumbView.style.height = _thumbView.offsetHeight + "px";

	_lastY = event.screenY;
}

/************************************************************************
*
*	function:	startContentResize
*
*	purpose:	
*
*************************************************************************/
function startContentResize(evt)
{
	// firefox disabling drag
	if (evt.preventDefault) evt.preventDefault();
	
	document.onmousemove = contentResize;
	document.onmouseup = endResize;
	document.body.style.cursor = "n-resize";
	
	// set the height only first time
	if (_contentView.style.height == "") _contentView.style.height = _contentView.offsetHeight + "px";

	_lastY = event.screenY;
}

/************************************************************************
*
*	function:	endResize
*
*	purpose:	
*
*************************************************************************/
function endResize(evt)
{
	document.onmousemove = null;
	document.onmouseup = null;
	document.body.style.cursor = "default";
}

/************************************************************************
*
*	function:	hResize
*
*	purpose:	
*
*************************************************************************/
function hResize(ev)
{
	ev = ev || window.event;
	var currentX = ev.screenX;
	
	var currentAlbumWidth = parseInt(_albumPanel.style.width.substring(0, _albumPanel.style.width.length - 2));
	var currentThumbWidth = parseInt(_thumbPanel.style.width.substring(0, _thumbPanel.style.width.length - 2));
	var delta = currentX - _lastX;
	
	if ( 	(currentAlbumWidth < 100 && delta < 0) || 
				(currentThumbWidth < 105 && delta > 0) ) return;
	
	var newAlbumWidth = currentAlbumWidth + delta;
	_albumPanel.style.width = newAlbumWidth;

	var newThumbWidth = currentThumbWidth - delta;
	_thumbPanel.style.width = newThumbWidth;

	_lastX = currentX;
}

/************************************************************************
*
*	function:	vResize
*
*	purpose:	
*
*************************************************************************/
function vResize(ev)
{
	ev = ev || window.event;
	var currentY = ev.screenY;
	
	var currentSelectorHeight = parseInt(_selector.style.height.substring(0, _selector.style.height.length - 2));
	var currentAlbumsHeight = parseInt(_albumView.style.height.substring(0, _albumView.style.height.length - 2));
	var currentThumbsHeight = parseInt(_thumbView.style.height.substring(0, _thumbView.style.height.length - 2));

	var delta = currentY - _lastY;

	if (currentSelectorHeight < 50 && delta < 0) return;
				
	_selector.style.height = currentSelectorHeight + delta;
	_albumView.style.height = currentAlbumsHeight + delta;
	_thumbView.style.height = currentThumbsHeight + delta;

	_lastY = currentY;
}

/************************************************************************
*
*	function:	contentResize
*
*	purpose:	
*
*************************************************************************/
function contentResize(ev)
{
	ev = ev || window.event;
	var currentY = ev.screenY;
	
	var currentHeight = parseInt(_contentView.style.height.substring(0, _contentView.style.height.length - 2));

	var delta = currentY - _lastY;

	if (currentHeight < 200 && delta < 0) return;
				
	_contentView.style.height = currentHeight + delta;
	_photoView.style.height = currentHeight + delta;
	_mapView.style.height = currentHeight + delta;
	_commentsView.style.height = currentHeight + delta;
	_photo.style.height = currentHeight + delta;

	_lastY = currentY;
}

/************************************************************************
*
*	function:	showPreferences
*
*	purpose:	
*
*************************************************************************/
function showPreferences()
{
	if (_preferencesView.style.display == "") 
	{
		_plusMinus.src = "images/aggregator/whistler/plus.gif";
		_preferencesView.style.display = "none";
	}
	else 
	{
		_plusMinus.src = "images/aggregator/whistler/minus.gif";
		_preferencesView.style.display = "";
	}
}


