	/***********************************************************************************************
	
	Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com
	
	UPDATE LOG:
	
	March, 10th, 2006 : Added support for a message while large image is loading
	
	Get this and other scripts at www.dhtmlgoodies.com
	
	You can use this script freely as long as this copyright message is kept intact.
	
	***********************************************************************************************/ 

	// VARIABLE FOR IMAGE LIBRARY
	var IMAGE_LIB = "images/lib/"
	var displayWaitMessage=true;	// Display a please wait message while images are loading?
	var activeImage = false;
	var imageGalleryLeftPos = false;
	var imageGalleryWidth = false;
	var imageGalleryObj = false;
	var maxGalleryXPos = false;
	var slideSpeed = 0;
	var maxslidespeed = 20;
	var imageGalleryCaptions = new Array();
	var poppedimage;
	// You can modify these three values
	var slideshow1_noFading = false;	// Just normal show/hide without fading ?
	var slideshow1_fadingSpeed = 10;	// Speed of fading
	var slideshow1_vertical=true; 

	/* Don't change any of these values */
	var slideshow1_currentOpacity;	// Initial opacity
	var ImgGallerySrc = new Array(); //preloaded images
		
	function startSlide(e)
	{
		if(document.all)e = event;
		var id = this.id;
		var imagepath = this.getElementsByTagName('IMG')[0].src
		if (imagepath.search(/_over.gif/) > 0){
			//already correct picture do nothing
		}else{
			this.getElementsByTagName('IMG')[0].src = imagepath.replace(/.gif/,"_over.gif");	
		}
		if (slideshow1_vertical) {
			var Y = e.clientY + document.body.scrollTop;
			if(this.id=='arrow_right'){
				slideSpeedMultiply = Math.floor((Y - this.offsetTop) / 5);
				slideSpeed = -1*slideSpeedMultiply;
				slideSpeed = Math.max(-10,slideSpeed);
			}else{			
				slideSpeedMultiply = 10 - Math.floor((Y - this.offsetTop) / 5);
				slideSpeed = 1*slideSpeedMultiply;
				slideSpeed = Math.min(10,slideSpeed);
				if(slideSpeed<0)slideSpeed=10;
			}
		} else {
			var X = e.clientX + document.body.scrollLeft
			if(this.id=='arrow_right'){
				slideSpeedMultiply = Math.floor((X - this.offsetLeft) / 5);
				slideSpeed = -1*slideSpeedMultiply;
				slideSpeed = Math.max(-10,slideSpeed);
			}else{			
				slideSpeedMultiply = 10 - Math.floor((X - this.offsetLeft) / 5);
				slideSpeed = 1*slideSpeedMultiply;
				slideSpeed = Math.min(10,slideSpeed);
				if(slideSpeed<0)slideSpeed=10;
			}
		}
	}
	
	function releaseSlide()
	{
		var id = this.id;
		var imagepath = this.getElementsByTagName('IMG')[0].src
		this.getElementsByTagName('IMG')[0].src = imagepath.replace(/_over.gif/,".gif");	
		slideSpeed=0;
		maxslidespeed=20;
	}
	function speedupslide(){
		maxslidespeed =5;	
	}
		
	function resetspeed(){
		maxslidespeed =20;
	}
	function gallerySlide()
	{
		if(slideSpeed!=0){
			if (slideshow1_vertical) {
				var leftPos = imageGalleryObj.offsetTop;
				leftPos = leftPos/1 + slideSpeed;
				if(leftPos>maxGalleryXPos){
					leftPos = maxGalleryXPos;
					slideSpeed = 0;
				}
				if(leftPos<minGalleryXPos){
					leftPos = minGalleryXPos;
					slideSpeed=0;
				}
				imageGalleryObj.style.top = leftPos + 'px';
			} else {
				var leftPos = imageGalleryObj.offsetLeft;
				leftPos = leftPos/1 + slideSpeed;
				if(leftPos>maxGalleryXPos){
					leftPos = maxGalleryXPos;
					slideSpeed = 0;
				}
				if(leftPos<minGalleryXPos){
					leftPos = minGalleryXPos;
					slideSpeed=0;
				}
				imageGalleryObj.style.left = leftPos + 'px';
			}
		}
		setTimeout('gallerySlide()',maxslidespeed);
		
	}
	
	function showImage()
	{
		if(activeImage){
			activeImage.style.filter = 'alpha(opacity=50)';	
			activeImage.style.opacity = 0.5;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		activeImage = this;	
	}
	
	function initSlideShow()
	{
		document.getElementById('arrow_left').onmousemove = startSlide;
		document.getElementById('arrow_left').onmouseout = releaseSlide;
		document.getElementById('arrow_left').onmousedown = speedupslide;
		document.getElementById('arrow_left').onmouseup = resetspeed;
		document.getElementById('arrow_right').onmousemove = startSlide;
		document.getElementById('arrow_right').onmouseout = releaseSlide;
		document.getElementById('arrow_right').onmousedown = speedupslide;
		document.getElementById('arrow_right').onmouseup = resetspeed;

		imageGalleryObj = document.getElementById('theImages');
		if (slideshow1_vertical) {
			imageGalleryLeftPos = imageGalleryObj.offsetTop;
			imageGalleryWidth = document.getElementById('galleryContainer').offsetHeight;
			maxGalleryXPos = imageGalleryObj.offsetTop; 
			minGalleryXPos = imageGalleryWidth - document.getElementById('picture_table').offsetHeight;
		} else {
			imageGalleryLeftPos = imageGalleryObj.offsetLeft;
			imageGalleryWidth = document.getElementById('galleryContainer').offsetWidth;
			maxGalleryXPos = imageGalleryObj.offsetLeft; 
			minGalleryXPos = imageGalleryWidth - document.getElementById('picture_table').offsetWidth;
		}
		var slideshowImages = imageGalleryObj.getElementsByTagName('IMG');
		for(var no=0;no<slideshowImages.length;no++){
			slideshowImages[no].onmouseover = showImage;
		}
		
		var divs = imageGalleryObj.getElementsByTagName('DIV');
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='imageCaption')imageGalleryCaptions[imageGalleryCaptions.length] = divs[no].innerHTML;
		}
		gallerySlide();
		//preload images
		InitImgGallerySrc('theImages');
		//Format first picture
		var thumbpath = slideshowImages[0].src
		var imagepath = thumbpath.replace(/_thumb.jpg/i,".jpg")
		showPreview(imagepath,1);
	}
	
	function showPreview(imagePath,imageIndex){
		var subImages = document.getElementById('previewPane').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			document.getElementById('previewPane').appendChild(img);
		}else img = subImages[0];
		if(displayWaitMessage){
			var waitobject = document.getElementById('waitmessage');
			var waitimg = waitobject.getElementsByTagName('IMG');
			waitobject.style.display="";
			img.style.display="none";
		}
		document.getElementById('largeImageCaption').style.display='none';
		img.onload = function(){hideWaitMessageAndShowCaption(imageIndex-1);};
	//make new image with original size
		var oimage = new Image();
		oimage.onload = function(){imgPreload(img,oimage,imageIndex);};
		oimage.src = imagePath;
	}
	
	function imgPreload(img, oimage, imageIndex)
	{
		var oldwidth = oimage.width;
		var oldheight = oimage.height;
	//resize picture to fit previewpane
		if (slideshow1_vertical) {
			var lwidth = 677;
			var lheight = 400;
		} else {
			var lwidth = 550;
			var lheight = 400;
		}
		var newratio = Math.min(lwidth/oldwidth, lheight/oldheight);
		var newheight = Math.round(oldheight * newratio);
		var newwidth = Math.round(oldwidth * newratio);
		var imagepath = oimage.src;
		img.setAttribute("pbSrcNL",imagepath);
		//img.pbSrcNL = oimage.src;
		var imagecaption = imageGalleryCaptions[imageIndex-1];
		img.setAttribute("pbCaption", imagecaption);	
		//img.pbCaption = imageGalleryCaptions[imageIndex-1];
		img.width = newwidth;
		img.height = newheight;
		img.style.filter = 'alpha(opacity=0)';
		img.src = oimage.src;
		img.style.display=''
		slideshow1_currentOpacity = 70;
		revealImageSlideShow(img)
	}
	
	function revealImageSlideShow(img){
		if(slideshow1_noFading){
			img.style.filter = 'alpha(opacity=100)';
			return;
		}
		if (navigator.userAgent.indexOf("MSIE")!=-1){
			img.style.filter = 'alpha(opacity='+(100-slideshow1_currentOpacity)+')';
		}else if (navigator.userAgent.indexOf("Firefox")!=-1){
			img.style.opacity = Math.min(0.99,(1 - (slideshow1_currentOpacity/100)));
		} else {
			img.style.filter = 'alpha(opacity=100)';
			return;
		}
		slideshow1_currentOpacity--;
		if(slideshow1_currentOpacity > 0){
			setTimeout(function(){revealImageSlideShow(img);},slideshow1_fadingSpeed);
		}
	}
	function hideWaitMessageAndShowCaption(imageIndex)
	{
		var waitobject = document.getElementById('waitmessage');
		var waitimg = waitobject.getElementsByTagName('IMG');
		waitobject.style.display="none";
		document.getElementById('largeImageCaption').innerHTML = imageGalleryCaptions[imageIndex];
		document.getElementById('largeImageCaption').style.display='block';
		
	}
	// add initialization to window.onload
	//Will be implemented at end of file //window.onload = initSlideShow; 

	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	// You can modify these three values
	var slideshow2_noFading = false;	// Just normal show/hide without fading ?
	var slideshow2_timeBetweenSlides = 1500;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 20;	// Speed of fading
	
	
	/* Don't change any of these values */
	var slideshow2_galleryHeigh;	// Height of galery	
	var slideshow2_galleryContainer;	// Reference to the gallery div
	var slideshow2_galleryWidth;	// Width of gallery	
	var slideshow2_slideIndex = -1;	// Index of current image shown
	var slideshow2_slideIndexNext = false;	// Index of next image shown
	var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = 100;	// Initial opacity
	var slideshow2_imagesInGallery = false;	// Number of images in gallery
	
	function getGalleryImageSize(imageIndex)
	{
		if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
		}else{
			var imgObj = document.getElementById('galleryImage' + imageIndex);
			var imgWidth = imgObj.width;
			var imgHeight = imgObj.height;
			if(imgWidth>50){						
				var tmpDiv = document.createElement('DIV');
				tmpDiv.id = 'galleryDiv' + imageIndex;
				tmpDiv.style.visibility = 'visible';
				tmpDiv.className='imageInGallery';
				imgObj.style.visibility = "hidden";
				slideshow2_galleryContainer.appendChild(tmpDiv);
				tmpDiv.appendChild(imgObj);
				//imgObj.style.left = Math.round((slideshow2_galleryWidth - imgWidth)/2)  + "px";
				//imgObj.style.top = Math.round((slideshow2_galleryHeight - imgHeight)/2)  + "px";
				//tmpDiv.style.visibility = 'hidden';
				slideshow2_imageDivs.push(tmpDiv);
				imageIndex++;
				getGalleryImageSize(imageIndex);
			}else{
				setTimeout('getGalleryImageSize(' + imageIndex + ')',10);
			}
		}		
	}
	
	function showGallery()
	{

		if(slideshow2_slideIndex==-1)slideshow2_slideIndex=0; else slideshow2_slideIndex++;	// Index of next image to show
		if(slideshow2_slideIndex==slideshow2_imageDivs.length)slideshow2_slideIndex=0;
		slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
		if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)slideshow2_slideIndexNext = 0;
		
		var dimgCurrent = slideshow2_imageDivs[slideshow2_slideIndex].childNodes[0];
		var dimgNext = slideshow2_imageDivs[slideshow2_slideIndexNext].childNodes[0];
		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		dimgCurrent.style.visibility = 'visible';
		if(navigator.userAgent.indexOf('Opera')<0){
			dimgNext.style.visibility = 'visible';
		}
		
		if(navigator.userAgent.indexOf("MSIE")!=-1){	// IE rules
			dimgCurrent.style.filter = 'alpha(opacity=100)';
			dimgNext.style.filter = 'alpha(opacity=1)';
		}else{
			dimgCurrent.style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			dimgNext.style.opacity = 0.01;
		}		
		

		setTimeout('revealImageImageGallery()',slideshow2_timeBetweenSlides);		
	}
	
	function revealImageImageGallery()
	{
		var dimgCurrent = slideshow2_imageDivs[slideshow2_slideIndex].childNodes[0];
		var dimgNext = slideshow2_imageDivs[slideshow2_slideIndexNext].childNodes[0];
		if(slideshow2_noFading){
			dimgCurrent.style.visibility = 'hidden';
			showGallery();
			return;
		}
		slideshow2_currentOpacity--;
		if(navigator.userAgent.indexOf("MSIE")!=-1){
			dimgCurrent.style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			dimgNext.style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			dimgCurrent.style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			dimgNext.style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		if(slideshow2_currentOpacity>0){
			setTimeout('revealImageImageGallery()',slideshow2_fadingSpeed);
		}else{
			dimgCurrent.style.visibility = 'hidden';			
			showGallery();
		}
	}
	
	function initImageGallery(){

		var tallest = 0;
		slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
		for(var no=0;no<galleryImgArray.length;no++){
			galleryImgArray[no].id = 'galleryImage' + no;
		//get tallest image in gallery
			tallest = tallest < galleryImgArray[no].height?galleryImgArray[no].height:tallest;
			slideshow2_galleryContainer.style.height = tallest + "px";
		}
		//preload images
		InitImgGallerySrc('imageSlideshowHolder');
		slideshow2_imagesInGallery = galleryImgArray.length;
		getGalleryImageSize(0);			
	}
	// loads all the popped src images
function InitImgGallerySrc(containerid){
	var images = null;
	if (document.body){
		if (document.body.getElementsByTagName){
			var sholder = document.getElementById(containerid);
			images = sholder.getElementsByTagName("img");
		} else if (document.body.all){
			//var sholder = document.getElementById(containerid);
			images = document.body.all.tags("img");
		}
	}
	if (images != null){
		for (var x = 0; x < images.length; x++){
			var oldimage = images[x].src;
			var poppedSrc = oldimage.replace("_thumb.jpg",".jpg");
			if (poppedSrc != null && ImgGallerySrc[poppedSrc] == null){
				ImgGallerySrc[poppedSrc] = new Image();
				ImgGallerySrc[poppedSrc].src = poppedSrc;
			}
		}
	}
}
/*****************************************************************************************************
the following code will be for the pop-up window
******************************************************************************************************/


/********************************************************************************************************************
* PopBox.js, v2.3 released September 20, 2007. Copyright (c) 2007, C6 Software, Inc. (http://www.c6software.com/)
* PopBox is released under the Creative Commons Attribution 3.0 license (http://creativecommons.org/licenses/by/3.0/)
* and is free to use in both commercial and non-commercial work, provided this header remains at the top.
* The latest version and documentation can be found at http://www.c6software.com/products/popbox/default.aspx.
* Questions and suggestions can be sent to john.reid@c6software.com. Please put "PopBox" somewhere in the
* email subject so I can easily filter. Send me your URL and I may post it!
* PopBox relies on many methods from Danny Goodman's (www.dannyg.com) javascript library DHTMLAPI.js
* and his books, without which scores of web developers would be totally lost. Thanks Danny.
********************************************************************************************************************/

// Seek nested NN4 layer from string name
function SeekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = SeekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference into a valid element object reference
function GetRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
		var isCSS = (document.body && document.body.style) ? true : false;
        if (isCSS && document.getElementById) {
            theObj = document.getElementById(obj);
        } else if (isCSS && document.all) {
            theObj = document.all(obj);
        } else if (document.layers) {
            theObj = SeekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference into a valid style (or NN4 layer) reference
function GetObject(obj) {
    var theObj = GetRawObject(obj);
    if (theObj && document.body && document.body.style) {
        theObj = theObj.style;
    }
    return theObj;
}

// Return the available content width and height space in browser window
function GetInsideWindowSize() {
	if (popBoxBrowserOnly) {
		if (window.innerWidth) {
		    return {x:window.innerWidth, y:window.innerHeight};
		} else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
		    return {x:document.body.parentNode.clientWidth, y:document.body.parentNode.clientHeight};
		} else if (document.body && document.body.clientWidth) {
		    return {x:document.body.clientWidth, y:document.body.clientHeight};
		}
    } else {
		return {x:screen.availWidth, y:screen.availHeight};
    }
    return 0;
}

// Retrieve the x coordinate of a positionable object
function GetObjectLeft(obj)  {
    var elem = GetRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (document.layers) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function GetObjectTop(obj)  {
    var elem = GetRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (document.layers) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the padding around an object
function GetObjectPadding(obj) {
	var elem = GetRawObject(obj);

	var l = 0;
	var r = 0;
	var t = 0;
	var b = 0;
	if (elem.currentStyle)
	{
		if (elem.currentStyle.paddingLeft)
			l = parseInt(elem.currentStyle.paddingLeft, 10);
		if (elem.currentStyle.paddingRight)
			r = parseInt(elem.currentStyle.paddingRight, 10);
		if (elem.currentStyle.paddingTop)
			t = parseInt(elem.currentStyle.paddingTop, 10);
		if (elem.currentStyle.paddingBottom)
			b = parseInt(elem.currentStyle.paddingBottom, 10);
	}
	else if (window.getComputedStyle)
	{
		l = parseInt(window.getComputedStyle(elem,null).paddingLeft, 10);
		r = parseInt(window.getComputedStyle(elem,null).paddingRight, 10);
		t = parseInt(window.getComputedStyle(elem,null).paddingTop, 10);
		b = parseInt(window.getComputedStyle(elem,null).paddingBottom, 10);
	}
	if (isNaN(l) == true) l = 0;
	if (isNaN(r) == true) r = 0;
	if (isNaN(t) == true) t = 0;
	if (isNaN(b) == true) b = 0;

	return {l:(l),r:(r),t:(t),b:(b)};
}

// Retrieve the rendered size of an element
function GetObjectSize(obj)  {
    var elem = GetRawObject(obj);
    var w = 0;
    var h = 0;
    if (elem.offsetWidth) {
			w = elem.offsetWidth; h = elem.offsetHeight;
    } else if (elem.clip && elem.clip.width) {
			w = elem.clip.width; h = elem.clip.height;
    } else if (elem.style && elem.style.pixelWidth) {
			w = elem.style.pixelWidth; h = elem.style.pixelHeight;
    }
    
    w = parseInt(w, 10);
    h = parseInt(h, 10);
    
   // remove any original element padding
   var padding = GetObjectPadding(elem);
   w -= (padding.l + padding.r);
   h -= (padding.t + padding.b);

   return {w:(w), h:(h)};
}

// Return the element position in the page, not it's parent container
function GetElementPosition(obj)
{
	var elem = GetRawObject(obj);
	var left = 0;
	var top = 0;

	// add any original element padding
	var elemPadding = GetObjectPadding(elem);
	left = elemPadding.l;
	top = elemPadding.t;

	if (elem.offsetParent)
	{
		left += elem.offsetLeft;
		top += elem.offsetTop;
		var parent = elem.offsetParent;
		while (parent)
		{
			left += parent.offsetLeft;
			top += parent.offsetTop;
			var parentTagName = parent.tagName.toLowerCase();
			if (parentTagName != "table" &&
				parentTagName != "body" && 
				parentTagName != "html" && 
				parentTagName != "div" && 
				parent.clientTop && 
				parent.clientLeft)
			{
				left += parent.clientLeft;
				top += parent.clientTop;
			}

			parent = parent.offsetParent;
		}
	}
	else if (elem.left && elem.top)
	{
		left = elem.left;
		top = elem.top;
	}
	else
	{
		if (elem.x)
			left = elem.x;
		if (elem.y)
			top = elem.y;
	}
	return {x:left, y:top};
}

// return the number of pixels the scrollbar has moved the visible window
function GetScrollOffset()
{
	if (popBoxBrowserOnly) {
		if (window.pageYOffset) {
		    return {x:window.pageXOffset, y:window.pageYOffset};
		} else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
		    return {x:document.documentElement.scrollLeft, y:document.documentElement.scrollTop};
		} else if (document.body && document.body.clientWidth) {
		    return {x:document.body.scrollLeft, y:document.body.scrollTop};
		}
    }
    return {x:0, y:0};
    
}

// Retrieve the element position if the object were centered in the browser window at the given width and height
function GetCenteredWindowPoint(w, h)
{
	var size = GetInsideWindowSize();
	var scroll = GetScrollOffset();

	// get half the window size for center, then add the scroll values and then subtract half of the element size to get the top left pixel
	var newLeft = ((size.x / 2) + scroll.x) - (w / 2);
	var newTop = ((size.y / 2) + scroll.y) - (h / 2);
	
	return {x:newLeft, y:newTop};
}

function CreateRandomId()
{
	var randomNum = 0.0;
	while (randomNum == 0.0)
		randomNum = Math.random();
	var random = randomNum + "";
	return "id" + random.substr(2);
}

// holds numerous properties related to position, size and motion
var popBox = new Array();
// holds positioning value for the z axis
var popBoxZ = 100;
// holds the popped image for each <img> tag with a pbsrc attribute
var pbSrc = new Array();
// holds the popbar function for each <img> tag with a pbShowPopBar attribute
var pbPopBarFunc = new Array();

// loads all the popped src images
function InitPbSrc()
{
	var images = null;
	if (document.body)
	{
		if (document.body.getElementsByTagName)
			images = document.body.getElementsByTagName("img");
		else if (document.body.all)
			images = document.body.all.tags("img");
	}

	if (images != null)
	{
		for (var x = 0; x < images.length; x++)
		{
			var poppedSrc = images[x].getAttribute('pbSrc');
			if (poppedSrc != null && pbSrc[images[x].src] == null)
			{
				pbSrc[images[x].src] = new Image();
				pbSrc[images[x].src].src = poppedSrc;
			}
		}
	}
}

// adds PopBar to images
function InitPbPopBar()
{
	var images = null;
	if (document.body)
	{
		if (document.body.getElementsByTagName)
			images = document.body.getElementsByTagName("img");
		else if (document.body.all)
			images = document.body.all.tags("img");
	}

	if (images != null)
	{
		var imgArray = new Array();
		for (var x = 0; x < images.length; x++)
		{
			if (images[x].id == "")
				images[x].id = CreateRandomId();
			
			imgArray[x] = images[x];
		}

		for (var x = 0; x < imgArray.length; x++)
			CreatePopBar(imgArray[x]);
	}
}

// initialize default popbox object
function InitPopBox(obj)
{
	obj = GetRawObject(obj);
	if (typeof popBox[obj.id] != undefined && popBox[obj.id] != null)
		return obj;
	var parent = document.body;
	if (obj.id == "")
		obj.id = CreateRandomId();

	var elem = obj;
	var startPos = GetElementPosition(elem);
	var initSize = GetObjectSize(elem);
	if (elem.style.position == "absolute" || elem.style.position == "relative")
	{
		parent = elem.parentNode;
		startPos.x = parseInt(elem.style.left, 10);
		startPos.y = parseInt(elem.style.top, 10);
	}
	
	// if there is a pbsrc then create that, else if it's not absolute or relative then create a copy
	if (pbSrc[elem.src] != null || (elem.style.position != "absolute" && elem.style.position != "relative"))
	{
		var img = document.createElement("img");
		// copy image properties
		img.border = elem.border;
		img.className = elem.className;
		img.height = elem.height;
		img.id = "popcopy" + elem.id;
		img.src = (pbSrc[elem.src] != null) ? pbSrc[elem.src].src : elem.src;
		img.alt = elem.alt;
		img.title = elem.title;
		img.width = elem.width;
		img.onclick = elem.onclick;
		img.ondblclick = elem.ondblclick;
		img.onmouseout = elem.onmouseout;

		// remove event so the object doesn't jump
		elem.onmouseout = null;

		img.style.width = initSize.w;
		img.style.height = initSize.h;
		img.style.position = "absolute";
		img.style.left = startPos.x + "px";
		img.style.top = startPos.y + "px";
		img.style.cursor = elem.style.cursor;
		
		parent.appendChild(img);
		elem.style.visibility = "hidden";
		elem = img;
	}
	
	popBox[elem.id] = {	elemId:elem.id,
							xCurr:0.0,
							yCurr:0.0,
							xTarg:0.0,
							yTarg:0.0,
							wCurr:0.0,
							hCurr:0.0,
							wTarg:0.0,
							hTarg:0.0,
							xStep:0.0,
							yStep:0.0,
							wStep:0.0,
							hStep:0.0,
							xDelta:0.0,
							yDelta:0.0,
							wDelta:0.0,
							hDelta:0.0,
							xTravel:0.0,
							yTravel:0.0,
							wTravel:0.0,
							hTravel:0.0,
							velM:1.0,
							velS:1.0,
							interval:null,
							isAnimating:false,
							xOriginal:0.0,
							yOriginal:0.0,
							wOriginal:0.0,
							hOriginal:0.0,
							isPopped:false,
							fnClick:null,
							fnDone:null,
							fnPre:null,
							originalId:null,
							cursor:""
							};
							
	popBox[elem.id].xOriginal = startPos.x;
	popBox[elem.id].yOriginal = startPos.y;
	popBox[elem.id].wOriginal = parseFloat(initSize.w);
	popBox[elem.id].hOriginal = parseFloat(initSize.h);

	if (typeof obj.onclick == "function")
	{
		popBox[elem.id].fnClick = elem.onclick;
		
		if (popBoxAutoClose == true && (typeof obj.ondblclick != "function" || obj.ondblclick == null) && typeof obj.onmouseover != "function")
			elem.ondblclick = function(){Revert(elem.id, null, elem.className);};
	}

	if (popBoxAutoClose == true && typeof obj.onmouseover == "function" && (typeof obj.onmouseout != "function" || obj.onmouseout == null))
	{
		elem.onmouseout = function(){Revert(elem.id, null, elem.className);};
	}

	if (obj.id != elem.id)
		popBox[elem.id].originalId = obj.id;
		
	return elem;
}

// calculate next steps and assign to style properties
function DoPopBox(elem)
{
	if (typeof elem == "string") elem = GetRawObject(elem);
	try
	{
		var bMDone = false;
		var bSDone = false;
		if ((popBox[elem.id].xTravel + Math.abs(popBox[elem.id].xStep)) < popBox[elem.id].xDelta)
		{
			var x = popBox[elem.id].xCurr + popBox[elem.id].xStep;
			elem.style.left = parseInt(x, 10) + "px";
			popBox[elem.id].xTravel += Math.abs(popBox[elem.id].xStep);
			popBox[elem.id].xCurr = x;
		} else {
			popBox[elem.id].xTravel += Math.abs(popBox[elem.id].xStep);
			elem.style.left = parseInt(popBox[elem.id].xTarg, 10) + "px";
			bMDone = true;
		}
		if ((popBox[elem.id].yTravel + Math.abs(popBox[elem.id].yStep)) < popBox[elem.id].yDelta)
		{
			var y = popBox[elem.id].yCurr + popBox[elem.id].yStep;
			elem.style.top = parseInt(y, 10) + "px";
			popBox[elem.id].yTravel += Math.abs(popBox[elem.id].yStep);
			popBox[elem.id].yCurr = y;
			bMDone = false;
		} else {
			popBox[elem.id].yTravel += Math.abs(popBox[elem.id].yStep);
			elem.style.top = parseInt(popBox[elem.id].yTarg, 10) + "px";
		}
		if ((popBox[elem.id].wTravel + Math.abs(popBox[elem.id].wStep)) < popBox[elem.id].wDelta)
		{
			var w = popBox[elem.id].wCurr + popBox[elem.id].wStep;
			elem.style.width = parseInt(w, 10) + "px";
			popBox[elem.id].wTravel += Math.abs(popBox[elem.id].wStep);
			popBox[elem.id].wCurr = w;
		} else {
			popBox[elem.id].wTravel += Math.abs(popBox[elem.id].wStep);
			elem.style.width = parseInt(popBox[elem.id].wTarg, 10) + "px";
			bSDone = true;
		}
		if ((popBox[elem.id].hTravel + Math.abs(popBox[elem.id].hStep)) < popBox[elem.id].hDelta)
		{
			var h = popBox[elem.id].hCurr + popBox[elem.id].hStep;
			elem.style.height = parseInt(h, 10) + "px";
			popBox[elem.id].hTravel += Math.abs(popBox[elem.id].hStep);
			popBox[elem.id].hCurr = h;
			bSDone = false;
		} else {
			popBox[elem.id].hTravel += Math.abs(popBox[elem.id].hStep);
			elem.style.height = parseInt(popBox[elem.id].hTarg, 10) + "px";
		}

		var obj = elem;
		
		if (bMDone == true && bSDone == true)
		{
			clearInterval(popBox[elem.id].interval);
			popBox[elem.id].isAnimating = false;
			
			elem.style.cursor = popBox[elem.id].cursor;

			var func = null;
			if (popBox[elem.id].fnDone != null && typeof popBox[elem.id].fnDone == "function")
				func = popBox[elem.id].fnDone;
			
			if (popBox[elem.id].isPopped == true)
			{
				elem.style.zIndex = null;
	
				if (popBox[elem.id].originalId != null)
				{
					obj = GetRawObject(popBox[elem.id].originalId);
					obj.onmouseout = elem.onmouseout; // copy method back to original
					obj.style.visibility = "visible";
					
					// remove the copied object from the body and the array
					elem.parentNode.removeChild(elem);
				}
				else
				{
					elem.style.width = parseInt(popBox[elem.id].wOriginal, 10) + "px";
					elem.style.height = parseInt(popBox[elem.id].hOriginal, 10) + "px";
				
					if (typeof popBox[elem.id].fnClick == "function")
						elem.onclick = popBox[elem.id].fnClick;
				}

				delete popBox[elem.id];
				popBox[elem.id] = null;
				CreatePopBar(obj);
			}
			else
			{
				popBox[elem.id].isPopped = true;
				CreateRevertBar(elem);
			}
				
			if (func != null && typeof func == "function")
				func(obj);
		}
	}
	catch(ex){}
}

function HasRevertBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowBar = elem.getAttribute('pbShowRevertBar');
	var pbShowText = elem.getAttribute('pbShowRevertText');
	var pbShowImage = elem.getAttribute('pbShowRevertImage');
	pbShowBar = (pbShowBar != null) ? (pbShowBar == "true" || pbShowBar == true) : popBoxShowRevertBar;
	pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowRevertText;
	pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowRevertImage;
	
	return (pbShowBar || pbShowText || pbShowImage);
}

function HasCaption(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowCaption = elem.getAttribute('pbShowCaption');
	pbShowCaption = (pbShowCaption != null) ? (pbShowCaption == "true" || pbShowCaption == true) : popBoxShowCaption;
	var pbCaption = null;
	if (pbShowCaption == true)
	{
		pbCaption = elem.getAttribute('pbCaption');
		if (pbCaption == null && elem.title != "") pbCaption = elem.title;
	}

	return (pbCaption != null && pbCaption != "");
}

function CreateRevertBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	
	var elem = obj;
	if (popBox[elem.id] != null && popBox[elem.id].originalId != null)
		elem = GetRawObject(popBox[elem.id].originalId);

	var pbShowBar = elem.getAttribute('pbShowRevertBar');
	var pbShowText = elem.getAttribute('pbShowRevertText');
	var pbShowImage = elem.getAttribute('pbShowRevertImage');
	var pbText = elem.getAttribute('pbRevertText');
	var pbImage = elem.getAttribute('pbRevertImage');
	pbShowBar = (pbShowBar != null) ? (pbShowBar == "true" || pbShowBar == true) : popBoxShowRevertBar;
	pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowRevertText;
	pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowRevertImage;
	if (pbText == null) pbText = popBoxRevertText;
	if (pbImage == null) pbImage = popBoxRevertImage;

	var pbShowCaption = elem.getAttribute('pbShowCaption');
	pbShowCaption = (pbShowCaption != null) ? (pbShowCaption == "true" || pbShowCaption == true) : popBoxShowCaption;
	var pbCaption = null;
	if (pbShowCaption == true)
	{
		pbCaption = elem.getAttribute('pbCaption');
		if (pbCaption == null && elem.title != "") pbCaption = elem.title;
	}

	CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, popBoxRevertBarAbove, true, pbCaption)
}

