var theahrefs = document.getElementsByTagName('a');
//fix dotted line thing when link is OnClicked
for(var x=0;x!=theahrefs.length;x++){
	theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
}

/* branding slides */
(function(){

	var BrandingSlides = new Class({
		slides : [],
		primaryContainer : null,
		secondaryContainer : null,
		holder : null,
		bound : {},
		initialize: function(options) {
			this.parseOptions(options);
			
			this.holder = $('branding-slides-holder');
			
			var slideHolders = $ES("div.branding-slide");
			if (slideHolders.length !== 2) {
				return;
			}
			
			this.bound.click = this.onClick.bindWithEvent(this);
			this.primaryContainer = slideHolders[0];
			this.secondaryContainer = slideHolders[1];
			
			this.buildSwitchList();
			
		},
		
		parseOptions : function(arr) {
		
			arr.each(function(item){
				var img = new Image();
				img.src = item.img;
			});
			
			while (arr.length > 0) {
				this.slides.push(arr.splice(0,2));
			}
		},
		buildSwitchList : function(){
			var ul = new Element('ul');
			var i = 0;
			this.slides.each(function(item) {
				var li = new Element('li');
				
				var a = new Element('a',{
					'href' : '#'
				});
				
				a.setText(parseInt( (i+1), 10) );
				
				if (i === 0) {
					a.addClass('current');
				}
				a.injectInside(li);
				li.injectInside(ul);
				
				a.slide = item;
				a.addEvent('click',this.bound.click);
				
				i = i + 1;
			},this);
			
			ul.injectInside(this.holder);
		},
		onClick : function(event) {
			event = new Event(event).stop();
			
			var slide = event.target.slide;
			
			this.switchImage(this.primaryContainer, slide[0]);
			this.switchImage(this.secondaryContainer, slide[1]);
			
			$ES('ul a',this.holder).each(function(item){
				$(item).removeClass('current');
			});
			
			$(event.target).addClass('current');
			
		},
		switchImage : function(container, toSlide) {
			
			var currentImg = $E('img',container),
				ps = $ES('p',container),
				description = ps[0],
				copyright= ps[1];
			
			var temp = new Element('img',{
				'class' : 'temporary',
				'src' : currentImg.getProperty('src')
			});
			
			temp.injectAfter(currentImg);
			
			currentImg.setProperty('src',toSlide.img);
			
			var mfx = new Fx.Style(	temp,'opacity',	{
				duration : 200,
				onComplete : function() {
					description.setHTML(toSlide.description);
					copyright.setHTML(toSlide.copyright);
					temp.remove();
				}
			});
			
			mfx.start(1,0);
		}
	});
	
	var slides = [
		{ 
			'img' : 'assets/desktop/xbox.jpg',
			'description' : 'The official Xbox desktop theme created for Microsoft Corporation',
			'copyright' : '&copy; Copyright 2002. Microsoft Corporation. All rights reserved.'
		},
		{ 
			'img' : 'assets/desktop/superman.jpg',
			'description' : 'Superman Special Edition desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2006. Alienware Corporation. All rights reserved.'
		},		
		{ 
			'img' : 'assets/desktop/redskins.jpg',
			'description' : 'The Washington Redskins desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2005. Alienware Corporation. All rights reserved.'
		},		
		{ 
			'img' : 'assets/desktop/starwars.jpg',
			'description' : 'Star Wars Edition desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2005. Alienware Corporation. All rights reserved.'
		},	
		{ 
			'img' : 'assets/desktop/invader.jpg',
			'description' : 'Alienware Invader desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2005. Alienware Corporation. All rights reserved.'
		},			
		{ 
			'img' : 'assets/desktop/alxmorph.jpg',
			'description' : 'Alienware ALXMorph desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2004. Alienware Corporation. All rights reserved.'
		},
		{ 
			'img' : 'assets/desktop/terminator3.jpg',
			'description' : 'Terminator 3 desktop theme created for Warner Bros.',
			'copyright' : '&copy; Copyright 2002. C2 Pictures &amp; Warner Bros. Entertainment.'
		},		
		{ 
			'img' : 'assets/desktop/nascar.jpg',
			'description' : 'NASCAR PC desktop theme created for ZT Group/Cisnet.',
			'copyright' : '&copy; Copyright 2005. ZT Group. All rights reserved.'
		},		
		{ 
			'img' : 'assets/desktop/mythology.jpg',
			'description' : 'Age of Mythology desktop theme created for Ensemble Studios.',
			'copyright' : '&copy; Copyright 2002. Microsoft Corporation. All rights reserved.'
		},		
		{ 
			'img' : 'assets/desktop/simulator.jpg',
			'description' : 'Combat Flight Simulator 3 desktop theme created for Microsoft.',
			'copyright' : '&copy; Copyright 2002. Microsoft Corporation. All rights reserved.'
		},			
		{ 
			'img' : 'assets/desktop/darkstar.jpg',
			'description' : 'Alienware Darkstar desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2005. Alienware Corporation. All rights reserved.'
		},				
		{ 
			'img' : 'assets/desktop/alienmorph.jpg',
			'description' : 'Alienware AlienMorph desktop theme created for Alienware.',
			'copyright' : '&copy; Copyright 2004. Alienware Corporation. All rights reserved.'
		}
	];
	
	var bs = new BrandingSlides(slides);
})();
