forgeapp = {};
(function() {
  
  this.smartSite = $('<div class="smartsite"/>').appendTo('body');
  this.start = {x: 0, y: 0};
  
  this.hPageNav = function(e) {
    var $page = $('.' + e.target.id),
        newPos = $page.position().left;
        
    $("html,body").animate( { scrollLeft: newPos - 100 }, "slow");
    
    e.preventDefault();
  };
  
  this.vPageNav = function(e) {
    var $page = $('.' + e.target.id),
        newPos = $page.position().top;
	
	$("html,body").animate( { scrollTop: newPos - 40 }, "slow");
	
    e.preventDefault();
  };
  
  this.setupNav = function() {
    
    // Force a redraw to fix FF 3.6 bug in rendering nav correctly when changing media queries
    $('body').append('<div class="redraw"/>'); $('.redraw').text(' ').remove();
    
    $('nav').unbind('click');
    if (forgeapp.mediaQuery == 2) {
      forgeapp.scrolling = 'horizontal';
      $('nav').bind('click', forgeapp.hPageNav);
    } else {
      forgeapp.scrolling = 'vertical';
      $('nav').bind('click', forgeapp.vPageNav);
    }
  };
    
  this.mediaQueryTest = function() {
    forgeapp.mediaQuery = parseInt(forgeapp.smartSite.css('font-size'), 10);
    forgeapp.smartSite.trigger('mediaQueryChange', [parseInt(forgeapp.smartSite.css('font-size'), 10)]);
  };
  
  this.resize = function() {
    
    if (forgeapp.scrolling === 'horizontal') {
      $('#wrapper').css({
        'padding-right': $(window).width() - $('footer').width() - 100,
        'padding-bottom': 0
      });
    } else if (forgeapp.scrolling === 'vertical') {
      $('#wrapper').css({
        'padding': 0
      });
    }
  };
  
}).apply(forgeapp);


$(document).ready(function() {
  // Smartsite
  forgeapp.smartSite.bind('mediaQueryChange', forgeapp.setupNav).trigger('mediaQueryChange');
  $(window).bind('resize', function() {
    forgeapp.resize();
    forgeapp.mediaQueryTest();
  }).trigger('resize');
  
  $(document).ready(function() {
    $("#twitter").getTwitter({
      userName: "forgeideas",
      numTweets: 4,
      loaderText: "Loading tweets...",
      slideIn: false,
      showHeading: false,
      headingText: "Latest Tweets",
      showProfileLink: false
    });
  });  

});