function CreatePopBar(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	if (typeof pbPopBarFunc[obj.id] != 'undefined' && pbPopBarFunc[obj.id] != null) return;
	var pbShowBar = obj.getAttribute('pbShowPopBar');
	if (pbShowBar != null)
	{
		var pbShowText = obj.getAttribute('pbShowPopText');
		var pbShowImage = obj.getAttribute('pbShowPopImage');
		var pbText = obj.getAttribute('pbPopText');
		var pbImage = obj.getAttribute('pbPopImage');
		pbShowBar = (pbShowBar == "true" || pbShowBar == true);
		pbShowText = (pbShowText != null) ? (pbShowText == "true" || pbShowText == true) : popBoxShowPopText;
		pbShowImage = (pbShowImage != null) ? (pbShowImage == "true" || pbShowImage == true) : popBoxShowPopImage;
		if (pbText == null) pbText = popBoxPopText;
		if (pbImage == null) pbImage = popBoxPopImage;

		CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, popBoxPopBarAbove, false, null)
	}
}

function CreatePbBar(obj, pbShowBar, pbShowText, pbShowImage, pbText, pbImage, pbBarAbove, isRevert, pbCaption)
{
	if (pbShowBar == false && pbShowText == false && pbShowImage == false && pbCaption == null) return;
	if (typeof obj == "string") obj = GetRawObject(obj);

	var objCursor = "hand";
	if (obj.currentStyle)
		objCursor = obj.currentStyle.cursor;
	else if (window.getComputedStyle)
		objCursor = window.getComputedStyle(obj,null).cursor;

	var fnClick = function(){if (typeof obj.onclick == 'function') obj.onclick();};
	var fnMouseOut = function(){if (typeof obj.onmouseout == 'function') obj.onmouseout();};
	var fnMouseOver = function(){if (typeof obj.onmouseover == 'function') obj.onmouseover();};
	var fnRemove = new Array();

	var isPositioned = (obj.style.position == "absolute" || obj.style.position == "relative");
	var left = 0;
	var top = 0;
	var parentNode = obj.parentNode;
	var objSpan = null;
	if (isPositioned == true)
	{
		left = parseInt(obj.style.left, 10);
		top = parseInt(obj.style.top, 10);
		var padding = GetObjectPadding(obj);
		left += padding.l;
		top += padding.t;	
	}
	else
	{
		objSpan = document.createElement("span");
		objSpan = (obj.nextSibling != null) ? parentNode.insertBefore(objSpan, obj.nextSibling) : parentNode.appendChild(objSpan);
		objSpan.style.position = "relative";
		objSpan.style.left = "0px";
		objSpan.style.top = "0px";
		var floatValue = "";
		if (obj.align == "left") floatValue = "left";
		else if (obj.align == "right") floatValue = "right";
		floatValue = (obj.style.styleFloat && obj.style.styleFloat != "") ? obj.style.styleFloat : (obj.style.cssFloat && obj.style.cssFloat != "") ? obj.style.cssFloat : floatValue;
		if (typeof obj.style.styleFloat != undefined) objSpan.style.styleFloat = floatValue;
		else if (typeof obj.style.cssFloat != undefined) objSpan.style.cssFloat = floatValue;
		
		var imgPos = GetElementPosition(obj);
		var spanPos = GetElementPosition(objSpan);
		objSpan.style.left = (spanPos.x > imgPos.x) ? (imgPos.x - spanPos.x) + "px" : imgPos.x - spanPos.x + "px";
		objSpan.style.top = (spanPos.y > imgPos.y) ? (imgPos.y - spanPos.y) + "px" : imgPos.y - spanPos.y + "px";
		
		objSpan.onclick = fnClick;
		if (isRevert == true)
			objSpan.onmouseout = fnMouseOut;
		else
			objSpan.onmouseover = fnMouseOver;
		parentNode = objSpan;
	}

	var width = parseInt(obj.style.width, 10);
	var height = parseInt(obj.style.height, 10);
	var size = GetObjectSize(obj);
	if (isNaN(width) == true)
		width = size.w;
	else if (size.w > width)
		left += ((size.w - width) / 2);
	if (isNaN(height) == true)
		height = size.h;
	else if (size.h > height)
		top += ((size.h - height) / 2);

	if (pbBarAbove == true) top -= 20;
	var z = obj.style.zIndex + 1;

	if (pbShowBar == true)
	{
		var divTrans = document.createElement("div");
		divTrans.id = "popBoxDivTrans" + z;
		divTrans.style.width = width + "px";
		divTrans.style.height = "20px";
		divTrans.style.borderStyle = "none";
		divTrans.style.padding = "0px";
		divTrans.style.margin = "0px";
		divTrans.style.position = "absolute";
		divTrans.style.left = left + "px";
		divTrans.style.top = top + "px";
		divTrans.style.backgroundColor = "#000000";
		divTrans.style.cursor = objCursor;
		divTrans.style.zIndex = z;
		if (pbBarAbove == false)
		{
			if (typeof divTrans.style.filter != 'undefined')
				divTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=20)";
			if (typeof divTrans.style.opacity != 'undefined')
				divTrans.style.opacity = "0.2";
		}
		divTrans.onclick = fnClick;
		if (isRevert == true)
			divTrans.onmouseout = fnMouseOut;
		else
			divTrans.onmouseover = fnMouseOver;
		parentNode.appendChild(divTrans);
		
		fnRemove.push(function(){divTrans.parentNode.removeChild(divTrans);});
	}

	if (pbShowText == true)
	{
		var divText = document.createElement("div");
		divText.id = "popBoxDivText" + z;
		divText.style.width = width + "px";
		divText.style.height = "20px";
		divText.style.borderStyle = "none";
		divText.style.padding = "0px";
		divText.style.margin = "0px";
		divText.style.position = "absolute";
		divText.style.left = left + "px";
		divText.style.top = top + "px";
		divText.style.cursor = objCursor;
		divText.style.textAlign = "center";
		divText.style.fontFamily = "Arial, Verdana, Sans-Serif";
		divText.style.fontSize = "10pt";
		divText.style.backgroundColor = "Transparent";
		divText.style.color = "#ffffff";
		divText.style.zIndex = z;
		divText.innerHTML = pbText;
		divText.onclick = fnClick;
		if (isRevert == true)
			divText.onmouseout = fnMouseOut;
		else
			divText.onmouseover = fnMouseOver;
		parentNode.appendChild(divText);

		fnRemove.push(function(){divText.parentNode.removeChild(divText);});
	}
	
	if (pbShowImage == true)
	{
		var imgPopped = document.createElement("img");
		imgPopped.id = "popBoxImgPopped" + z;
		imgPopped.src = pbImage;
		imgPopped.style.width = "20px";
		imgPopped.style.height = "20px";
		imgPopped.style.borderStyle = "none";
		imgPopped.style.padding = "0px";
		imgPopped.style.margin = "0px";
		imgPopped.style.position = "absolute";
		imgPopped.style.left = (left + width - 20) + "px";
		imgPopped.style.top = top + "px";
		imgPopped.style.cursor = objCursor;
		imgPopped.style.zIndex = z;
		imgPopped.onclick = fnClick;
		if (isRevert == true)
			imgPopped.onmouseout = fnMouseOut;
		else
			imgPopped.onmouseover = fnMouseOver;
		parentNode.appendChild(imgPopped);

		fnRemove.push(function(){imgPopped.parentNode.removeChild(imgPopped);});
	}
	
	if (pbCaption != null && pbCaption != "")
	{
		top += (height - 20);
		if (pbBarAbove == true) top += 20;
		if (popBoxCaptionBelow == true)  top += 20;

		var divCapTrans = document.createElement("div");
		divCapTrans.id = "popBoxDivCapTrans" + z;
		divCapTrans.style.width = width - 2 + "px";
		divCapTrans.style.height = "20px";
		divCapTrans.style.borderStyle = "solid";
		divCapTrans.style.borderWidth = "1px";
		divCapTrans.style.borderColor = "#999999";
		divCapTrans.style.padding = "0px";
		divCapTrans.style.margin = "0px";
		divCapTrans.style.position = "absolute";
		divCapTrans.style.left = left + "px";
		divCapTrans.style.top = top - 1 + "px";
		divCapTrans.style.backgroundColor = "#ffffdd";
		divCapTrans.style.zIndex = z;
		if (popBoxCaptionBelow == false)
		{
			if (typeof divCapTrans.style.filter != 'undefined')
				divCapTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
			if (typeof divCapTrans.style.opacity != 'undefined')
				divCapTrans.style.opacity = "0.7";
		}
		parentNode.appendChild(divCapTrans);
		fnRemove.push(function(){divCapTrans.parentNode.removeChild(divCapTrans);});

		var divCapText = document.createElement("div");
		divCapText.id = "popBoxDivCapText" + z;
		divCapText.style.width = width - 20 + "px";
		divCapText.style.height = "20px";
		divCapText.style.borderStyle = "none";
		divCapText.style.padding = "0px";
		divCapText.style.margin = "0px";
		divCapText.style.position = "relative";
		//divCapText.style.left = left + 10 + "px";
		//divCapText.style.top = top + "px";
		divCapText.style.textAlign = "center";
		divCapText.style.fontFamily = "Arial, Verdana, Sans-Serif";
		divCapText.style.fontSize = "10pt";
		divCapText.style.overflowY = "hidden";
		divCapText.style.backgroundColor = "Transparent";
		divCapText.style.color = "#000000";
		divCapText.style.zIndex = z;
		divCapTrans.appendChild(divCapText);
		fnRemove.push(function(){divCapText.parentNode.removeChild(divCapText);});

		AddCaptionText(divCapTrans, divCapText, pbCaption);
	}

	if (fnRemove.length != 0)
	{
		if (objSpan != null)
			fnRemove.push(function(){objSpan.parentNode.removeChild(objSpan);});
		
		if (isRevert == true)
		{
			if(popBox[obj.id].fnPre != null && typeof(popBox[obj.id].fnPre) == 'function')
				fnRemove.push(popBox[obj.id].fnPre);
		
			popBox[obj.id].fnPre = function(){for(var x = 0; x < fnRemove.length; x++){fnRemove[x]();}};
		}
		else
		{
			pbPopBarFunc[obj.id] = function(){for(var x = 0; x < fnRemove.length; x++){fnRemove[x]();}};
		}
	}
}

