/*
 * @class   Main
 * @company Hatem+D
 */

// Auto init

$(document).ready(function(){ 
	new Main();
});

 // Class
var Main = function() { this.initialize.apply(this, arguments) };
Main.prototype = (function() { var pro = {};

	//  Contants
	var BG_SIZE = { width: 1440, height: 846 };
      
  //  Variables
  var DOMWindow             = $(window),
			background 						= $('.page').children('img'),
			navSeq									=	$('.nav-seq'),
			wrap									=	$('.wrap'),
			page									=	$('.page'),
			ambiance							=	''

  //  public
  pro.initialize = function(opts) {
      initialize(); 
  };

  //  private
  var initialize = function()
  {
			initResize();
			initAmbiance();
      blockEmptyLinks();
      extendNavSeq();
			
			if(page != null) setTimeout(showContent,200);
			//if(navSeq != null) setTimeout(showNavSeq,200);
  }
  
	// resize management
  var initResize = function()
  {
      DOMWindow.bind('resize', resize);
      resize(null);
			background.show();
  };
  
  var resize = function ( e )
  {
		var scale     = 1,
        winSize   = { width: DOMWindow.width(), height: DOMWindow.height() },
        winRatio  = winSize.width / winSize.height,
        bgRatio   = BG_SIZE.width / BG_SIZE.height,
        newWidth  = 0;
    
    if ( winRatio > bgRatio ) scale = winSize.width / BG_SIZE.width;
    else                      scale = winSize.height / BG_SIZE.height;
    
    newWidth = BG_SIZE.width * scale;      
    background.css({
      'width' : newWidth + 'px',
      'left'  : -(newWidth - winSize.width) / 2 + 'px'
    });
  };

	// Ambiance management
	var initAmbiance = function()
	{		
			var hash = window.location.hash;
			
			$('#nav-ambiance').live('click', function(){
				ambiance = new Ambiance();
			});
			
			if(hash == '#ambiance'){
				$('#nav-ambiance').trigger('click');
			}
	};
	
	// blockEmpty management
  var blockEmptyLinks = function()
  {
      $('a[href=#]').bind('click', function(e){
        e.preventDefault();
      });
  };
  
  // Nav Seq management
  var extendNavSeq = function()
  {
      var navSeq = $('.nav-seq');
      if ( navSeq.size() == 0 )  return;
      
      var ul  = navSeq.children('ul'),
          div = navSeq.children('div');
      
      div.width(navSeq.width() - ul.width() + 'px');
  };
  
	var showContent = function(){		
		page.css({
			opacity: '1'
		});
	};

	var showNavSeq = function(){		
		navSeq.css({
			opacity: '1'
		});
	};


return pro })();
