var Site = {   
	
	loadhome: function() {
		$('logo').fade('hide');
		$('nav').fade('hide');
		$('content').fade('hide');
		$('tag').fade('hide'); 
		$('subscribe').fade('hide'); 
		
		var x = new Chain();
		
		var uno = function() { 
			$('logo').fade('in');
			$$('#logo img').fade('in');
		};
		
		var dos = function() { 
			$('nav').fade('in');
		};
		
		var tres = function() { 
			$('content').fade('in');
		};
		
		var quatro = function() { 
			$('tag').fade('in');
			$$('#tag img').fade('in');
		}; 
		
		var cinco = function() { 
			$('subscribe').fade('in');
		};
		
		x.chain(uno);
		x.chain(dos);
		x.chain(tres);
		x.chain(quatro);
	   
		x.callChain();
		x.callChain.delay(500, x);
		x.callChain.delay(1000, x);
		x.callChain.delay(1500, x);
		
	},
	
	
	
	linky: function() {
		var trigs = $$('#nav a, div.left a, div.right a, div.round a, div.point a, div.bow a');
		
		trigs.each(function(e){
			
			e.addEvent('mousedown',function(){
				  $('content').fade('out');
				  $$('h1.title').fade('out');
			}); 
			
			e.addEvent('mouseleave',function(){
				this.removeClass('active');
			});
		});       
		
		var links = $$('#nav a, #content a');
		
		links.each(function(f){
			//initalize
			f.morph('.navNormal');
			
			//format the active menu item
			$$('#nav li.active a').morph('.navHover');
			
			//add mouse events to menu
			f.addEvent('mouseenter',function(){
				  this.morph('.navHover');
			});
			
			f.addEvent('mouseleave',function(){
				  this.morph('.navNormal');
			}); 
			
		});
		
		//mouse events for form buttons
		if($$('input.submit')) $$('input.submit').addEvent('mouseenter',function(){
			  this.morph('.input.submit:hover');
		}); 
		
		if($$('input.submit')) $$('input.submit').addEvent('mouseleave',function(){
			  this.morph('.input.submit');
		}); 
		
	    //fade the whole page on logo click
		$$('#logo a').addEvent('click', function(){
			  $('wrapper').fade('out');
		});
		
		$$('#tag a').addEvent('click', function(){
			  $('wrapper').fade('out');
		});
	},
	
	intro: function() {   
		
		var c = new Chain();
		
		var one = function() { 
			$$('h1').fade('in');
		};
		
		var two = function() { 
			$('content').fade('in');
		};
		
		//call the chain
		c.chain(one);
		c.chain(two);
	    //execute the chain
		c.callChain();
		c.callChain.delay(500, c);
	}, 
	
	smoothscroll: function() {
	   var mySmoothScroll = new SmoothScroll();
	},  
	
	scroller : function() {
	    var scroll = new Scroller('content', {area: 150, velocity: 1});
	    $('content').addEvent('mouseenter', scroll.start.bind(scroll));
	    	$('content').addEvent('mouseleave', scroll.stop.bind(scroll));
			$('content').setStyle('overflow','hidden');
  	},
	
	tips: function() {
		$$('.tips').each(function(element,index) {  
		        var content = element.get('title').split('::');  
		        element.store('tip:title', content[0]);  
		        element.store('tip:text', content[1]);  
		    });  
	   
			var myTips = new Tips('.tips');
		
		    	myTips.addEvents({  
			    'show': function(tip) {  
			        tip.fade('in');  
			    },  
			    'hide': function(tip) {  
			        tip.fade('out');  
			    }  
			});
	}, 
	
	hide: function() {
		$('content').fade('hide');
		$$('h1').fade('hide');
	},            
	
	logo: function() {  
		var log = $('logo');
		var img = $$('#logo img'); 
		
		log.addEvent('mouseenter', function(){
			$$('#logo img').fade('out');
		}); 
		
		log.addEvent('mouseleave', function(){
			$$('#logo img').fade('in');
		}); 
		
		img.fade('in');
	},     
	
	collection: function() {
		var ul = $$('body.collection #content ul li a');
		var img = $$('body.collection div.images img');
		
		//hide all images
		img.each(function(lo) {
		    lo.fade('hide');
		});     		
		
	    //parse links
		ul.each(function(el) {
			//get the ID of the menu item  
		    var id = el.get('id'); 
		     
			//add mouse events to fade in images
		  	el.addEvent('mouseenter', function(){
				$$('img.on').fade('out');
				$$('img.' + id).fade('in');
			}); 
			
			el.addEvent('mouseleave', function(){
				//$$('img.on').fade('in');
				$$('img.' + id).fade('out');
			});
		}); 
		
		//restore the initial state on mouseleave
		$$('body.collection #content ul').addEvent('mouseleave', function(){
			$$('img.on').fade('in');
		})
		
		//add classes for initial state and fade them in
		$$('img.mm_fly').fade('in');
		$$('img.mm_fly').addClass('on');
		$$('img.mm_oxford').fade('in');
		$$('img.mm_oxford').addClass('on');
	},
	
    colorselect: function() {       
	    
		var trans = Browser.getQueryStringValue('color');
		
		//var transnew = trans.parseQuery(); 
		
		//check if the query is defined
		if (trans == undefined) {
			//do nothing
	    } else {	  
		
		//set color selection to query color				
		//$('colorselect').set({value: trans});
		$('colorselect').setProperty('value', trans);
		
		
		//set the color from the url
		 	//stop the magiczoom while we do some stuff
	   	 	MagicZoom_stopZooms();
	
			var zoomLink = $('zoom1');
			//find the link for the query color
			var myLink = $$('a.'+trans); 
		
			// Change the URL for the large image
			zoomLink.href = myLink;
			
			// Change the small image
			$$('#zoom1 img').setProperty('src', myLink);
			
			// Re-initialize Magic Zoom
		    MagicZoom_findZooms();
	    }
		
		//get the current value of the color select
		var currentcolor = $('colorselect').getSelectedValue();
		//empty the color name
		$('colorname').empty();
		//set the color name to the query color						
		$('colorname').set({html: currentcolor}); 
		
		//get all swatches
		var image = $$('#options a');
        
		//add mouse events to swatches 
		image.addEvent('mouseenter', function(){
			//get the color name of the current swatch
			 var color = this.getProperty('class');
			//update the color select
			 $('colorselect').setSelected(color);
			//reset the color name text
			 $('colorname').empty();
			 $('colorname').set({html: color}); 
			
			//get the delivery status
			//var delivery =  this.getProperty('title');
			//alert(delivery);
		});  
		
		//preload images 
		
		var images = $$('#options a').getProperty('rev');
		
		var loader = new Asset.images(images, {
			
			onProgress: function(counter,index) {
 //                 progressBar.set((counter + 1) * (100 / images.length));
			},
			
			onComplete: function() {
				images.each(function(im) {
//					new Element('img',{ src:im, width:200, style:'width:200px;margin:20px 20px 20px 0;' }).inject($('images-holder'));
				});
			}
		});
		
			
		
	},
	
	login: function() {
		//var loginSlide = new Fx.Slide('login').hide();
		$('login').setStyle('display', 'inline');
		$('login').fade('hide');
		
		$$('#myaccount a').addEvent('click', function() {
			$('login').fade('toggle');
		});
	},     
	
	returns: function() {
		var transaction_id = $('transaction_id').get('text');
		$('transaction_id_form').set('value', transaction_id);
		
		var email = $('email').get('text');
		$('email_form').set('value', email);
				
	},
	
	externalLinks: function() {
    	var externallinks = function(){
    		document.getElements('a').addEvent('click',function(){
    			if (this.get('href').toString().substr(0,7) == 'http://' && (this.get('href').toString().match(/^http:\/\/[(www.)]*cotoluxe\.com/) == null)){
    				window.open(this.get('href'));
    				return false;
    			}
    			return true;
    		});
    	}
	},
		
	init: function() { 
	 	if($('myGallery1')) { Site.loadhome(); } else { Site.intro(); }
		if($('colorselect')) Site.colorselect();
		Site.linky(); 
		Site.scroller();
		Site.logo();    
		//Site.externalLinks();
		if($('returns')) Site.returns();
		if($('login')) Site.login();
		if($$('body.collection')) Site.collection();
	}    
	
};

window.addEvent('load', Site.init); 
window.addEvent('domready', Site.hide);