// JavaScript Document for Irish Times MooTools Plugins */


/****************************************************
* Global Vars
*****************************************************/

var bannerContentTimer;
var is_homepage = 0;
var is_sliding = false;
/* 20090625 ED 'load' for IE6 and IE7, 'domready' for all other browsers */
var itEventType = 'domready';
if (window.ie6 || window.ie7) {
	itEventType = 'load';
}
/* TESTING ONLY...
	alert('Cross Browser TEST - window.ie6 or window.ie7. itEventType=' +itEventType);
} else {
	alert('Cross Browser TEST - not ie6 or ie7. itEventType=' +itEventType);
}
*/


/****************************************************
* Initialise MooTools Elements						*
*****************************************************/

function initMooTools(){ 
	//initWeatherPopUp();
	initBannerCarousel(); 
	initSiteIndex(); 
	initFeaturesSliders(); 
	initSupplementsSlider();
	initFeaturedTopicsFaders();
	initFeaturedTopicsVideoFader();
	kwicksFunc.initKwicks(); 

    // Event Listings

    if ( ! $('eventconsideration')) { return };

    $('eventconsideration').addEvent( 'change', function() {

      var email = this.options[this.selectedIndex].value;

      if ( ! $('eventcontactemail')) { return };

      $('eventcontactemail').href = "mailto:" + email;
      $('eventcontactemail').innerHTML = email;

      if ( ! $('eventcontact')) { return };
      $('eventcontact').setStyle( 'display', 'block' );

    });

}


/****************************************************
* Weather Icon Popup
*****************************************************/

function initWeatherPopUp(){
	//20090605 ED Replaced WFs code with mootools 1.11 Fx.Styles. New version has show-weather div. 
	if ( document.getElementById("show-weather") ){ return }
	
	if(document.getElementById("logo-date-area")){
		var aryClassElements = getElementsByClassName("weather", document.getElementById("logo-date-area"));
		// 20100113 ED: skip if empty
		if (aryClassElements.length==0 ) { return }
		
		for (var i=0; i<1; i++){
			if(aryClassElements[i].childNodes[0].nodeName.toLowerCase() == "a"){
				aryClassElements[i].childNodes[0].id = "weather-rollover";
			}
		}
		
		var aryClassElements = getElementsByClassName("arrow", document.getElementById("logo-date-area"));
		for (i=0; i<1; i++){
			aryClassElements[i].id = "weather-arrow";
		}
		
		if(document.getElementById("weather-rollover") && document.getElementById("weather-further-info") && document.getElementById("weather-arrow")){
			
			$("weather-further-info").style.display = "block";
			
			var fx1 = new Fx.Style($("weather-further-info"), 'opacity', {duration:600, wait:false, transition:Fx.Transitions.cubicOut}).hide();
			var fx2 = new Fx.Style($("weather-further-info"), 'top', {duration:600, wait:false, transition:Fx.Transitions.cubicOut});
		    var fx3 = new Fx.Style($("weather-arrow"), 'top', {duration:600, wait:false, transition:Fx.Transitions.cubicOut});
			var fx4 = new Fx.Style($("weather-arrow"), 'opacity', {duration:1, wait:false, transition:Fx.Transitions.cubicOut, onComplete: function(){ $("weather-arrow").style.display = "none"; }});
			var fx5 = new Fx.Style($("weather-arrow"), 'opacity', {duration:1, wait:false, transition:Fx.Transitions.cubicOut});
			var fx6 = new Fx.Style($("weather-arrow"), 'opacity', {duration:600, wait:false, transition:Fx.Transitions.cubicOut});
	 
			$("weather-rollover").addEvent('mouseenter', function(){
				fx1.start(0,1);
				fx2.start(20,35);
				if(!browser.isIE6 && !browser.isIE5) fx5.set(1);
				$("weather-arrow").style.display = "block";
				$("weather-arrow").style.left = "3px";
				if(!browser.isIE6 && !browser.isIE5){
					$("weather-arrow").style.background = $("weather-arrow").getStyle('background-image');
					$("weather-arrow").style.backgroundPosition = "left top";
					$("weather-arrow").style.backgroundRepeat = "no-repeat";
				}
				fx3.start(14,27);
			});
		 
			$("weather-rollover").addEvent('mouseleave', function(){
				if(browser.isIE6 || browser.isIE5) $("weather-arrow").style.display = "none";
				else fx4.start(1,0);
				fx3.start(27,14);																  
				fx2.start(35,20);
				if(browser.isIE && !browser.isIE6 && !browser.isIE5) $("weather-arrow").style.backgroundColor = "#FFF";
				fx1.start(1,0);
			});
		}
	}
}




/****************************************************
* Banner Content Carousel							*
*													*
*****************************************************/