//holds caption for popped image
var fullCaption='';
var defaultHeight = 0;
var defaultTop	= '';
var defaultdWidth = 0;	//determines how much text is initially displayed
var noFilter			= ''; //will determine if filter should be applied
function AddCaptionText(divCapTrans, divCapText, caption, dWidth, booNoFilter)
{
	if (!dWidth && defaultdWidth == 0) {
		defaultdWidth = 0.14;
	} else {
		if (dWidth){
			defaultdWidth = dWidth;
		}
	}
	if (!noFilter) noFilter = booNoFilter;
	
	var width = parseInt(divCapText.style.width, 10);
	var divSizer = document.createElement("div");
	divSizer.style.position = "absolute";
	divSizer.style.width = width + "px";
	divSizer.style.margin = "0px";
	divSizer.style.fontFamily = divCapText.style.fontFamily;
	divSizer.style.fontSize = divCapText.style.fontSize;
	divSizer.style.visibility = "hidden";
	divSizer.innerHTML = caption;
	document.body.appendChild(divSizer);
	var newSize = GetObjectSize(divSizer);
	defaultHeight = parseInt(divCapText.style.height, 10); 

	if (newSize.h > defaultHeight)
	{
		divSizer.innerHTML = caption + "...less";
		newSize = GetObjectSize(divSizer);

		fullCaption = caption;
		var charCount = parseInt(width * defaultdWidth, 10) - 5; // safe estimate
		divCapText.innerHTML = caption.substr(0, charCount) + "...";
		
		var spanMore = document.createElement("span");
		spanMore.style.color = "#0000ff";
		spanMore.style.textDecoration = "underline";
		spanMore.style.cursor = "pointer";
		spanMore.onclick = function(){spanMore.parentNode.removeChild(spanMore);ResizeCaption(divCapTrans.id,divCapText.id,newSize.h);};
		spanMore.innerHTML = "more";
		divCapText.appendChild(spanMore);
	}
	else
		divCapText.innerHTML = caption;

	document.body.removeChild(divSizer);
}

