var onAjaxLoad = function() {};

(function($){
  $(function() {
    
    if($("body#home").length!=0) {
      $("<img>").appendTo("body#home").hide().load(function(){
        $("<img>").appendTo("body#home").hide().load(function(){
          $("<div id='swirl'></div>").prependTo("#headerEffect");
          $("<div id='rainbow'><div></div></div>").prependTo("#headerEffect");
          startRainbow();    
        }).attr("src",rainbow);
      }).attr("src",swirl);
    }
    
    var startRainbow = function() {
      // capture the rainbow element
      var rainbow = document.getElementById('rainbow'), 
        lastPos, // stores the last scrollLeft position
        width = 1600; // the repeating point on the background
      
      // we always reset when the page reloads so that the background is always the same
      rainbow.scrollLeft = width;
      
      // use an interval to scroll the rainbow
      setInterval(function () {
        // subtract to make the background scroll from left to right
        rainbow.scrollLeft -= 5;
        
        // if we've hit the beginning then the lastPos will be the same as the scrollLeft
        if (lastPos == rainbow.scrollLeft) {
          // reset
          rainbow.scrollLeft = width;
        }
        
        lastPos = rainbow.scrollLeft;
      }, 50); // the combination of milliseconds
    }; 
    
  	var rubs = $("div.item_content");

    var menus = $("#menu li a").click(function(){
  		menus.removeClass("on");
  		var index = menus.index(this);
  		var el = rubs.eq(index).find("div.item:first");
      $(this).addClass("on")
      $("#content").slideBannersTo(el);
  	})
   
    $('#content').slideBanners({
  		target: 'div.item',
  		direction: 'bt',
  		jump: 120,
  		duration:500,
  		easing: "easeInOutBack"
  	}).bind("beforeSlideIn",function(e){
      var rub = $(e.target).parent();
      var index = rubs.index(rub);
      menus.removeClass("on").eq(index).addClass("on");
    }).find("a.out").attr("target","_blank");
	
	$('#community a.out').attr("target","_blank");

  });
})(jQuery);
