/**
 * Main javascript file
 */

var DEBUG_MODE = false;

//page file name constants
var PAGE_BIO = "bio";
var PAGE_CONTACT = "contact";
var PAGE_FURNITURE = "furniture";
var PAGE_RAILINGS = "railings";
var PAGE_SCULPTURE = "sculpture";
var PAGE_TREEFORT = "treefort";
var PAGE_OTHER = "other";
var PAGES = [PAGE_BIO, PAGE_CONTACT, PAGE_FURNITURE, PAGE_RAILINGS, PAGE_SCULPTURE, PAGE_TREEFORT, PAGE_OTHER];

$(function() {
	
	setNavigation();
	
});

function trace(msg)
{
	if(DEBUG_MODE)
		console.log(msg);
}

// CSS and DHTML powered ImageGallery  
// Created in April 2004 by Dasme - dasme *at* dasme.org
//  - http://dasme.org/imagegal/
//
// Script based on ideas from Jeremy Keith and AListApart.com
// http://www.alistapart.com/articles/imagegallery/
//
// If you use this code in your page, please leave these comments in.
// A quick email with the location of your gallery would be cool too. 
// I always like to see what others have done with my scripts.
//

function DOMCall(name) {
	if (document.layers) 
		return document.layers[name];
	else if (document.all)
		return document.all[name];
	else if (document.getElementById)
		return document.getElementById(name);
}
function showPic (whichpic) {
	DOMCall('placeholder').src = whichpic.href;
	if (whichpic.title) {
		DOMCall('imageCaption').innerHTML = whichpic.title;
		DOMCall('imageCaption').className = "";
	} else {
		DOMCall('imageCaption').className = "hidden";
	}
 	return false;
}

function switchPage(pageId) {
DOMCall('page1').className = "hidden";
DOMCall('page2').className = "hidden";

DOMCall(pageId).className = "asdasd"; // set the current page to junk so it becomes visible
}

//rollover of logo

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
 * load treefort slideshow code into an iframe into the main centre div
 */
function loadTreefortModule()
{
	$('#centre').hide();
	$('#thumbnails').hide();
	$('#dyn_content').show();
	
	var loc = window.location.toString();
	if(loc.indexOf('.htm') != -1 || loc.indexOf('.html') != -1){
		var index = loc.lastIndexOf('/');
		loc = loc.substring(0, index);
	}
	var url = loc + "/treefort_slideshow/index.htm";
	$('#dyn_content iframe').attr('src', url);
	trace("Loading treefort module: " + url);
}

/*
 * sets the navigation depending on the page name, page name is set with the constant variables at the top of this file
 */
function setNavigation()
{
	var location = window.location.toString();
	var page = PAGE_RAILINGS;
	
	for(var i=0; i<PAGES.length; i++)
	{
		if(location.indexOf(PAGES[i]) != -1){
			page = PAGES[i];
			break;
		}
	}
	
	var nav = "#nav_" + page;
	$(nav).css("font-weight", "bold");
	$(nav).text(page);
	
	trace("Current page is: " + page);
	
	if(page == PAGE_TREEFORT)
		loadTreefortModule();
}

function resetNavigation()
{
	for(var i=0; i<PAGES.length; i++)
	{
		var nav = "#nav_" + PAGES[i];
		$(nav).css("font-weight", "normal");
		var link = "<a href='" + PAGES[i] + ".htm'>" + PAGES[i] + "</a>";
		$(nav).html(link); 
	}
}