function ResizeCaption(divCapTrans, divCapText, height)
{
	if (typeof divCapTrans == "string") divCapTrans = GetRawObject(divCapTrans);
	if (typeof divCapText == "string") divCapText = GetRawObject(divCapText);
	var h = parseInt(divCapText.style.height, 10);
	var top = divCapTrans.offsetTop; //parseInt(divCapText.style.top, 10);
	var caption = fullCaption;
	var windowSize = GetInsideWindowSize();
	if (defaultTop==''){
		defaultTop	= divCapTrans.offsetTop; // parseInt(divCapText.style.top, 10);
	}

	if (h < height)
	{
		if (h == defaultHeight)
		{
			height += 10;
			divCapTrans.style.position = "absolute";
			divCapText.style.paddingTop = "5px";
			divCapText.innerHTML = caption + "...";
			
			var spanLess = document.createElement("span");
			spanLess.style.color = "#0000ff";
			spanLess.style.textDecoration = "underline";
			spanLess.style.cursor = "pointer";
			spanLess.onclick = function(){spanLess.parentNode.removeChild(spanLess);divCapText.innerHTML = caption;ResizeCaption(divCapTrans.id,divCapText.id,defaultHeight);};
			spanLess.innerHTML = "less";
			divCapText.appendChild(spanLess);
			if (popBoxCaptionBelow == false && !noFilter)
			{
				if (typeof divCapTrans.style.filter != undefined)
					divCapTrans.style.filter = "";
				if (typeof divCapTrans.style.opacity != undefined)
					divCapTrans.style.opacity = "1.0";
			}
		}
		
		if ((h + 10) >= height)
		{
			top -= (height - h);
			if (top<1) 	top = 1;
			h = height;
		}
		else
		{
			top -= 10;
			if (top<1) 	top = 1;
			h += 10;
		}

		divCapTrans.style.height = Math.min(h,windowSize.y-5) + "px"; //minus ten to compensate for padding in resizecaption function
		divCapText.style.height = Math.min(h,windowSize.y-5) + "px"; //minus ten to compensate for padding in resizecaption function
		divCapTrans.style.top = (top - 1) + "px";
		//divCapText.style.top = top + "px";
		if (h != height && h < windowSize.y){
			setTimeout("ResizeCaption(\"" + divCapTrans.id + "\",\"" + divCapText.id + "\"," + height + ")", 10);
		} else {
			if (noFilter) { //product description
				divCapTrans.onmouseout = function(){divCapText.innerHTML = caption;ResizeCaption(divCapTrans.id,divCapText.id,defaultHeight);};
			}
		}
	}
	else
	{
		if ((h - 10) <= height)
		{
			//top += (h - height);
			//if (top>defaultTop) top = defaultTop;
			top = defaultTop;
			h = height;
		}
		else
		{
			top += 10;
			if (top>defaultTop) top = defaultTop;
			h -= 10;
		}
		divCapTrans.style.height = h + "px";
		divCapText.style.height = h + "px";
		divCapTrans.style.top = top + "px";
		//divCapText.style.top = top + "px";
		divCapText.style.paddingTop = "0px";
		if (h == height)
		{
			if (popBoxCaptionBelow == false && !noFilter)
			{
				if (typeof divCapTrans.style.filter != 'undefined')
					divCapTrans.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
				if (typeof divCapTrans.style.opacity != 'undefined')
					divCapTrans.style.opacity = "0.7";
			}
			AddCaptionText(divCapTrans, divCapText, caption);
			divCapTrans.onmouseout = "";
		}
		else
		{
			setTimeout("ResizeCaption(\"" + divCapTrans.id + "\",\"" + divCapText.id + "\"," + height + ")", 10);
		}
	}
}

function CreateWaitImage(obj)
{
	if (typeof obj == "string") obj = GetRawObject(obj);

	var newId = "popBoxImgWait" + obj.id;
	var imgWait = GetRawObject(newId);
	if (imgWait != null)
		return imgWait;

	var left = 0;
	var top = 0;
	if (obj.style.position == "absolute" || obj.style.position == "relative")
	{
		left = parseInt(obj.style.left, 10);
		top = parseInt(obj.style.top, 10);
	}
	else
	{
		var xy = GetElementPosition(obj);
		left = xy.x;
		top = xy.y
		var padding = GetObjectPadding(obj);
		left -= padding.l;
		top -= padding.t;
	}

	var width = parseInt(obj.style.width, 10);
	var height = parseInt(obj.style.height, 10);
	var size = GetObjectSize(obj);
	if (isNaN(width) == true)
		width = size.w;
	else if (size.w > width)
		left += ((size.w - width) / 2);
	if (isNaN(height) == true)
		height = size.h;
	else if (size.h > height)
		top += ((size.h - height) / 2);

	var parentNode = obj.parentNode;

	imgWait = document.createElement("img");
	imgWait.id = newId;
	imgWait.src = popBoxWaitImage.src;
	imgWait.style.position = "absolute";
	imgWait.style.left = (left + (width / 2) - (popBoxWaitImage.width / 2)) + "px";
	imgWait.style.top = (top + (height / 2) - (popBoxWaitImage.height / 2)) + "px";
	imgWait.style.cursor = obj.style.cursor;
	imgWait.style.zIndex = obj.style.zIndex + 1;
	parentNode.appendChild(imgWait);

	return imgWait;
}

/***************************************************************************************************
* This is where the user-callable section starts.
* Function signatures above this line are subject to change.
***************************************************************************************************/

// Globals you can assign
var popBoxAutoClose = true;
var popBoxWaitImage = new Image();
popBoxWaitImage.src = IMAGE_LIB + "spinner40.gif";

var popBoxShowRevertBar = true;
var popBoxShowRevertText = true;
var popBoxShowRevertImage = true;
var popBoxRevertText = "Click the image to shrink it.";
var popBoxRevertImage = IMAGE_LIB + "magminus.gif";
var popBoxRevertBarAbove = false;

var popBoxBrowserOnly = true; //will pop to available size of browser window when true, otherwise it will
								//pop to screen size

// there is no popBoxShowPopBar global, but instead the pbShowPopBar attribute must be
// set on the img for the PopBar funtionality to work (can be true or false)
var popBoxShowPopText = true;
var popBoxShowPopImage = true;
var popBoxPopText = "Click to expand.";
var popBoxPopImage = IMAGE_LIB + "magplus.gif";
var popBoxPopBarAbove = false;

var popBoxShowCaption = true;
var popBoxCaptionBelow = false;

// these custom attributes on the <img> element will override the globals above
// pbShowRevertBar, pbShowRevertText, pbShowRevertImage, pbRevertText, pbRevertImage
// pbShowPopBar, pbShowPopText, pbShowPopImage, pbPopText, pbPopImage, pbShowCaption

// Advanced method to begin moves and resizes. (Use Pop/PopEx and Revert where possible instead.)
// X and Y postfixes refer to the top left pixel. W and H postfixes refer to the width and height
// speedM and speedS are the speeds of the move and size respectively
// className denotes the CSS class to apply to the object that is being moved and/or sized
// fnDone denotes the script method to run when the move/resize is complete. It must have a single
// parameter that holds the object itself.
function PopBox(obj, startX, startY, endX, endY, startW, startH, endW, endH, speedM, speedS, className, fnDone)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	if (obj == null || typeof obj != "object" || isNaN(startX) || isNaN(startY) || isNaN(endX) || isNaN(endY) || isNaN(startW) || isNaN(startH) || isNaN(endW) || isNaN(endH) || isNaN(speedM) || isNaN(speedS))
		return;
	var elem = InitPopBox(obj);

	if (popBox[elem.id].isAnimating == true)
	{
		var str = "PopBox('" + elem.id + "'," + startX + "," + startY + "," + endX + "," + endY + "," + startW + "," + endW + "," + startH + "," + endH + "," + speedM + "," + speedS + ",'" + className + "');";
		setTimeout(str, 10);
	}
	else
	{
		popBox[elem.id].isAnimating = true;
		popBox[elem.id].xCurr = parseFloat(startX);
		popBox[elem.id].yCurr = parseFloat(startY);
		popBox[elem.id].wCurr = parseFloat(startW);
		popBox[elem.id].hCurr = parseFloat(startH);
		popBox[elem.id].xTarg = parseFloat(endX);
		popBox[elem.id].yTarg = parseFloat(endY);
		popBox[elem.id].wTarg = parseFloat(endW);
		popBox[elem.id].hTarg = parseFloat(endH);
		popBox[elem.id].xDelta = Math.abs(parseFloat(endX) - parseFloat(startX));
		popBox[elem.id].yDelta = Math.abs(parseFloat(endY) - parseFloat(startY));
		popBox[elem.id].wDelta = Math.abs(parseFloat(endW) - parseFloat(startW));
		popBox[elem.id].hDelta = Math.abs(parseFloat(endH) - parseFloat(startH));
		popBox[elem.id].velM = (speedM) ? Math.abs(parseFloat(speedM)) : 1.0;
		popBox[elem.id].velS = (speedS) ? Math.abs(parseFloat(speedS)) : 1.0;
		popBox[elem.id].xTravel = 0.0;
		popBox[elem.id].yTravel = 0.0;
		popBox[elem.id].wTravel = 0.0;
		popBox[elem.id].hTravel = 0.0;
		// set element's start position
		elem.style.position = "absolute";
		elem.style.left = startX + "px";
		elem.style.top = startY + "px";
		// set element's start size
		elem.style.width = startW + "px";
		elem.style.height = startH + "px";
		elem.style.display = "inline";

		// the length of the line between start and end points
		var lenMove = Math.sqrt((Math.pow((startX - endX), 2)) + (Math.pow((startY - endY), 2)));
		var lenSize = Math.sqrt((Math.pow((startW - endW), 2)) + (Math.pow((startH - endH), 2)));
		// if the speeds are the same then they should be in sync
		if (popBox[elem.id].velM == popBox[elem.id].velS)
			lenMove = lenSize = Math.sqrt(Math.pow(lenMove, 2) + Math.pow(lenSize, 2));

		// how big the pixel steps are along each axis
		popBox[elem.id].xStep = ((popBox[elem.id].xTarg - popBox[elem.id].xCurr) / lenMove) * popBox[elem.id].velM;
		popBox[elem.id].yStep = ((popBox[elem.id].yTarg - popBox[elem.id].yCurr) / lenMove) * popBox[elem.id].velM;

		// how big the pixel steps are for each resize
		popBox[elem.id].wStep = ((popBox[elem.id].wTarg - popBox[elem.id].wCurr) / lenSize) * popBox[elem.id].velS;
		popBox[elem.id].hStep = ((popBox[elem.id].hTarg - popBox[elem.id].hCurr) / lenSize) * popBox[elem.id].velS;
		
		popBox[elem.id].fnDone = fnDone;
		if (className != null)
			elem.className = className;

		popBox[elem.id].cursor = elem.style.cursor;
		elem.style.cursor = "default";

		if (popBox[elem.id].isPopped == false)
			elem.style.zIndex = ++popBoxZ;

		var id = elem.id;
		if (popBox[elem.id].originalId != null) id = popBox[elem.id].originalId;
		if (pbPopBarFunc[id] != null)
		{
			pbPopBarFunc[id]();
			pbPopBarFunc[id] = null;
		}
			
		if (popBox[elem.id].fnPre != null && typeof popBox[elem.id].fnPre == 'function')
			popBox[elem.id].fnPre();

		// start the repeated invocation of the animation
		popBox[elem.id].interval = setInterval("DoPopBox('" + elem.id + "')", 10);
	}
}

/***************************************************************************************************
* Helper functions. Use these! They are much easier. Call Pop/PopEx and then Revert, or set the
* popBoxAutoClose global to true and Revert will be called for you.
***************************************************************************************************/

// this basic method centers the image in the browser and displays it at its full resolution
function Pop(obj, speed, className)
{
	PopEx(obj, null, null, 0, 0, speed, className);
}

