/*=============================================================================

			 TITLE:		Standard Utility Library
		MODIFIED:		2006.02.14
   AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		REQUIRES:		Prototype - conio.prototype.js ( www.conio.com )
								Behavior - bennolan.behavior.js
								Scriptaculous - scriptaculous.core.js, scriptaculous.effects.js (script.aculo.us)

=============================================================================*/

var behaviorRules = {
	".GalleryThumbnail img" : function(element)
					{
						Event.observe( element, "click", function() { showLargeImage(element); }, false );
					}
};


function imgOn( img )
{
	$(img).src = $(img).src.replace( "-off.", "-on." );
}

function imgOff( img )
{
	$(img).src = $(img).src.replace( "-on.", "-off." );
}

function showLargeImage(thumbnail)
{
	var sOffset = nmoGetScrollOffset();
	var pSize = nmoGetPageSize();
	var newHTML = '<img src="' + thumbnail.src.replace( "-tn", "" ) + '" alt="" class="BorderedPic" onclick="hideLargeImage();">';
	Element.setOpacity( "galleryImageViewer", 0 );
	Element.update( "galleryImageViewerImg", newHTML );
	Element.setStyle( "galleryImageViewer", { "top" : ( sOffset[1] + 20 ) + "px" } );
	Element.setStyle( "popupScreen", { "padding-bottom" : ( pSize[1] / 4 ) + "px" } );
	$( "popupScreen" ).style.display = "block";
	Effect.Appear( "galleryImageViewer", { "duration" : .25 } );
}

function hideLargeImage()
{
	$( "popupScreen" ).style.display = "none";
	Effect.Fade( "galleryImageViewer", { "duration" : .25 } );
}

function findParentByClassName ( el, className )
{
	var foundEl = "NULL";
	if ( hasClass( el.parentNode, className ) )
	{
		foundEl = el.parentNode;
	}
	else
	{
		foundEl = findParentByClassName( el.parentNode, className );
	}
	return foundEl;
}

// className functions

// Dean Edwards 2004.10.24

function addClass(element, className) {
    if (!hasClass(element, className)) {
        if (element.className) element.className += " " + className;
        else element.className = className;
    }
};

function removeClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    element.className = element.className.replace(regexp, "$2");
};

function hasClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    return regexp.test(element.className);
};

function nmoInit()
{
	//
	//	VIEWPORT DETECTION
	//
	Element.setOpacity( "popupScreen", .55 );
}

function nmoGetViewportSize()
{
	var w, h;
	var dimensions = new Array();
	
	// WINDOW SIZE
	if (self.innerHeight) // all except Explorer
	{
		w = self.innerWidth;
		h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	dimensions.push(w);
	dimensions.push(h);
	return dimensions;
}

function nmoGetScrollOffset()
{
	var x, y;
	var coords = new Array();

// SCROLL OFFSET
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	coords.push(x);
	coords.push(y);
	return coords;
}

function nmoGetPageSize()
{
	var w, h;
	var dimensions = new Array();
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	
	// PAGE HEIGHT
	if ( test1 > test2 ) // all but Explorer Mac
	{
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	}
	else // Explorer Mac;
			 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	}
	dimensions.push(w);
	dimensions.push(h);
	return dimensions;
}

Behaviour.register(behaviorRules);
Event.observe( window, "load", nmoInit, false );

