﻿// -------------------------------------------------------------
//  Client-side global variables
// -------------------------------------------------------------
    var absFromTop = "179px";
    var absFromLeft = "263px";
    
/* ****************************************************
 *  
 *  Control Description box display
 * 
**************************************************** */	
var DescriptionBox={ //begin object DescriptionBox
// -------------------------------------------------------------
//  Description Box , display , hide , populate
// -------------------------------------------------------------
CurrentImage : new String(),
FirstImage : new String(),
sOpenDescID : null, 
NotFoundtImage : "notfound",
iChunk : 0,
iChunkStep : 6,
iChunkDelay : 15,
iFixedSouth : 10,
iFixedEast : 10,
// ---------------------------------------------------------------------------------
//  dummy constructor
// ---------------------------------------------------------------------------------
Constructor : function(aSouth, aEast, aCurrentImage, aFirstImage)
{
    if (aSouth != "") this.iFixedSouth = aSouth;
    if (aEast != "") this.iFixedEast = aEast;
    if (aCurrentImage != "" || aCurrentImage != null) this.CurrentImage = aCurrentImage.replace(".jpg","");
    if (aFirstImage != "" || aFirstImage != null) this.FirstImage = aFirstImage.replace(".jpg","");
    if (this.CurrentImage == null || this.CurrentImage == "")
        this.CurrentImage = this.FirstImage;
        
    //if (this.CurrentImage != "" || this.CurrentImage != null)
    //    this.CurrentImage = this.CurrentImage.replace(".jpg","");       
    //if (this.FirstImage != "" || this.FirstImage != null)
    //    this.FirstImage = this.FirstImage.replace(".jpg","");       
},
// ---------------------------------------------------------------------------------
//  main function, doDesc, that hides any open pop-up Descs, determines 
// which Desc DIV to access, and starts its display of current Description 
// public method
// ---------------------------------------------------------------------------------
RollUp : function(e) 
{ 
	if (!e)  //for ff
        var e = window.event;  // ie code
	e.cancelBubble = true;
	e.returnValue = false;
    this.sOpenDescID = this.CurrentImage.toLowerCase();
    var eDesc = document.getElementById(this.sOpenDescID);
	if (eDesc == null)
    {
        this.sOpenDescID = this.NotFoundtImage;
        eDesc = document.getElementById(this.sOpenDescID);
		if (eDesc == null) return false;
	}
	this.iChunk =  eDesc.clientHeight;
	var eDescWidth = eDesc.clientWidth;  //bug fix?
	var eDescHeight = eDesc.clientHeight; //bug fix?
	with (eDesc)
	{
	    style.cssText = ""; 
	    style.clip = "rect(0 0 0 0)";
	    style.left = (this.iFixedEast -eDescWidth) + "px"; 
	    style.top = (this.iFixedSouth - eDescHeight) + "px";
	    style.visibility = "visible";
	}
	var t = setTimeout("DescriptionBox.ShowDesc("+eDescWidth+", "+eDescHeight+")", this.iChunkDelay);
}, // end Display method
// ---------------------------------------------------------------------------------
// remove the box by rolling down 
// public method
// ---------------------------------------------------------------------------------
RollDown : function(e) 
{ 
    if (this.sOpenDescID != null) 
    {
        var eDesc = document.getElementById(this.sOpenDescID);
	    if (eDesc == null) 
	    {
	    DescriptionBox.Remove();
	    return false;
	    }
	    this.iChunk =  0;  
	    var eDescWidth = eDesc.clientWidth; //bug fix?
	    var eDescHeight = eDesc.clientHeight; //bug fix?
	    var t = setTimeout("DescriptionBox.HideDesc("+eDescWidth+", "+eDescHeight+")", this.iChunkDelay);
	}
}, // end RollDown method
// --------------------------------------------------------------------------
// Function Kill the description text : public method
// --------------------------------------------------------------------------
Remove : function() 
{
    if (this.sOpenDescID != null) 
	{
        var eDesc = document.getElementById(this.sOpenDescID);
	    with (eDesc)
	    {
		    style.visibility = "hidden";
		    style.clip = "rect(0 0 0 0)";
		    style.cssText = ""; 
		    style.left = "-800px"; 
		    style.top = "-800px";
		}
		this.sOpenDescID = null;
	}
}, // end RemoveDesc method 
// ----------------------------------------------------------------------------
// Function which incrementally displays Desc in appropriate style
// private method
// ----------------------------------------------------------------------------
ShowDesc : function(aWidth, aHeight)
{
    if (this.sOpenDescID != null) 
	{
        var eDesc = document.getElementById(this.sOpenDescID);
        this.iChunk -= this.iChunkStep;
	    eDesc.style.clip = "rect(" + this.iChunk + "pt " + aWidth + "pt " + aHeight + "pt 0pt)";
	    if (this.iChunk > 0) 
		    var t = setTimeout("DescriptionBox.ShowDesc("+aWidth+", "+aHeight+")", this.iChunkDelay);
	}
}, // end ShowDesc method
// ----------------------------------------------------------------------------
// Function which incrementally hide Desc in appropriate style
// private method
// ----------------------------------------------------------------------------
HideDesc : function(aWidth, aHeight)
{
    if (this.sOpenDescID != null)
    {
        var eDesc = document.getElementById(this.sOpenDescID);
        this.iChunk += this.iChunkStep;
	    eDesc.style.clip = "rect(" + this.iChunk + "pt " + aWidth + "pt " + aHeight + "pt 0pt)";
	    if (this.iChunk <= aHeight) 
		    var t = setTimeout("DescriptionBox.HideDesc("+aWidth+", "+aHeight+")", this.iChunkDelay);
		else
    	    DescriptionLink.Display();    
	}
	else 
	{
        DescriptionBox.Remove();
	    DescriptionLink.Display();    
    }
} // end HideDesc method

} // end Object DescriptionBox

