﻿//<!--
var Window = {

	Init: function ( ) { },
	
	$: function ( name, doc )
	{
		if (!doc) {doc = document};
		if (doc.getElementById) return doc.getElementById(name);
		else if (doc.all) return doc.all[name];
		else if (doc.layers) return this.__NN4(doc,name);
		else return false;	
	}, // End $
	
	__NN4: function ( obj, name )
	{
		var x = obj.layers;
		var thereturn;
		for (var i = 0; i < x.length; i++)
		{
			if (x[i].id == name)
	 			thereturn = x[i];
			else if (x[i].layers.length)
				var tmp = this.__NN4( x[i], name );
			if (tmp) thereturn = tmp;
		}
		return thereturn;	
	} // End __NN4
	
} // End Window

Window.Init();

var SlideShow = {
	
	Init: function( ) { setTimeout('SlideShow.Setup();', 10); },
	
	DisplayWaitImage: function ( display ) 
	{
		if ( !this.displayWait ) this.displayWait = true;
		if ( display ) this.displayWait = display;
		return this.displayWait; 
	}, // End DisplayWaitImage
	
  ActualImageWidth: function ( width ) 
	{ 
		if ( !this.actualImageWidth ) this.actualImageWidth = 0;
		if ( width ) this.actualImageWidth = width;
		return this.actualImageWidth;
	}, // End ActualImageWidth
	
	ActiveImage: function ( image )
	{
		if ( !this.activeImage ) this.activeImage = false;
		if ( image ) this.activeImage = image;
		return this.activeImage;
	}, // End ActiveImage
	
	ActiveImagePath: function ( path )
	{
		if ( !this.activeImagePath ) this.activeImagePath = null;
		if ( path ) this.activeImagePath = path;
		return this.activeImagePath;
	}, // End ActiveImagePath

  ImageGalleryWidth: function ( width ) 
	{ 
		if ( !this.imageGalleryWidth ) this.imageGalleryWidth = false;
		if ( width ) this.imageGalleryWidth = width;
		return this.imageGalleryWidth;
	}, // End ImageGalleryWidth
	
	ImageGalleryLeftPos: function ( position )
	{
		if ( !this.imageGalleryLeftPos ) this.imageGalleryLeftPos = false;
		if ( position ) this.imageGalleryLeftPos = position;
		return this.imageGalleryLeftPos;
	}, // End ImageGalleryLeftPos
	
	MaxGalleryXPos: function ( position )
	{
		if ( !this.maxGalleryXPos ) this.maxGalleryXPos = false;
		if ( position ) this.maxGalleryXPos = position;
		return this.maxGalleryXPos;
	}, // End MaxGalleryXPos
	
	MinGalleryXPos: function ( position )
	{
		if ( !this.minGalleryXPos ) this.minGalleryXPos = false;
		if ( position ) this.minGalleryXPos = position;
		return this.minGalleryXPos;
	}, // End MinGalleryXPos
	
	ImageGalleryObj: function ( obj )
	{
		if ( !this.imageGalleryObj ) this.imageGalleryObj = false;
		if ( obj ) this.imageGalleryObj = obj;
		return this.imageGalleryObj;
	}, // End ImageGalleryObj
	
	ImageGalleryCaptions: function ( )
	{
		if ( !this.imageGalleryCaptions ) 
			this.imageGalleryCaptions = new Array( );
			
		return this.imageGalleryCaptions;
	}, // End ImageGalleryCaptions
	
	ImageGalleryPaths: function ( )
	{
		if ( !this.imageGalleryPaths ) 
			this.imageGalleryPaths = new Array( );
			
		return this.imageGalleryPaths;
	}, // End ImageGalleryPaths
	
	SlideSpeed: function ( slidingSpeed )
	{
		if ( !this.slideSpeed ) this.slideSpeed = 0;
		if ( slidingSpeed || slidingSpeed == 0 ) this.slideSpeed = slidingSpeed;
		return this.slideSpeed;
	}, // End SlideSpeed
	
	Setup: function( )
	{
		Window.$('arrow_left').onmousemove = SlideShow.StartSlide;
		Window.$('arrow_left').onmouseout = SlideShow.ReleaseSlide;
		Window.$('arrow_right').onmousemove = SlideShow.StartSlide;
		Window.$('arrow_right').onmouseout = SlideShow.ReleaseSlide;

		SlideShow.ImageGalleryObj ( Window.$('theImages') )
		SlideShow.ImageGalleryLeftPos ( SlideShow.ImageGalleryObj().offsetLeft );
		SlideShow.ImageGalleryWidth ( Window.$('galleryContainer').offsetWidth );
		//if( navigator.appName.indexOf("Internet Explorer") != -1 )
		//	SlideShow.MaxGalleryXPos ( SlideShow.ImageGalleryObj().offsetLeft + 1 ); 
		//else
			//SlideShow.MaxGalleryXPos ( SlideShow.ImageGalleryObj().offsetLeft ); 
		SlideShow.MaxGalleryXPos ( SlideShow.ImageGalleryLeftPos() ); 
			
		SlideShow.MinGalleryXPos ( SlideShow.ImageGalleryWidth() - Window.$('slideEnd').offsetLeft - 40 );
		
		var slideshowImages = SlideShow.ImageGalleryObj().getElementsByTagName('IMG');
		for(var i=0; i < slideshowImages.length; i++){
			slideshowImages[i].onmouseover = SlideShow.ShowImage;
			SlideShow.ActualImageWidth( SlideShow.ActualImageWidth() + slideshowImages[i].width + 5 );
		}
		// Add another 40 for the left arrow.
		SlideShow.ActualImageWidth( SlideShow.ActualImageWidth() + 80 );
		
		var divs = SlideShow.ImageGalleryObj().getElementsByTagName('DIV');
		for( var i=0; i < divs.length; i++ ) {
			// Cache image captions
			if( divs[i].className == 'imageCaption' ) 
				SlideShow.ImageGalleryCaptions()[SlideShow.ImageGalleryCaptions().length] = divs[i].innerHTML;
			// Cache the full path to the original image. Used for popups
			if( divs[i].className == 'imagePaths' ) 
				SlideShow.ImageGalleryPaths()[SlideShow.ImageGalleryPaths().length] = divs[i].innerHTML;
		}
		
		if ( SlideShow.ActualImageWidth() >= SlideShow.ImageGalleryWidth() )
			SlideShow.GallerySlide();
		else
		{
			// Expand the last element to cover the transparent area below when there are not enough images.
			var spans = Window.$('carouselImages').getElementsByTagName('SPAN');
			spans[spans.length-1].className = 'carousel-spacer-last';
		}
		
		if ( SlideShow.ImageGalleryPaths().length > 0 ) 
			SlideShow.ActiveImagePath( SlideShow.ImageGalleryPaths()[0] );
					
	}, // End Setup
	
	ShowImage: function ( )
	{
		if( SlideShow.ActiveImage() ){
			SlideShow.ActiveImage().style.filter = 'alpha(opacity=20)';	
			SlideShow.ActiveImage().style.opacity = 0.2;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		SlideShow.ActiveImage ( this );
		
	}, // End ShowImage
	
	ReleaseSlide: function ( )
	{
		SlideShow.SlideSpeed ( 0 );
		var imgSrc = '/WebResource.axd?d=CCMlxvsidfpWhWo816oJdhpME0rC72ZFiKPQ5SNtX9AhxoJ0FbQCvS2UbqPj6uCefJkIv0huuqDHbhBikdV4sMnwqFQbXZHfB9PRu1woM_EhhflcKPEdJV2ycOEK-VgF0&t=634009732798395000';
		if( this.id == 'arrow_left' ){
			imgSrc = '/WebResource.axd?d=CCMlxvsidfpWhWo816oJdhpME0rC72ZFiKPQ5SNtX9AhxoJ0FbQCvS2UbqPj6uCefJkIv0huuqDHbhBikdV4sMnwqFQbXZHfB9PRu1woM_GsA-cyEnNxhWxLOPAR-lLR0&t=634009732798395000';
		}
		//alert(imgSrc);
		this.getElementsByTagName('IMG')[0].src = imgSrc;
	}, // End ReleaseSlide
	
	StartSlide: function ( e )
	{
		if ( SlideShow.ActualImageWidth() >= SlideShow.ImageGalleryWidth() )
		{		
			if( document.all ) e = event;
			var id = this.id;
			var leftPos = SlideShow.FindPos(this)[0];
			if( this.id == 'arrow_right' ){
				this.getElementsByTagName('IMG')[0].src = '/WebResource.axd?d=CCMlxvsidfpWhWo816oJdhpME0rC72ZFiKPQ5SNtX9AhxoJ0FbQCvS2UbqPj6uCefJkIv0huuqDHbhBikdV4sMnwqFQbXZHfB9PRu1woM_EhhflcKPEdJRSQwv1rukdL4ZC00dOiIXY1&t=634009732798395000';
				//slideSpeedMultiply = Math.floor((e.clientX - this.offsetLeft) / 10);
				slideSpeedMultiply = Math.floor((e.clientX - leftPos) / 3);
				SlideShow.SlideSpeed ( -1*slideSpeedMultiply );
				SlideShow.SlideSpeed ( Math.max( -10, SlideShow.SlideSpeed() ) );
			}else{
				this.getElementsByTagName('IMG')[0].src = '/WebResource.axd?d=CCMlxvsidfpWhWo816oJdhpME0rC72ZFiKPQ5SNtX9AhxoJ0FbQCvS2UbqPj6uCefJkIv0huuqDHbhBikdV4sMnwqFQbXZHfB9PRu1woM_GsA-cyEnNxheMNf84wrLhxM-q8onXW3F41&t=634009732798395000';
				//slideSpeedMultiply = 10 - Math.floor((e.clientX - this.offsetLeft) / 5);
				slideSpeedMultiply = 10 - Math.floor((e.clientX - leftPos) / 5);
				SlideShow.SlideSpeed ( 1*slideSpeedMultiply );
				SlideShow.SlideSpeed ( Math.min( 10, SlideShow.SlideSpeed() ) );
				if( SlideShow.SlideSpeed() < 0 ) SlideShow.SlideSpeed ( 10 );
			}
		}
	}, // End StartSlide
	
	FindPos: function(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) 
		{
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	},
	
	GallerySlide: function ( )
	{
		if( SlideShow.SlideSpeed() != 0 ){
			var leftPos = SlideShow.ImageGalleryObj().offsetLeft;
			var maxXPos = SlideShow.MaxGalleryXPos();
			var minXPos = SlideShow.MinGalleryXPos();
			leftPos = leftPos/1 + SlideShow.SlideSpeed();
			
			if( navigator.appName.indexOf("Internet Explorer") != -1 )
			{
				maxXPos += .1;
			}
			if( leftPos > maxXPos ){
				leftPos = maxXPos;
				SlideShow.SlideSpeed ( 0 );
			}
			if( leftPos <= minXPos ){
				leftPos = minXPos;
				SlideShow.SlideSpeed ( 0 );
			}
			//Window.$('debug').innerHTML += leftPos + '<br />';
			if ( leftPos )
				SlideShow.ImageGalleryObj().style.left = leftPos + 'px';
				
			//Window.$('debug').innerHTML += SlideShow.SlideSpeed() + '<br />';
		}
		
		setTimeout('SlideShow.GallerySlide();', 20);
		
	}, // End GallerySlide
	
	ShowPreview: function ( imagePath, imageIndex )
	{
		var subImages = Window.$('previewPane').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			Window.$('previewPane').appendChild(img);
		}else img = subImages[0];
		
		//if( SlideShow.DisplayWaitMessage() ){
		if( SlideShow.DisplayWaitImage() ){
			Window.$('waitMessage').style.display='inline';
		}
		//Window.$('largeImageCaption').style.display='none';
		Window.$('imageCaption').style.display='none';
		img.onload = function() 
		{ 
			Window.$('waitMessage').style.display='none';	
			Window.$('largeImageCaption').innerHTML = SlideShow.ImageGalleryCaptions()[imageIndex - 1];
			//Window.$('largeImageCaption').style.display='block';
			
			// *** Removed the caption as per request 13/08/2008 ***
			//Window.$('imageCaption').style.display='block';
		};
		img.src = imagePath;
		
		SlideShow.ActiveImagePath ( null );
		if ( (imageIndex - 1) <= SlideShow.ImageGalleryPaths().length ) 
			SlideShow.ActiveImagePath( SlideShow.ImageGalleryPaths()[imageIndex - 1] );
						
	}, // End ShowPreview
	
	PopUp: function ( ) 
	{
		if ( !SlideShow.ActiveImagePath() ) return;
		//alert(currentImage);
		var w = 600; var h = 500;
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1'
		window.open( SlideShow.ActiveImagePath(), "ImageGallery", winprops)	
		return false;
	} // End PopUp
	
} // End SlideShow

