// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

// place any jQuery/helper plugins in here, instead of separate, slower script files.

(function($){
   $.fn.jAccordion = function(options){
	   
	var options = $.extend({
		
	},options);

	return this.each(function() {            
		var hndl = this;
		
		this.section = $(this);
		this.section.addClass("accordion");
		
		this.first_level_box = this.section.children(".section");
		this.section_list = this.section.parent().find(".container");
		
		this.open_close = function(box){
			
			var section = box.parent().find(".container");
			
			hndl.section_list.each(function(){
			
				if($.data($(this)) != $.data(section)){
					$(this).animate({
						opacity: '0'
					}, 300).slideUp({duration: 200, easing: 'easeInOutCubic'});
				}				
			});
			
			if(section.is(":visible")){
				section.animate({
						opacity: '0'
					}, 300).slideUp({duration: 200, easing: 'easeInOutCubic'});
					$(this).find(".sets-nav").slideUp({duration:300 , easing: 'easeInOutCubic'});
				section.parent().find("h2").removeClass("active");
				section.parent().removeClass("open");
			}
			else{
				section.slideDown({duration: 200, easing: 'easeInOutCubic'}).animate({
						opacity: '1'
					}, 300);
				section.parent().parent().find("h2").removeClass("active");
				section.parent().parent().find(".section").removeClass("open");
				section.parent().find("h2").addClass("active");
				section.parent().addClass("open");
			}
		};
		
		this.init = function(){
			hndl.section_list.hide();
			
			hndl.first_level_box.find("h2").click(function(e){
			
				e.stopPropagation();
				hndl.open_close($(this).parent());
			});
			
			hndl.section.find("div.open .container").slideDown({duration: 200, easing: 'easeInOutCubic'}).animate({
						opacity: '1'
					}, 300);
			hndl.section.find("div.open h2").addClass("active");
		};
		
		this.init();		
	});    
   };
})(jQuery);