/* ****************************************************
 *  
 *  Control Description link to description box
 * 
 * ****************************************************/	
var DescriptionLink={ //begin DescriptionLink Object
// ---------------------------------------------------------------------
//  Description Link : hide or show the link to the description
// ---------------------------------------------------------------------
sDescriptionLinkID : "",
sPhotoDescID : "",
    
iLinkTop : 553,
iLinkLeft : 332,
iChunk : 0,
iChunkStep : 6,
iChunkDelay : 15,

/* -----------------------------------------------------------------------------------
   Constructor for the Object
-------------------	---------------------------------------------------------------- */
Constructor : function(aTop, aLeft, aDescriptionLinkID)
{ 
    if (aTop != "") this.iLinkTop = aTop;
    if (aLeft != "") this.iLinkLeft = aLeft;
    if (aDescriptionLinkID != "") this.sDescriptionLinkID = aDescriptionLinkID;
},
/* -----------------------------------------------------------------------------------
   Display, will display the "photo description link" over the image
   public method
-------------------	---------------------------------------------------------------- */
Display : function(e) 
{ 
    if (!e) { e = window.event; }
	if (e == null)  
	{
	    DescriptionLink.ShowLink();
	}
	else
	{
	    e.cancelBubble = true;
	    e.returnValue = false;
        DescriptionLink.ShowLink();
    }	
}, // end Display function
/* -----------------------------------------------------------------------------------
   private method, Display the discription link
-------------------	---------------------------------------------------------------- */
ShowLink : function ()
{
    this.sPhotoDescID = this.sDescriptionLinkID;
    if ("object" == typeof(document.getElementById(this.sPhotoDescID)))
	{
	    this.iChunk = this.iChunkStep;
		var eDescLink = document.getElementById(this.sPhotoDescID);
		with (eDescLink)
		{
		    style.left = this.iLinkLeft + "px"; 
		    style.top = this.iLinkTop + "px";
		    style.clip = "rect(0 0 0 0)";
		    style.visibility = "visible";
    	}
		var t = setTimeout("DescriptionLink.Layout()", this.iChunkDelay);
	}
	return;
},
/* -------------------------------------------------------------------------------
   Function Kill the description link
 --------------------------------------------------------------------------------*/
 Remove :	function() 
 {
    this.sPhotoDescID = this.sDescriptionLinkID;
	if ("object" == typeof(document.getElementById(this.sPhotoDescID))) 
	{
	    document.getElementById(this.sPhotoDescID).style.visibility = "hidden";
		this.sPhotoDescID = "";
	}
 },
/* ---------------------------------------------------------------------------------
// Function which incrementally displays Desc link in appropriate style
----------------------------------------------------------------------------------*/    
Layout : function()
{
	if ("object" == typeof(document.getElementById(this.sPhotoDescID)))
	{
		var eDescLink = document.getElementById(this.sPhotoDescID);
	    var xWidth = eDescLink.clientWidth;   // ff fix?
	    var xHeight = eDescLink.clientHeight; // ff fix? 
	    var iPctWidth = xWidth * (this.iChunk / 100);
	    eDescLink.style.clip =  "rect(0pt " + iPctWidth + "pt " + xHeight + "pt 0pt)";
	    if (100 >= this.iChunk) 
		    var t =setTimeout("DescriptionLink.Layout()", this.iChunkDelay);
	    this.iChunk += this.iChunkStep;
	}
}

} // end DescriptionLink Object

