/* 
...............................................................
                            							
    ::  
	
	squarehead design studio 				

    845.331.1953   
    www.squarehead.com 
    sbliss@squarehead.com  
			 
    copyright 2007     
                                                     	  
............................................................... 

	kripalu semester intensive
                                                   
    DEPENDENCIES                             
    
	mootools.v1.11.js
    MIT-style license
	copyright 2007 Valerio Proietti
	mad4milk.net
...............................................................
*/

function initApp(){
	
	
// --------> init accordion

initPanels('.toggle','.panel',5);

$$('.toggle').addEvents({
	click: function(){getPage('homepage.html')}
});

// --------> init ajax links

var links = $$('.ajax');
links.each(function(item) {
	item.addEvent('click', function(evt) {
		new Event(evt).stop();
		links.each(function(el, i) {
			getPage(item.getProperty('href'));
		});
	});
});

var links = $$('.ajaxToo');
links.each(function(item) {
	item.addEvent('click', function(evt) {
		new Event(evt).stop();
		links.each(function(el, i) {
			getPage(item.getProperty('href'));
			mainNav.display(-1);
		});
	});
});

// --------> init secondary nav

$$('#secondaryNav li').setOpacity(.6);

var list = $$('#secondaryNav li');
list.each(function(element) {
	var fx = new Fx.Styles(element, {duration:200, wait:false});
	element.addEvent('mouseenter', function(){
		fx.start({
			'margin-left': 0,
			'opacity': 1
		});
	});
	element.addEvent('mouseleave', function(){
		fx.start({
			'margin-left': -20,
			'opacity': .6
		});
	});
});

///////////////////////////////////////////////////////
// Quotes
///////////////////////////////////////////////////////

$('close').addEvent('click', function() {
		$('quotes').setOpacity(0);
});

// --------> init quotes

slidingtabs = new SlidingTabs('buttons', 'quote');

	$('previous').addEvent('click', slidingtabs.previous.bind(slidingtabs));
	$('next').addEvent('click', slidingtabs.next.bind(slidingtabs));

			
			// you can use one of these to selectively stop the user from changing to certain panes
			slidingtabs.addEvent('change', function(event) {
				//event.cancel = true;
			});



// --------> load homepage

currentPage = '';
getPage('homepage.html');

}

///////////////////////////////////////////////////////
// Ajax
///////////////////////////////////////////////////////


function getPage(page)
{
	if(currentPage==page) { return; }
	currentPage = page;	
	$('innerContent').setOpacity(0);
	new Ajax(page, {method: 'get', update: $('innerContent'), evalScripts: false, onComplete: showContent}).request();
}

function showContent(){

// --------> re-init scrollbars
	
	CSBfleXcroll('content');
	var scrollDiv = $('content');
	scrollDiv.contentScroll(false,"0px",false); // sets scroll back to top
	
	$('content').setOpacity(0);
	$('innerContent').setOpacity(1);
// --------> show inner content

	fade = new Fx.Style($('content'),'opacity',{
		duration: 1000
	});
	fade.start(1);
	
}

///////////////////////////////////////////////////////
// Accordion
///////////////////////////////////////////////////////


function initPanels(toggle,panel,show) {
	mainNav = new Accordion($$(toggle), $$(panel), {duration: 400, alwaysHide: true, show: show,
			onActive: function(toggler){
			toggler.effects().start({
				'background-color':['#FFFFFF','#85282D'],
				'height':[25,50],
				'color':['#000000','#FFFFFF']
			});
			},
			onBackground: function(toggler){	
				toggler.effects().start({
					'background-color':['#FFFFFF'],
					'height':[25],
					'color':['#000000']
				});	
			}			  					    
	});
}

///////////////////////////////////////////////////////
// Show Quotes
///////////////////////////////////////////////////////

function showQuote() {
	$('quotes').effect('opacity', {duration: 500}).start(0,1);
}

///////////////////////////////////////////////////////
// Initialize App
///////////////////////////////////////////////////////

window.addEvent('domready', function(){
	initApp();
});

