// -----------------------------------------------------------------------------------
//
//	Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com
//	3/31/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------
/*

	Table of Contents
	-----------------
	Configuration
	Global Variables

	Extending Built-in Objects	
	- Object.extend(Element)
	- Array.prototype.removeDuplicates()
	- Array.prototype.empty()

	Lightbox Class Declaration
	- initialize()
	- flashstart()
	- changeImage()
	- resizeImageContainer()
	- showImage()
	- updateDetails()
	- updateNav()
	- enableKeyboardNav()
	- disableKeyboardNav()
	- keyboardAction()
	- preloadNeighborImages()
	- end()
	
	Miscellaneous Functions
	- getPageScroll()
	- getPageSize()
	- getKey()
	- listenKey()
	- showSelectBoxes()
	- hideSelectBoxes()
	- pause()
	- initLightbox()
	
	Function Calls
	- addLoadEvent(initLightbox)
	
*/
// -----------------------------------------------------------------------------------


//
//	Configuration
//
var flashfileLoadingImage = "/javascript/lightbox/images/loading.gif";		
var flashfileBottomNavCloseImage = "closelabel.gif";

var flashresizeSpeed = 0;	// controls the speed of the image resizing (1=slowest and 10=fastest)

var flashborderSize = 32;	//if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var flag = false;
var typeChk = ""; 
var floorFlag = false;
var flashimageArray = new Array;
var flashactiveImage;
var flashwidths = new Array(); // for storing flash width
var flashheights = new Array();// for storing flash height
var flasharrayAnchors = new Array();// for storing flash href
var flashanchorNoArray = new Array();//for storing anchors no
var specialflag = false;

if(flashresizeSpeed > 10){ flashresizeSpeed = 10;}
if(flashresizeSpeed < 1){ flashresizeSpeed = 1;}
flashresizeDuration = (11 - flashresizeSpeed) * 0.15;

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- flashstart()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var flashLightbox = Class.create();

flashLightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function(anchor) {
	    		
	  	if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByName('flash');
        
		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if(anchor.getAttribute('flashpath').indexOf('GMAP') == 1)
			{
			    specialflag = true;
			}
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('flashbox'))){
				flashwidths[i] = anchor.getAttribute('Bigflashwidth');
				flashheights[i]= anchor.getAttribute('Bigflashheight');
				flasharrayAnchors[i] = anchor.getAttribute('flashpath');
				flashanchorNoArray[i] = anchor.getAttribute('flashNo');
				anchor.onclick = function () {
				if(objFlashData != null){
				var currentFlash = this.getAttribute('flashNo');
				if(this.getAttribute('IsFloorPlan') != null)
				{
				  floorFlag = true;
				  if(document.getElementById('dynamicText') != null)
				        document.getElementById('dynamicText').innerHTML = 'Floor Plan';
				   
				   typeChk = "floorPlan";     
				   
				}
				
				if(this.getAttribute('isGmap') != null)
				{ 
				if(document.getElementById('dynamicText') != null)
				        document.getElementById('dynamicText').innerHTML = 'Google Map';
				flag = true;
				typeChk = "googleMap";			    
				}
				
				if(this.getAttribute('IsThreeSixty') != null)
				{ 
				typeChk = "ThreeSixty";			    
				if(document.getElementById('dynamicText') != null)
				        document.getElementById('dynamicText').innerHTML = '360 Virtual Tour';
				floorFlag = false;
				}
				
				else { flag = false;
				if(specialflag == true)
				{
				
				 flashgetbar(1,1,objFlashData,flag);
				}
				 else
				{
				 flashgetbar(1,1,objFlashData,flag);
				}
				 }
				 myflashLightbox.flashstart(this); return false;}
				 else { myflashLightbox.flashstart(this); return false; }
				 }
			}
		}
       
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','flashoverlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myflashLightbox.flashend(); return false; }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','flashlightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);
		
		//Creating text Container div
		var objTopTextContainer = document.createElement("div");
		objTopTextContainer.setAttribute('id','flashtopTextContainer');
		objTopTextContainer.className = 'clearfix';
				
		//Creating TextContainer Div
		var objTextContainer = document.createElement("div");
		objTextContainer.setAttribute('id','flashTextContainer');
				
		//heading div
		var objHeading = document.createElement("div");
		objHeading.className = 'flashheading';
		
		//blue color span
		var objHeadingSpanFirst = document.createElement("span");
		objHeadingSpanFirst.setAttribute('id','bluepart');
		objHeadingSpanFirst.className = 'flashbluecolor';
				
		//pink color span
		var objHeadingSpanSecond = document.createElement("span");
		objHeadingSpanSecond.setAttribute('id','pinkpart');
		objHeadingSpanSecond.className = 'flashpinkcolor';
				
		//appending above two span to h1
		objHeading.appendChild(objHeadingSpanFirst);
		objHeading.appendChild(objHeadingSpanSecond);
		
		//append heading to TextContainer div
		objTextContainer.appendChild(objHeading);
				
		//creating close class
		var objClose = document.createElement("div");
		objClose.className = 'flashclose';
								
		//creating close image class
		var objCloseImg = document.createElement("img");
		objCloseImg.setAttribute('src','/images/close_button.gif');
		objCloseImg.setAttribute('border','0');
		objCloseImg.setAttribute('titile','Close');
		objCloseImg.setAttribute('alt','Close');
		objCloseImg.style.cursor = 'pointer';
		objCloseImg.onclick = function() { myflashLightbox.flashend(); return false; };
		
		//append close img to close div
		objClose.appendChild(objCloseImg);
		
		//append close div to Text close div
		objTextContainer.appendChild(objClose);
		
		
		var clearDiv = document.createElement("div");
		clearDiv.className = "clear";
		
		objTextContainer.appendChild(clearDiv);
				
		//appending text container div to toptextcontainer
		objTopTextContainer.appendChild(objTextContainer);
					
		
		//creating text div
		var objText2 = document.createElement("div");
		objText2.setAttribute('id','dynamicText');
		objText2.style.marginLeft = "30px";
		objText2.style.marginTop = "-2px";
		objText2.style.fontSize = "12px";
			
		//creating span
		var objTextSpan = document.createElement("span");
		objTextSpan.setAttribute('id','flashtypeText');
		objTextSpan.className = "Imagebluecolor";
		objTextSpan.style.color = "#304382";
		objTextSpan.style.fontSize = "12px";
		
		//appending span to text2 div
		objText2.appendChild(objTextSpan);
		
		//appending text div to Text close div
		objTopTextContainer.appendChild(objText2);
		
		//appending text close div to lightbox
		objLightbox.appendChild(objTopTextContainer);
		
		//creating outer img container div
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','flashouterImageContainer');
	    objOuterImageContainer.style.borderBottom = "none";
		objOuterImageContainer.style.borderTop = "none";
		objLightbox.appendChild(objOuterImageContainer);
		
		var outerTable = document.createElement("table");
		outerTable.cellSpacing = "0";
		outerTable.cellPadding = "0";
		outerTable.setAttribute("align","center");
		objOuterImageContainer.appendChild(outerTable);
			
		var outerbody = document.createElement("tbody");
		outerTable.appendChild(outerbody);
		
		var outertr = document.createElement("tr");
		outerbody.appendChild(outertr);
		
		var outertd = document.createElement("td");
		outertd.style.verticalAlign = "bottom";
		//outertd.style.width = "12px";
		outertr.appendChild(outertd);

		var leftBorderImage = document.createElement("img");
		leftBorderImage.setAttribute('id','leftborder');
		leftBorderImage.setAttribute("src","/images/border_pic_left.gif");
		outertd.appendChild(leftBorderImage);
		
		var innertd = document.createElement("td");
		outertr.appendChild(innertd);
				
		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','flashimageContainer');
		objImageContainer.style.background = "transparent url(/images/border_pic_bottom.gif) repeat-x scroll center bottom";
		objImageContainer.style.verticalAlign = "bottom";
		
		innertd.appendChild(objImageContainer);
			
		/*var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','lightboxImage');
		objLightboxImage.style.margin = "0px";
		objImageContainer.appendChild(objLightboxImage);*/
	
	    var righttd = document.createElement("td");
	    //righttd.style.width = "12px";
	    righttd.style.verticalAlign = "bottom";
	    outertr.appendChild(righttd);
	    
	    var RightBorderImage = document.createElement("img");
		RightBorderImage.setAttribute('id','rightborder');
		RightBorderImage.setAttribute("src","/images/border_pic_right.gif");
		righttd.appendChild(RightBorderImage);
		
		var objflashLoading = document.createElement("div");
		objflashLoading.setAttribute('id','flashloading');
		objImageContainer.appendChild(objflashLoading);
				
		var objflashLoadingImage = document.createElement("img");
		objflashLoadingImage.setAttribute('src', flashfileLoadingImage);
		objflashLoadingImage.style.width = "183px";
		objflashLoadingImage.style.height = "45px";
		objflashLoadingImage.style.border = "none";
		objflashLoading.appendChild(objflashLoadingImage);
		
		var objdivlayer = document.createElement("div");
        objdivlayer.setAttribute('id','flashlayer');
        objdivlayer.className = 'clearfix';
        objImageContainer.appendChild(objdivlayer);
		
		//imageDataContainer
        var objFlashDataContainer = document.createElement("div");
		objFlashDataContainer.setAttribute('id','flashimageDataContainer');
		objFlashDataContainer.className = 'clearfix';
        objLightbox.appendChild(objFlashDataContainer);
        
        //imageData
		var objFlashData = document.createElement("div");
		objFlashData.setAttribute('id','flashimageData');
		objFlashDataContainer.appendChild(objFlashData);

        //calling get bar       
        if(specialflag == true)
        {
        flashgetbar(1,1,objFlashData,false);
        }
        else
        {
        flashgetbar(1,1,objFlashData,false);
        }		
	    //imageDetails
		var objFlashDetails = document.createElement("div");
		objFlashDetails.setAttribute('id','flashimageDetails');
		objFlashDataContainer.appendChild(objFlashDetails);
        
        //creating text2 div
        var objtext2 = document.createElement("div");
        objtext2.className = 'flashtext';
        
        //creating text2 div innerText
        var objtext2InnerText = document.createTextNode("Our 360");
        objtext2.appendChild(objtext2InnerText);
        
        //creating sup for text div
		var objSuptext2 = document.createElement("sup");
		var objSupText2o = document.createTextNode("o");
		objSuptext2.appendChild(objSupText2o);
		
		//appending sup to text div
		objtext2.appendChild(objSuptext2);
                
        //creating virtual data information
        var objvirtualtext2 = "Our 360 virtual tour can be viewed using Adobe Flash Player and can be downloaded for free <a style='text-decoration:underline;' target='blank' href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'>here.</a>";
        
        //append virtual text to text2 div 
        objtext2.innerHTML = objvirtualtext2;
        
        //appending text2 div to Image Details
        objFlashDetails.appendChild(objtext2);
	},
	
	//
	//	flashstart()
	//	Display overlay and lightbox. If image is part of a set, add siblings to flashimageArray.
	//
	flashstart: function(imageLink) {	

        var flashpath = imageLink.getAttribute('flashpath');
        var width = imageLink.getAttribute('Bigflashwidth');
        var height = imageLink.getAttribute('Bigflashheight');
        //var apniFlash = flashNo;
        
		hideSelectBoxes();
        
        // stretch overlay to fill page and fade in
		var flasharrayPageSize = flashgetPageSize();
		Element.setHeight('flashoverlay', flasharrayPageSize[1]);
		new Effect.Appear('flashoverlay', { duration: 0.2, from: 0.0, to: 0.8 });

		flashimageArray = [];
		flashimageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'flashbox')){
			// add single image to flashimageArray
			flashimageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('apnatitle')));			
		} else {
		// if image is part of a set..

			// loop through anchors, find other images in set, and add them to flashimageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					flashimageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('apnatitle')));
				}
			}
			flashimageArray.removeDuplicates();
			while(flashimageArray[flashimageNum][0] != imageLink.getAttribute('href')) { flashimageNum++;}
		}

		// calculate top offset for the lightbox and display 
		var flasharrayPageSize = flashgetPageSize();
		var flasharrayPageScroll = flashgetPageScroll();
		var flashlightboxTop = flasharrayPageScroll[1] + (flasharrayPageSize[3] / 15);

		Element.setTop('flashlightbox', flashlightboxTop);
		Element.show('flashlightbox');
				
		this.flashchangeImage(flashimageNum,flashpath,width,height);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	flashchangeImage: function(flashimageNum,flashpath,width,height) {	
		
		flashactiveImage = flashimageNum;	// update global var
                       		        
        Element.show('flashloading');
			
		Element.hide('leftborder');
		Element.hide('lightboxImage');
		Element.hide('rightborder');
		 hide();
        
		resizeFlash(flashwidths[flashactiveImage],flashheights[flashactiveImage],flashpath,width,height);
	},

	//
	//	resizeImageContainer()
	//
	flashresizeImageContainer: function(imgWidth, imgHeight,flashpath,flashwidth,flashheight) {
        
        var width = new String();
        var height = new String();
        
        width = imgWidth;
        width = width.substring(0,width.length-2);
        
        if(imgHeight == null)
        {
            height = flashheight;
            height = height.substring(0,height.length-2);
        }
        else{
            height = imgHeight;
            height = height.substring(0,height.length-2);
        }
        
        imgWidth = width;
        imgHeight = height;
        
        // get current height and width
		this.wCur = Element.getWidth('flashouterImageContainer');
		this.hCur = Element.getHeight('flashouterImageContainer');

		// scalars based on change from old to new
		//imgWidth = imgWidth.remove("px");
				
		this.xScale = ((imgWidth + (flashborderSize )) / this.wCur);
		this.yScale = ((imgHeight  + (flashborderSize )) / this.hCur);

		// calculate size difference between new and old image, and resize if necessary
		wDiff = (this.wCur - flashborderSize * 2) - imgWidth - 2;
		hDiff = (this.hCur - flashborderSize * 2) - imgHeight + 3;

        // if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		if(!( hDiff == 0)){ new Effect.Scale('flashouterImageContainer', this.yScale, {scaleX: false, duration: 0, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('flashouterImageContainer', this.xScale, {scaleY: false, delay: 0, duration: 0}); }

		var b = 0;
        
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
        var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion==6)
        {  b = 20; }
        else if (ieversion==7)
        {  b = 20; }
        }
        else
        { b = 20;  }
	//	Element.setHeight('prevLink', imgHeight);
	//	Element.setHeight('nextLink', imgHeight);
		Element.setWidth('flashimageDataContainer', ((imgWidth + (flashborderSize * 2))/100)+b);
		Element.setWidth('flashtopTextContainer', ((imgWidth + (flashborderSize * 2))/100)+20);
   
		this.flashshowImage(flashpath,flashwidth,flashheight);
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	flashshowImage: function(flashpath,width,height){
		Element.hide('flashloading');
		new Effect.Appear('flashouterImageContainer', { duration: 0.0, queue: 'end', afterFinish: function(){ hide(); Flash(flashpath,width,height);
	    
		 myflashLightbox.flashupdateDetails();
		
		
		if(flag == false){ UpdateBorders("HIDE");} else { UpdateBorders("dynamic"); } } });
	//	this.preloadNeighborImages();
	  	 
	  	
	  	 
	  	 
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	flashupdateDetails: function() {
	
	
	if(document.getElementById("flashouterImageContainer").style.width != '')
	{	
	//a;ert("a");
	if(document.getElementById("flashouterImageContainer").style.width == "800px" || document.getElementById("flashouterImageContainer").style.width == "640px")
            document.getElementById("flashouterImageContainer").style.width = parseInt(document.getElementById("flashouterImageContainer").style.width) + 64 + "px";
        else
            document.getElementById("flashouterImageContainer").style.width = "864px";
    }
     else
            document.getElementById("flashouterImageContainer").style.width = "864px";
    
    //alert(document.getElementById("flashouterImageContainer").style.width);
    
    
    document.getElementById("flashtopTextContainer").style.width = parseInt(document.getElementById("flashtopTextContainer").style.width) + 44 + "px";
    document.getElementById("flashimageDataContainer").style.width = parseInt(document.getElementById("flashimageDataContainer").style.width) + 44 + "px";
		
	
	
//	if(floorFlag == true)
//	{
//	    document.getElementById('dynamicText').innerHTML = '';
//	    document.getElementById('dynamicText').innerHTML = 'Floor Plan';	    	   
//	}
//	else if(flag == false)
//	{
//	    document.getElementById('dynamicText').innerHTML = '';
//	    document.getElementById('dynamicText').innerHTML = '360 Virtual Tour';
//	}
//	else
//	{
//	    document.getElementById('dynamicText').innerHTML = '';
//	    document.getElementById('dynamicText').innerHTML = 'Google Map';
//	    UpdateBorders("dynamic");
//	}
//	}
	var blue = document.getElementById('bluepart');
	var pink = document.getElementById('pinkpart');
	
	var obj = flashimageArray[flashactiveImage][1].split("-");
	blue.innerHTML = obj[0];
	pink.innerHTML = "- " + obj[1];
	
	
	if(typeChk == "ThreeSixty")
	{
	    new Effect.Parallel(
			[ new Effect.SlideDown( 'flashimageDataContainer', { sync: true, duration: 0, from: 0.0, to: 0.0 }), 
			  new Effect.Appear('flashimageDataContainer', { sync: true, duration: 0.0 }) ], 
			{ duration: 0.0, afterFinish: function() { myflashLightbox.flashupdateNav();   }  } 
		);
		
		UpdateBorders("Hide");
	}
	else
	{
	    document.getElementById("flashimageDataContainer").style.display = "none";
	    document.getElementById("flashouterImageContainer").style.height = parseInt(document.getElementById("flashouterImageContainer").style.height) + 20 + "px";
	    UpdateBorders("dynamic");
	}
		
		new Effect.Parallel(
		    [ new Effect.SlideDown( 'flashtopTextContainer', { sync: true, duration: 0.0, from: 0.0, to: 0.0 }),
		      new Effect.Appear('flashtopTextContainer', { sync: true, duration: 0.0 }) ],
		    { duration:0.0, afterFinish: function() { myflashLightbox.flashupdateNav();  } }
		);
		
	
    
	},
	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	flashupdateNav: function() {
	
	if(typeChk == "floorPlan" || typeChk == "ThreeSixty")
	{
		document.getElementById("flashouterImageContainer").style.width = "864px";
		if(typeChk == "ThreeSixty")
		{
		    UpdateBorders("HIDE");
		}
		
	}
	else
	{
		 document.getElementById("flashouterImageContainer").style.width = "704px";
		 UpdateBorders("dynamic");
    }
    
		 
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c')){	// close lightbox
			myflashLightbox.flashend();
		} else if(key == 'p'){	// display previous image
			if(flashactiveImage != 0){
				myflashLightbox.disableKeyboardNav();
				myflashLightbox.flashchangeImage(flashactiveImage - 1);
			}
		} else if(key == 'n'){	// display next image
			if(flashactiveImage != (flashimageArray.length - 1)){
				myflashLightbox.disableKeyboardNav();
				myflashLightbox.flashchangeImage(flashactiveImage + 1);
			}
		}


	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	flashpreloadNeighborImages: function(){

		if((flashimageArray.length - 1) > flashactiveImage){
			preloadNextImage = new Image();
			preloadNextImage.src = flashimageArray[flashactiveImage + 1][0];
		}
		if(flashactiveImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = flashimageArray[flashactiveImage - 1][0];
		}
		
		//document.getElementById('flashlightboxImage').style.height = '0px';
		//document.getElementById('flashlightboxImage').style.width = '0px';
		
	},

	//
	//	end()
	//
	flashend: function() {
		this.disableKeyboardNav();
		Element.hide('flashlightbox');
		new Effect.Fade('flashoverlay', { duration: 0.2});
		showSelectBoxes();
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function flashgetPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	flasharrayPageScroll = new Array('',yScroll) 
	return flasharrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function flashgetPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	flasharrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return flasharrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

// ---------------------------------------------------



function flashinitLightbox() { myflashLightbox = new flashLightbox(); }
Event.observe(window, 'load', flashinitLightbox, false);

function UpdateBorders(action)
{
    var obj = document.getElementById('flashouterImageContainer');
    if(floorFlag == false)
    {
    if(action == "HIDE"){
        obj.style.borderTop="none";
        obj.style.borderBottom="none";
    }
    }
    if(action == "SHOW"){
        obj.style.borderTop="1px solid #D8D8D6";
        obj.style.borderBottom="1px solid #D8D8D6";
    }
    if(action == "dynamic"){
        obj.style.borderTop="none";
        obj.style.borderBottom="1px solid #D8D8D6";
    }
   
}

function flashgetbar(CurrentIndex,TotalPages,objFlashData,flags)
{
        if(flags == true)
        {
        var a = document.getElementById('flashimageDataContainer');
        while(a.hasChildNodes())
        {
            a.removeChild(objFlashData.lastChild);
        }
            return;
        }
     while(objFlashData.hasChildNodes())
     {
        objFlashData.removeChild(objFlashData.lastChild);
     }
        //creating count div
        var objcount = document.createElement("div");
        objcount.className = 'count2';
        objcount.style.height='27px';
        objcount.style.dislplay='block';
        var barIcons = 10;
        var minindex = 0;
        var maxindex = 0;
        var enablePrevious = false;
        var enableNext = false;
        var temp = 0;
        if(TotalPages > barIcons && CurrentIndex > barIcons /2)
        {
            var enablepaging = true;
        }
        else{
            var enablepaging = false;
        }
        
        if(enablepaging)//if paging true
        {
        
        if ((CurrentIndex + 5) > TotalPages)
            {
                minIndex = TotalPages - barIcons;
            }
        else
            {
                minIndex = CurrentIndex - barIcons / 2;
            }
            
         if ((CurrentIndex + 5) > TotalPages)
         {
                maxIndex = TotalPages;
         }
         else if (CurrentIndex > TotalPages - barIcons / 2)
         {
                maxIndex = TotalPages;
         }
         else
         {
              maxIndex = CurrentIndex + ((barIcons / 2) - 1);
         }
            
        }//end if
        else
        {
            minIndex = 1;
            maxIndex = TotalPages > barIcons ? barIcons : TotalPages;
        }
        enablePrevious = CurrentIndex > 1 ? true : false;
        enableNext = CurrentIndex == TotalPages ? false : true;
       
        if (enablePrevious)
        {
        
        var objcount2anch = document.createElement("a");
        objcount2anch.title = "Previous Image";
        objcount2anch.className = "PreviousAnchor";
        objcount2anch.style.background='transparent url(/images/active_back.gif) no-repeat scroll 0% 0%';
        objcount2anch.style.padding = '5px 11px';
        objcount2anch.setAttribute('flashpath',flasharrayAnchors[CurrentIndex-2]);
        objcount2anch.setAttribute('Bigflashwidth',flashwidths[CurrentIndex-2]);
        objcount2anch.setAttribute('Bigflashheight',flashheights[CurrentIndex-2]);
        objcount2anch.setAttribute('href','javascript:void(0);');
        if(speicalflag == true)
            flashgetbar(1,1,objFlashData,false);
        else
            flashgetbar(1,1,objFlashData,false);
         myflashLightbox.flashchangeImage(CurrentIndex-1,this.getAttribute('flashpath'),this.getAttribute('Bigflashwidth'),this.getAttribute('Bigflashheight')); 
        var objcount2anchText = document.createTextNode("Previous");
        objcount2anch.appendChild(objcount2anchText);
        objcount.appendChild(objcount2anch);
		}
        else
        {
        var objcount2 = document.createElement("span");
        objcount2.className = 'countdisabled3';
        var objcount2anch = document.createElement("a");
        objcount2anch.title = "Previous Image unavailable";
        objcount2anch.setAttribute('href','javascript:void(0);');
        objcount2anch.style.padding = "5px 1px 5px 0px";
        var objcount2anchText = document.createTextNode("Previous");
        objcount2anch.appendChild(objcount2anchText);
        objcount2.appendChild(objcount2anch);
		objcount.appendChild(objcount2);
        }
        var topi = "a";
        var divid = "b";
        for (var i = minIndex; i <= maxIndex; i++)
        {
            topi += "a";
            divid += "b";
            if (i != CurrentIndex)
            {
               if(i > 9)
               {
                 //creating anchor1 for count2 div
                 var objanchor = document.createElement("a");
                 objanchor.style.padding = '5px 9px 5px 6px';
                 objanchor.setAttribute('flashpath',flasharrayAnchors[i-1]);
                 objanchor.setAttribute('Bigflashwidth',flashwidths[i-1]);
                 objanchor.setAttribute('Bigflashheight',flashheights[i-1]);
                 objanchor.setAttribute('flashNo',flashanchorNoArray[i-1]);
                 objanchor.setAttribute('href','javascript:void(0);');
                 objanchor.setAttribute('ImageNo',anchorNoImageArray[i-1]);
                 objanchor.onclick = function() {  
                 var currentImage = parseInt(this.getAttribute('ImageNo'));
                 if(internationalFlag == true)
                 {
                 flashgetbar(1,1,objFlashData,false,true);
                 }
                 else
                 {
                 flashgetbar(1,1,objFlashData,false,false);
                 }
                 myLightbox.changeImage(currentImage-1); return false; }
                 var objanchorText = document.createTextNode(i);
                 objanchor.appendChild(objanchorText);
                 objcount.appendChild(objanchor);
               }
               else{
                 var objanchor = document.createElement("a");
                 objanchor.setAttribute('href','javascript:void(0);');
                 objanchor.setAttribute('ImageNo',anchorNoImageArray[i-1]);
                 objanchor.setAttribute('flashpath',flasharrayAnchors[i-1]);
                 objanchor.setAttribute('Bigflashwidth',flashwidths[i-1]);
                 objanchor.setAttribute('Bigflashheight',flashheights[i-1]);
                 objanchor.setAttribute('flashNo',flashanchorNoArray[i-1]);
                 objanchor.onclick = function() { 
                 var currentImage = parseInt(this.getAttribute('ImageNo'));
                 if(internationalFlag == true)
                 {
                 flashgetbar(1,1,objFlashData,false,true);
                 }
                 else
                 {
                 flashgetbar(1,1,objFlashData,false,false);
                 }
                 myLightbox.changeImage(currentImage-1); return false;
                 }
                 var objanchorText = document.createTextNode(i);
                 objanchor.appendChild(objanchorText);
                 objcount.appendChild(objanchor);
                 temp = temp + 1;
                 }
             }
             else{
                if(i>9 && i<99)
                {
                 var objanchor = document.createElement("a");
                 objanchor.style.padding='5px 9px 5px 6px';
                 objanchor.style.color = "rgb(209, 0, 116)";
                 objanchor.style.background='url(/images/number_back.gif) no-repeat';
                 objanchor.style.cursor='default';
                 objanchor.setAttribute('flashpath',flasharrayAnchors[i-1]);
                 objanchor.setAttribute('Bigflashwidth',flashwidths[i-1]);
                 objanchor.setAttribute('Bigflashheight',flashheights[i-1]);
                 objanchor.setAttribute('flashNo',flashanchorNoArray[i-1]);
                 objanchor.setAttribute('href','javascript:void(0);');
                 objanchor.setAttribute('id',topi);
                 objanchor.setAttribute('ImageNo',anchorNoImageArray[i-1]);
                 objanchor.onclick = function() { javascript:void(0); }
                 var objanchorText = document.createTextNode(i);
                 objanchor.appendChild(objanchorText);
                 objcount.appendChild(objanchor);          
                 }
                 else
                 {
                 var objanchor = document.createElement("a");
                 objanchor.style.background='transparent url(/images/number_back.gif) no-repeat scroll 0% 0%';
                 objanchor.style.color='rgb(209, 0, 116)';
                 objanchor.style.cursor='default';
                 objanchor.setAttribute('href','javascript:void(0);');
                 objanchor.setAttribute('id',topi);
                 objanchor.setAttribute('flashpath',flasharrayAnchors[i-1]);
                 objanchor.setAttribute('Bigflashwidth',flashwidths[i-1]);
                 objanchor.setAttribute('Bigflashheight',flashheights[i-1]);
                 objanchor.setAttribute('flashNo',flashanchorNoArray[i-1]);
                 objanchor.onclick = function() { javascript:void(0); }
                 var objanchorText = document.createTextNode(i);
                 objanchor.appendChild(objanchorText);
                 objcount.appendChild(objanchor);  
                 }
             }
        }
        objFlashData.appendChild(objcount);
       if(enableNext)
       {
        //creating next anchor for count2 div
        var objanchorNext = document.createElement("a");
        objanchorNext.title = "Next Image";
        objanchorNext.style.padding = "5px 26px 5px 22px";
        objanchorNext.style.background='transparent url(/images/active_back.gif) no-repeat scroll 0% 0%';
        objanchorNext.setAttribute('href','javascript:void(0);');
        objanchorNext.className = 'NextAnchor';
        
        objanchorNext.setAttribute('flashpath',flasharrayAnchors[CurrentIndex]);
        objanchorNext.setAttribute('Bigflashwidth',flashwidths[CurrentIndex]);
        objanchorNext.setAttribute('Bigflashheight',flashheights[CurrentIndex]);
        objanchorNext.onclick = function() { 
        if(specialflag == true)
            flashgetbar(1,1,objFlashData,false);
        else
            flashgetbar(1,1,objFlashData,false);
        
         myflashLightbox.flashchangeImage(CurrentIndex,this.getAttribute('flashpath'),this.getAttribute('Bigflashwidth'),this.getAttribute('Bigflashheight')); 
         }
       
        var objanchorNextText = document.createTextNode("Next");
        objanchorNext.appendChild(objanchorNextText);
        objcount.appendChild(objanchorNext);
        }
      else{
        var objNextDiv = document.createElement("span");
        objNextDiv.className = 'countdisabled3';
        var objanchorNext = document.createElement("a");
        objanchorNext.title = "Next image unavailable";
        objanchorNext.setAttribute('href','javascript:void(0);');
        objanchorNext.style.padding = "5px 0px";
        var objanchorNextText = document.createTextNode("Next");
        objanchorNext.appendChild(objanchorNextText);
        objNextDiv.appendChild(objanchorNext);
        objcount.appendChild(objNextDiv);
      }
  }



function showHide(apnidiv,topi,e) {
if(document.getElementById("flashlayer").innerHTML=='') {
// Get the hover location
var height = e.clientY + parseInt('5');
// Get the height inside the hover anchor
var offsetHeight = parseInt(e.offsetY);
height = (height - offsetHeight) - 400;

// Get the hover location(width)
var width = e.clientX
// Get the width inside the hover anchor
var offsetWidth = parseInt(e.offsetX);
width = width - offsetWidth;

var filepath = topi.getAttribute('flashpath');
var flashwidth = "144px";
var flashheight = "50px";

//var localdiv = findPosX(apnidiv);
//var verylocal = findPosY(apnidiv);
var layer = document.getElementById("flashlayer");

layer.style.position = 'relative';

// Set the div top to the height 
layer.style.top = parseInt(height) + parseInt('240') ;

// Set the div Left to the height 
layer.style.left = parseInt(width) - parseInt('600');

layer.style.display = 'block';

document.getElementById('flashlayer').innerHTML='<object type="application/x-shockwave-flash" '+
        ' data="' + filepath + '"' + ' width="'+ flashwidth +'"' + 'height="' + flashheight + '">'+
        '<param name="movie" value="'+ filepath + '" />'+
        '<param name="wmode" value="transparent"/>'+
        '</object>';
 }
else {
document.getElementById("flashlayer").innerHTML='';
  }

 }
 
 function hide() {
 document.getElementById('flashlayer').innerHTML = '';
 document.getElementById('flashlayer').style.display = 'none';
 }
 
 // JScript File
 var time = 0;
 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
 
  function displayFlash(topi) {
    var filepath = topi.getAttribute('flashpath');
    var width = topi.getAttribute('Bigflashwidth');
    var height = topi.getAttribute('Bigflashheight');
    var temp = document.getElementById('flash');
    

    temp.style.display = 'block';
    temp.style.position = 'relative';
    document.getElementById("flashlayer").innerHTML='<object type="application/x-shockwave-flash" '+
        ' data="' + filepath + '"' + ' width="'+ width +'"' + 'height="' + height + '">'+
        '<param name="movie" value="'+ filepath + '" />'+
        '<param name="wmode" value="transparent"/>'+
        '</object>';
        }
    
  function Flash(filepath,width,height)
  {
    var flashtemp = document.getElementById('flashlayer');
    flashtemp.style.display = 'block';
    flashtemp.style.position = 'relative';
    document.getElementById('flashlayer').innerHTML='<iframe frameborder="0" scrolling="no" src ="'
    + filepath + '" width="'+ width +'px"' + 'height="' + height + 'px"></iframe>';
  }
    
        
  function hideFlash() {
    var temp = document.getElementById('flash');
    document.getElementById('flash').innerHTML = '';
    temp.style.display = 'none';
  }
  
  function resizeFlash(width,height,filepath,flashwidth,flashheight) {
     myflashLightbox.flashresizeImageContainer(flashwidth,flashheight,filepath,flashwidth,flashheight);
  }
  
  function saveScrollPositions() {
        var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
        var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
       // theForm.scrollx.value = scrollx;
     //   theForm.scrolly.value = scrolly;
    }