/* ****************************************************
 *  
 *  zoomify : wrappers 
 * 
**************************************************** */
function unHideZoom(aDo)
{   // display the div element
    if (aDo == 'true')
    {
        document.getElementById("zoomBox").style.left= absFromLeft;  
        document.getElementById("zoomBox").style.top= absFromTop;
        document.getElementById("zoomBox").style.visibility="visible";
    }
}  
function HideZoom()
{   // hide the zoom display the div element
    document.getElementById('hiddenCurrentImage').value = "";
    document.getElementById("zoomBox").style.visibility="hidden";
}  //end function 
function CanClickZoom(aImage)
{  // make visible the 'click to zoom' link if a match in array
    for (i=0; i <= gblZoomFolderList.length; i++)
    {
        if (aImage == gblZoomFolderList[i])
        {
            document.getElementById('hiddenCurrentImage').value = DescriptionBox.CurrentImage;
            document.getElementById("ClickAndZoom").style.visibility="visible";
            return;
        }
    }
    document.getElementById('hiddenCurrentImage').value = "";
    document.getElementById("ClickAndZoom").style.visibility = "hidden";
}
/******************************************************************
* CMotion Image Gallery II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Modified by jscheuer1 for vertical orientation, at http://www.dynamicDrive.com/forums
******************************************************************/

var restarea=100 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed=2 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.

var iedom=document.all||document.getElementById;
var scrollspeed=0;
var movestate="";
var actualheight=0;
var loadedyes=0
var cross_scroll = null;
var crossmain = null;
var mainobjoffset = 0;
var menu_height = 0; 

function carouselarrow(direction) {
scrollspeed = 1; 
if ("up" == direction) {
    movestate = "up";
    moveup();
}    
if ("down" == direction) {
    movestate = "down";
    movedown();
}    
}

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function moveup(){
if (loadedyes){
    movestate="up"
    if (iedom&&parseInt(cross_scroll.style.top)>(menu_height-actualheight)){
        cross_scroll.style.top=parseInt(cross_scroll.style.top)-scrollspeed+"px"
    }
}
uptime=setTimeout("moveup()",10)
}

function movedown(){
if (loadedyes){
    movestate="down"
    if (iedom&&parseInt(cross_scroll.style.top)<0){
        cross_scroll.style.top=parseInt(cross_scroll.style.top)+scrollspeed+"px"
    }
}
downtime=setTimeout("movedown()",10)
}

