/** 
 * Main dombehaviour
 *
 * @author Dodi Raditya
 * @version 1.0
 *
 * Note: This code works only in combination with Mootools
 */






/***
 * Main Application
 */
var App = {
  
  
  init: function() {
    App.setupExternalLinks();
    App.setupAccordion();
    App.setupSmoothscroll();
    App.resizeAbout();
    //App.setupVideos();
  },
  
   
  /** 
   * Setup external links to other sites
   */
	setupExternalLinks: function() {
	  var ext = $$('a[rel="external"]');
	  ext.each(function(a) {
	    a.addEvent('click', function(e) {
	      window.open(this.href, '', '');
	      new Event(e).stop();
	    });
	  });
	},
  
   
   
  /** 
   * Setup accordion
   */
	setupAccordion: function() {
	  //create our Accordion instance
		var myAccordion = new Accordion($('accordion'), 'div.project-title', 'div.project-content', {
			opacity: false,
			start: -1,
			onActive: function(toggler, element){
			  element.addClass('project-active');
				toggler.setStyle('color', '#000');
			},
			onBackground: function(toggler, element){
			  element.removeClass('project-active');
				toggler.setStyle('color', '#555');
			}
		});
	},
  
   
   
  /** 
   * Smooth scroll
   */
	setupSmoothscroll: function() {
	  var mySmoothScroll = new SmoothScroll({
      wheelStops: false
    });
	},
  	
	/** 
   * Resize about
   */
	resizeAbout: function() {
	  var containerSize = $('about-wrapper').getSize();
	  var viewportSize = this.getScreenSize();
	  //if(containerSize.y < viewportSize.height)
	    $('about-wrapper').style.height = viewportSize.height + 'px';
	},
	
  
  /** 
   * Get screen size
   */
  getScreenSize: function() {
	  var size = {
	    width: 1024,
	    height: 600
	  };
	  
	  if(typeof(window.innerWidth) == 'number') {
	    //Non-IE
	    size.width = window.innerWidth;
	    size.height = window.innerHeight;
	  }
	  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	    //IE 6+ in 'standards compliant mode'
	    size.width = document.documentElement.clientWidth;
	    size.height = document.documentElement.clientHeight;
	  }
	  else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
	    //IE 4 compatible
	    size.width = document.body.clientWidth;
	    size.height = document.body.clientHeight;
	  }
	  return size;  
  }

	
	
};





/** 
 * Setup @ DOMloaded event
 */
function onLoaded(func) {
  window.addEvent('load', func);
}



/** 
 * Initialize startup functions
 */
onLoaded(App.init);
onLoaded(function() {
  $(document.body).addClass('js-enhanced');
});