function initBannerCarousel(){
	
	//if ( document.getElementById("banner-topic")===null || document.getElementById("banner-topic")==="undefined" ){	console.log("banner null"); return }
	if ( document.getElementById("banner-topic")===null || document.getElementById("banner-topic")==="undefined" ){	return }
	if ( document.getElementById("banner-topic-content")===null || document.getElementById("banner-topic-content")==="undefined" ){	return }
	
	if(document.getElementById("banner-topic")){	
		
		var aryClassElements = getElementsByClassName("content", document.getElementById("banner-topic"));
		for (var i=0; i<1; i++){
			aryClassElements[i].id = "banner-topic-content";
			$("banner-topic-content").setAttribute("viewport",0);
		}
		
		var content_links;
		if(document.getElementById("banner-topic-content")){
			content_links = document.getElementById("banner-topic-content").getElementsByTagName("a");
		}
		
		if(content_links.length > 1) eval('bannerContentTimer = setTimeout("rotateBannerContent(' + content_links.length + ')", 5000);');			
		
		var aryClassElementsPrevNext = getElementsByClassName("prev-next", document.getElementById("banner-topic"));
		for (i=0; i<aryClassElementsPrevNext.length; i++){
			aryClassElementsPrevNext[i].id = "banner-topic-prev-next";
		}
		
		var children;
		if(document.getElementById("banner-topic-prev-next")){
			children = $("banner-topic-prev-next").getElementsByTagName("li");
			if(children.length == 2){
				children[0].id = "banner-topic-prev-butt";
				children[1].id = "banner-topic-next-butt";
			}
		}
		
		if(content_links.length <= 1 && document.getElementById("banner-topic-prev-butt") && document.getElementById("banner-topic-next-butt")){
			$("banner-topic-prev-butt").style.display = "none";
			$("banner-topic-next-butt").style.display = "none";
		} else if(content_links.length > 1 && document.getElementById("banner-topic-prev-butt") && document.getElementById("banner-topic-next-butt")){
			$("banner-topic-prev-next").style.display = "block";
		}
		
		
		if(document.getElementById("banner-topic-content") && children.length == 2){
			
			var fx = $("banner-topic-content").effects({duration:300, wait:true, transition:Fx.Transitions.cubicOut});
			var left_pos = 0;
			var distance;
			
			if(browser.isIE6 || browser.isIE5) distance = -209;
			else distance = -219;
			
			$('banner-topic-prev-butt').addEvent('click', function(){
				clearTimeout(bannerContentTimer);
				fx.start({
					'opacity': 0
				}).chain(function(){
					$("banner-topic-content").setAttribute("viewport", parseInt($("banner-topic-content").getAttribute("viewport")) - 1);
					if(parseInt($("banner-topic-content").getAttribute("viewport")) < 0){
						$("banner-topic-content").setAttribute("viewport", content_links.length-1);
					}
					left_pos = distance * parseInt($("banner-topic-content").getAttribute("viewport"));
					this.start({
						'margin-left': left_pos
					});
				}).chain(function() {
					this.start.delay(1, this, {
						'opacity': 1
					});
				}).chain(function() {
					eval('bannerContentTimer = setTimeout("rotateBannerContent(' + content_links.length + ')", 5000);');
				});
			});
		 
			$('banner-topic-next-butt').addEvent('click', function() {
				clearTimeout(bannerContentTimer);
				fx.start({
					'opacity': 0
				}).chain(function(){
					$("banner-topic-content").setAttribute("viewport", parseInt($("banner-topic-content").getAttribute("viewport")) + 1);
					if(parseInt($("banner-topic-content").getAttribute("viewport")) == content_links.length){
						$("banner-topic-content").setAttribute("viewport", 0);
					}
					left_pos = distance * parseInt($("banner-topic-content").getAttribute("viewport"));
					this.start({
						'margin-left': left_pos
					});
				}).chain(function() {
					this.start.delay(1, this, {
						'opacity': 1
					});
				}).chain(function() {
					eval('bannerContentTimer = setTimeout("rotateBannerContent(' + content_links.length + ')", 5000);');
				});
			});
		}
	}
}




/****************************************************
* Banner Content Auotmatic Rotation					*
*													*
*****************************************************/

function rotateBannerContent(length){
	clearTimeout(bannerContentTimer);
	var fx = $("banner-topic-content").effects({duration:300, transition:Fx.Transitions.cubicOut});
	var left_pos = 0;
	var distance;
	
	if(browser.isIE6 || browser.isIE5) distance = -209;
	else distance = -219;
 
	fx.start({
		'opacity': '0'
	}).chain(function(){
		$("banner-topic-content").setAttribute("viewport", parseInt($("banner-topic-content").getAttribute("viewport")) + 1);
		if(parseInt($("banner-topic-content").getAttribute("viewport")) == length){
			$("banner-topic-content").setAttribute("viewport", 0);
		}
		left_pos = distance * parseInt($("banner-topic-content").getAttribute("viewport"));
		this.start({
			'margin-left': left_pos
		});
	}).chain(function() {
		this.start.delay(1, this, {
			'opacity': '1'
		});
	});
	
	eval('bannerContentTimer = setTimeout("rotateBannerContent(' + length + ')", 5000);');
}


	



/****************************************************
* Setup Site Index									*
*													*
*****************************************************/

function initSiteIndex(){
	if ( document.getElementById("site-index-link")===null || document.getElementById("site-index-link")==="undefined" ){ return }	
	SiteIndex.create('site-index-content', 'site-index-link', 'vertical');		// Do Site Index
}

 


/****************************************************
* Site Index										*
*													*
*****************************************************/

var SiteIndex = {
	create: function (elementID, indexButton, direction, noevents) {
		var newindex = Object();
		var openSiteIndex = false;
		
				
		
		newindex.props = 0;
		newindex.mode = 'vertical';
		if (typeof(direction) != "undefined" && direction != null) newindex.mode = direction;
			
		//Move the index of the screen, show the index, create the index, collapse the index, replace the index.
		newindex.menu = $(elementID);
		newindex.menu.slider = newindex;
		if (!noevents)
		{
			newindex.menu.addEvent('mouseover', function(){this.slider.prop();});
			newindex.menu.addEvent('mouseout', function(){this.slider.unprop();});
			if (indexButton)
			{
				$(indexButton).slider = newindex;
				if($(indexButton).id == "site-index-link"){
					$(indexButton).hideFocus = true;
					$(indexButton).addEvent('mousedown', function(e){ $(indexButton).blur(); });
					$(indexButton).addEvent('click', function(e){ this.slider.handleClick(); e = new Event(e); e.stop(); });	
					$("site-index-close").addEvent('click', function(e){ newindex.unprop(); newindex.unprop(); });
				}
			}
		}
	
		newindex.menu.style.visibility = "hidden";
		newindex.menu.style.display = "block";
		newindex.menu.style.left = (newindex.menu.offsetLeft - 1000) + "px";
		newindex.menu.style.visibility = "visible";
		newindex.slider = new Fx.Slide(elementID, {duration:500, mode:newindex.mode, wait:true}).hide();
		newindex.menu.style.left = (newindex.menu.offsetLeft + 1000) + "px";
			
		newindex.instanceID = elementID;	
		SiteIndex.instances[newindex.instanceID] = newindex;
		
		
		newindex.handleClick = function(){
			if(openSiteIndex || $("site-index-holder").getStyle("height").toInt() > 3) this.unprop();
			else this.show();
		}
		
				
		newindex.show = function(force) {
			this.showTabOverlay(true);
			openSiteIndex = true;
				
			if (force) this.props = 0;
			if (this.props == 0)
			{
				this.slider.stop();
				this.slider.slideIn();
				this.prop();
			}
			
		}
				
		newindex.hide = function() {
			if (this.props == 0)
			{
				this.slider.stop();
				this.slider.slideOut();
			}
		}
		
		newindex.tabTimer = null;
		newindex.showTabOverlay = function(show) {
			if(document.getElementById("crossword-tab-holder")){
				var tabs_as = document.getElementById("crossword-tab-holder").getElementsByTagName("a");
				if(show){
					for(var i=0; i<tabs_as.length; i++){
						if(tabs_as[i].parentNode.className == "nav-on"){
							tabs_as[i].style.height = "23px";
							tabs_as[i].style.minHeight = "23px";
							tabs_as[i].style.marginBottom = "0px";
						}
					}
				} else {
					if($("site-index-holder").getStyle("height").toInt() > 3){
						clearTimeout(this.tabTimer);
						this.tabTimer = setTimeout("SiteIndex.instances['"+this.instanceID+"'].showTabOverlay(false);", 10);
					} else {
						for(var i=0; i<tabs_as.length; i++){
							if(tabs_as[i].parentNode.className == "nav-on"){
								tabs_as[i].style.height = "26px";
								tabs_as[i].style.minHeight = "26px";
								tabs_as[i].style.marginBottom = "-3px";
							}
						}
					}
				}
			}
		}
			
		newindex.prop = function() {
			this.props++;
		}
			
		newindex.hideTimer = null;
		newindex.unprop = function() {			
			if (this.props <= 0)
				this.props = 0;
			else
				this.props--;
			clearTimeout(this.hideTimer);
			this.hideTimer = setTimeout("SiteIndex.instances['"+this.instanceID+"'].hide();", 200);
			openSiteIndex = false;
			this.showTabOverlay(false);
		}
				
		return newindex;
	},
		

	instances: new Array(),	//Public static member containing references to all isntances of SiteIndex objects.
	
	//show will show a menu if it is not already shown, prop it open, and set a timeout for it to auto-hide when it is unpropped.
	show:	function (id, force) {
		if (typeof(SiteIndex.instances[id]) == "object")
			SiteIndex.instances[id].show(force || false);
	},
	//unprop takes the prop off a menu so it can hide the next time it tries.
	unprop:	function (id) {
		if (typeof(SiteIndex.instances[id]) == "object")
			SiteIndex.instances[id].unprop();
	},
	//prop adds another prop to the menu so that it won't hide until it is unpropped.
	prop:	function (id) {
		if (typeof(SiteIndex.instances[id]) == "object")
			SiteIndex.instances[id].prop();
	}
};