// If either newLeft or newTop are null then the image is centered in the browser.
// End newLeft and/or newTop with "A" for an absolute position, otherwise it is treated as a relative position.
// Ex: a newLeft of 20 would move right 20 pixels, "20A" would position 20 pixels from the left of it's containing element.
// If either newWidth or newHeight is 0 then the full image size is used
function PopEx(obj, newLeft, newTop, newWidth, newHeight, speed, className)
{
	if (typeof obj == "string") obj = GetRawObject(obj);
	var poppedSrc = obj.getAttribute('pbSrcNL');
	if (poppedSrc != null)
	{
		if (pbSrc[obj.src] != null)
		{
			if (pbSrc[obj.src].src != poppedSrc)
				pbSrc[obj.src].src = poppedSrc;
		}
		else
		{
			pbSrc[obj.src] = new Image();
			pbSrc[obj.src].src = poppedSrc;
		}
	}
	else if (pbSrc[obj.src] == null)
	{
		poppedSrc = obj.getAttribute('pbSrc');
		if (poppedSrc != null)
		{
			pbSrc[obj.src] = new Image();
			pbSrc[obj.src].src = poppedSrc;
		}
	}
	var objToPop = (pbSrc[obj.src] != null) ? pbSrc[obj.src] : obj;
	var isReady = (typeof objToPop.readyState != 'undefined') ? (objToPop.readyState == "complete") : ((typeof objToPop.complete != 'undefined') ? (objToPop.complete == true) : true);
	if (isReady == false)
	{
		var imgWait = CreateWaitImage(obj);
		var str = "var imgWait = GetRawObject('" + imgWait.id + "'); imgWait.parentNode.removeChild(imgWait); PopEx('" + obj.id + "'," + newLeft + "," + newTop + "," + newWidth + "," + newHeight + "," + speed + ",'" + className + "');";
		objToPop.onload = new Function("", str);
		return;
	}

	var elem = InitPopBox(obj);
	//store image to global variable 
	poppedimage = elem;
	if (popBox[elem.id].isPopped == true) return;

	if (typeof elem.ondblclick == "function")
		elem.onclick = elem.ondblclick;

	var startX = parseInt(elem.style.left);
	var startY = parseInt(elem.style.top);

	if (newWidth == 0 || newHeight == 0)
	{
		// get size from original object
		if (pbSrc[obj.src] != null)
		{
			newWidth = pbSrc[obj.src].width;
			newHeight = pbSrc[obj.src].height;
		}
		else if (obj.naturalWidth && obj.naturalHeight)
		{
			newWidth = obj.naturalWidth;
			newHeight = obj.naturalHeight;
		}
		else
		{
			var img = new Image();
			img.src = elem.src;
			newWidth = img.width;
			newHeight = img.height;
			delete img;
		}
		
		// some browsers have a race condition where it still doesn't get set so just fill the window
		if (newWidth == 0 || newHeight == 0)
		{
			var windowSize = GetInsideWindowSize();
			var scale = Math.min(parseFloat(windowSize.x) / parseFloat(elem.width), parseFloat(windowSize.y) / parseFloat(elem.height));
			newWidth = parseInt(elem.width * scale);
			newHeight = parseInt(elem.height * scale);
		}
	}
	
	if (newLeft == null || newTop == null) // center it
	{
		// if image is bigger than the window scale it down (does not take into account any border)
		var windowSize = GetInsideWindowSize();
		var hasRevertBar = HasRevertBar(obj);
		var hasCaption = HasCaption(obj);
		if (hasRevertBar == true && popBoxRevertBarAbove == true) windowSize.y -= 20;
		if (hasCaption == true && popBoxCaptionBelow == true) windowSize.y -= 20;
		if (windowSize.x < newWidth || windowSize.y < newHeight)
		{
			var scale = Math.min(parseFloat(windowSize.x) / parseFloat(newWidth), parseFloat(windowSize.y) / parseFloat(newHeight));
			newWidth = parseInt(newWidth * scale);
			newHeight = parseInt(newHeight * scale);
		}

		var endPos = GetCenteredWindowPoint(newWidth, newHeight);
		newLeft = endPos.x;
		newTop = endPos.y;
		if (hasRevertBar == true && popBoxRevertBarAbove == true) newTop += 10;
		if (hasCaption == true && popBoxCaptionBelow == true) newTop -= 10;
	}
	else // check for absolute vs. relative positioning
	{
		if (typeof newLeft == "string" && newLeft.indexOf("A") == (newLeft.length - 1))
			newLeft = parseInt(newLeft, 10);
		else
			newLeft = popBox[elem.id].xOriginal + parseInt(newLeft, 10);

		if (typeof newTop == "string" && newTop.indexOf("A") == (newTop.length - 1))
			newTop = parseInt(newTop, 10);
		else
			newTop = popBox[elem.id].yOriginal + parseInt(newTop, 10);
	}

	var func = null;
	if (typeof PostPopProcessing == "function")
		func = PostPopProcessing;
	
	PopBox(elem, startX, startY, newLeft, newTop, popBox[elem.id].wOriginal, popBox[elem.id].hOriginal, newWidth, newHeight, speed, speed, className, func);
}

// Helper function for PopBox to move/resize the image back to its original position/size. Use this! It's much easier.
function Revert(obj, speed, className)
{
	if (typeof obj == "string") obj = GetRawObject(obj); 
	if (typeof popBox[obj.id] == undefined || popBox[obj.id] == null) return;
	var iCurrentLeft = GetObjectLeft(obj);
	var iCurrentTop = GetObjectTop(obj);
	var iCurrentWidth = parseInt(obj.style.width, 10);
	var iCurrentHeight = parseInt(obj.style.height, 10);
	
	if (typeof speed == 'undefined' || speed == null || speed == 0)
		speed = Math.max(popBox[obj.id].velM, popBox[obj.id].velS);
		
	if (typeof className == 'undefined')
		className = popBox[obj.id].originalClassName;
	
	var func = null;
	if (typeof PostRevertProcessing == "function")
		func = PostRevertProcessing;

	PopBox(obj, iCurrentLeft, iCurrentTop, popBox[obj.id].xOriginal, popBox[obj.id].yOriginal, iCurrentWidth, iCurrentHeight, popBox[obj.id].wOriginal, popBox[obj.id].hOriginal, speed, speed, className, func);
	
}

/***************************************************************************************************
* These methods are the post processing events for Pop/PopEx and Revert.
* Feel free to copy them to your own page script and add your own code to the method bodies.
***************************************************************************************************/

// Function that Pop calls after the move/resize is complete. The one parameter is the object.
//function PostPopProcessing(obj)
//{
	// if (typeof obj == "string") obj = GetRawObject(obj);
//}

// Function that Revert calls after the move/resize is complete. The one parameter is the object.
//function PostRevertProcessing(obj)
//{
	// if (typeof obj == "string") obj = GetRawObject(obj);
//}

