/**
 * This class handles InTheNews modules functionality. 
 * @Depricated use bc.module.TabMananger instead.
 * @See bc.module.TabMananger class
 */
bc.InTheNews = function() {
}

/**
 * This class constant field holds the animation interval in milliseconds.
 */
bc.InTheNews.ANIMATION_INTERVAL = 5000;

/**
 * This class parameter reflects the current tab index (0, 1, ....).
 */
bc.InTheNews.currentTab = 0;

/**
 * This class constant field holds the number of tabs.
 */
bc.InTheNews.NUMBER_OF_TABS = 4;

/**
 * This class field represents the system interval ID for the animation.
 */
bc.InTheNews.intervalId = null;

/**
 * This class handles switching the tabs.
 *
 * @param tab The tab we can to switch. 
 */
bc.InTheNews.showNewsTab = function (tab) {

	for (var index = 0; index < bc.InTheNews.NUMBER_OF_TABS; index++){
		
		if (index == tab) {
			bc.InTheNews['bigdivs' + index].style.display = 'block';
		} else {
			bc.InTheNews['bigdivs' + index].style.display = 'none';
		}
	}
}

/**
 * This class method starts animation of the tabs.
 */
bc.InTheNews.startAnimation = function() {

	bc.InTheNews.intervalId = window.setInterval(function() {
		bc.InTheNews.showNewsTab(bc.InTheNews.currentTab);
		bc.InTheNews.currentTab = ++bc.InTheNews.currentTab % bc.InTheNews.NUMBER_OF_TABS;
	}, bc.InTheNews.ANIMATION_INTERVAL);
}

/**
 * This class method stops animation of the tabs.
 */
bc.InTheNews.stopAnimation = function() {
	
	window.clearInterval(bc.InTheNews.intervalId);
}

/**
 * This class method registers module events. It attaches the mouseover and
 * mouseout events to the in the news tabs. This gives us the fancy animation
 * like behavior where the page auto scrolls through the tabs. Then we attach
 * the click events to the actual tabs. The click even will then show the tab. 
 */
bc.InTheNews.registerEvents = function() {
	

	bc.InTheNews.startAnimation();
	
	bc.Event.addEventListener(bc.InTheNews.bigdivs0, bc.Event.MOUSEOVER, bc.InTheNews.stopAnimation);
	bc.Event.addEventListener(bc.InTheNews.bigdivs0, bc.Event.MOUSEOUT, bc.InTheNews.startAnimation);
	
	bc.Event.addEventListener(bc.InTheNews.bigdivs1, bc.Event.MOUSEOVER, bc.InTheNews.stopAnimation);
	bc.Event.addEventListener(bc.InTheNews.bigdivs1, bc.Event.MOUSEOUT, bc.InTheNews.startAnimation);
	
	bc.Event.addEventListener(bc.InTheNews.bigdivs2, bc.Event.MOUSEOVER, bc.InTheNews.stopAnimation);
	bc.Event.addEventListener(bc.InTheNews.bigdivs2, bc.Event.MOUSEOUT, bc.InTheNews.startAnimation);
	
	bc.Event.addEventListener(bc.InTheNews.bigdivs3, bc.Event.MOUSEOVER, bc.InTheNews.stopAnimation);
	bc.Event.addEventListener(bc.InTheNews.bigdivs3, bc.Event.MOUSEOUT, bc.InTheNews.startAnimation);
	
	bc.Event.addEventListener(bc.InTheNews.tabStyle0tab0, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(0);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle0tab1, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(1);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle0tab2, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(2);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle0tab3, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(3);
	});
	
	bc.Event.addEventListener(bc.InTheNews.tabStyle1tab0, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(0);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle1tab1, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(1);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle1tab2, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(2);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle1tab3, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(3);
	});
	
	bc.Event.addEventListener(bc.InTheNews.tabStyle2tab0, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(0);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle2tab1, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(1);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle2tab2, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(2);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle2tab3, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(3);
	});
	
	bc.Event.addEventListener(bc.InTheNews.tabStyle3tab0, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(0);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle3tab1, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(1);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle3tab2, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(2);
	});
	bc.Event.addEventListener(bc.InTheNews.tabStyle3tab3, bc.Event.CLICK, function() {
		bc.InTheNews.showNewsTab(3);
	});
}

/**
 * This class method initializes the elements we want to attach the events to
 * and then calls the registerEvents.
 */
bc.InTheNews.initialize = function() {
	
	bc.InTheNews.bigdivs0 = document.getElementById('bigDiv0');
  	bc.InTheNews.bigdivs1 = document.getElementById('bigDiv1');
  	bc.InTheNews.bigdivs2 = document.getElementById('bigDiv2');
  	bc.InTheNews.bigdivs3 = document.getElementById('bigDiv3');
  	
  	bc.InTheNews.tabStyle0tab0 = document.getElementById('tabStyle0tab0');
  	bc.InTheNews.tabStyle0tab1 = document.getElementById('tabStyle0tab1');
  	bc.InTheNews.tabStyle0tab2 = document.getElementById('tabStyle0tab2');
  	bc.InTheNews.tabStyle0tab3 = document.getElementById('tabStyle0tab3');
  	
  	bc.InTheNews.tabStyle1tab0 = document.getElementById('tabStyle1tab0');
  	bc.InTheNews.tabStyle1tab1 = document.getElementById('tabStyle1tab1');
  	bc.InTheNews.tabStyle1tab2 = document.getElementById('tabStyle1tab2');
  	bc.InTheNews.tabStyle1tab3 = document.getElementById('tabStyle1tab3');
  	
  	bc.InTheNews.tabStyle2tab0 = document.getElementById('tabStyle2tab0');
  	bc.InTheNews.tabStyle2tab1 = document.getElementById('tabStyle2tab1');
  	bc.InTheNews.tabStyle2tab2 = document.getElementById('tabStyle2tab2');
  	bc.InTheNews.tabStyle2tab3 = document.getElementById('tabStyle2tab3');
  	
  	bc.InTheNews.tabStyle3tab0 = document.getElementById('tabStyle3tab0');
  	bc.InTheNews.tabStyle3tab1 = document.getElementById('tabStyle3tab1');
  	bc.InTheNews.tabStyle3tab2 = document.getElementById('tabStyle3tab2');
  	bc.InTheNews.tabStyle3tab3 = document.getElementById('tabStyle3tab3');
  	
	// Register events.
	bc.InTheNews.registerEvents();
}

/*
 * Add an event listener to our window on load method to then call the initialize
 * method in here.
 */
bc.Event.addEventListener(window, bc.Event.LOAD, bc.InTheNews.initialize);