/****************************************************
* Features Slider
*****************************************************/

function initFeaturesSliders(){
	$$("div.features li a span.content").each(
		function(e) {

    	var fx = new Fx.Styles(e, {duration:300, wait:false, transition:Fx.Transitions.cubicOut});

			var a = e.getParent().getParent(); // 'a' 
	    var height = e.getSize().scrollSize.y;
	    var usablearea = a.getStyle('height').toInt() * 0.6; // expressed as ratio: 128px = 78px (0.6) + 50px (0.4)
	    var usedarea = e.getStyle('height').toInt();

			a.addEvent('mouseenter', function(){
				new_top = usablearea - (e.getSize().scrollSize.y - usedarea);
				new_top += (e.getStyle('padding').toInt() * 2); // compensate for padding

				if (new_top < 0) { new_top = 0; }

				if((usablearea - new_top) > 5){
					fx.start({
						'max-height': height,
						'height': height,
						'top': new_top
					});
				}
				return false;
			});

			a.addEvent('mouseleave', function(){
				if((usablearea - new_top) > 5){
					fx.start({
						'max-height': usedarea,
						'height': usedarea,
						'top': usablearea
					});
				}
				return false;
			});
		}
	);
}







/****************************************************
* Supplements Sliders								*
*													*
*****************************************************/

function initSupplementsSlider(){
	if(document.getElementById("supplements")){
		var left_pos = 0;
		var ul_ind = 0;
		var aryClassElements = getElementsByClassName("move-left", document.getElementById("supplements"));
		for (var i=0; i<aryClassElements.length; i++){
			aryClassElements[i].id = "move-left-control";
		}
		
		aryClassElements = getElementsByClassName("move-right", document.getElementById("supplements"));
		for (i=0; i<aryClassElements.length; i++){
			aryClassElements[i].id = "move-right-control";
		}
		
		aryClassElements = getElementsByClassName("content", document.getElementById("supplements"));
		for (i=0; i<1; i++){
			aryClassElements[i].id = "supplements-content";
		}
		
		if(document.getElementById("move-left-control") && document.getElementById("move-right-control")){
			if($ES('ul','supplements-content').length > 1){
				$("move-left-control").style.display = "block";
				$("move-right-control").style.display = "block";
				$("move-left-control").addEvent('click', function(e){ if(!is_sliding) handleSupplementsSlider(e, this); });
				$("move-right-control").addEvent('click', function(e){ if(!is_sliding) handleSupplementsSlider(e, this); });
				$("move-left-control").addEvent('dblclick', function(e){ return false; });
				$("move-right-control").addEvent('dblclick', function(e){ return false; });
				$$('#supplements ul.paginate')[0].style.display = "block";
			}
		}
		
		var uls = $ES('ul','supplements-content');
		$("supplements-content").setAttribute("viewport",0);
		for(i=0; i<uls.length; i++){
			uls[i].id = "supplements-ul-" + ul_ind;
			uls[i].style.position = "absolute";
			uls[i].style.left = "-100000px";
			ul_ind++;
		}

		if(uls.length >= 3){
			uls[uls.length-1].style.left = "-881px";
			uls[0].style.left = "0px";
			uls[1].style.left = "881px";
		} else if(uls.length == 2){
			uls[0].style.left = "0px";
			uls[1].style.left = "881px";
		} else if(uls.length == 1){
			uls[0].style.left = "0px";
		}
		
		
		var dots = $$('#supplements ul.paginate')[0].getElementsByTagName("li");
		for(i=0; i<dots.length; i++){
			dots[i].id = "supplementsdot" + i;
			eval("$('supplementsdot" + i + "').addEvent('click', function(e){ if(!is_sliding) supplementsPaginate(e); });");
		}
	}
}