/*****************************************************************************************************
*thse methods are for the title bar buttons
******************************************************************************************************/
	var secondbartype = "shop";
	var maincontentwidth = 795;
	var revealspeed = 20;
	var LASTPAGEID = '';
	
	function ButtonUpdate(strID){
		var ButtonImage = document.getElementById(strID);
	//set event procedures
		ButtonImage.onmouseover = function(){Showbutton(strID,"Over")};
		ButtonImage.onmouseout = function(){Showbutton(strID,"Out")};
		ButtonImage.onmousedown = function(){Showbutton(strID,"Down")};
		ButtonImage.onmouseup = function(){Showbutton(strID,"Up")};
	}
	
	function Showbutton(strID, strAction){
		var ext = "png";
		var nbutton = "normal_";
		var hbutton = "highlighted_";
		var cbutton = "clicked_";
		var dbutton = "depressed_";
		
		var subImages = document.getElementById(strID);
		var oldImage = subImages.src;
		if (strAction == "Over") {
			var newImage = oldImage.replace(nbutton,hbutton);
			subImages.src = newImage;
		} else if (strAction == "Out") {
			if (oldImage.search(hbutton) > -1) {
				var newImage = oldImage.replace(hbutton,nbutton);
				subImages.src = newImage;
			} else if (oldImage.search(cbutton) > -1) {
				var newImage = oldImage.replace(cbutton,nbutton);
				subImages.src = newImage;
			}
		} else if (strAction == "Down") {
			if (oldImage.search(hbutton) > -1) {
				var newImage = oldImage.replace(hbutton,cbutton);
				subImages.src = newImage;
			} 
		} else if (strAction == "Up") {
			//dyloadpage(strID);
			//updatedepressed();
		} else if (strAction == "Normal") {
			var newImage = oldImage.replace(dbutton,nbutton);
			newImage = newImage.replace(hbutton,nbutton);
			newImage = newImage.replace(cbutton,nbutton);
			subImages.src = newImage;
		} else if (strAction == "Depressed") {
			var newImage = oldImage.replace(nbutton,dbutton);
			newImage = newImage.replace(hbutton,dbutton);
			newImage = newImage.replace(cbutton,dbutton);
			subImages.src = newImage;
		}
	}
	
	function displayDiv(divID){
		var divs = document.getElementsByTagName('div');
		if (divs != undefined && divs != null){
			for (var i = 0; i < divs.length; i++){
				if (divs[i].id == divID){
					divs[i].style.display = '';        
				}
			}
		}
	}
	
	function revealsecondbar(){
		var sbar = document.getElementById("second_button_images");
		var maxheight=36;
		
		var sstatus = getsecondbarstatus(); // determine if second bar was visible on previous page result > than -1 if true
		var rstatus = getpagetypestatus();  //determine if previous page was a shopping page result > than -1 if true
		var status = (sstatus > -1) && (rstatus == -1);

		if (status) {
			//sbar.style.display="";
			displayDiv(sbar.id);
			return;
		}

		if (sbar.style.display=="none"){
			sbar.style.height = 0 + "px";
			sbar.style.display="";
		}
		var newheight = sbar.offsetHeight;
		if (newheight < maxheight) {
			newheight+=2; //increment height
			if (newheight > maxheight ) newheight = maxheight;
			sbar.style.height = newheight + "px";
			setTimeout("revealsecondbar()",revealspeed);
		}
	}
	function hidesecondbar(){
		var sbar = document.getElementById("second_button_images");
		var maxheight=36;
		
		var sstatus = getsecondbarstatus(); // determine if second bar was visible on previous page result > than -1 if true
		var rstatus = getpagetypestatus();  //determine if previous page was a shopping page result > than -1 if true
		var status = (sstatus > -1) && (rstatus == -1);
		if (sstatus > -1) {
			if (rstatus > -1){
					sbar.style.display="none";
					return;
			} else {
				if (sbar.style.display=="none"){
					sbar.style.height = maxheight + "px";
					sbar.style.display="";
					sbar.style.lineHeight = 0;
				}
			}
		} else {
			return;
		}
		var newheight = (sbar.style.height.replace("px","")*1);
		if (newheight > 0) {
			newheight-=2; //increment height
			if (newheight < 1 ) {
				sbar.style.display = "none";
			} else {
				sbar.style.height = newheight + "px";
				if (newheight < 1 ) newheight = 1;
				setTimeout("hidesecondbar()",revealspeed);
			}
		}
	}
	
	function revealnavbar(){
		var sbar = document.getElementById("shop_navigation");
		var maxheight=24;
		
		var sstatus = getsecondbarstatus(); // determine if second bar was visible on previous page result > than -1 if true
		var rstatus = getpagetypestatus();  //determine if previous page was a shopping page result > than -1 if true
		var status = (sstatus > -1) && (rstatus > -1);

		if (status) {
			sbar.style.height = maxheight + "px";
			sbar.style.display="";
			return;
		}
		if (sbar.style.display=="none"){
			sbar.style.height = 0 + "px";
			sbar.style.display="";
		}
		var newheight = sbar.offsetHeight;
		if (newheight < maxheight) {
			newheight+=2; //increment height
			if (newheight > maxheight ) newheight = maxheight;
			sbar.style.height = newheight + "px";
			setTimeout("revealnavbar()",revealspeed);
		}
	}

	function hidenavbar(){
		var sbar = document.getElementById("shop_navigation");
		var maxheight=24;
		
		var sstatus = getsecondbarstatus(); // determine if second bar was visible on previous page result > than -1 if true
		var rstatus = getpagetypestatus();  //determine if previous page was a shopping page result > than -1 if true
		var status = (sstatus > -1) && (rstatus > -1);
		if (status) {
			if (sbar.style.display=="none"){
				sbar.style.height = maxheight + "px";
				sbar.style.display="";
				sbar.style.lineHeight = 0;
			}
		} else {
			return;
		}
		var newheight = (sbar.style.height.replace("px","")*1);
		if (newheight > 0) {
			newheight-=2; //increment height
			if (newheight < 1 ) {
				sbar.style.display = "none";
			} else {
				if (newheight < 0 ) newheight = 0;
				sbar.style.height = newheight + "px";
				setTimeout("hidenavbar()",revealspeed);
			}
		}
	}

	function revealsidebar(){
		var rbar = document.getElementById("column");
		var rbarcontent = document.getElementById("right_sidebar_content");
		var maxwidth =140;
		var mx = 0;
		var omaincontent = document.getElementById("main_center");
		var cwidth = document.getElementById("content").offsetWidth;
		var loffset = cssStyle("content","padding-left");
		var roffset = cssStyle("content","padding-right");
		if (loffset!=undefined){
			loffset = loffset.replace("px","");
		} else {
			loffset=0;
		}
		if (roffset != undefined){
			roffset = roffset.replace("px","");
		} else {
			roffset=0;
		}
		if (cwidth != undefined){
		 	mx = cwidth-loffset-roffset;
		} else {
			mx = maincontentwidth - maxwidth - loffset - roffset;
		}
		var rstatus = getpagetypestatus();
		if (rstatus > -1) {
			rbar.style.width = maxwidth + "px";
			omaincontent.style.width = mx + "px";
			rbar.style.display="";
			return;
		}
		if (rbar.style.display=="none"){
			rbar.style.width = 0 + "px";
			rbar.style.display="";
		}
		var newwidth = rbar.offsetWidth;
		var newmainwidth = (omaincontent.style.width.replace("px","")*1);
		if (newwidth < maxwidth) {
			newwidth+=4;
			newmainwidth-=4;
			if (newwidth  > maxwidth) newwidth = maxwidth;
			if (newmainwidth < mx) newmainwidth=mx;
			omaincontent.style.width = newmainwidth + "px";
			rbar.style.width = newwidth + "px";
			setTimeout("revealsidebar()",revealspeed);
		}
	}
	
	function revealbanner(){
		var obanner = document.getElementById("page_banner_content");
		var obannerparent = document.getElementById("page_banner");
		var maxheight= 72;
		var rstatus = getpagetypestatus();
		if (rstatus > -1) {
			obannerparent.style.display="";
			return;
		}
		if (obannerparent.style.display=="none"){
			obannerparent.style.height = 0 + "px";
			obannerparent.style.display="";
		}
		var newheight = obannerparent.offsetHeight;
		if (newheight < maxheight) {
			newheight+=4; //increment width
			if (newheight > maxheight) newheight=maxheight;
			obannerparent.style.height = newheight + "px";
			setTimeout("revealbanner()",revealspeed);
		}
	}

	function hidesidebar(){
		var rbar = document.getElementById("column");
		var maxwidth =140;
		var omaincontent = document.getElementById("main_center");
		//var opagetoplinks = document.getElementById("pagetoplinks");

		var rstatus = getpagetypestatus();
		if (rstatus > -1) {
			if (rbar.style.display == "none") {
				rbar.style.width = 140 + "px";
				rbar.style.display="";
				omaincontent.style.width = (maincontentwidth - maxwidth) + "px";
				//opagetoplinks.style.width = (maincontentwidth - maxwidth) + "px";
			}
		} else {
			omaincontent.style.width = maincontentwidth + "px";
			return;
		}
		var newwidth = (rbar.style.width.replace("px","")*1);
		var newmainwidth = (omaincontent.style.width.replace("px","")*1);
		if (newwidth > 0) {
			newwidth-=4; //increment width
			newmainwidth+=4;
			if (newwidth < 0) newwidth=0;
			if (newmainwidth > maincontentwidth) newmainwidth = maincontentwidth;
			rbar.style.width = newwidth + "px";
			omaincontent.style.width = newmainwidth + "px";
			//opagetoplinks.style.width = newmainwidth + "px";
			setTimeout("hidesidebar()",revealspeed);
		} else {
			rbar.style.display = "none";
		}
	}

	function hidebanner(){
		var obannerparent = document.getElementById("page_banner");
		var maxheight = 72;
		
		var rstatus = getpagetypestatus();
		if (rstatus > -1) {
			if (obannerparent.style.display == "none"){
				obannerparent.style.height = maxheight + "px";
				obannerparent.style.display="";
			}
		} else {
			return;
		}
		var newwidth = (obannerparent.style.height.replace("px","")*1);
		if (newwidth > 0) {
			newwidth-=4; //increment width
			if (newwidth < 0) newwidth=0;
			obannerparent.style.height = newwidth + "px";
			setTimeout("hidebanner()",revealspeed);
		}
		
	}

	function updatedepressed(){
		var bodyid = document.body.id; //document.getAttribute('ID');
		var bb="";
		var bb2="";
		switch(bodyid) {
			case "intro":
				hidesecondbar();
				hidenavbar();
				break;
			case "gallery1":
				bb = "gallery_button";
				bb2 = "gallery_button_2";
				hidenavbar();
				revealsecondbar();
				break;
			case "gallery2":
				bb = "gallery_button";
				bb2 = "gallery_button_3";
				revealsecondbar();
				hidenavbar();
				break;
			case "gallery3":
				bb = "gallery_button";
				bb2 = "gallery_button_4";
				revealsecondbar();
				hidenavbar();
				break;
			case "service1":
				bb = "services_button";
				hidesecondbar();
				hidenavbar();
				break;
			case "faqs2":
				bb = "faqs_button";
				hidesecondbar();
				hidenavbar();
				break;
			case "contact1":
				bb = "contact_button";
				hidesecondbar();
				hidenavbar();
				break;
			case "shopcart":
				bb = "cart_button";
				revealnavbar();
				hidesecondbar();
				break;
			default: 
				if(bodyid.search('shop')>-1){
					bb = "shop_button";
					revealnavbar();
					hidesecondbar();
				} else {
					//bb = "contact_button";
					hidesecondbar();
					hidenavbar();
				}
		}
		if (bb.length>0) {
			Showbutton(bb,"Depressed");
		}
		if (bb2.length>0) {
			Showbutton(bb2,"Depressed");
		}
	
	}
	function setShoporGalleryformat(strtype){
		var pgfooterline = document.getElementById("footerline");
		var pagecontent = document.getElementById("page_content");

		secondbartype=strtype
		if (strtype == "gallery"){
			if(pgfooterline){
				pgfooterline.style.backgroundColor = "#ffffff";
			}
			document.body.style.backgroundColor = "#000000";
			document.body.text =  "#cccccc";
		} else {
		//default to shop pages format
			if(pgfooterline){
				pgfooterline.style.backgroundColor = "#ffffff";
			}
			document.body.style.backgroundColor = "#000000";
			document.body.text =  "#cccccc";
		}
		//formatborder(strtype);
	}
	
	function formatborder(strtype){
		var lborder = document.getElementById("leftborder");
		var tlborder = document.getElementById("topleftborder");
		var rborder = document.getElementById("rightborder");
		var trborder = document.getElementById("toprightborder");
		var tborderrow = document.getElementById("topborderrow");
		var pagecontent = document.getElementById("page_content");
		var topbuttons = document.getElementById("button_images");
		var second1 = document.getElementById("second_button_images");
		var second2 = document.getElementById("shop_navigation");
		var maincell = document.getElementById("main_content_cell");
		var bannerBackground = document.getElementById("page_banner");
		var toffset = 76;
		
		//topbuttons.style.background = "url(lib/buttonbarblank_full.png) no-repeat";
		//second1.style.background = "url(lib/buttonbarblank36_full.png) no-repeat";
		//second2.style.background = "url(lib/nav-spacer.gif) repeat-x";
		
		if (strtype == "gallery") {
			lborder.style.background = "none";
			rborder.style.background = "none";
			tlborder.style.background = "none";			
			trborder.style.background ="none";
			tborderrow.style.background = "none";
			maincell.style.background = "none";
			bannerBackground.style.background = "none";
			//lborder.style.backgroundColor = "#ffffff";
			//rborder.style.backgroundColor = "#ffffff";
			//tlborder.style.backgroundColor = "#ffffff";
			//trborder.style.backgroundColor = "#ffffff";
			//tborderrow.style.backgroundRepeat = "repeat-x";
		}else {
			lborder.style.background = "none"; //"url(lib/shopbackground_left.png) no-repeat";
			lborder.style.backgroundPosition = "0px " + -toffset + "px";				
			rborder.style.background = "none"; //"url(lib/shopbackground_right.png) no-repeat";
			//rborder.style.backgroundPosition = "0px " + -toffset + "px";
			tlborder.style.background = "none"; //"url(lib/shopbackground_left.png) no-repeat";			
			trborder.style.background = "none"; //"url(lib/shopbackground_right.png) no-repeat";
			tborderrow.style.background ="none"; //"url(lib/shopbackground_middle.png) repeat-x";
			//pagecontent.style.background = "none"; //"url(lib/shopbackground_middle.png) repeat-x";
			//pagecontent.style.backgroundPosition = "0px " + -toffset + "px";				
			lborder.style.backgroundColor = ""; //"#ffffff";
			rborder.style.backgroundColor = ""; //"#ffffff";
			//tlborder.style.backgroundColor = "#000000";			
			//trborder.style.backgroundColor ="#000000";
			tborderrow.style.backgroundColor = "";
			maincell.style.background = "none";
			bannerBackground.style.background = "none";
		}
	}
	
	function revealall(strtype){
		switch(strtype) {
			case "secondbar":
				updatedepressed();
				break;
			case "banner":
				var strID = document.body.id;
				var bgshop = strID.search("shop");
				if (bgshop > -1) {
					revealbanner();
				} else {
					hidebanner();
				}
				break;
			case "sidebar":
				var strID = document.body.id;
				var bgshop = strID.search("shop");
			if (bgshop > -1) {
					revealsidebar();
				} else {
					hidesidebar();
				}
				break;
			case "pageformat":
				var strID = document.body.id;
				var bgshop = strID.search("shop");
				if (bgshop > -1) {
					setShoporGalleryformat("shop");
				} else {
					setShoporGalleryformat("gallery");
				}
				break;
			default:
		}
	}
	function dyloadpage(){
		var strID = document.body.id;
		var bgshop = strID.search("shop");
		switch(strID) {
			case "shop":
				setShoporGalleryformat("gallery");
				SetColHeight_Same();
				ColorGradientText('page_banner_content' , true , 255 , 153, 0  , 255 , 255 , 255 ,  40 );
				break;
			case "gallery1":
				//UpdateSecondBarLinks("gallery");
				setShoporGalleryformat("gallery");
				InitPbSrc();
				InitPbPopBar();
				initSlideShow();
				break;
			case "gallery2":
				//UpdateSecondBarLinks("gallery");
				setShoporGalleryformat("gallery");
				InitPbSrc();
				InitPbPopBar();
				break;
			case "gallery3":
				//UpdateSecondBarLinks("gallery");
				setShoporGalleryformat("gallery");
				break;
			case "service1":
				setShoporGalleryformat("gallery");
				initImageGallery();
				break;
			case "faqs2":
				setShoporGalleryformat("gallery");
				break;
			case "contact1":
				setShoporGalleryformat("gallery");
				break;
			default: 
				if (bgshop > -1) {
				//default to shop format
					//UpdateSecondBarLinks("shop");
					setShoporGalleryformat("shop");
					SetColHeight_Same();
					ColorGradientText('page_banner_content' , true , 255 , 153, 0  , 255 , 255 , 255 ,  40 );
					ProductDescriptionSizer();
				} else {
				//gallery format
					setShoporGalleryformat("gallery");
				}
		}
		initImageGallery();
	//call function to preload images for navigation
		preloadnavigation();
	}
function preloadnavigation(){
//preload images for navigation
	var nbutton = "normal_";
	var hbutton = "highlighted_";
	var cbutton = "clicked_";
	var dbutton = "depressed_";
	var strID = "";
	for(var j=0;j<2;j++){
		if (j==0){
		//main navigation
			strID = "button_images";
		} else {
		//secondary navigation
			strID = "second_button_images";
		}
		var navImages = document.getElementById(strID);
		var ButtonImages = navImages.getElementsByTagName("IMG");
		for(var i=0;i<ButtonImages.length;i++){
			var ButtonImage = ButtonImages[i];
			if (ButtonImage.onload) {
				var oldImage = ButtonImage.src;
			//call function to preload images
				MM_preloadImages(oldImage.replace(nbutton,hbutton));
				MM_preloadImages(oldImage.replace(nbutton,cbutton));
				MM_preloadImages(oldImage.replace(nbutton,dbutton));
			}
		}
	}
//shop navigation
	strID = "shop_navigation";
	var navImages = document.getElementById(strID);
	var ButtonImages = navImages.getElementsByTagName("IMG");
	for(var i=0;i<ButtonImages.length;i++){
		var ButtonImage = ButtonImages[i];
		var oldImage = ButtonImage.src;
		var newImage = oldImage.replace(".png","-on.png");
	//call function to preload images
		MM_preloadImages(newImage);
	}	
}

function getsecondbarstatus(){
	var ReferringURL = document.URL;
	var lid = LASTPAGEID;
	var res = 0;

if (lid != undefined){
		switch(lid){
			case "gallery1":
				res = true;
				break;
			case "gallery2":
				res = true;
				break;
			case "gallery3":
				res = true;
				break;
			default:
				if (lid.search("shop") > -1) {
					res = true;
				} else {
					res = -1;
				}
		}
	} else {
		res = true;
	}
	return res;
}

function getpagetypestatus(){
	var ReferringURL = document.URL;
	var lid = LASTPAGEID;
	
	if (lid != undefined){
		if (lid.search("shop") > -1){
			return true;
		} else {
			return -1;
		}
	} else {
		return true;
	}
}

function UpdateSecondBarLinks(spagetype){
	var pagelinks = document.getElementsByTagName("a");
	var icount = pagelinks.length;
	
	for (var no=0;no<icount;no++){
		var oldlink = pagelinks[no].href;
		var ipound = oldlink.search("#");
		var ilength = oldlink.length;
		var ptext = "";
		var urlGET = GetURLRequest(pagelinks[0].href);
		
		if (ipound >-1) {
			ptext = oldlink.substring(ipound,ilength);
			oldlink = oldlink.substring(0, ipound);
		}
	//check for link already marked, or yahoo link
		var itest = (oldlink.search("secondbar")>-1 || oldlink.search("yahoo")>-1 || oldlink.search("javascript:")>-1);
		if (itest) {
			//do not update link

		} else {
			if (urlGET.length > 1) {
				var newlink = oldlink + "&secondbar=true";
			} else {
				var newlink = oldlink + "?secondbar=true";
			}
				
			if (spagetype=="gallery"){
				newlink = newlink + "&gallerypage=true" + ptext;
			} else {
				newlink = newlink + "&shoppage=true" + ptext;
			}
			pagelinks[no].href = newlink;
		}
	}
}

function SetColHeight_Same(){
	var cols = document.getElementsByName("col");
	var maxh = 0;
	
//validate 
	if (cols==undefined) return;
//get tallest column
	for (var col=0;col<=cols.length-1;col++){
		if (cols[col].offsetHeight != undefined){
			maxh = Math.max(cols[col].offsetHeight,maxh);
		}
	}
//set all columns equal to tallest column
	if (maxh>0){
		for (var col=0;col<=cols.length-1;col++){
			cols[col].style.height = maxh + "px";
		}
	}
}

function GetURLRequest(url){
			var array = url.indexOf('#') == -1 ?
									url.substring(url.indexOf('?') + 1).split(/&;/):
									url.substring(url.indexOf('?') + 1, url.indexOf('#')).split(/&;/);
															//URLs can be like either "sample.html?test1=hi&test2=bye" or
																	//"sample.html?test1=hi;test2=bye"
			//window._GET = {};
			var uGET = {};
			for(var i = 0; i < array.length; i++){
					var assign = array[i].indexOf('=');
					if(assign == -1){
							uGET[array[i]] = true;//if no value, treat as boolean
					}else{
							uGET[array[i].substring(0, assign)] = array[i].substring(assign + 1);
					}
			}
			return uGET;
}