function motionengine(e){
var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
var curposy=window.event? event.clientY : e.clientY? e.clientY: ""
curposy-=mainobjoffset-dsocy
var leftbound=(menu_height-restarea)/2
var rightbound=(menu_height+restarea)/2
if (curposy>rightbound){
    scrollspeed=(curposy-rightbound)/((menu_height-restarea)/2) * maxspeed
    if (window.downtime) clearTimeout(downtime)
    if (movestate!="up") moveup()
}
else if (curposy<leftbound){
    scrollspeed=(leftbound-curposy)/((menu_height-restarea)/2) * maxspeed
    if (window.uptime) clearTimeout(uptime)
    if (movestate!="down") movedown()
}
else
    scrollspeed=0
}

function contains_ns6(a, b) {
while (b.parentNode)
    if ((b = b.parentNode) == a)
        return true;
return false;
}

function stopmotion(e){
if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
    if (window.downtime) clearTimeout(downtime)
    if (window.uptime) clearTimeout(uptime)
    movestate=""
}
}

function fillup(){
if (iedom){
    crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer
    menu_height=parseInt(crossmain.style.height)
    mainobjoffset=getposOffset(crossmain, "top")
    cross_scroll=document.getElementById? document.getElementById("motiongallery") : document.all.motiongallery
    actualheight=cross_scroll.offsetHeight
    crossmain.onmousemove=function(e) { motionengine(e) }
    crossmain.onmouseout=function(e) { stopmotion(e) }
}
if (window.opera){
    cross_scroll.style.top=menu_height-actualheight+'px'
    setTimeout('cross_scroll.style.top=0', 10)
}
loadedyes=1
}

// ************************************************************************

// Image Thumbnail Viewer Script- By Dynamic Drive, available at: http://www.dynamicdrive.com
// Last updated: Jan 22nd, 2007

// ************************************************************************