function handleSupplementsSlider(e, el){
	
	var current_viewport = parseInt($("supplements-content").getAttribute("viewport"));
	var previous_viewport = 0;
	var numViewPorts = 1;
	var direction = "right";
	
	
	if($ES('ul','supplements-content').length >= 3){
		if(el.className.indexOf("-right") != -1){
			if(current_viewport < $ES('ul','supplements-content').length - 1)
				$("supplements-content").setAttribute("viewport", parseInt(current_viewport+1));
			else
				$("supplements-content").setAttribute("viewport", 0);
			
			direction = "right";
			
			if(current_viewport > 0)
				previous_viewport = parseInt(current_viewport - 1);
			else if(current_viewport == 0)
				previous_viewport = parseInt($ES('ul','supplements-content').length - 1);
			
		} else {
			if(current_viewport > 0)
				$("supplements-content").setAttribute("viewport", parseInt(current_viewport-1));
			else
				$("supplements-content").setAttribute("viewport", parseInt($ES('ul','supplements-content').length - 1));
				
			direction = "left";

			if(current_viewport < $ES('ul','supplements-content').length - 1)
				previous_viewport = parseInt(current_viewport + 1);
			else if(current_viewport == 0)
				previous_viewport = 0;

		}				
			
		numViewPorts = 3;
		
	} else if($ES('ul','supplements-content').length == 2){
		if(current_viewport == 0)
			$("supplements-content").setAttribute("viewport", 1);
		else
			$("supplements-content").setAttribute("viewport", 0);
		
		numViewPorts = 2;
		
		if(el.className.indexOf("-right") != -1) direction = "right";
		else direction = "left";
	
	} else { numViewPorts = 1; }
	
	
	
	var viewPorts = new Array();
	for(var i=0; i<numViewPorts; i++){
		if(i==0 && numViewPorts==3){
			if(direction == "right") viewPorts.push(previous_viewport);
			if(direction == "left") viewPorts.push($("supplements-content").getAttribute("viewport"));
		} else if(i==0 && (numViewPorts==2 || numViewPorts==1)){
			viewPorts.push(current_viewport);
		} else if(i==1 && numViewPorts==3){
			viewPorts.push(current_viewport);
		} else if(i==1 && numViewPorts==2){
			viewPorts.push($("supplements-content").getAttribute("viewport"));
		} else if(i==2){			
			if(direction == "right") viewPorts.push($("supplements-content").getAttribute("viewport"));
			if(direction == "left") viewPorts.push(previous_viewport);
		}
	}
	
	

	var supplementsEffects = new Fx.Elements($ES('ul','supplements-content'), {duration:600, wait:true, transition:Fx.Transitions.cubicOut, onComplete: function(){ updateSupplementsOrder(); updateSupplementsPaginate(); }});
	
	
	var statement = "";
	var statement2 = "";
	var current_left;
	
	if($ES('ul','supplements-content').length > 2) current_left = -881;
	else if($ES('ul','supplements-content').length = 2) current_left = 0;
	
	if($ES('ul','supplements-content').length > 1){		
		statement = "supplementsEffects.start({";
		for(i=0; i<numViewPorts; i++){
			$ES('ul','supplements-content')[viewPorts[i]].style.left = current_left + "px"			
			if(direction == "right") { statement += "'" + viewPorts[i] + "': { 'left': [" + current_left + "," + (current_left - 881) + "]}" }
			else { statement += "'" + viewPorts[i] + "': { 'left': [" + current_left + "," + (current_left + 881) + "]}" }
			if(i < ($ES('ul','supplements-content').length - 1)) statement += ",";
			if($ES('ul','supplements-content').length == 2 && direction == "left") current_left -= 881;
			else current_left += 881;
		}
		
		statement += "});";
		eval(statement);
		is_sliding = true;
		
	}
}



function updateSupplementsOrder(){
	var furthest_left = (-881) * ($("supplements-content").getAttribute("viewport").toInt());
	for(var i=0; i<$ES('ul','supplements-content').length; i++){
		$ES('ul','supplements-content')[i].style.left = furthest_left + "px";
		furthest_left += 881;
	}
	
	is_sliding = false;
}



function supplementsPaginate(e){
	if (!e) var e = window.event;	
	var tgt = e.target || e.srcElement;
	
	var dir;
	var steps = 0;
	
	var tmp_id = tgt.id.replace(/supplementsdot/,"");
	if(tmp_id.toInt() > $("supplements-content").getAttribute("viewport")){
		dir = "right";
		steps = tmp_id.toInt() - $("supplements-content").getAttribute("viewport");
	} else if(tmp_id.toInt() < $("supplements-content").getAttribute("viewport")){
		dir = "left";
		steps = $("supplements-content").getAttribute("viewport") - tmp_id.toInt();
	} else {
		return;
	}
	
	
	$("supplements-content").setAttribute("viewport", tmp_id.toInt());		
	
	var statement = "";	
	var supplementsEffects = new Fx.Elements($ES('ul','supplements-content'), {duration:600, wait:true, transition:Fx.Transitions.cubicOut, onComplete: function(){ updateSupplementsOrder(); updateSupplementsPaginate(); }});
	
	
	if($ES('ul','supplements-content').length > 1){
		statement = "supplementsEffects.start({";
		for(var i=0; i<$ES('ul','supplements-content').length; i++){			
			if(dir == "right"){ statement += "'" + i + "': { 'left': [" + $ES('ul','supplements-content')[i].getStyle('left').toInt() + "," + ($ES('ul','supplements-content')[i].getStyle('left').toInt() - parseInt(steps*881)) + "]}" }
			else { statement += "'" + i + "': { 'left': [" + $ES('ul','supplements-content')[i].getStyle('left').toInt() + "," + ($ES('ul','supplements-content')[i].getStyle('left').toInt() + parseInt(steps*881)) + "]}" }
			if(i < ($ES('ul','supplements-content').length - 1)) statement += ",";
		}
		
		statement += "});";
		eval(statement);
		is_sliding = false;
	}
}



function updateSupplementsPaginate(){
	var dots = $$('#supplements ul.paginate')[0].getElementsByTagName("li");
	for(var i=0; i<dots.length; i++){
		dots[i].className = "";
	}
	
	for(i=0; i<$ES('ul','supplements-content').length; i++){
		if($ES('ul','supplements-content')[i].getStyle('left').toInt() == 0){
			if(dots[i]){
				dots[i].className = "nav-on";
			}
		}
	}
}





/****************************************************
* Featured Topics Faders							*
* Todays Images & In Depth							*
*													*
*****************************************************/

