/* ---- Copyright to http://metalabdesign.com/ -------------------------- */
/* ---- Modifications by Jason for Cloud 9 Labs ------------------------- */

var totalSct = 0;
var articles = false;

$(document).ready(function(){
	
	if(document.getElementById("schedule")!=null){
		switchTo('sct2');
	}else{
		switchTo('sct1');
	}
	
	
	foundSct = true; // We suppose we have at least one section
	sctNumber = 1; // The first section is section #1
	while(foundSct==true){
		if(document.getElementById("scroller-sct"+sctNumber+"-window")!=null){
			sctNumber++;
		}else{
			foundSct = false;
			totalSct = sctNumber-1;
		}
	}
	
	for(var i=1; i<=totalSct; i++){
		$("#scroller-sct"+i+"-window").scrollable({
			easing: 'swing',
			size: '1',
			items: '#scroller-sct'+i+'-wrap',
			loop: 'true',
			next: '#button-next-project-sct'+i ,
			navi: '#project-dots-sct'+i,
			naviItem: 'a',
			keyboard: true,
			speed: '800'
		});	
	}
			
 	//set up events to handle browsing project categories
	// Gallery
	$("#projects .gallery-yoga-asana a ").bind("click", function(){ switchTo("sct1");});
	$("#projects .gallery-yoga-asana2 a ").bind("click", function(){ switchTo("sct2");});
	$("#projects .gallery-india a ").bind("click", function(){ switchTo("sct3");});
	$("#projects .gallery-kino a ").bind("click", function(){ switchTo("sct4");}); 
	$("#projects .gallery-lifestyle a ").bind("click", function(){ switchTo("sct5");});
	$("#projects .gallery-teaching a ").bind("click", function(){ switchTo("sct6");}); 
	$("#projects .gallery-teaching2 a ").bind("click", function(){ switchTo("sct7");});
	
	// DVD
	$("#projects .dvd-journey a ").bind("click", function(){ switchTo("sct1");});
	$("#projects .dvd-primary a ").bind("click", function(){ switchTo("sct2");});
	$("#projects .dvd-secondary a ").bind("click", function(){ switchTo("sct3");}); 
 
	// Schedule
	$("#projects .schedule-20112 a ").bind("click", function(){ switchTo("sct1"); });	
	$("#projects .schedule-20111 a ").bind("click", function(){ switchTo("sct2"); });	
	$("#projects .schedule-20102 a ").bind("click", function(){ switchTo("sct3"); });	
	$("#projects .schedule-20101 a ").bind("click", function(){ switchTo("sct4"); });		
	$("#projects .schedule-2009 a ").bind("click", function(){ switchTo("sct5"); });	
	$("#projects .schedule-2008 a ").bind("click", function(){ switchTo("sct6"); });	
	$("#projects .schedule-2007 a ").bind("click", function(){ switchTo("sct7"); });	
	$("#projects .schedule-2006 a ").bind("click", function(){ switchTo("sct8"); });	
	$("#projects .schedule-2005 a ").bind("click", function(){ switchTo("sct9"); });	
	$("#projects .schedule-2004 a ").bind("click", function(){ switchTo("sct10"); });
	// Articles
	$("#projects .ashtangaguru1 a ").bind("click", function(){ switchTo("sct1"); });
	$("#projects .ashtangaguru2 a ").bind("click", function(){ switchTo("sct2"); });
	$("#projects .bendingover1 a ").bind("click", function(){ switchTo("sct3"); });
	$("#projects .bendingover2 a ").bind("click", function(){ switchTo("sct4"); });
	$("#projects .beyondthegame a ").bind("click", function(){ switchTo("sct5"); });
	$("#projects .bodydoesnt a ").bind("click", function(){ switchTo("sct6"); });
	$("#projects .bravenew a ").bind("click", function(){ switchTo("sct7"); });
	$("#projects .choosingpeace a ").bind("click", function(){ switchTo("sct8"); });
	$("#projects .conciousstate a ").bind("click", function(){ switchTo("sct9"); });
	
	$("#projects .delicatetime a ").bind("click", function(){ switchTo("sct1"); });
	$("#projects .developingdevotion a ").bind("click", function(){ switchTo("sct2"); });
	$("#projects .dirtysounds a ").bind("click", function(){ switchTo("sct3"); });
	$("#projects .everydayawakening a ").bind("click", function(){ switchTo("sct4"); });
	$("#projects .evolutionofknowledge a ").bind("click", function(){ switchTo("sct5"); });
	$("#projects .findinglifelong1 a ").bind("click", function(){ switchTo("sct6"); });
	$("#projects .findinglifelong2 a ").bind("click", function(){ switchTo("sct7"); });
	
	$("#projects .havingfaith1 a ").bind("click", function(){ switchTo("sct1"); });
	$("#projects .havingfaith2 a ").bind("click", function(){ switchTo("sct2"); });
	$("#projects .hiddenkey a ").bind("click", function(){ switchTo("sct3"); });
	$("#projects .inevitabilitychange a ").bind("click", function(){ switchTo("sct4"); });
	$("#projects .integratingpractice a ").bind("click", function(){ switchTo("sct5"); });
	$("#projects .lovestest a ").bind("click", function(){ switchTo("sct6"); });
	
	$("#projects .managingvibrations a ").bind("click", function(){ switchTo("sct1"); });
	$("#projects .muddydrama a ").bind("click", function(){ switchTo("sct2"); });
	$("#projects .navigatingstormy a ").bind("click", function(){ switchTo("sct3"); });
	$("#projects .onthelanguage a ").bind("click", function(){ switchTo("sct4"); });
	$("#projects .onebreath a ").bind("click", function(){ switchTo("sct5"); });

	$("#projects .peacefulsolution a ").bind("click", function(){ switchTo("sct1"); });
	$("#projects .quietstrength1 a ").bind("click", function(){ switchTo("sct2"); });
	$("#projects .quietstrength2 a ").bind("click", function(){ switchTo("sct3"); });
	$("#projects .relaxinto a ").bind("click", function(){ switchTo("sct4"); });
	$("#projects .relaxingattachment a ").bind("click", function(){ switchTo("sct5"); });
	$("#projects .silverlining a ").bind("click", function(){ switchTo("sct6"); });
	$("#projects .stayingthrough a ").bind("click", function(){ switchTo("sct7"); });

	$("#projects .unhappymonk a ").bind("click", function(){ switchTo("sct1"); });
});

