/* --------------------------------------------------
	1. Photo gallery overlay effect
-------------------------------------------------- */

General.event.register( document , 'click' , function( e ){ 	
	var theNode = e.targetNode;
	if( theNode.nodeName != "A" )
	{
		if( theNode.parentNode && theNode.parentNode.nodeName == "A" )
		{
			theNode = theNode.parentNode;
		}else
		{
			return true;
		}
	}
	if( theNode.className.indexOf( "zoom-simple" ) == -1 )
	{
		return true;
	}
	if( theNode.parentNode == undefined )
	{
		return true;
	}
	
	photoGallery.displaySimplePhoto( theNode.getAttribute( "HREF" ) );	
	e.cancelEvent( );
	return false;
} );

General.event.register( document , 'click' , function( e ){ 	
	var theNode = e.targetNode;
	if( theNode.nodeName != "A" )
	{
		if( theNode.parentNode && theNode.parentNode.nodeName == "A" )
		{
			theNode = theNode.parentNode;
		}else
		{
			return true;
		}
	}
	if( theNode.className.indexOf( "zoom-details" ) == -1 )
	{
		return true;
	}
	if( theNode.parentNode == undefined )
	{
		return true;
	}
	
	theNode = theNode.parentNode;
	
	while( theNode.parentNode && ( theNode.nodeName != "DIV" && theNode.nodeName != "BODY" ) )
	{
		theNode = theNode.parentNode;
	}
	
	if( theNode.nodeName != "DIV" || theNode.className.indexOf( "photo" ) == -1 )
	{
		return true;
	}
	
	var detailDiv = theNode.getElementsByTagName( "DIV" );
	if( detailDiv == undefined || detailDiv.length < 1 )
	{
		return true;
	}
	
	detailDiv = detailDiv[0];
	if( detailDiv.className.indexOf( "details" ) == -1 )
	{
		return true;
	}
	
	try {
		var sTitle = detailDiv.getElementsByTagName( "H4" )[0].innerHTML;
		var sDescription = detailDiv.getElementsByTagName( "P" )[0];
		if (sDescription) {
			sDescription = sDescription.innerHTML;
		}
		else {
			sDescription = detailDiv.getElementsByTagName( "DIV" )[0].innerHTML;
		}
		var sImage = detailDiv.getElementsByTagName( "A" )[0].getAttribute( "HREF" );
		if( detailDiv.getElementsByTagName( "A" )[1] )
		{
			var sHighRes = detailDiv.getElementsByTagName( "A" )[1].getAttribute( "HREF" );
		}else
		{
			var sHighRes = false;
		}
		if( detailDiv.getElementsByTagName( "A" )[2] )
		{
			var sLowRes = detailDiv.getElementsByTagName( "A" )[2].getAttribute( "HREF" );
		}else
		{
			var sLowRes = false;
		}
		if (detailDiv.getElementsByTagName( "STRONG" )[0]) {
			var sPrice = detailDiv.getElementsByTagName( "STRONG" )[0].innerHTML;	
		}
		else {
			var sPrice = false;	
		}
	}catch( e )
	{
		return true;
	}
	
	photoGallery.displayPhoto( sTitle , sDescription , sImage , sHighRes , sLowRes , sPrice );
	
	e.cancelEvent( );
	return false;
} );