function initFeaturedTopicsFaders(){
	if(document.getElementById("featured-topics")){
		var top_level_lis;
		for(var i=0; i<$("featured-topics").getChildren().length; i++){
			if($("featured-topics").getChildren()[i].nodeName.toLowerCase() == "ul"){
				top_level_lis = $("featured-topics").getChildren()[i].getChildren();
				break;
			}
		}
		
		for(i=0; i<top_level_lis.length; i++){
			top_level_lis[i].setAttribute("cur_height", top_level_lis[i].offsetHeight);
			
			var li_divs = top_level_lis[i].getElementsByTagName("div");
			for(var j=0; j<li_divs.length; j++){
				if(li_divs[j].id == "todays-images" || li_divs[j].id == "in-depth-images"){
					top_level_lis[i].setAttribute("cur_height", parseInt(li_divs[j].offsetHeight+52));
				}
			}
		}
		
		
		var max_height = 0, max_on = 0, orig_max_on = 0;
		var new_height = 0;
		var lis = document.getElementById("featured-topics").getElementsByTagName("li");
		for(i=0; i<lis.length; i++){
			if(lis[i].parentNode.parentNode){
				if(lis[i].parentNode.parentNode.id == "featured-topics" && lis[i].offsetHeight > max_height){
					max_height = lis[i].offsetHeight;
					max_on = i;
					orig_max_on = max_on;
				}
			}
		}
		
		orig_max_height = max_height;
		
		for(i=0; i<lis.length; i++){
			if(lis[i].parentNode.parentNode){
				if(lis[i].parentNode.parentNode.id == "featured-topics"){
					lis[i].setAttribute("orig-height", lis[i].offsetHeight);
					if(lis[i].className.indexOf("with-prev-next") != -1){
						lis[i].style.height = parseInt(max_height - 52) + "px";
						lis[i].style.minHeight = parseInt(max_height - 52) + "px";
					} else {
						lis[i].style.height = parseInt(max_height - 22) + "px";
						lis[i].style.minHeight = parseInt(max_height - 22) + "px";
					}					
				}
			}
		}
		

		
		var tempPrevNextLis = getElementsByClassName("with-prev-next", document.getElementById("featured-topics"));
		var prevNextLis = new Array();
		for (i=0; i<tempPrevNextLis.length; i++){
			if(tempPrevNextLis[i].innerHTML.indexOf("todays-images") != -1 || tempPrevNextLis[i].innerHTML.indexOf("in-depth-images") != -1){
				prevNextLis.push(tempPrevNextLis[i]);
			}
		}
		
		is_homepage = prevNextLis.length;
		
		var aryClassElements;
		var content_links = new Array(prevNextLis.length);
		var content_spans = new Array(prevNextLis.length);
		var content_html = new Array(prevNextLis.length);
		var enlarge_links = new Array(prevNextLis.length);
		var children;
		var span_el, span_el_clone;
		var span_height_1 = 0; var span_height_2 = 0;
		var link_height_1 = 0; var link_height_2 = 0;
		var div_content = false;
		
		
		for (i=0; i<prevNextLis.length; i++){
			prevNextLis[i].id = "featured-topics-content-" + i;
			eval('$("featured-topics-content-' + i + '").setAttribute("viewport",0);');
			eval('aryClassElements = getElementsByClassName("images-holder", document.getElementById("featured-topics-content-' + i + '"));');
			for (j=0; j<1; j++){
				aryClassElements[j].id = "featured-topics-images-holder-" + i;
				content_links[i] = aryClassElements[j].getElementsByTagName("a");
				for (var k=0; k<content_links[i].length; k++){
					if(content_links[i][k].parentNode.parentNode){
						if(content_links[i][k].parentNode.parentNode.id == "todays-images"){
							content_links[i][k].id = "multibox_" + i + "_" + k;
							if(content_links[i][k].className.length > 0){
								content_links[i][k].className += " mb"+i;
							} else {
								content_links[i][k].className = "mb"+i;
							}
						}
					}
				}
			}
			eval('aryClassElements = getElementsByClassName("captions-holder", document.getElementById("featured-topics-content-' + i + '"));');
			for (j=0; j<1; j++){
				aryClassElements[j].id = "featured-topics-captions-holder-" + i;
				content_spans[i] = aryClassElements[j].getElementsByTagName("span");
				eval("content_html[i] = $$('#featured-topics-captions-holder-" + i + " div.content')");
				if(content_spans[i][0]){
					aryClassElements[j].style.height = content_spans[i][0].offsetHeight + "px";
					aryClassElements[j].style.minHeight = content_spans[i][0].offsetHeight + "px";
					aryClassElements[j].style.maxHeight = content_spans[i][0].offsetHeight + "px";
				}
			}
			eval('aryClassElements = getElementsByClassName("prev-next", document.getElementById("featured-topics-content-' + i + '"));');
			for (j=1; j<2; j++){
				aryClassElements[j].id = "featured-topics-prev-next-" + i;
				if(content_links[i].length > 1){
					aryClassElements[j].style.display = "block";
				}
				
				eval('if(document.getElementById("featured-topics-prev-next-' + i + '")){ children = $("featured-topics-prev-next-' + i + '").getElementsByTagName("li"); if(children.length == 2){ children[0].id = "featured-topics-prev-butt-' + i + '"; children[1].id = "featured-topics-next-butt-' + i + '"; } }');
				
				eval('if(content_links[i].length <= 1 && document.getElementById("featured-topics-prev-butt-' + i +'") && document.getElementById("featured-topics-next-butt-' + i +'")){ $("featured-topics-prev-butt-' + i +'").style.display == "none"; $("featured-topics-next-butt-' + i +'").style.display == "none"; }');
				
			}
			eval('aryClassElements = getElementsByClassName("enlarge", document.getElementById("featured-topics-content-' + i + '"));');
			for (j=0; j<aryClassElements.length; j++){
				if(aryClassElements[j].nodeName.toLowerCase() == "a"){
					enlarge_links[i] = aryClassElements[j];
					enlarge_links[i].className = "mb" + i + " enlarge";
				}
			}
			
			for (j=0; j<content_spans[i].length; j++){
				span_el = document.createElement('span');
				span_el.style.display = "none";
				if(content_spans[i][j] && content_links[i][j]){
					span_el.innerHTML = "<h4>" + content_spans[i][j].innerHTML + "</h4>";					
					span_el.className = "multiBoxDesc " + content_links[i][j].id;
					span_el.id = "temp_span";
					try {
						if(content_html[i][j]){
							content_html[i][j].className += " multiBoxDesc " + content_links[i][j].id;
							content_html[i][j].innerHTML = "<h4>" + content_spans[i][j].innerHTML + "</h4>" + content_html[i][j].innerHTML;
							div_content = true;
						}
					
					} catch(err) {
						content_links[i][j].appendChild(span_el);
					}
					
					if(enlarge_links[i] && j==0){
						if(!div_content){
							span_el_clone = $("temp_span").clone();
							$("temp_span").id = "";
						} else {
							span_el_clone = document.createElement('div');
							span_el_clone.style.display = "none";
							span_el_clone.innerHTML = content_html[i][j].innerHTML;
						}
						
						span_el_clone.className = "multiBoxDesc enlarge_link_" + i;
						enlarge_links[i].appendChild(span_el_clone);
						enlarge_links[i].id = "enlarge_link_" + i;
					}
				}
			}
		}
		
		


		var featuredTopicsOverallEffect = new Fx.Elements(top_level_lis, {duration:300, wait:true, transition:Fx.Transitions.cubicOut, onComplete: function(){ is_sliding = false; } });
		var li_array;

		
		
		
		
		var featuredTopicsEffects0 = new Fx.Elements($ES('div','todays-images'), {duration:300, wait:true, transition:Fx.Transitions.cubicOut});
		var featuredTopicsEffects1 = new Fx.Elements($ES('div','in-depth-images'), {duration:300, wait:true, transition:Fx.Transitions.cubicOut});
		// ADD MORE HERE AS REQUIRED
		
		for(i=0; i<$ES('div','todays-images').length; i++){
			if($ES('div','todays-images')[0].className != "images-holder" || $ES('div','todays-images')[1].className != "captions-holder"){
				break;
				return false;
			}
		}
		for(i=0; i<$ES('div','in-depth-images').length; i++){
			if($ES('div','in-depth-images')[0].className != "images-holder" || $ES('div','in-depth-images')[1].className != "captions-holder"){
				break;
				return false;
			}
		}
	
	
		var left_pos = new Array(prevNextLis.length);		
		var distance = -172;
		var span_diff = 0;
		var link_diff = 0;
		var past_threshold = false;
		var tempHeight;
		var offsetHeight = 0;
		
		for(i=0; i<prevNextLis.length; i++){
			left_pos[i] = 0;
		
			eval('if(document.getElementById("featured-topics-images-holder-' + i + '") && document.getElementById("featured-topics-captions-holder-' + i + '") && document.getElementById("featured-topics-prev-butt-' + i + '") && document.getElementById("featured-topics-next-butt-' + i + '")){ $(\'featured-topics-prev-butt-' + i + '\').addEvent(\'click\', function(){ if(!is_sliding){ is_sliding = true; featuredTopicsEffects' + i + '.start({ \'0\': { \'opacity\': [1,0] }, \'1\': { \'opacity\': [1,0] }	}).chain(function(){ if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ link_height_1 = content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].offsetHeight; span_height_1 = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].offsetHeight; } content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].style.display = "none"; $("featured-topics-content-' + i + '").setAttribute("viewport", parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")) - 1); if(parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")) < 0){ $("featured-topics-content-' + i + '").setAttribute("viewport", content_links[' + i + '].length-1); } content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].style.display = "block"; left_pos[' + i + '] = distance * parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")); if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ link_height_2 = content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].offsetHeight; span_height_2 = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].offsetHeight; } this.start({ \'0\': { \'margin-left\': [0,0] }, \'1\': { \'margin-left\': [parseInt(left_pos[' + i + ']-distance),left_pos[' + i + ']] } }); }).chain(function() { if(enlarge_links[' + i + '] && content_links[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ enlarge_links[' + i + '].href = content_links[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].href; children = enlarge_links[' + i + '].getElementsByTagName("span"); if(children[0]){ if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ children[0].innerHTML = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].innerHTML; } else { children[0].innerHTML = ""; } } }  li_array = {}; link_diff = link_height_2 - link_height_1; span_diff = span_height_2 - span_height_1; tempHeight = top_level_lis[' + i + '].getStyle("height"); document.getElementById("featured-topics-prev-next-' + i + '").style.display="none"; top_level_lis[' + i + '].style.height = "auto"; top_level_lis[' + i + '].style.minHeight = "0px"; offsetHeight = parseInt(top_level_lis[' + i + '].offsetHeight + link_diff + span_diff); top_level_lis[' + i + '].style.height = tempHeight; top_level_lis[' + i + '].style.minHeight = tempHeight; document.getElementById("featured-topics-prev-next-' + i + '").style.display="block"; if((' + i + ' == 0 && offsetHeight > max_height) || (' + i + ' == 1 && offsetHeight - 18 > max_height)){ top_level_lis.each(function(tli, j) { if(tli.className.indexOf("with-prev-next") != -1){ li_array[j] = {\'height\': [parseInt(max_height - 52), parseInt(offsetHeight - 52)], \'min-height\': [parseInt(max_height - 52), parseInt(offsetHeight - 52)]} } else { li_array[j] = {\'height\': [parseInt(max_height - 22),parseInt(offsetHeight-22)], \'min-height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)]} } }); max_height = offsetHeight; max_on = ' + i + '; } else if(' + i + ' == max_on) { top_level_lis.each(function(tli, j) { if(tli.className.indexOf("with-prev-next") != -1){ if((orig_max_height - 52) < parseInt(offsetHeight-52)){ li_array[j] = {\'height\': [parseInt(max_height - 52), parseInt(offsetHeight-52)], \'min-height\': [parseInt(max_height - 52), parseInt(offsetHeight-52)]} } else { li_array[j] = {\'height\': [parseInt(orig_max_height - 52), parseInt(orig_max_height - 52)], \'min-height\': [parseInt(orig_max_height - 52), parseInt(orig_max_height - 52)]} } } else { if((orig_max_height - 22) < parseInt(offsetHeight-22)){ li_array[j] = {\'height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)], \'min-height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)]} } else { li_array[j] = {\'height\': [parseInt(orig_max_height - 22), parseInt(orig_max_height - 22)], \'min-height\': [parseInt(orig_max_height - 22), parseInt(orig_max_height - 22)]} } } }); max_height = 0; top_level_lis.each(function(tli, j) { if(tli.offsetHeight > max_height){ max_height = tli.offsetHeight; max_on = j; } }); } content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].style.height = span_height_2 + "px"; content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].style.maxHeight = span_height_2 + "px"; featuredTopicsOverallEffect.start(li_array); this.start.delay(1, this, { \'0\': { \'opacity\': [0,1], \'height\': [link_height_1,link_height_2] }, \'1\': { \'opacity\': [0,1], \'height\': [span_height_1,span_height_2], \'min-height\': [span_height_1,span_height_2], \'max-height\': [span_height_1,span_height_2] } }); }); }}); $(\'featured-topics-next-butt-' + i + '\').addEvent(\'click\', function() { if(!is_sliding){ is_sliding = true; featuredTopicsEffects' + i + '.start({ \'0\': { \'opacity\': [1,0] }, \'1\': { \'opacity\': [1,0] } }).chain(function(){ if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ link_height_1 = content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].offsetHeight; span_height_1 = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].offsetHeight; } content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].style.display = "none"; $("featured-topics-content-' + i + '").setAttribute("viewport", parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")) + 1); if(parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")) == content_links[' + i + '].length){ $("featured-topics-content-' + i + '").setAttribute("viewport", 0); } content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].style.display = "block"; left_pos[' + i + '] = distance * parseInt($("featured-topics-content-' + i + '").getAttribute("viewport")); if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ link_height_2 = content_links[' + i + '][parseInt($("featured-topics-content-' +  i + '").getAttribute("viewport"))].offsetHeight; span_height_2 = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].offsetHeight; } this.start({ \'0\': { \'margin-left\': [0,0] }, \'1\': { \'margin-left\': [parseInt(left_pos[' + i + ']-distance),left_pos[' + i + ']] } }); }).chain(function() { if(enlarge_links[' + i + '] && content_links[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ enlarge_links[' + i + '].href = content_links[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].href; children = enlarge_links[' + i + '].getElementsByTagName("span"); if(children[0]){ if(content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))]){ children[0].innerHTML = content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].innerHTML; } else { children[0].innerHTML = ""; } } } li_array = {}; link_diff = link_height_2 - link_height_1; span_diff = span_height_2 - span_height_1; tempHeight = top_level_lis[' + i + '].getStyle("height"); document.getElementById("featured-topics-prev-next-' + i + '").style.display="none"; top_level_lis[' + i + '].style.height = "auto"; top_level_lis[' + i + '].style.minHeight = "0px"; offsetHeight = parseInt(top_level_lis[' + i + '].offsetHeight + link_diff + span_diff); top_level_lis[' + i + '].style.height = tempHeight; top_level_lis[' + i + '].style.minHeight = tempHeight; document.getElementById("featured-topics-prev-next-' + i + '").style.display="block"; if((' + i + ' == 0 && offsetHeight > max_height) || (' + i + ' == 1 && offsetHeight - 18 > max_height)){ top_level_lis.each(function(tli, j) { if(tli.className.indexOf("with-prev-next") != -1){ li_array[j] = {\'height\': [parseInt(max_height - 52), parseInt(offsetHeight - 52)], \'min-height\': [parseInt(max_height - 52), parseInt(offsetHeight - 52)]} } else { li_array[j] = {\'height\': [parseInt(max_height - 22),parseInt(offsetHeight-22)], \'min-height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)]} } }); max_height = offsetHeight; max_on = ' + i + '; } else if(' + i + ' == max_on) { top_level_lis.each(function(tli, j) { if(tli.className.indexOf("with-prev-next") != -1){ if((orig_max_height - 52) < parseInt(offsetHeight-52)){ li_array[j] = {\'height\': [parseInt(max_height - 52), parseInt(offsetHeight-52)], \'min-height\': [parseInt(max_height - 52), parseInt(offsetHeight-52)]} } else { li_array[j] = {\'height\': [parseInt(orig_max_height - 52), parseInt(orig_max_height - 52)], \'min-height\': [parseInt(orig_max_height - 52), parseInt(orig_max_height - 52)]} } } else { if((orig_max_height - 22) < parseInt(offsetHeight-22)){ li_array[j] = {\'height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)], \'min-height\': [parseInt(max_height - 22), parseInt(offsetHeight-22)]} } else { li_array[j] = {\'height\': [parseInt(orig_max_height - 22), parseInt(orig_max_height - 22)], \'min-height\': [parseInt(orig_max_height - 22), parseInt(orig_max_height - 22)]} } } }); max_height = 0; top_level_lis.each(function(tli, j) { if(tli.offsetHeight > max_height){ max_height = tli.offsetHeight; max_on = j; } }); } content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].style.height = span_height_2 + "px"; content_spans[' + i + '][parseInt($("featured-topics-content-' + i + '").getAttribute("viewport"))].style.maxHeight = span_height_2 + "px"; featuredTopicsOverallEffect.start(li_array); this.start.delay(1, this, { \'0\': { \'opacity\': [0,1], \'height\': [link_height_1,link_height_2] }, \'1\': { \'opacity\': [0,1], \'height\': [span_height_1,span_height_2], \'min-height\': [span_height_1,span_height_2], \'max-height\': [span_height_1,span_height_2] }	}); }); }}); }');
			
		}
	}
}