var thumbnailviewer={ // begin thumbnailviewer object
enableTitle: false, //Should "title" attribute of link be used as description?
enableAnimation: false, //Enable fading animation?
defineLoading: '<img src="images/loading.gif" /> Loading Image...', //Define HTML for "loading" div

scrollbarwidth: 16,
targetlinks:[], //Array to hold links with rel="thumbnail"

createthumbBox:function()
{
    document.write('<div id="thumbBox"><div id="thumbImage"></div></div>')
    document.write('<div id="thumbLoading">'+this.defineLoading+'</div>')
    this.thumbBox=document.getElementById("thumbBox")
    this.thumbImage=document.getElementById("thumbImage") //Reference div that holds the shown image
    this.thumbLoading=document.getElementById("thumbLoading") //Reference "loading" div that will be shown while image is fetched
    this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
},

centerDiv:function(divobj)
{ //Centers a div element on the page
    var ie=document.all && !window.opera
    var dom=document.getElementById
    var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
    var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
    var docwidth=(ie)? this.standardbody.clientWidth : window.innerWidth-this.scrollbarwidth
    var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
    var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
    var objwidth=divobj.offsetWidth //width of div element
    var objheight=divobj.offsetHeight //height of div element
    divobj.style.left=absFromLeft  
    divobj.style.top=absFromTop
    divobj.style.visibility="visible"
},

showthumbBox:function()
{ //Show ThumbBox div
    HideZoom();
    DescriptionBox.Remove();
    this.centerDiv(this.thumbBox);
    DescriptionLink.Display(null);
    CanClickZoom(DescriptionBox.CurrentImage);
},

loadimage:function(link)
{ //Load image function that gets attached to each link on the page with rel="thumbnail"
    if (document.getElementById("zoomBox").style.visibility=="visible") //if zoomBox is visible on the page already
        document.getElementById("zoomBox").style.visibility=="hidden"
    if (this.thumbBox.style.visibility=="visible") //if thumbox is visible on the page already
        this.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
    var imageHTML='<img src="' + link.getAttribute("href") + '" style="height: 393px; width: 564px;" height="393" width="564" />' //Construct HTML for shown image
    DescriptionBox.CurrentImage = link.getAttribute("href").replace(".jpg","");
    DescriptionBox.CurrentImage = DescriptionBox.CurrentImage.substring(DescriptionBox.CurrentImage.lastIndexOf("/")+1);
    this.centerDiv(this.thumbLoading) //Center and display "loading" div while we set up the image to be shown
    this.thumbImage.innerHTML=imageHTML //Populate thumbImage div with shown image's HTML (while still hidden)
    this.featureImage=this.thumbImage.getElementsByTagName("img")[0] //Reference shown image itself
    this.featureImage.onload=function()
    { //When target image has completely loaded
        thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div
        thumbnailviewer.showthumbBox() //Display "thumbbox" div to the world!
    }
    if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload bug: panoramio.com/blog/onload-event/
        this.featureImage.src=link.getAttribute("href")
    this.featureImage.onerror=function()
    { //If an error has occurred while loading the image to show
        thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div, game over
    }
}, //end of function loadimage

closeit:function()
{ //Close "thumbbox" div function
    this.thumbBox.style.visibility="hidden"
    this.thumbImage.innerHTML=""
},

cleanup:function()
{ //Clean up routine on page unload
    this.thumbLoading=null
    if (this.featureImage) this.featureImage.onload=null
    this.featureImage=null
    this.thumbImage=null
    for (var i=0; i<this.targetlinks.length; i++)
        this.targetlinks[i].onclick=null
    this.thumbBox=null
},

dotask:function(target, functionref, tasktype)
{ //assign a function to execute to an event handler (ie: onunload)
    var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
    if (target.addEventListener)
        target.addEventListener(tasktype, functionref, false)
    else if (target.attachEvent)
        target.attachEvent(tasktype, functionref)
},

loadfirst:function()
{ //Load first image 
    if (document.getElementById("zoomBox").style.visibility=="visible") //if zoomBox is visible on the page already
        document.getElementById("zoomBox").style.visibility=="hidden"
    if (this.thumbBox.style.visibility=="visible") //if thumbox is visible on the page already
        this.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
    if (DescriptionBox.CurrentImage == "" || DescriptionBox.CurrentImage == null)
        DescriptionBox.CurrentImage = DescriptionBox.FirstImage.replace(".jpg","")
    else    
        DescriptionBox.CurrentImage = DescriptionBox.CurrentImage.replace(".jpg","")
    var imageHTML='<img src="images/'+gblGallery+'/'+DescriptionBox.CurrentImage+".jpg"+'" style="height: 393px; width: 564px;" height="393" width="564" />' //Construct HTML for shown image
    this.thumbImage.innerHTML=imageHTML //Populate thumbImage div with shown image's HTML (while still hidden)
    this.featureImage=this.thumbImage.getElementsByTagName("img")[0] //Reference shown image itself
    this.centerDiv(this.thumbBox)
    DescriptionLink.Display(null);
    CanClickZoom(DescriptionBox.CurrentImage);
    if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload bug: panoramio.com/blog/onload-event/
        this.featureImage.src=DescriptionBox.CurrentImage
}, //end of function loadfirst

init:function()
{ //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
    var pagelinks=document.getElementsByTagName("a")
    for (var i=0; i<pagelinks.length; i++)
    { //BEGIN FOR LOOP
        if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="thumbnail")
        { //Begin if statement
            pagelinks[i].onclick=function() 
            {
                thumbnailviewer.loadimage(this) //Load image
                return false
            }
            this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
        } //end if statement
    } //END FOR LOOP
thumbnailviewer.loadfirst()
} //END init() function

} // end thumbnailviewer object

/* ***************************************
 *
 * onload and page functions
 *
 * **************************************/
window.onload=function(){
    mm_preloadImages('images/tal_left.jpg','images/tal2.jpg','images/tal_left.jpg','images/tal_l_up.jpg','images/bgr_head.jpg','images/tal_right.jpg','images/bgr_cont.jpg');
    unHideZoom(gblZoom);
    fillup();
    DescriptionLink.Display();
    }
thumbnailviewer.createthumbBox() //Output HTML for the image thumbnail viewer
thumbnailviewer.dotask(window, function(){thumbnailviewer.init()}, "load") //Initialize script on page load
thumbnailviewer.dotask(window, function(){thumbnailviewer.cleanup()}, "unload")