var photoGallery = {
	overlay: null,
	details: null,
	
	language: {
		highRes: "High Res" ,
		lowRes: "Low Res" ,
		description: "Description" ,
		download: "Download"
	} ,
	
	showDownload: true,
	
	createOverlay: function( isVideo )
	{
		if( photoGallery.overlay != null )
		{
			return;
		}
		
		photoGallery.overlay = document.createElement( "DIV" );
		var overlay = photoGallery.overlay;
		var isVideo = isVideo ? isVideo : false;
		overlay.style.display = 'none';
		overlay.style.position = 'absolute';
		overlay.style.left = '0';
		overlay.style.top = '0';
		overlay.style.width = General.page.getWidth( ) + "px";
		overlay.style.height = General.page.getHeight( ) + "px";
		overlay.style.minHeight = "100%";
		overlay.style.minWidth = "100%";
		overlay.style.backgroundColor = '#000000';
		if( isVideo ) {
			overlay.style.opacity = 0.8;
			overlay.style.filter = "Alpha(opacity=80);";	
		} else {
			overlay.style.opacity = 0.6;
			overlay.style.filter = "Alpha(opacity=60);";	
		}
		
		overlay.style.zIndex = 100;
		document.body.appendChild( overlay );
		
		General.event.register( overlay , 'mousedown' , function( e ){ 
			photoGallery.closeWindow( );
			e.cancelEvent( );
			return false;
		} );
		
		General.event.register( document , 'keydown' , function( e ){
			if( e.keyCode == 88 && photoGallery.details != null )
			{
				photoGallery.closeWindow( );
			}
		} );
	} ,
	
	adjustOverlay: function( isVideo )
	{
		var overlay = photoGallery.overlay;
		var isVideo = isVideo ? isVideo : false;
		overlay.style.width = General.page.getWidth( ) + "px";
		overlay.style.height = General.page.getHeight( ) + "px";
		if( isVideo ) {
			overlay.style.opacity = 0.8;
			overlay.style.filter = "Alpha(opacity=80);";	
		} else {
			overlay.style.opacity = 0.6;
			overlay.style.filter = "Alpha(opacity=60);";	
		}
	},
	
	closeWindow: function( )
	{
		var parent = photoGallery.details.parentNode;
		parent.removeChild( photoGallery.details );
		photoGallery.details = null;
		photoGallery.overlay.style.display = 'none';
		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
				if( document.all && Browser.Version() <= 6 ) {
					var selects = document.getElementsByTagName( "SELECT" );
					for( var i = 0; i < selects.length; i++ )
					{
						if( selects[i] )
						{
							selects[i].style.visibility = "visible";
						}
					}
				}
			@end
		@*/
	},
	
	displaySimpleVideo: function( url, width, height )
	{
		if( photoGallery.overlay == null )
		{
			photoGallery.createOverlay( true );
		}else 
		{
			photoGallery.adjustOverlay( true );
		}
		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
				if( document.all && Browser.Version() <= 6 ) {
					var selects = document.getElementsByTagName( "SELECT" );
					for( var i = 0; i < selects.length; i++ )
					{
						if( selects[i] )
						{
							selects[i].style.visibility = "hidden";
						}
					}
				}
			@end
		@*/
		
		var overlay = photoGallery.overlay;
		overlay.style.display = 'block';

		photoGallery.details = document.createElement( "DIV" );
		var details = photoGallery.details;
		details.style.position = "fixed";
		details.style.backgroundColor = "#ffffff";
		details.style.zIndex = 110;
		details.style.display = 'block';
		details.style.visibility = "hidden";
		details.className = "photo-simple-overlay video-overlay";
		
		var html = AC_FL_getFlashObject(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', width,
			'height', height,
			'src', url,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'video',
			'bgcolor', '#ffffff',
			'name', 'video',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', url,
			'salign', ''
			); //end AC code
			
		if( !closeWindowLabel ) {
			var closeWindowLabel = "Close this window";
		}
		
		details.innerHTML = "<div class=\"video\">"+html+"</div><div class=\"bottom\"><a href=\"#close\" onclick=\"photoGallery.closeWindow( );return false;\" class=\"close\">"+closeWindowLabel+"</div>";
		
		setTimeout( function( ) {
			var details = photoGallery.details;
			var intLeft = General.window.getWidth( ) / 2 - details.offsetWidth / 2;
			var intTop = General.window.getHeight( ) / 2 - details.offsetHeight / 2;

			details.style.top = Math.round( intTop ) + "px";
			details.style.left = Math.round( intLeft ) + "px";
			details.style.visibility = "visible";
			
			/*@cc_on
				@if( @_jscript_version <= 5.7 )
				if( document.all && Browser.Version() <= 6 ) {
					if( _IE6_StayFixed != undefined )
					{
						window.onscroll( );
					}
				}
				@end
			@*/
		} , 200 );
		
		document.body.appendChild( details );		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
			if( document.all && Browser.Version() <= 6 ) {
				if( _IE6_StayFixed != undefined )
				{
					_IE6_StayFixed( details );
				}
			}
			@end
		@*/
	}, 
	
	displaySimplePhoto: function( image )
	{
		if( photoGallery.overlay == null )
		{
			photoGallery.createOverlay( );
		}else 
		{
			photoGallery.adjustOverlay( );
		}
		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
				if( document.all && Browser.Version() <= 6 ) {
					var selects = document.getElementsByTagName( "SELECT" );
					for( var i = 0; i < selects.length; i++ )
					{
						if( selects[i] )
						{
							selects[i].style.visibility = "hidden";
						}
					}
				}
			@end
		@*/
		
		var overlay = photoGallery.overlay;
		overlay.style.display = 'block';
		
		photoGallery.details = document.createElement( "DIV" );
		var details = photoGallery.details;
		details.style.position = "fixed";
		details.style.backgroundColor = "#ffffff";
		details.style.zIndex = 110;
		details.style.display = 'block';
		details.style.visibility = "hidden";
		details.className = "photo-simple-overlay";
		
		var ePhoto = document.createElement( "IMG" );
		ePhoto.setAttribute( "src" , image );
		ePhoto.setAttribute( "alt" , "" );
		ePhoto.className = "big-image";

		if( parseInt( ePhoto.height ) <= 1 ) 
		{
			details.appendChild( ePhoto );
			ePhoto.onload = function( e ) 
			{
				var details = photoGallery.details;
				var intLeft = General.window.getWidth( ) / 2 - details.offsetWidth / 2;
				var intTop = General.window.getHeight( ) / 2 - details.offsetHeight / 2;
			
				details.style.top = Math.round( intTop ) + "px";
				details.style.left = Math.round( intLeft ) + "px";
				details.style.visibility = "visible";
				
				/*@cc_on
					@if( @_jscript_version <= 5.7 )
					if( document.all && Browser.Version() <= 6 ) { 
						if( _IE6_StayFixed != undefined )
						{
							window.onscroll( );
						}
					}
					@end
				@*/
			};
		}else 
		{
			details.appendChild( ePhoto );
			setTimeout( function( ) {
				var details = photoGallery.details;
				var intLeft = General.window.getWidth( ) / 2 - details.offsetWidth / 2;
				var intTop = General.window.getHeight( ) / 2 - details.offsetHeight / 2;

				details.style.top = Math.round( intTop ) + "px";
				details.style.left = Math.round( intLeft ) + "px";
				details.style.visibility = "visible";
				
				/*@cc_on
					@if( @_jscript_version <= 5.7 )
					if( document.all && Browser.Version() <= 6 ) {
						if( _IE6_StayFixed != undefined )
						{
							window.onscroll( );
						}
					}
					@end
				@*/
			} , 200 );
		}
		
		document.body.appendChild( details );		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
			if( document.all && Browser.Version() <= 6 ) {
				if( _IE6_StayFixed != undefined )
				{
					_IE6_StayFixed( details );
				}
			}
			@end
		@*/
	}, 
	
	displayPhoto: function( title , desc , image , highres , lowres, price )
	{
		if( photoGallery.overlay == null )
		{
			photoGallery.createOverlay( );
		}else 
		{
			photoGallery.adjustOverlay( );
		}
		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
				if( document.all && Browser.Version() <= 6 ) {
					var selects = document.getElementsByTagName( "SELECT" );
					for( var i = 0; i < selects.length; i++ )
					{
						if( selects[i] )
						{
							selects[i].style.visibility = "hidden";
						}
					}
				}
			@end
		@*/
			
		var overlay = photoGallery.overlay;
		overlay.style.display = 'block';

		photoGallery.details = document.createElement( "DIV" );
		var details = photoGallery.details;
		details.style.position = "fixed";
		details.style.backgroundColor = "#ffffff";
		details.style.zIndex = 110;
		details.style.display = 'block';
		details.style.visibility = "hidden";
		details.className = "photo-detail-overlay";
		
		/* Create new elements */
		var eHeading = document.createElement( "DIV" );
		details.appendChild( eHeading );
		
		var eTitle = document.createElement( "H4" );
		eHeading.appendChild( eTitle );
		
		var eCloseButton = document.createElement( "A" );
		eHeading.appendChild( eCloseButton );
		
		var ePhoto = document.createElement( "IMG" );
		ePhoto.setAttribute( "src" , image );
		ePhoto.setAttribute( "alt" , "" );
		ePhoto.className = "big-image";

		if( parseInt( ePhoto.height ) <= 1 ) 
		{
			details.appendChild( ePhoto );
			ePhoto.onload = function( e ) 
			{
				var details = photoGallery.details;
				details.style.width = this.width + 20 + "px";
				
				var intLeft = General.window.getWidth( ) / 2 - details.offsetWidth / 2;
				var intTop = General.window.getHeight( ) / 2 - details.offsetHeight / 2;
			
				details.style.top = Math.round( intTop ) + "px";
				details.style.left = Math.round( intLeft ) + "px";
				details.style.visibility = "visible";

				/*@cc_on
					@if( @_jscript_version <= 5.7 )
					if( document.all && Browser.Version() <= 6 ) { 
						if( _IE6_StayFixed != undefined )
						{
							window.onscroll( );
						}
					}
					@end
				@*/

			};
		}else 
		{
			details.style.width = ePhoto.width + 20 + "px";
			details.appendChild( ePhoto );
			setTimeout( function( ) {
				var details = photoGallery.details;
				var intLeft = General.window.getWidth( ) / 2 - details.offsetWidth / 2;
				var intTop = General.window.getHeight( ) / 2 - details.offsetHeight / 2;

				details.style.top = Math.round( intTop ) + "px";
				details.style.left = Math.round( intLeft ) + "px";
				details.style.visibility = "visible";
				
				/*@cc_on
					@if( @_jscript_version <= 5.7 )
					if( document.all && Browser.Version() <= 6 ) {
						if( _IE6_StayFixed != undefined )
						{
							window.onscroll( );
						}
					}
					@end
				@*/

			} , 200 );
		}
		
		var eInfo = document.createElement( "DIV" );
		details.appendChild( eInfo );
		
		if(highres || lowres) {
		
			var eDownloads = document.createElement( "div" );
			if( photoGallery.showDownload ) eInfo.appendChild( eDownloads );
			
			var lblDownloads = document.createElement( "h5" );
			eDownloads.appendChild( lblDownloads );	
			
			var eList = document.createElement( "ul" );
			eDownloads.appendChild( eList );
			
			eDownloads.className = "download";
			
			lblDownloads.appendChild( document.createTextNode( photoGallery.language.download ) );
		
		}
		else if ( price ) {
			
			var ePrice = document.createElement( "strong" );
			ePrice.appendChild(document.createTextNode(price));
			ePrice.className = "price";
			eInfo.appendChild( ePrice );
				
		}
		
		var lblDescription = document.createElement( "h5" );
		eInfo.appendChild( lblDescription );	
		
		var eDescription = document.createElement( "p" );
		eInfo.appendChild( eDescription );	
		
			
		
		if( highres != false )
		{
			var eHighRes = document.createElement( "li" );
			eList.appendChild( eHighRes );
		}
		
		if( lowres != false )
		{
			var eLowRes = document.createElement( "li" );
			eList.appendChild( eLowRes );
		}
		
		/* Give the elements content, styling and events */
		eHeading.className = "heading";
		
		eTitle.appendChild( document.createTextNode( title ) );
		
		eCloseButton.setAttribute( "href" , "#close" );
		eCloseButton.className = "close";
		eCloseButton.appendChild( document.createTextNode( "close" ) );
		
		General.event.register( eCloseButton , 'click' , function( e ){ 
			photoGallery.closeWindow( );
			e.cancelEvent( );
			return false;
		} );
		
		eInfo.className = "photo-info";
		lblDescription.appendChild( document.createTextNode( photoGallery.language.description ) );
		eDescription.appendChild( document.createTextNode( desc ) );
		
		if( highres  != false )
		{
			var lblCaption = document.createElement( "span" );
			lblCaption.appendChild( document.createTextNode( photoGallery.language.highRes ) );
			eHighRes.appendChild( lblCaption );
			eHighRes.className = "highres";
		}
		
		if( lowres  != false )
		{
			var lblCaption = document.createElement( "span" );
			lblCaption.appendChild( document.createTextNode( photoGallery.language.lowRes ) );
			eLowRes.appendChild( lblCaption );
			eLowRes.className = "lowres";	
		}
		
		if( highres  != false )
		{
			var btnDownload = document.createElement( "IMG" );
			btnDownload.setAttribute( "src" , "/Style%20Library/Images/Icons/download.gif" );
		
			General.event.register( btnDownload , 'click' , function( e ){ 
				//window.open( highres );
				window.location.href = highres;
				//alert( "Download high-res\n" + highres );
			} );
			
			eHighRes.appendChild( btnDownload );
		}

		if( lowres != false ) 
		{		
			var btnDownload = document.createElement( "IMG" );
			btnDownload.setAttribute( "src" , "/Style%20Library/Images/Icons/download.gif" );
		
			General.event.register( btnDownload , 'click' , function( e ){ 
				//alert( "Download low-res\n" + lowres );
				window.location.href = lowres;
				//window.open( lowres );
			} );
		
			eLowRes.appendChild( btnDownload );
		}
		document.body.appendChild( details );
		
		/*@cc_on
			@if( @_jscript_version <= 5.7 )
			if( document.all && Browser.Version() <= 6 ) {
				if( _IE6_StayFixed != undefined )
				{
					_IE6_StayFixed( details );
				}
			}
			@end
		@*/
	}
};

/* @eof */