/****************************************************
* Featured Topics Faders							*
* Videos Slider										*
*													*
*****************************************************/


function initFeaturedTopicsVideoFader(){
	if(document.getElementById("featured-topics")){
		var left_pos = 0;
		var ul_ind = 0;
		var aryClassElements = getElementsByClassName("content", document.getElementById("featured-topics"));
		for (i=0; i<aryClassElements.length; i++){
			if(aryClassElements[i].parentNode.className == "slider" && aryClassElements[i].parentNode.parentNode.innerHTML.indexOf("Video") != -1){
				aryClassElements[i].id = "featured-topics-video-content"; 
			}
		}
		
		if(document.getElementById("featured-topics-video-content")){
			if($ES('ul','featured-topics-video-content').length > 1){
				if($("featured-topics-video-content").parentNode.parentNode){
					if($("featured-topics-video-content").parentNode.parentNode.className.indexOf("with-prev-next") != -1){
						aryClassElements = getElementsByClassName("prev-next", $("featured-topics-video-content").parentNode.parentNode);			
						
						for (i=1; i<2; i++){
							aryClassElements[i].style.display = "block";
							var aryPrevNextClassElements = aryClassElements[i].getElementsByTagName("li");
							if(aryPrevNextClassElements.length == 2){
								aryPrevNextClassElements[0].id = "featured-topics-video-prev-butt";
								aryPrevNextClassElements[1].id = "featured-topics-video-next-butt";
								$("featured-topics-video-prev-butt").addEvent('click', function(e){ if(!is_sliding) handleVideoSlider(e, this); });
								$("featured-topics-video-next-butt").addEvent('click', function(e){ if(!is_sliding) handleVideoSlider(e, this); });
							}
						}
					}
				}
			}
		}
		
		
		var uls = $ES('ul','featured-topics-video-content');
		$("featured-topics-video-content").setAttribute("viewport",0);
		for(i=0; i<uls.length; i++){
			uls[i].id = "featured-topics-video-ul-" + ul_ind;
			uls[i].style.position = "absolute"; //pos:rel here fixes .content from becoming invisible - but breaks the prev links
			uls[i].style.top = "-100000px";  
			ul_ind++;
		}

		if(uls.length >= 3){
			uls[uls.length-1].style.top = parseInt(-1* uls[uls.length-1].offsetHeight) + "px";
			uls[0].style.top = "0px";
			uls[1].style.top =  parseInt(uls[0].offsetHeight) + "px";
		} else if(uls.length == 2){
			uls[0].style.top = "0px";
			uls[1].style.top =  parseInt(uls[0].offsetHeight) + "px";
		} else if(uls.length == 1){
			uls[0].style.top = "0px";
		}
		
	}
}




