  
   //////////////////////////////////////////////
   //                                          //
   //   Xaia Media :: CMS 3.0 -- JS Dynamics   //
   //   By Bob Dohmen (c) 2009/2010            //
   //                                          //
   //////////////////////////////////////////////

window.addEvent('domready', function() 
{	
	
	/* ::::::::::::::::::::: Artist Viewer ::::::::::::::::::::::
	   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
	
	if($('artists') && $('artists').hasClass('viewer'))
	{		
		$('artists').getElements('ul').setStyles(
		{
			'opacity': 0,
			'display': 'none'
		});
		
		$$('.first').setStyles(
		{
			'display': 'block'
		});
		
		$$('.first').fade(1);
		
		var activeEl = $$('.first').get('id');
		var nextEl = 0;
		
		var getNextA = function(el)
		{
			el = el.getNext();
			
			if(el == null)
			{
				nextEl = $('heading').getElement('p').getElement('a').get('id');
			}
			else
			{
				if(el.hasClass('listletter'))
				{
					nextEl = el.get('id');
				}
				else
				{
					getNextA(el);
				}
			}
		}
		
		var showNext = function()
		{			
			getNextA($('list-' + activeEl));
			var strElId = nextEl;
				
			var strElSplit = strElId.split('-');
			
			$(activeEl[0]).fade(0);
			$(activeEl[0]).setStyles(
			{
				'display': 'none'
			});
			$('list-'+activeEl[0]).setStyles(
			{
				'text-decoration': ''
			});	
			
			$(strElSplit[1]).setStyles(
			{
				'display': 'block'
			});				
			$(strElSplit[1]).fade(1);
			
			$('list-'+strElSplit[1]).setStyles(
			{
				'text-decoration': 'underline'
			});		
			
			activeEl = new Array(strElSplit[1]);
			showNextdelay = showNext.delay(8000);
		}
		var showNextdelay = showNext.delay(8000);
		
		$$('.listletter').addEvents(
		{
			click: function()
			{
				var strElId = this.get('id');
				
				var strElSplit = strElId.split('-');
				
				$(activeEl[0]).fade(0);
				$(activeEl[0]).setStyles(
				{
					'display': 'none'
				});
				$('list-'+activeEl[0]).setStyles(
				{
					'text-decoration': ''
				});	
				
				$(strElSplit[1]).setStyles(
				{
					'display': 'block'
				});				
				$(strElSplit[1]).fade(1);
				
				$('list-'+strElSplit[1]).setStyles(
				{
					'text-decoration': 'underline'
				});		
				
				activeEl = new Array(strElSplit[1]);
				
				showNextdelay = $clear(showNextdelay);
				showNextdelay = showNext.delay(8000);
			}
		});
	}
	
	/* :::::::::::::::::::::: Photo Viewer ::::::::::::::::::::::
	   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
	
	if($('photos'))
	{		
		$('photoviewerbg').setStyles(
		{
			'opacity': 0,
			'display': 'block',
			'background': '#000'
		});
		
		$('photoviewer').setStyles(
		{
			'opacity': 0,
			'display': 'block'
		});
		
		$('next').setStyles(
		{
			'opacity': 0.4,
			'display': 'block'
		});
		
		$('back').setStyles(
		{
			'opacity': 0.4,
			'display': 'block'
		});
		
		$$('.photoholder').setStyles(
		{
			'opacity': 0,
			'display': 'block',
			'float': 'left'
		});
		
		(function(){
			$$('.photoholder').each(function(el, intKey)
			{
				var elimg = el.getElement('img');
				
				if(elimg.get('height') > elimg.get('width'))
				{
					elimg.set('width', 120);
					elimg.setStyles(
					{
						'left': '50%',
						'top': '50%',
						'margin-left': '-' + Math.round(elimg.getStyle('width').toInt() / 2) + 'px',
						'margin-top': '-' + Math.round(elimg.getStyle('height').toInt() / 2) + 'px'
					});
				}
				else
				{
					elimg.set('height', 120);
					elimg.setStyles(
					{
						'left': '50%',
						'top': '50%',
						'margin-left': '-' + Math.round(elimg.getStyle('width').toInt() / 2) + 'px',
						'margin-top': '-' + Math.round(elimg.getStyle('height').toInt() / 2) + 'px'
					});
				}
				
				el.fade(1);
			});
		}.delay(2000));
		
		$('photoviewerbg').addEvents(
		{
			click: function()
			{
				$('photoviewer').fade(0);
				this.fade(0);
				var waitDisplay = function()
				{
					$$('.photo').setStyles(
					{
						'display': 'none'
					});
				}.delay(500);
			}
		});
		
		$('next').addEvents(
		{
			click: function(event)
			{
				event.preventDefault();
				showLargeImage(this.get('rel'));
			},
			
			mouseover: function()
			{
				this.fade(1);
			},
			
			mouseout: function()
			{
				this.fade(0.4);
			}
		});
		
		$('back').addEvents(
		{
			click: function(event)
			{
				event.preventDefault();
				showLargeImage(this.get('rel'));
			},
			
			mouseover: function()
			{
				this.fade(1);
			},
			
			mouseout: function()
			{
				this.fade(0.4);
			}
		});
		
		$$('.photoholder').addEvents(
		{
			click: function(event)
			{
				event.preventDefault();
				showLargeImage(this.get('id'));
			},
			
			mouseover: function()
			{
				$$('.photoholder').fade(1);
				$$('.photoholder').setStyle('border', '1px solid #CCCCB3');
				this.fade(0.8);
				this.setStyle('border', '1px solid #999');
			},
			
			mouseout: function()
			{
				this.setStyle('border', '1px solid #CCCCB3');
				this.fade(1);
			}
		});
	}

});

var elActive = 'photo1';

var showLargeImage = function(id)
{	
	$$('.photo').setStyles(
	{
		'opacity': 0,
		'display': 'block'
	});
			
	var elImg = $('photo'+id).getElement('img');
	
	var nextId = id.toInt() + 1;
	var backId = id.toInt() - 1;
	var allCount = $$('.photo').length - 1;
	
	if(nextId > allCount)
	{
		$('next').setStyle('display', 'none');
	}
	else
	{
		$('next').setStyle('display', 'block');
	}
	
	if(backId < 0)
	{
		$('back').setStyle('display', 'none');
	}
	else
	{
		$('back').setStyle('display', 'block');
	}
	
	$('back').set('rel', (id.toInt() - 1));
	$('next').set('rel', (id.toInt() + 1));
	
	if(elImg.getStyle('height').toInt() > 580)
	{
		var elImgHeight = 580;
		elImg.set('height', elImgHeight);
	}
	else
	{
		var elImgHeight = elImg.getStyle('height').toInt();
	}
	
	if(elImg.getStyle('width').toInt() > 580 && elImgHeight != 580)
	{
		var elImgWidth = 580;
		elImg.set('width', elImgWidth);
	}
	else
	{
		var elImgWidth = elImg.getStyle('width').toInt();
	}
	
	$('photoviewer').setStyles(
	{
		'margin-left': '-'+(elImgWidth / 2)+'px',
		'width': elImgWidth,
		'height': elImgHeight
	});
	
	$('photoviewerbg').fade(0.85);
	$('photoviewer').fade(1);
	
	//$(elActive).fade(0);
	$('photo'+id).fade(1);
	elActive = 'photo'+id;
}