var Carousel = {

  Hide: function ( eleId ) 
	{ 
		if ( !this.carouselHide ) this.carouselHide = null;
		if ( eleId ) this.carouselHide = eleId;
		return this.carouselHide;
	}, // End Hide

  Height: function ( height ) 
	{ 
		if ( !this.carouselOffsetHeight ) this.carouselOffsetHeight = 0;
		if ( height || height == 0 ) this.carouselOffsetHeight = height;
		return this.carouselOffsetHeight;
	}, // End Height
	
  VarHeight: function ( height ) 
	{ 
		if ( !this.carouselVarHeight ) this.carouselVarHeight = 0;
		if ( height || height == 0 ) this.carouselVarHeight = height;
		return this.carouselVarHeight;
	}, // End VarHeight	
	
  Speed: function ( speed ) 
	{ 
		if ( !this.carouselSpeed ) this.carouselSpeed = 0;
		if ( speed || speed === 0 ) this.carouselSpeed = speed;
		return this.carouselSpeed;
	}, // End Speed
	
	x: function ( x )
	{
		//if ( !this.carouselX ) this.carouselX = false;
		if ( x || x == 0 ) this.carouselX = x;
		return this.carouselX;	
	}, // End x
	
	y: function ( y )
	{
		if ( !this.carouselY ) this.carouselY = 10;
		if ( y || y == 0 ) this.carouselY = y;
		return this.carouselY;	
	}, // End y
	
	z: function ( z )
	{
		if ( !this.carouselZ ) this.carouselZ = 1;
		if ( z || z == 0 ) this.carouselZ = z;
		return this.carouselZ;	
	}, // End z
	
	Init: function ( divId, speed )
	{	
		Carousel.Hide ( divId );
		Carousel.Height ( Window.$(divId).offsetHeight );
		
		if( navigator.appName.indexOf("Internet Explorer") != -1 ) Carousel.Height ( Carousel.Height() - 23 );
		else Carousel.Height ( Carousel.Height() - 7 );
		
		Carousel.VarHeight ( 0 );
		
		if ( speed ) Carousel.Speed ( speed )
		else Carousel.Speed ( 5 );
		
		if (Carousel.Speed() == 1) { Carousel.y ( 100 ); Carousel.z ( 1 ); }
		if (Carousel.Speed() == 2) { Carousel.y ( 70 );	 Carousel.z ( 1 ); }
		if (Carousel.Speed() == 3) { Carousel.y ( 40 );	 Carousel.z ( 1 ); }
		if (Carousel.Speed() == 4) { Carousel.y ( 20 );	 Carousel.z ( 1 ); }
		if (Carousel.Speed() == 5) { Carousel.y ( 10 );	 Carousel.z ( 1 ); }
		if (Carousel.Speed() == 6) { Carousel.y ( 10 );	 Carousel.z ( 2 ); }
		if (Carousel.Speed() == 7) { Carousel.y ( 10 );	 Carousel.z ( 4 ); }
		if (Carousel.Speed() == 8) { Carousel.y ( 10 );	 Carousel.z ( 7 ); }
		if (Carousel.Speed() == 9) { Carousel.y ( 10 );	 Carousel.z ( 10 ); }
		
	}, // End Init
	
	Toggle: function () {
		
		//if ( Window.$('debug') ) Window.$('debug').innerHTML += Carousel.x() + '<br />';
		
		if (Carousel.x() === 0) {
			Window.$( Carousel.Hide() ).style.marginTop = "-" + Carousel.VarHeight() + "px";
			if ( ( Carousel.VarHeight() < Carousel.z() ) && ( Carousel.VarHeight() !== 0 ) ) {
				Carousel.VarHeight ( 0 );
			} else {
				Carousel.VarHeight( Carousel.VarHeight() - Carousel.z() );
			}
			if (Carousel.VarHeight() >= 0) {
				setTimeout('Carousel.Toggle();', Carousel.y() );
			}
			if ( Carousel.VarHeight() < 0 ) {
				Carousel.VarHeight ( 0 );
				Carousel.x ( 1 );
			}
		} else {
			Window.$( Carousel.Hide() ).style.marginTop = "-" + Carousel.VarHeight() + "px";
			Carousel.VarHeight ( Carousel.VarHeight() + Carousel.z() );
			if ( Carousel.VarHeight() <= Carousel.Height() ) {
				setTimeout('Carousel.Toggle();', Carousel.y() );
			}
			if ( Carousel.VarHeight() > Carousel.Height() ) {
				Carousel.VarHeight ( Carousel.Height() );
				Window.$( Carousel.Hide() ).style.marginTop = "-" + Carousel.VarHeight() + "px";
				Carousel.x ( 0 );
			}
		}
	} // End Toggle
} // End Carousel Object
//-->