// JavaScript Document

$(document).ready( function(){	

  $(".bl_more").click(function() {
	  current = "#" + $(this).parents("table").attr("id");
	  target = "#bl-p" + (current.split("-")[1].slice(1)-1);
	  $(current).hide();
	  $(target).show();
  });
  
  var promos = $(".news-promo");
  $(promos[0]).fadeIn(500);
  var tabs = $(".story-tab a");
  $(tabs[0]).addClass("on");
  
  var intervalID;
  var f=0;
  var n = $(promos).size();
  rotate();
  
  function rotate() {
    intervalID=setInterval(change, 10000);
	//change number for different staying time//
  }
    
  function change() {
	$(promos).hide();
	$(tabs).removeClass("on");
    if (f == n-1) {
	  $(promos[0]).fadeIn(500);
	  $(tabs[0]).addClass("on");
	  f = 0;
    } else {
	  $(promos[f+1]).fadeIn(500);
	  $(tabs[f+1]).addClass("on");
	  f = f+1;
    }
  }
  
  $(tabs).click(function() {
    $(tabs).removeClass("on");
    $(this).addClass("on");
	i = $(this).text() - 1;
	$(promos).hide();
	$(promos[i]).fadeIn(1000);		
	clearInterval(intervalID);
	rotate();
	f = i;
  });

});