/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	INITIALIZE
	
-----------------------------------------------------------------------------------------------------------------------------

	DEPENDENCIES: 
	MooTools - version 1.20              
	copyright 2007 | Valerio Proietti | http://mootools.net/
	MIT-style license | http://www.opensource.org/licenses/mit-license.php
	
	Clientside CNET Libraries for MooTools
	For descriptions and documentation: http://clientside.cnet.com/wiki/cnet-libraries
	
-----------------------------------------------------------------------------------------------------------------------------

	:: squarehead design studio   -  845.331.1953 | www.squarehead.com | sbliss@squarehead.com
	
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

/* 	initialize menu
---------------------------------------------------------------------------------------------------------------------------*/
function initMenu(){
	var n = 0;
	var itemWidth = 90; // width of each menu item
	
// create drop-downs from .links
$('drop_down_menu').getElements('li.menu').each( function( elem ){
	
	var list = elem.getElement('ul.links');	
	var inFx = new Fx.Slide(list, { duration: 1000, transition: Fx.Transitions.Elastic.easeOut }).hide();
	var outFx = new Fx.Slide(list, { duration: 200 }).hide();
	// position nav elements on navbar: itemWidth wide
	// elem.setStyle('left', n); **** lets do this in the CSS, slow page load causes problems with display ****
	n = n + itemWidth;
	
	elem.addEvents({
		'mouseenter' : function(){ 					
			outFx.cancel();
			inFx.slideIn();
		},
		'mouseleave' : function(){ 
			inFx.cancel();
			outFx.slideOut();								
		}
	});	
});

// add movement to li elements on drop-down list
$$('ul.links li a').addEvents({
	'mouseenter': function(){
		this.set('tween', {
			duration: 700,
			transition: Fx.Transitions.Elastic.easeOut
		}).tween('padding-left', '10px');
	},
	'mouseleave': function(){
		this.set('tween', { duration: 200 }).tween('padding-left', '0px');
	}
});	
}

/* 	initialize accordions
---------------------------------------------------------------------------------------------------------------------------*/

function initAccordions(){
	if ($$('aToggle')){
		aPanels = new Accordion($$('.aToggle'), $$('.aPanel'), {
			duration: 400,
			opacity: false,
			alwaysHide: true, 
			start: 'all-closed',
			onActive: function(toggler, element){
				toggler.addClass('toggler-open');
			},
			onBackground: function(toggler, element){
				toggler.removeClass('toggler-open');
			}
		});
	}
}

/* 	Carousel - CNET framework - Clentside docs: http://clientside.cnet.com/docs/Layout/SimpleCarousel
---------------------------------------------------------------------------------------------------------------------------*/

function initCarousel(){
	if ($('viewer')){
		
		// preload all banner images here
		var myImages = new Asset.images(['img-banner/001.jpg', 'img-banner/002.jpg', 'img-banner/003.jpg', 
		'img-banner/004.jpg', 'img-banner/005.jpg', 'img-banner/006.jpg'], {
			
			// create carousel after loading
		    onComplete: function(){
				var pos = "";
				var banner = new SimpleCarousel($('viewer'), $$('#viewer div.slide'), $$('#viewer div.button'), {
					slideInterval: 3000,
					rotateAction: 'click',
					onRotate: function(i){
						pos++;
						if(pos == 11){
							banner.stop();
						}
					}
				});
				
				// now you can display the finished carousel, and remove the loading graphic
				$('loader').setStyle('display', 'none');
				$('viewer').setStyle('display', 'block');
		    }
		});
	}
}


/* 	INITIALIZE STUFF AFTER DOM LOADS
---------------------------------------------------------------------------------------------------------------------------*/
window.addEvent('domready', function(){
	initMenu();
	initAccordions();
	initCarousel();
});


