/*
  <3 JS
*/
var concentrated = {};

concentrated.init = function() {
  concentrated.scrolls();
  concentrated.modals('a.ajax-work','#modal');
  concentrated.tabs();
  concentrated.featured();
  concentrated.filtering();
  concentrated.nav();
  concentrated.twitter();
};

concentrated.twitter = function(){
  getTwitters('live', { 
    id: 'concentratedtv', 
    count: 1, 
    enableLinks: true, 
    ignoreReplies: true, 
    clearContents: true,
    template: '"%text%"'
  });
}

concentrated.nav = function(){
  $("#main-navigation > ul > li").children().each(function(){
    $(this).hover(function(){
      $(this).stop().animate({ color: '#ff0000' }, 400);
    },function(){
      $(this).stop().animate({ color: '#ffffff' }, 400);
    });
  });
  $("a.tag, div.tagcloud > a").each(function(){
    $(this).hover(function(){
      $(this).stop().animate({ backgroundColor: '#000000' }, 400);
    },function(){
      $(this).stop().animate({ backgroundColor: '#ff0000' }, 400);
    });
  });
  $("a.showall").each(function(){
    $(this).hover(function(){
      $(this).stop().animate({ backgroundColor: '#000000', color: '#ffffff' }, 400);
    },function(){
      $(this).stop().animate({ backgroundColor: '#E9E9E9', color: '#565656' }, 400);
    });
  });
}

concentrated.filtering = function(){
  $('#filtering').isotope({ filter: '*' });
  $('a.tag').click(function(){
    var selector = $(this).attr('data-filter');
    $('#filtering').isotope({ filter: selector, animationEngine : 'best-available' });
    return false;
  });
}

concentrated.featured = function(){
  $("#home-slider > ul").cycle({
    next: "#next",
    prev: "#prev",
    speed: 300
  });
  $("#pulldown").live("click", function(){
    if($(this).hasClass("up")){
      $("#home-slider").animate({
        marginTop: -306
      }, 200, function(){
        $("#pulldown").removeClass("up");
      });
    }
    else{
      $("#home-slider").animate({
        marginTop: 0
      }, 200, function(){
        $("#pulldown").addClass("up");
      });
    }
  });
}

concentrated.tabs = function(){
  $("#work-tabs").tabs();
}

concentrated.scrolls = function(){
  var widthCounter = 0;
  
  $("#work-scroller").find("li").each(function(){
    widthCounter = widthCounter + $(this).width();
    widthCounter = widthCounter + 30;
  });
  
  $("#work-scroller").find("ul").width(widthCounter);
  
  $(".custom-scroll").jScrollPane();
}

concentrated.modals = function(btn,modal){
  
  var $btn = $(btn);
  var $modal = $(modal);
  var $overlay = $('#overlay');
  var $close = $('a.close', $modal);
  
  // set overlay height
  var docHeight = $(document).height();
  $overlay.css({ height : docHeight });
  
  // open link
  $btn.each(function(){
    $(this).click(function(e){      
      e.preventDefault();
      
      var $url = $(this).attr("href");
      
      $overlay.fadeTo('fast',.9,function(){
        //populate modal
        $modal.load($url);
        
        // center modal
        $modal.css("top", ($(window).height() - 600) / 2+$(window).scrollTop() + "px");
        $modal.css("left", ($(window).width() - $modal.width() ) / 2+$(window).scrollLeft() + "px");
        
        //fade in modal
        $modal.fadeIn('slow');
      });
    });
  });
  
  // overlay close
  $overlay.click(function(){
    $modal.fadeOut('slow',function(){
      $overlay.fadeOut('fast');
      $modal.html("");
    });
  });
  
  // close
  $close.live("click", function(e){
    e.preventDefault();
    $modal.fadeOut('slow',function(){
      $overlay.fadeOut('fast');
      $modal.html("");
    });
  });
};

$(function() { concentrated.init(); });