function ProductDescriptionSizer(){
		var obj = document.getElementById('details_product_1');
		if (obj==undefined) {
			return;
		}
		var width = obj.parentNode.offsetWidth;
		var z = obj.style.zIndex + 1;
		var parentNode = obj.parentNode;
		var pbCaption = obj.innerHTML;
		var left = parentNode.offsetLeft;
		var top = parentNode.offsetTop;
		
		var divCapTrans = document.createElement("div");
		divCapTrans.id = "popBoxDivCapTrans" + z;
		divCapTrans.style.width = width + "px";
		divCapTrans.style.height = "140px";
		//divCapTrans.style.borderStyle = "solid";
		//divCapTrans.style.borderWidth = "1px";
		//divCapTrans.style.borderColor = "#999999";
		divCapTrans.style.padding = "0px";
		divCapTrans.style.margin = "0px";
		divCapTrans.style.position = "relative";
		//divCapTrans.style.left = left + "px";
		//divCapTrans.style.top = top - 1 + "px";
		divCapTrans.style.backgroundColor = "transparent";
		divCapTrans.style.zIndex = z;

		parentNode.appendChild(divCapTrans);

		var divCapText = document.createElement("div");
		divCapText.id = "popBoxDivCapText" + z;
		divCapText.style.width = width + "px";
		divCapText.style.height = "140px";
		divCapText.style.borderStyle = "none";
		//divCapText.style.padding = "0px";
		divCapText.style.margin = "0px";
		divCapText.style.position = "relative";
		//divCapText.style.left = left + 1 + "px";
		//divCapText.style.top = top + "px";
		divCapText.style.textAlign = "left";
		divCapText.style.fontFamily = "Arial, Verdana, Sans-Serif";
		divCapText.style.fontSize = "9pt";
		divCapText.style.overflowY = "scroll";
		divCapText.style.backgroundColor = document.body.style.backgroundColor;
		divCapText.style.color = cssStyle(obj.id,'color');
		divCapText.style.zIndex = z;
		divCapTrans.appendChild(divCapText);
		AddCaptionText(divCapTrans, divCapText, pbCaption, 0.7, true);	
}
function file_exists (url) {
    // http://kevin.vanzonneveld.net
    // +   original by: Enrique Gonzalez
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes. 
    // *     example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
    
    var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) throw new Error('XMLHttpRequest not supported');
      
    // HEAD Results are usually shorter (faster) than GET
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200){
        return true;
    }
    
    return false;
}
/************************************************************************************************************
*the following code will scroll message across shop banner
************************************************************************************************************/
// WebTicker by Mioplanet
// www.mioplanet.com

var TICKER_CONTENT = "New lower shipping rates now available!!!";
 
var TICKER_RIGHTTOLEFT = false;
var TICKER_SPEED = 2;
var TICKER_STYLE = "font-family:Arial; font-size:24px; color: #ff9900";
var TICKER_PAUSED = false;

function ticker_start() {
	var tickerSupported = false;
	var oticker = document.getElementById("page_banner_content");
	var TICKER_WIDTH = oticker.style.width;
	var img = "<img src=IMAGE_LIB + 'transpix.gif' width="+TICKER_WIDTH+" height=0>";

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
		oticker.innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
		tickerSupported = true;
	}
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
		oticker.innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
		tickerSupported = true;
	}
	if(!tickerSupported) oticker.outerHTML = ""; else {
		oticker.scrollLeft = TICKER_RIGHTTOLEFT ? oticker.scrollWidth - oticker.offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
		oticker.style.overflow = "hidden";
		oticker.style.display="block";
		TICKER_tick();
	}
}

function TICKER_tick() {
	var oticker = document.getElementById("page_banner_content");
	if(!TICKER_PAUSED) oticker.scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	if(TICKER_RIGHTTOLEFT && oticker.scrollLeft <= 0) oticker.scrollLeft = oticker.scrollWidth - oticker.offsetWidth;
	if(!TICKER_RIGHTTOLEFT && oticker.scrollLeft >= oticker.scrollWidth - oticker.offsetWidth) oticker.scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);
}

//Color gradient
//ColorGradientText 1.0
//
//Author: Alexandr Kot ( alexandr.kot ?at?  gmail *dot* com , http://vril.vn.ua/ )
//
// ColorGradientText is the script that implements advanced text decoration, such as color gradients and animation, using JavaScript and Dynamic HTML.
// With the ColorGradientText you can easily add striking decoration to your web pages:
// *	You can decorate your HTML text with the color gradient
// *	Attractive JavaScript animation
// *	Several text blocs on one page can be decorated independently of one another
// *	No significant changes in HTML code required.
// *	Users can view your decorated text whether they use Internet Explorer, FireFox, Netscape or some other browser. 
// *	Text can be freely indexed by search engines
// *	Absolutely free


// Examples:
// Example 1: 
// This example implements the static colored text. First letter is red, last letter is yellow.
//<html>
//	<head>
//		<title>Example 1</title>
//		<script src="ColorGradientText.js"></script>
//		<style>
//			body{background-color:#000000; color:#FFFFFF; font-size:36px;}
//		</style>
//	</head>
//	<body onload="ColorGradientText('color_me' , false , 255 , 0, 0  , 255 , 255 , 0 ,  0 );" >
//		<p id="color_me">Color me.</p> 
//	</body>
//</html>
//
// Example 2: 
// This example implements the animated text. First letter is red, last letter is yellow, timeout is 80 milliseconds
//<html>
//	<head>
//		<title>Example 2</title>
//		<script src="ColorGradientText.js"></script>
//		<style>
//			body{background-color:#000000; color:#FFFFFF; font-size:36px;}
//		</style>
//	</head>
//	<body onload="ColorGradientText('color_me' , true , 255 , 0, 0  , 255 , 255 , 0 ,  80 );" >
//		<p id="color_me">Color me.</p> 
//	</body>
//</html>
//
// Example 3: 
// This example implements the set animated texts.
//<html>
//	<head>
//		<title>Example 3</title>
//		<script src="ColorGradientText.js"></script>
//		<style>
//			body{background-color:#000000; color:#FFFFFF; font-size:36px;}
//		</style>
//	</head>
//	<body onload="ColorGradientText('color_me' , true , 255 , 0, 0  , 255 , 255 , 0 ,  80 );ColorGradientText('color_me_too' , false , 0 , 255, 0  , 00 , 255 , 255 ,  40 );" >
//		<p id="color_me">Color me.</p> 
//		<p id="color_me_too">Color me too.</p> 
//	</body>
//</html>

var arrayColorsHolder             = new Array();  //arrayColorsHolder             contains the arrays of color values.             
var arrayAnimationDirectionHolder = new Array();  //arrayAnimationDirectionHolder keeps the state of iteration's direction through the arrayColorsHolder array.
var arrayAnimationCountersHolder  = new Array();  //arrayAnimationCountersHolder variable keeps the counters through the iterations. 
var banner_msg = "New lower shipping rates now available!!!";
var banner_style = "align:center; font-family:Helvicta; font-size:24px; color: #ff9900";

// AnimationIterator(strElementName , fForvard , r1 , g1 , b1 , r2, g2, b2 , nMilliSecondsTimeout) 
//
// Recurs the animation or colors the specified element only one time.
//
// Do not call this function directly.
//
// Parameters:
// 		strElementName - String that specifies the name of element to be coloured
// 		fForvard       - Boolean that specifies the direction of animation. 
//							Possible values:
//             					true  ->	from left  to right
//	             				false ->	from right to left
//      r1 - Integer that specifies the red channel's value of the first letter's color. 
//							Possible values: from 0 to 255
//      g1 - Integer that specifies the green channel's value of the first letter's color. 
//							Possible values: from 0 to 255
//      b1 - Integer that specifies the blue  channel's value of the first letter's color. 
//							Possible values: from 0 to 255 
//      r2 - Integer that specifies the red channel's value of the last letter's color. 
//							Possible values: from 0 to 255
//      g2 - Integer that specifies the green channel's value of the last letter's color. 
//							Possible values: from 0 to 255
//      b2 - Integer that specifies the blue  channel's value of the last letter's color. 
//							Possible values: from 0 to 255 
//      nMilliSecondsTimeout - Integer that specifies the number of milliseconds.
//							Possible values: 
//                               Less than 0 -> AnimationIterator executes only one time
//                               More than 0 -> AnimationIterator recurs the animation after a specified number of milliseconds has elapsed
function AnimationIterator(strElementName , fForvard , r1 , g1 , b1 , r2, g2, b2 , nMilliSecondsTimeout) 
{
	var currentElement = null;
	var nAnimationCounter = 0;
	var nFinalElement = arrayColorsHolder[strElementName].length - 1;
	var fInnerDirection = null;
	
	//Define the moving direction
	if(fForvard)
	{
		fInnerDirection = !arrayAnimationDirectionHolder[strElementName];
	}
	else
	{
		fInnerDirection = arrayAnimationDirectionHolder[strElementName];
	}
	
	nAnimationCounter = arrayAnimationCountersHolder[strElementName];
	for(var j = 0; j <= nFinalElement ; j++ )
	{
		//Get element within the text container
		currentElement = document.getElementById(strElementName + '_animated_child_' + j);
		
		
		if(currentElement) // if current element exists
		{
			//set span's color 
			currentElement.style.color = 'rgb(' + 
				arrayColorsHolder[strElementName][nAnimationCounter]['red']   + ','+ 
				arrayColorsHolder[strElementName][nAnimationCounter]['green'] + ','+
				arrayColorsHolder[strElementName][nAnimationCounter]['blue']  +
				')';
			
			 // Rule of painting.  -- BEGIN 
			if(fInnerDirection)
			{
				if(nAnimationCounter < nFinalElement )
				{
					nAnimationCounter ++ ;
				}
				else
				{
					fInnerDirection = ! fInnerDirection;
				}
			}
			else
			{
				if(nAnimationCounter > 0 )
				{
					nAnimationCounter --;
				}
				else
				{
					fInnerDirection = ! fInnerDirection;
				}
			} 
			// Rule of painting.  -- END 
		}
		else
		{
			window.status = 'Text container "' + strElementName + '" is modified or not initialized';
			return;
		}
	}		
	
	// Rule of painting.  -- BEGIN 
	if(arrayAnimationDirectionHolder[strElementName])
	{
		if(arrayAnimationCountersHolder[strElementName] < nFinalElement )
		{
			arrayAnimationCountersHolder[strElementName] ++ ;
		}
		else
		{
			arrayAnimationDirectionHolder[strElementName] = ! arrayAnimationDirectionHolder[strElementName];
		}
	}
	else
	{
		if(arrayAnimationCountersHolder[strElementName] > 0 )
		{
			arrayAnimationCountersHolder[strElementName] --;
		}
		else
		{
			arrayAnimationDirectionHolder[strElementName] = ! arrayAnimationDirectionHolder[strElementName];
		}
	}
	// Rule of painting.  -- END 
	
	//Launch the next iteration 
	if(nMilliSecondsTimeout > 0 )
	{
		window.setTimeout('AnimationIterator("' + 
		strElementName + 
		'", '+ fForvard.toString() + 
		', ' + r1.toString() + 
		', ' + g1.toString() + 
		', ' + b1.toString() + 
		', ' + r2.toString() + 
		', ' + g2.toString() + 
		', ' + b2.toString() + 	
		', ' + nMilliSecondsTimeout.toString() + 	 
		' )', nMilliSecondsTimeout);
	}
}


// ColorGradientText(strElementName , fForvard , r1 , g1 , b1 , r2, g2, b2 , nMilliSecondsTimeout) 
//
// Fill the specified element with the color gradient.
//
// Parameters:
// 		strElementName - String that specifies the name of element to be coloured
// 		fForvard       - Boolean that specifies the direction of animation. 
//							Possible values:
//             					true  ->	from left  to right
//	             				false ->	from right to left
//      r1 - Integer that specifies the red channel's value of the first letter's color. 
//							Possible values: from 0 to 255
//      g1 - Integer that specifies the green channel's value of the first letter's color. 
//							Possible values: from 0 to 255
//      b1 - Integer that specifies the blue  channel's value of the first letter's color. 
//							Possible values: from 0 to 255 
//      r2 - Integer that specifies the red channel's value of the last letter's color. 
//							Possible values: from 0 to 255
//      g2 - Integer that specifies the green channel's value of the last letter's color. 
//							Possible values: from 0 to 255
//      b2 - Integer that specifies the blue  channel's value of the last letter's color. 
//							Possible values: from 0 to 255 
//      nMilliSecondsTimeout - Integer that specifies the number of milliseconds.
//							Possible values: 
//                               Less than 0 -> AnimationIterator executes only one time
//                               More than 0 -> AnimationIterator recurs the animation after a specified number of milliseconds has elapsed
//

function ColorGradientText(strElementName , fForvard ,  r1 , g1 , b1 , r2, g2, b2 , nMilliSecondsTimeout)
{
	 
	var textContainer = document.getElementById(strElementName);
	var tContainer_Width = textContainer.style.width;
	var img = "<img src=IMAGE_LIB + 'transpix.gif' width="+tContainer_Width+" height=0>";	
	
	if(textContainer === null){
		window.status += 'Text container "' + strElementName + '" is not defined.';
		return;
	}
	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
		textContainer.innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD align=center nowrap='nowrap'><br>"+img+"<SPAN style='"+banner_style+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
	}
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
		textContainer.innerHTML = "<DIV nowrap='nowrap' style='width:100%;'><br>"+img+"<SPAN style='"+banner_style+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
	}	
	textContainer = document.getElementById("TICKER_BODY");
	textContainer.innerHTML = banner_msg;
	textContainer.style.overflow = "hidden";
	textContainer.style.display="block";
	var strText  = textContainer.innerText || textContainer.textContent ;

if(!strText)
	{
		window.status += 'Text container "' + strElementName + '" is empty.';
		return;
	}

	arrayColorsHolder            [strElementName] = new Array();
	
	var nLetersCount = strText.length;
	
	// Define steps for creating color gradient
	var steps = new Array ();
	steps['red']   = (r2 - r1) / nLetersCount ;
	steps['green'] = (g2 - g1) / nLetersCount ;
	steps['blue']  = (b2 - b1) / nLetersCount ;

	// Generate array of color values
	for( var  i = 0; i < strText.length ; i++ )
	{
		arrayColorsHolder[strElementName][i]          = new Array();
		arrayColorsHolder[strElementName][i]['red']   = Math.round(r1 + steps['red']*i)  ;
		arrayColorsHolder[strElementName][i]['green'] = Math.round(g1 + steps['green']*i);  
		arrayColorsHolder[strElementName][i]['blue']  = Math.round(b1 + steps['blue']*i) ; 			
	}
	
	// Set initial values for harmonic oscillations emulator
	arrayAnimationDirectionHolder[strElementName] = true;
	arrayAnimationCountersHolder [strElementName] = 0;
	
	//Split original string. Result of this operation is the chain of span elements.
	var strResultString = '';
	for(var j = 0; j < strText.length ; j++ )
	{
		
		strResultString += '<span id="'+
				strElementName + '_animated_child_' + j +
				'"  >' + strText.charAt(j)  +'</span>';
				
	}			
	
	//Fill container by <span>s 
	textContainer.innerHTML = strResultString;
	 
	//Start the animation
	AnimationIterator(strElementName ,  fForvard , r1 , g1 , b1 , r2, g2, b2 , nMilliSecondsTimeout)
}	
//Validate add to cart qauntity field
 
