window.addEvent('domready', function(){
	
	slider = $$('div.sliderPanel')[0];
	
	//remove swatches for later (if they exist) and add additional class for js-users styling
	if($('swatches')){
		var swatches = $('swatches').dispose();
		swatches.addClass('swatchesJS');
		
		//position swatches in the dom
		swatches.inject(slider, 'after');
		//
		$$('div.swatchesJS')[0].setStyle('display','none');
		
		//add multibox features
		var box = new multiBox('mb', {
			overlay: new overlay()
		});
	}
	
	//check for sliderpanel and do your stuff
	if(slider){
		
		if($('why')){
			$$('div.words')[0].set('opacity',0).fade('in');
		}else{
			
			//generate second image url from first image
			var imageOneUrl = $$('div.collections img')[0].getProperty('src');
			var imageTwoUrl = imageOneUrl.substring(0,imageOneUrl.length-5);
			imageTwoUrl += "2.html";
			
			//preload second image
			var imageCache = new Asset.image(imageTwoUrl);
			
			//insert buttons for js users
			var myLi = new Element('ul', {
				'html': '<li class="nxtImg"><a href="#">Next Image</a><li><a class="colours" href="#swatches">View Colours</a></li>'
			}).inject($$('div.sliderPanel p')[0], 'after');

	
			//add event to next button
			$$('div.sliderPanel ul li.nxtImg a')[0].addEvent('click', function(event){
				new Event(event).stop();
				var img = $$('div.collections img')[0];
				var imgSrc = img.getProperty('src');
				var imgText = $$('div.sliderPanel p.featImg')[0];
	
				if(imgSrc == imageOneUrl){
					img.setProperty('src', imageTwoUrl);
					if(imageTwoUrl == "_common/img/boutique02.jpg"){
						img.setProperty('alt', 'Photgraph of Opulence');
						imgText.set('text', 'Wetwall panel featured - Opulence');
					}
					if(imageTwoUrl == "_common/img/italian02.jpg"){
						img.setProperty('alt', 'Photgraph of Levanto Sand');
						imgText.set('text', 'Wetwall panel featured - Levanto Sand');
					}
					if(imageTwoUrl == "_common/img/classics02.jpg"){
						img.setProperty('alt', 'Photgraph of Caspian Marble');
						imgText.set('text', 'Wetwall panel featured - Caspian Marble');
					}
					if(imageTwoUrl == "_common/img/vanities02.jpg"){
						img.setProperty('alt', 'Photgraph of Sicilian Slate');
						imgText.set('text', 'Wetwall panel featured - Sicilian Slate');
					}
					$$('div.sliderPanel ul li.nxtImg a')[0].set('text', 'Previous Image');
					$$('div.arrows a').removeClass('next');
					$$('div.arrows a').addClass('prev');
				}else if(imgSrc == imageTwoUrl){
					img.setProperty('src', imageOneUrl);
					if(imageOneUrl == "_common/img/boutique01.jpg"){
						img.setProperty('alt', 'Photgraph of Opulence');
						imgText.set('text', 'Wetwall panel featured - Black Pixels');
					}
					if(imageOneUrl == "_common/img/italian01.jpg"){
						img.setProperty('alt', 'Photgraph of Rossano and Ponente Sand');
						imgText.set('text', 'Wetwall panel featured - Rossano and Ponente Sand');
					}
					if(imageOneUrl == "_common/img/classics01.jpg"){
						img.setProperty('alt', 'Photgraph of Natural Pearl');
						imgText.set('text', 'Wetwall panel featured - Natural Pearl');
					}
					if(imageOneUrl == "_common/img/vanities01.jpg"){
						img.setProperty('alt', 'Photgraph of White Frost');
						imgText.set('text', 'Wetwall panel featured - White Frost');
					}
					$$('div.sliderPanel ul li.nxtImg a')[0].set('text', 'Next Image');
					$$('div.arrows a').removeClass('prev');
					$$('div.arrows a').addClass('next');
				}
				
				
				
				//set opacity to 0 and fade
				img.set('opacity',0).fade('in');
				
			});
			
			//insert arrows for large images
			var myLi = new Element('div', {
				'html': '<a href="#" class="next"><span>Next Image</span></a>',
				'class': 'arrows'
			}).inject(slider, 'before');
			
			//$$('div.arrows a')[0].cloneEvents($$('div.sliderPanel ul li.nxtImg a')[0]);
			$$('div.arrows a').cloneEvents($$('div.sliderPanel ul li.nxtImg a')[0]);

			
			//add event to colours button
			$$('div.sliderPanel ul li a.colours')[0].addEvent('click', function(event){
				new Event(event).stop();
				//console.log("boo");
				var swatches = $$('div.swatchesJS')[0];

				if(swatches.getStyle('display') == 'none'){
					swatches.setStyle('display','block');
					this.set('text', 'Hide Colours');
				}else if(swatches.getStyle('display') != 'none'){
					swatches.setStyle('display','none');
					this.set('text', 'View Colours');
				}
			});
			
		}//if why

		//slide in
		var myFx = new Fx.Tween(slider, {transition: 'sine:out', duration: 1500});
		myFx.start('margin-left', '-320', '0');
	}
	
	//external links
	$$('a[rel=external]').set('target', '_blank');
	
	//Site Show
	$(document.body).setStyle("visibility","visible");
	
});