var curSect = "";

function switchTo(which){
	jQuery.easing.def = "easeInOutSine";
	
	h = $(".project").height();  //so we don't have to hardcode the row height;
	n = which.charAt(3); //the number of the current element
	if (which == curSect) { return; }  //don't switch if we are on the selected tab
	
	$(".button-next-project").hide();
	$("#button-next-project-"+which).show();		
	$(".project-dots").hide();
	$("#project-dots-"+which).show(300);		
	$("#project-type-nav span").animate({opacity: '.65'}, { "duration": 300 } );	
	$("#project-type-nav a").css("cursor", "pointer");		
	$("#project-type-nav ."+which+" a").css("cursor", "default");
	var theTop = (n-1)*45;
	$("#project-type-nav .current").animate({top: theTop+"px"  }, { "duration": 300 } );
	$("#project-type-nav ."+which+" span").animate({opacity: '1.0'}, { "duration": 300 } );
	if(n==1){
		$("#scroller-vertical").animate({top: "0"}, { "duration": 300 } );
	}else{
		n--;
		$("#scroller-vertical").animate({top: "-"+(h*n)+"px"}, { "duration": 300 } );
	}
	curSect = which;
	// Become TRUE if articles.js in included
	if(articles){
		changeImg(which.charAt(3));
	}
}

