var Site = {
	
	start: function(){		
		if ($('kwick')) 			Site.parseKwicks();		
		if ($('accordion')) 		Site.accordion();
		if ($('mainMenu')) 			Site.buildMenu();
		if ($('contactCherri')) 	Site.contactAjax();
		if ($('homeContent'))		Site.slideshow();
	},
	slideshow: function(args) {
		myShow = new Slideshow('homeContent',{ 
			hu: 'siteAssets/homeSlideShow/',
			images: ['NewStore01.jpg','NewStore02.jpg'],
			duration: [1000,7500],
			height: 430,
			width: 608,
			type: 'fade'
		});
	},
	
	parseKwicks: function(){
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 185]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 105) obj[j] = {'width': [w, 130]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 150]};
			});
			fx.start(obj);
		});
	},
	
	buildMenu: function(){
		var list = $$('#mainMenu li');
		list.each(function(element) {

			var fx = new Fx.Styles(element, {duration:200, wait:false});

			element.addEvent('mouseenter', function(){
				if(element.className != 'selected') {
					fx.start({
						'padding-left': 11,
						//'background-position': '-120px 0',
						color: '#ff8'
					});
				}
			});

			element.addEvent('mouseleave', function(){
				if(element.className != 'selected') {
					fx.start({
						'padding-left': 2,
						//'background-position': '0 0',
						'color': '#888'
					});
				}
			});
		});
	},
	
	accordion: function(){
		
		var accordion = new Accordion('h4.atStart', 'div.atStart', {
			opacity: false,
			onActive: function(toggler, element){
				//toggler.setStyle('color', '#ff3300');
				toggler.addClass('selected');
			},

			onBackground: function(toggler, element){
				//toggler.setStyle('color', '#222');
				toggler.removeClass('selected');
			}
		}, $('accordion'));
  	},
	contactAjax: function() {

	   var logSlide = new Fx.Slide('log').hide(); 
		
		$('contactCherri').addEvent('submit', function(e) {
			//Prevent the submit event
	      logSlide.hide();

			new Event(e).stop();

			//This empties the log.
			var log = $('log').empty();
			//send takes care of encoding and returns the Ajax instance.
		  	//onComplete removes the spinner from the log.
			this.send({
				update: log,
				onComplete: function() {
					logSlide.slideIn();
					logOpen = true; 					
				}
			});   
		});
	}
  
};

window.addEvent('domready', Site.start);