function handleVideoSlider(e, el){
	var current_viewport = parseInt($("featured-topics-video-content").getAttribute("viewport"));
	var previous_viewport = 0;
	var numViewPorts = 1;
	var direction = "down";
	
	
	if($ES('ul','featured-topics-video-content').length >= 3){
		if(el.className.indexOf("last") != -1){
			if(current_viewport < $ES('ul','featured-topics-video-content').length - 1)
				$("featured-topics-video-content").setAttribute("viewport", parseInt(current_viewport+1));				
			else
				$("featured-topics-video-content").setAttribute("viewport", 0);
			
			direction = "up";
			
			if(current_viewport > 0)
				previous_viewport = parseInt(current_viewport - 1);
			else if(current_viewport == 0)
				previous_viewport = parseInt($ES('ul','featured-topics-video-content').length - 1);
			
		} else {
			if(current_viewport > 0)
				$("featured-topics-video-content").setAttribute("viewport", parseInt(current_viewport-1));
			else
				$("featured-topics-video-content").setAttribute("viewport", parseInt($ES('ul','featured-topics-video-content').length - 1));
				
			direction = "down";

			if(current_viewport < $ES('ul','featured-topics-video-content').length - 1)
				previous_viewport = parseInt(current_viewport + 1);
			else if(current_viewport == 0)
				previous_viewport = 0;

		}				
			
		numViewPorts = 3;
		
	} else if($ES('ul','featured-topics-video-content').length == 2){
		if(current_viewport == 0)
			$("featured-topics-video-content").setAttribute("viewport", 1);
		else
			$("featured-topics-video-content").setAttribute("viewport", 0);
		
		numViewPorts = 2;
		
		if(el.className.indexOf("last") != -1) direction = "up";
		else direction = "down";
	
	} else { numViewPorts = 1; }
	
	
	
	var viewPorts = new Array();
	for(var i=0; i<numViewPorts; i++){
		if(i==0 && numViewPorts==3){
			if(direction == "up") viewPorts.push(previous_viewport);
			if(direction == "down") viewPorts.push($("featured-topics-video-content").getAttribute("viewport"));
		} else if(i==0 && (numViewPorts==2 || numViewPorts==1)){
			viewPorts.push(current_viewport);
		} else if(i==1 && numViewPorts==3){
			viewPorts.push(current_viewport);
		} else if(i==1 && numViewPorts==2){
			viewPorts.push($("featured-topics-video-content").getAttribute("viewport"));
		} else if(i==2){			
			if(direction == "up") viewPorts.push($("featured-topics-video-content").getAttribute("viewport"));
			if(direction == "down") viewPorts.push(previous_viewport);
		}
	}
	
	

	var videoEffects = new Fx.Elements($ES('ul','featured-topics-video-content'), {duration:600, wait:true, transition:Fx.Transitions.cubicOut, onComplete: function(){ is_sliding = false; }});
	var top_level_lis;
	for(var i=0; i<$("featured-topics").getChildren().length; i++){
		if($("featured-topics").getChildren()[i].nodeName.toLowerCase() == "ul"){
			top_level_lis = $("featured-topics").getChildren()[i].getChildren();
			break;
		}
	}
	
	/*	ADJUST OTHER LI HEIGHTS IF NECESSARY
	var featuredTopicsOverallEffect = new Fx.Elements(top_level_lis, {duration:300, wait:true, transition:Fx.Transitions.cubicOut});
	var li_array = {};
	top_level_lis.each(function(tli, i) {
		li_array[i] = {height: [tli.getStyle("height").toInt(), tli.getStyle("height").toInt()]}
	});
	featuredTopicsOverallEffect.start(li_array);
	*/
	
	
	var statement = "";
	var statement2 = "";
	var current_top;
	
	if($ES('ul','featured-topics-video-content').length > 2) current_top = parseInt(-1* $ES('ul','featured-topics-video-content')[$ES('ul','featured-topics-video-content').length-1].offsetHeight);
	else if($ES('ul','featured-topics-video-content').length = 2) current_top = 0;
	
	if($ES('ul','featured-topics-video-content').length > 1){		
		statement = "videoEffects.start({";
		for(i=0; i<numViewPorts; i++){
			$ES('ul','featured-topics-video-content')[viewPorts[i]].style.top = current_top + "px"			
			if(direction == "up") { statement += "'" + viewPorts[i] + "': { 'top': [" + current_top + "," + (current_top - parseInt($ES('ul','featured-topics-video-content')[viewPorts[i]].offsetHeight)) + "]}" }
			else { statement += "'" + viewPorts[i] + "': { 'top': [" + current_top + "," + parseInt(current_top + parseInt($ES('ul','featured-topics-video-content')[viewPorts[i]].offsetHeight)) + "]}" }
			if(i < ($ES('ul','featured-topics-video-content').length - 1)) statement += ",";
			if($ES('ul','featured-topics-video-content').length == 2 && direction == "up") current_top -= parseInt($ES('ul','featured-topics-video-content')[$ES('ul','featured-topics-video-content').length-1].offsetHeight);
			else current_top += parseInt($ES('ul','featured-topics-video-content')[$ES('ul','featured-topics-video-content').length-1].offsetHeight);
		}
		
		statement += "});";
		eval(statement);
		is_sliding = true;
	}
}







