(function($){
  
  var AboutSection = function(options, elem) {
    
    var $this = $(elem),
				$sections = $this.find('.regular-content section'),
				$sectionsContainer = null,
				$phygitalSection = $this.find('#phygital'), 
				$valuesSection = $this.find('#values'),
				$communicationSection = $this.find('#communication'),
				pRibbonNav = null,
				_curSectionIndex = -1;
    		
    // ----------------------------------------------------------------
    
    function _init() {
			debug.log("AboutSection :: initialized");
      
			// add padding to the top of section
			$this.find('.regular-content').css('padding-top', '75px');
			
			// apply section title plugin to title
			$this.find('.section-title').sectionTitle();
						
			
			// add container to all the sections where we'll put features ribbon navigation 
			$sectionsContainer = $sections.wrapAll('<div id="about-sections"></div>').parent();
			$sectionsContainer.css('position', 'relative');
			pRibbonNav = $sectionsContainer.ribbonNav({ribbonSections:$sections}).data("RibbonNav");
			
			$sectionsContainer.bind(MomentumWW.events.RIBBON_NAV_CLICK+'.aboutSection', _onRibbonNavClick);
			
			// setup individual sub sections plugins
			$phygitalSection.phygitalPlugin();
			$valuesSection.valuesPlugin();
			$communicationSection.communicationPlugin();

						
			_gotoSection(0);
			_activate();
    }; // _init()
    
    // ----------------------------------------------------------------
		function _onRibbonNavClick(e, index) {
			debug.log("_onRibbonNavClick :: index: "+index);
			// scroll to section
			_gotoSection(index);
		};
		
		function _gotoSection(index) {
			if (_curSectionIndex != index) {
				if (_curSectionIndex != -1) {
					// do any necessary deactivation on current section
					var $curSection = $sections.eq(_curSectionIndex);
					// activate new section
					$curSection.data('SectionPlugin').deactivate()
				}
				
				var $section = $sections.eq(index);
				// activate new section
				$section.data('SectionPlugin').activate();
				
				// update nav
				pRibbonNav.setSelectedBtn(index);
			
				_curSectionIndex = index;
			}
		}
		
		function _activate() {
		  debug.log("AboutSection :: _activate");
		}
    
    function _deactivate() {
		  debug.log("AboutSection :: _deactivate");
		}
    
    _init();
    
    return {
      activate: function() {
				_activate();
			},
			
			deactivate: function() {
				_deactivate();
			}
    };
    
  };
  
  // ==================================================================
  
  $.fn.aboutSection = function(options) {
    
    var pluginName = "AboutSection";
    
    options = $.extend({}, $.fn.aboutSection.defaults, options);
    
    return this.each(function(){
      
      var $this = $(this);
      
      if($this.data(pluginName)) {
        return;
      }
      
      // No JavaScript plugin instance exists, so add it as data attribute.
      var pluginInstance = new AboutSection(options, this);
      $this.data(pluginName, pluginInstance);
      $this.data('sectionController', pluginInstance);
    });
    
  };
  
  // ==================================================================
  
  $.fn.aboutSection.defaults = {
    
  };
 
	(function($){
	  
	  var PhygitalPlugin = function(options, elem) {
	    
	    var $this = $(elem),
					_isActive = false;
	    	    
	    // ----------------------------------------------------------------
	    
	    function _init() {
	      $this.addClass('hidden');
	    }; // _init()
	    
	    // ----------------------------------------------------------------
	    
			function _activate() {
				if(!_isActive) {
	        _isActive = true;
					$this.css('opacity','0');
					$this.removeClass('hidden');
					$this.stop().animate({opacity:1}, 750, 'easeOutQuart');
	      }
			};
			
			function _deactivate() {
				if(_isActive) {
	        _isActive = false;
					$this.addClass('hidden');
	      }
			};
			
		 // ----------------------------------------------------------------
	
	    _init();
	    
	    return {
	      activate: function() {
					_activate();
				},
				
				deactivate: function() {
					_deactivate();
				}
	    };
	    
	  };
	  
	  // ==================================================================
	  
	  $.fn.phygitalPlugin = function(options) {
	    
	    var pluginName = "PhygitalPlugin";
	    
	    options = $.extend({}, $.fn.phygitalPlugin.defaults, options);
	    
	    return this.each(function(){
	      
	      var $this = $(this);
	      
	      if($this.data(pluginName)) {
	        return;
	      }
	      
	      // No JavaScript plugin instance exists, so add it as data attribute.
	      var pluginInstance = new PhygitalPlugin(options, this);
	      $this.data('SectionPlugin', pluginInstance);
	      
	    });
	    
	  };
	  
	  // ==================================================================
	  
	  $.fn.phygitalPlugin.defaults = {
	    
	  };
	  
	})(jQuery);
	
  // ==================================================================
  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  // ==================================================================
  
  // @ValuesPlugin
  var ValuesPlugin = function(options, elem) {
    
    var $this = $(elem),
				$valuesBtns = $this.find('.values-nav a'),
				$valueContents = $this.find('.values-content'),
				_isActive = false;
    
    // ----------------------------------------------------------------
    
    function _init() {
			$valueContents.each(function() {
				var $valueContent = $(this);
				$valueContent.data('destH', $valueContent.outerHeight());
				$valueContent.css('height', '0px');
				$valueContents.data('open', 'false');
			});	
		
			$valuesBtns.each( function(){
					var plusMinusHtml = '<div class="plus-minus"></div>';
					var $plusMinus = $.browser.msie ? $(innerShiv(plusMinusHtml, false)) : $(plusMinusHtml);
					$(this).append($plusMinus);
			});
			
      $valuesBtns.click(function (e) {
				e.preventDefault();
				var $self = $(this)
				var $valueContent = $self.next();
				if ($valueContent.data('open') == 'true') {
					$valueContent.animate({height:0}, 300, 'easeInOutExpo');
					$valueContent.data('open', 'false');
					$self.find('.plus-minus').removeClass('open');
				} else {
					$valueContent.animate({height:$valueContent.data('destH')}, 300, 'easeInOutExpo');
					$valueContent.data('open', 'true');
					$self.find('.plus-minus').addClass('open');
				}
				
			});
			
      $this.addClass('hidden');
    }; // _init()
    
    // ----------------------------------------------------------------
    
		function _activate() {
			if(!_isActive) {
        _isActive = true;
				$this.css('opacity','0');
				$this.removeClass('hidden');
				$this.stop().animate({opacity:1}, 750, 'easeOutQuart');
      }
		};
		
		function _deactivate() {
			if(_isActive) {
        _isActive = false;
				$this.addClass('hidden');
      }
		};
		
	 // ----------------------------------------------------------------

    _init();
    
    return {
      activate: function() {
				_activate();
			},
			
			deactivate: function() {
				_deactivate();
			}
    };
    
  };
  
  // ==================================================================
  
  $.fn.valuesPlugin = function(options) {
    
    var pluginName = "ValuesPlugin";
    
    options = $.extend({}, $.fn.valuesPlugin.defaults, options);
    
    return this.each(function(){
      
      var $this = $(this);
      
      if($this.data(pluginName)) {
        return;
      }
      
      // No JavaScript plugin instance exists, so add it as data attribute.
      var pluginInstance = new ValuesPlugin(options, this);
      $this.data("SectionPlugin", pluginInstance);
    });
    
  };
  
  // ==================================================================
  
  $.fn.valuesPlugin.defaults = {
    
  };
  
 	// ==================================================================
  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  // ==================================================================

  // @CommunicationPlugin	
  var CommunicationPlugin = function(options, elem) {
    
    var $this = $(elem),
				$communicationList = $this.find('#communication-list'),
				_isActive = false;
    		
    
    // ----------------------------------------------------------------
    
    function _init() {
			// communication list
      $communicationList.find('a:first').css('border-top','1px dashed #666666');
			$communicationList.find('a').each(function() {
				var arrowHtml = '<div class="com-link-arrow"></div>';
				var $arrow = $.browser.msie ? $(innerShiv(arrowHtml, false)) : $(arrowHtml);
				$(this).append($arrow);
				
				$(this).bind('mouseenter', function () {
					$(this).addClass('hover');
				});

				$(this).bind('mouseleave', function () {
					$(this).removeClass('hover');
				});
			});
			
			$communicationList.find('li').each(function () {
					$(this).bind('mouseenter', function () {
						$(this).addClass('hover');
					});

					$(this).bind('mouseleave', function () {
						$(this).removeClass('hover');
					});
			})

			$this.addClass('hidden');
    }; // _init()
    
    // ----------------------------------------------------------------
    
		function _activate() {
			if(!_isActive) {
        _isActive = true;
				$this.css('opacity','0');
				$this.removeClass('hidden');
				$this.stop().animate({opacity:1}, 750, 'easeOutQuart');
      }
		};
		
		function _deactivate() {
			if(_isActive) {
        _isActive = false;
				$this.addClass('hidden');
      }
		};
		
	 // ----------------------------------------------------------------

    _init();
    
    return {
      activate: function() {
				_activate();
			},
			
			deactivate: function() {
				_deactivate();
			}
    };
   
  };

  // ==================================================================
  
  $.fn.communicationPlugin = function(options) {
    
    var pluginName = "CommunicationPlugin";
    
    options = $.extend({}, $.fn.communicationPlugin.defaults, options);
    
    return this.each(function(){
      
      var $this = $(this);
      
      if($this.data(pluginName)) {
        return;
      }
      
      // No JavaScript plugin instance exists, so add it as data attribute.
      var pluginInstance = new CommunicationPlugin(options, this);
      $this.data("SectionPlugin", pluginInstance);
    });
    
  };
  
  // ==================================================================
  
  $.fn.communicationPlugin.defaults = {
    
  };
  
})(jQuery);