function validate(strform) {
		var frm = document.getElementById(strform);
		var qty = frm.vwquantity0.value;
		if(qty=="" || qty <= 0){
			alert('Please enter a quantity greater than zero to add to your cart.')
			return false;
		} else {
			return true;
		}
}
/*********************************************************************************************************
*Original script
**********************************************************************************************************/

function MM_preloadImages() { //v3.0
  	var d=document; 
  
	if(d.images){ 
		if(!d.MM_p) d.MM_p=new Array();
		var i;
		var j=d.MM_p.length;
		var 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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}

var func1 = function(){MM_preloadImages(IMAGE_lib+"nav-aquariums-on.gif",IMAGE_lib+"nav-fishverts-on.gif",IMAGE_lib+"nav-inverts-on.gif",IMAGE_lib+"nav-liverock-on.gif",IMAGE_lib+"nav-coralhard-on.gif",IMAGE_lib+"nav-coralsoft-on.gif",IMAGE_lib+"nav-hardware-on.gif",IMAGE_lib+"nav-supplies-on.gif",IMAGE_lib+"gnav-aquariums-on.gif",IMAGE_lib+"gnav-fish-on.gif",IMAGE_lib+"gnav-inverts-on.gif",IMAGE_lib+"gnav-liverocks-on.gif",IMAGE_lib+"gnav-coralhard-on.gif",IMAGE_lib+"gnav-coralsoft-on.gif",IMAGE_lib+"gnav-hardware-on.gif",IMAGE_lib+"gnav-supplies-on.gif");}

if (typeof window.onload == 'function'){
	//var func = window.onload
	//functions already loaded // window.onload = function(){func();func1();};
} else {
	window.onload = function(){func1();};
}

function cssStyle(ElementId, CssProperty){
		var cssEll = document.getElementById(ElementId);
    if(cssEll.currentStyle){
        var convertToCamelCase = CssProperty; //.replace(/\-(.)/g, function(m, l){return l.toUpperCase()});
        return cssEll.currentStyle[convertToCamelCase];
    } else {
			if (window.getComputedStyle){
        var elementStyle = window.getComputedStyle(cssEll, "");
        return elementStyle.getPropertyValue(CssProperty);
			}
    }
} 

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
	 
/*
 * Copyright (C) 2006 Baron Schwartz <baron at xaprb dot com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, version 2.1.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * $Id: html-form-input-mask.js,v 1.6 2006-11-03 04:04:29 baron Exp $
 */

/* Set up a global Xaprb object to act as the Xaprb namespace, without colliding
 * with other Xaprb scripts.
 */
///*if ( typeof(Xaprb) === 'undefined' ) {
//   Xaprb = new Object();
//}
//
//
//Function.prototype.bindAsEventListener = function(object) {
//	var __method = this;
//	return function(event) {
//		return __method.call(object, event || window.event);
//	}
//}
//
//
// The Xaprb.InputMask object acts as the namespace for input masking
// * functionality.
// 
//Xaprb.InputMask = {
//
//    Each mask has a format and regex property.  The format consists
//    * of spaces and non-spaces.  A space is a placeholder for a value the user
//    * enters.  A non-space is a literal character that gets copied to that
//    * position in the value.  The regex is used to validate each character, one
//    * at a time (it is not applied against the entire value in the form field,
//    * just the characters the user enters).
//    *
//    * The way you name your masks is significant.  If you create a mask called
//    * date_us, you cause it to be applied to a form field by a) adding the
//    * input_mask class to that form field, which triggers this script to treat
//    * it specially, and b) adding the class mask_date_us to the form field,
//    * which causes this script to apply the date_us mask to it.
//    
//   masks: {
//      date_iso: {
//         format: '    -  -  ',
//         regex:  /\d/
//      },
//      date_us: {
//         format: '  /  /    ',
//         regex:  /\d/
//      },
//      time: {
//         format: '  :  :  ',
//         regex:  /\d/
//      },
//      phone: {
//         format: '(   )   -    ',
//         regex:  /\d/
//      },
//      ssn: {
//         format: '   -  -    ',
//         regex:  /\d/
//      },
//      Visa: {
//         format: '    -    -    -    ',
//         regex:  /\d/
//      },
//      MasterCard: {
//         format: '    -    -    -    ',
//         regex:  /\d/
//      },
//      Discover: {
//         format: '    -    -    -    ',
//         regex:  /\d/
//      },
//      American_Express: {
//         format: '    -      -     ',
//         regex:  /\d/
//      },
//			Integer_2: {
//				format: '  ',
//				regex: /\d/
//			},
//			Integer_3: {
//				format: '   ',
//				regex: /\d/
//			},
//			Integer_4: {
//				format: '    ',
//				regex: /\d/
//			},
//   },
//
//    Finds every element with class input_mask and applies masks to them.
//    
//		
//   setupElementMasks: function() {
//      if ( document.getElementsByClassName ) { // Requires the Prototype library
//					maskClasses = document.getElementsByClassName('input_mask');
//         	maskClasses.each(function(item) {
//            								Event.observe(item, 'keypress', Xaprb.InputMask.applyMask.bindAsEventListener(item), true);
//         									});
//      }
//   },
//   
//
//    This is triggered when the key is pressed in the form input.  It is
//    * bound to the element, so 'this' is the input element.
//    
//   applyMask: function(event) {
//      var match = /mask_(\w+)/.exec(this.className);
//      if ( match.length == 2 && Xaprb.InputMask.masks[match[1]] ) {
//         var mask = Xaprb.InputMask.masks[match[1]];
//         var key  = Xaprb.InputMask.getKey(event);
//
//         if ( Xaprb.InputMask.isPrintable(key) ) {
//            var ch      = String.fromCharCode(key);
//            var str     = this.value + ch;
//            var pos     = str.length;
//            if ( mask.regex.test(ch) && pos <= mask.format.length ) {
//               if ( mask.format.charAt(pos - 1) != ' ' ) {
//                  str = this.value + mask.format.charAt(pos - 1) + ch;
//               }
//               this.value = str;
//            }
//            Event.stop(event);
//         }
//      }
//   },
//
//    Returns true if the key is a printable character.
//    
//   isPrintable: function(key) {
//      return ( key >= 32 && key < 127 );
//   },
//
//    Returns the key code associated with the event.
//    */
//   getKey: function(e) {
//      return window.event ? window.event.keyCode
//           : e            ? e.which
//           :                0;
//   }
//};

/*
sessvars ver 1.01
- JavaScript based session object
copyright 2008 Thomas Frank

This EULA grants you the following rights:

Installation and Use. You may install and use an unlimited number of copies of the SOFTWARE PRODUCT.

Reproduction and Distribution. You may reproduce and distribute an unlimited number of copies of the SOFTWARE PRODUCT either in whole or in part; each copy should include all copyright and trademark notices, and shall be accompanied by a copy of this EULA. Copies of the SOFTWARE PRODUCT may be distributed as a standalone product or included with your own product.

Commercial Use. You may sell for profit and freely distribute scripts and/or compiled scripts that were created with the SOFTWARE PRODUCT.

v 1.0 --> 1.01
sanitizer added to toObject-method & includeFunctions flag now defaults to false

*/

sessvars=function(){

	var x={};
	
	x.$={
		prefs:{
			memLimit:2000,
			autoFlush:true,
			crossDomain:false,
			includeProtos:false,
			includeFunctions:false
		},
		parent:x,
		clearMem:function(){
			for(var i in this.parent){if(i!="$"){this.parent[i]=undefined}};
			this.flush();
		},
		usedMem:function(){
			x={};
			return Math.round(this.flush(x)/1024);
		},
		usedMemPercent:function(){
			return Math.round(this.usedMem()/this.prefs.memLimit);
		},
		flush:function(x){
			var y,o={},j=this.$$;
			x=x||top;
			for(var i in this.parent){o[i]=this.parent[i]};
			o.$=this.prefs;
			j.includeProtos=this.prefs.includeProtos;
			j.includeFunctions=this.prefs.includeFunctions;
			y=this.$$.make(o);
			if(x!=top){return y.length};
			if(y.length/1024>this.prefs.memLimit){return false}
			x.name=y;
			return true;
		},
		getDomain:function(){
				var l=location.href
				l=l.split("///").join("//");
				l=l.substring(l.indexOf("://")+3).split("/")[0];
				while(l.split(".").length>2){l=l.substring(l.indexOf(".")+1)};
				return l
		},
		debug:function(t){
			var t=t||this,a=arguments.callee;
			if(!document.body){setTimeout(function(){a(t)},200);return};
			t.flush();
			var d=document.getElementById("sessvarsDebugDiv");
			if(!d){d=document.createElement("div");document.body.insertBefore(d,document.body.firstChild)};
			d.id="sessvarsDebugDiv";
			d.innerHTML='<div style="line-height:20px;padding:5px;font-size:11px;font-family:Verdana,Arial,Helvetica;'+
						'z-index:10000;background:#FFFFCC;border: 1px solid #333;margin-bottom:12px">'+
						'<b style="font-family:Trebuchet MS;font-size:20px">sessvars.js - debug info:</b><br/><br/>'+
						'Memory usage: '+t.usedMem()+' Kb ('+t.usedMemPercent()+'%)&nbsp;&nbsp;&nbsp;'+
						'<span style="cursor:pointer"><b>[Clear memory]</b></span><br/>'+
						top.name.split('\n').join('<br/>')+'</div>';
			d.getElementsByTagName('span')[0].onclick=function(){t.clearMem();location.reload()}
		},
		init:function(){
			var o={}, t=this;
			try {o=this.$$.toObject(top.name)} catch(e){o={}};
			this.prefs=o.$||t.prefs;
			if(this.prefs.crossDomain || this.prefs.currentDomain==this.getDomain()){
				for(var i in o){this.parent[i]=o[i]};
			}
			else {
				this.prefs.currentDomain=this.getDomain();
			};
			this.parent.$=t;
			t.flush();
			var f=function(){if(t.prefs.autoFlush){t.flush()}};
			if(window["addEventListener"]){addEventListener("unload",f,false)}
			else if(window["attachEvent"]){window.attachEvent("onunload",f)}
			else {this.prefs.autoFlush=false};
		}
	};
	
	x.$.$$={
		compactOutput:false, 		
		includeProtos:false, 	
		includeFunctions: false,
		detectCirculars:true,
		restoreCirculars:true,
		make:function(arg,restore) {
			this.restore=restore;
			this.mem=[];this.pathMem=[];
			return this.toJsonStringArray(arg).join('');
		},
		toObject:function(x){
			if(!this.cleaner){
				try{this.cleaner=new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$')}
				catch(a){this.cleaner=/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/}
			};
			if(!this.cleaner.test(x)){return {}};
			eval("this.myObj="+x);
			if(!this.restoreCirculars || !alert){return this.myObj};
			if(this.includeFunctions){
				var x=this.myObj;
				for(var i in x){if(typeof x[i]=="string" && !x[i].indexOf("JSONincludedFunc:")){
					x[i]=x[i].substring(17);
					eval("x[i]="+x[i])
				}}
			};
			this.restoreCode=[];
			this.make(this.myObj,true);
			var r=this.restoreCode.join(";")+";";
			eval('r=r.replace(/\\W([0-9]{1,})(\\W)/g,"[$1]$2").replace(/\\.\\;/g,";")');
			eval(r);
			return this.myObj
		},
		toJsonStringArray:function(arg, out) {
			if(!out){this.path=[]};
			out = out || [];
			var u; // undefined
			switch (typeof arg) {
			case 'object':
				this.lastObj=arg;
				if(this.detectCirculars){
					var m=this.mem; var n=this.pathMem;
					for(var i=0;i<m.length;i++){
						if(arg===m[i]){
							out.push('"JSONcircRef:'+n[i]+'"');return out
						}
					};
					m.push(arg); n.push(this.path.join("."));
				};
				if (arg) {
					if (arg.constructor == Array) {
						out.push('[');
						for (var i = 0; i < arg.length; ++i) {
							this.path.push(i);
							if (i > 0)
								out.push(',\n');
							this.toJsonStringArray(arg[i], out);
							this.path.pop();
						}
						out.push(']');
						return out;
					} else if (typeof arg.toString != 'undefined') {
						out.push('{');
						var first = true;
						for (var i in arg) {
							if(!this.includeProtos && arg[i]===arg.constructor.prototype[i]){continue};
							this.path.push(i);
							var curr = out.length; 
							if (!first)
								out.push(this.compactOutput?',':',\n');
							this.toJsonStringArray(i, out);
							out.push(':');                    
							this.toJsonStringArray(arg[i], out);
							if (out[out.length - 1] == u)
								out.splice(curr, out.length - curr);
							else
								first = false;
							this.path.pop();
						}
						out.push('}');
						return out;
					}
					return out;
				}
				out.push('null');
				return out;
			case 'unknown':
			case 'undefined':
			case 'function':
				if(!this.includeFunctions){out.push(u);return out};
				arg="JSONincludedFunc:"+arg;
				out.push('"');
				var a=['\n','\\n','\r','\\r','"','\\"'];
				arg+=""; for(var i=0;i<6;i+=2){arg=arg.split(a[i]).join(a[i+1])};
				out.push(arg);
				out.push('"');
				return out;
			case 'string':
				if(this.restore && arg.indexOf("JSONcircRef:")==0){
					this.restoreCode.push('this.myObj.'+this.path.join(".")+"="+arg.split("JSONcircRef:").join("this.myObj."));
				};
				out.push('"');
				var a=['\n','\\n','\r','\\r','"','\\"'];
				arg+=""; for(var i=0;i<6;i+=2){arg=arg.split(a[i]).join(a[i+1])};
				out.push(arg);
				out.push('"');
				return out;
			default:
				out.push(String(arg));
				return out;
			}
		}
	};
	
	x.$.init();
	return x;
}()