/****************************************************
* Services Kwicks									*
*													*
*****************************************************/


var kwicksFunc = {	
	initKwicks: function(){
		var tds;	
		var max_height = 0;
		if(document.getElementById("services")){
			lis = document.getElementById("services").getElementsByTagName("li");
			for(var i=0; i<lis.length; i++){
				if(lis[i].parentNode.parentNode){
					if(lis[i].parentNode.parentNode.id == "services" && lis[i].parentNode.className != "right"){
						if(lis[i].className.length > 0){
							lis[i].className += " kwick";
						} else if(lis[i].className != "last"){
							lis[i].className = "kwick";							
						}
					} else if(lis[i].parentNode.parentNode.id == "services" || lis[i].parentNode.className == "right") {
						if(lis[i].offsetHeight > max_height){
							max_height = lis[i].offsetHeight;
						}
						if(lis[i].parentNode.className == "right"){
							lis[i].id = "service-login";
						}
					}
				}
			}
			
			for(var i=0; i<lis.length; i++){
				if(lis[i].parentNode.parentNode){
					if(lis[i].parentNode.parentNode.id == "services" && lis[i].parentNode.className != "right"){
						lis[i].style.height = parseInt(max_height-5) + "px";
						lis[i].style.minHeight = parseInt(max_height-5) + "px";
					}
				}
			}
			
			$("services").style.background = "none";
			kwicksFunc.parseKwicks();
		}
	},
	
	parseKwicks: function(){
		var kwicks = $$('#services .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				$('services').setAttribute("sliding", 1);
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 157]
				};
				kwicks.each(function(other, j){
					if (other != kwick){						
						var w = other.getStyle('width').toInt();
						if (w != 240) obj[j] = {'width': [w, 99]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('service-login').addEvent('mouseenter', function(e){
			if($('services').getAttribute("sliding") == 1){
				var obj = {};
				kwicks.each(function(other, j){
					if(other.getStyle('width').toInt() == 157)
						obj[j] = {'width': [157, 109]};
					else
						obj[j] = {'width': [99, 109]};
				});
				fx.start(obj);
				$('services').setAttribute("sliding", 0);
			}
		});
		
		$('services').addEvent('mouseleave', function(e){
			if($('services').getAttribute("sliding") == 1){
				var obj = {};
				kwicks.each(function(other, j){
					if(other.getStyle('width').toInt() == 157)
						obj[j] = {'width': [157, 109]};
					else
						obj[j] = {'width': [99, 109]};
				});
				fx.start(obj);
				$('services').setAttribute("sliding", 0);
			}
		});
	}	
};



window.addEvent('domready', initMooTools);

