/*****************************************************************************
 *
 * File     : main.js
 * 
 * Project  : Whistler
 * 
 * Contents : Main dump
 *
 * Author: 
 *
 * Copyright 2007 Whistler Info
 * http://www.whistlerinfo.ca
 * All rights reserved.
 * 
 ***|***************************|***********************|*******************|*/

var _gallery;

var _selector;
var _albumPanel;
var _albumView;
var _thumbPanel;
var _thumbView;

var _contentView;
var _photoView;
var _photo;
var _mapView;
var _commentsView;

var _descriptionView;
var _lastX;
var _lastY;
var _xmlhttp;

var _preferencesView;
var _plusMinus;


/************************************************************************
*
*	function:	initializeGallery
*
*	purpose:	initial photo display
*
*************************************************************************/
function initializeGallery()
{
	_gallery = document.getElementById("gallery");

	_selector = document.getElementById("selector");
	_albumPanel = document.getElementById("albumPanel");
	_albumView = document.getElementById("albumView");
	_thumbPanel = document.getElementById("thumbPanel");
	_thumbView = document.getElementById("thumbView");

	_contentView = document.getElementById("contentView");
	_photoView = document.getElementById("photoView");
	_photo = document.getElementById("photo");
	_mapView = document.getElementById("mapView");
	_commentsView = document.getElementById("commentsView");
	
	_descriptionView = document.getElementById("descriptionView");
	
	_preferencesView = document.getElementById("preferencesView");
	_plusMinus = document.getElementById("plusMinus");

	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		_thumbPanel.style.width = "508px";
		//_thumbPanel.style.width = "563px";
		//_mapView.style.width = "782px";
		//_mapView.style.height = "482px";
	}

	_gallery.style.display = "";
	
	loadAlbums();
}

/************************************************************************
*
*	function:	loadAlbums
*
*	purpose:	
*
*************************************************************************/
function loadAlbums()
{
	try
	{
		_xmlhttp = createXMLHTTPObject();
		_xmlhttp.onreadystatechange = albumsLoaded;
		// Use POST because no time for finding how to disable IE caching of GET
		//_xmlhttp.open("POST", "http://dev.whistlerinfo.ca:8050/wmst/http?request=getgallery&app=whistler", true);
		_xmlhttp.open("POST", "?request=getgallery&app=whistler", true);
		_xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		_xmlhttp.send(null);
	}
	catch (exception)
	{
		alert("can't load albums" + exception.name + ": " + exception.message);
	}
}

/************************************************************************
*
*	function:	albumsLoaded
*
*	purpose:	
*
*************************************************************************/
function albumsLoaded()
{
	if (_xmlhttp.readyState != 4) return;
	_albumView.innerHTML = _xmlhttp.responseText;
	
	var albums = getChildNodes(_albumView, "div");
	var albumIndex = Math.floor(Math.random()*3)
	changeAlbum(albums[albumIndex]);
}

