
function scrollNews(index){
	var leftValue = -1 * (index - 1) * 860;
	$('#news-scroll div.tape_newsscroller').animate({ left: leftValue }, { queue: true, duration: 500 });
	$('#news-scroll #news-pagination a').removeClass("selected");
    $('#news-scroll #news-pagination a[rel=news-block'+index+']').addClass("selected");
}

function cufonReplace() {
	Cufon.replace('h1.replace');
	Cufon.replace('div.textcaption h2.replace');
	Cufon.replace('a.leadershipButton', {hover: true});
}

$(document).ready(function(){
	cufonReplace();
	
	$('ul.top li').hover(function() {
        $(this).find('ul.submenu').show();
    },
    function() {
      $(this).find('ul.submenu').hide();
	});
	
	$('ul.submenu li').hover(function() {
        $(this).addClass('hovered');
    },
    function() {
      $(this).removeClass('hovered');
	});
		
	// To remove the last line in the left menu
	$("div.leftNavContainer ul li:last").addClass('last');
	
	$('#news-pagination a').click(function () {
    	var to = $(this).attr("rel");
    	scrollNews(to.replace("news-block", ""));
    	$('#news-pagination a').removeClass("selected");
        $('#news-pagination a[rel='+to+']').addClass("selected");
    });
	
	
	$('div#news-scroll a.nav').click(function (){
		//check direction - left or right
		var to = '';
		if ($(this).hasClass('left')) {
			to = $('div#news-pagination a.selected').prev().attr('rel');
		} else {
			to = $('div#news-pagination a.selected + a').attr('rel');
		}
    	if (to == null) {
			return false; //you have come to the end of the list
		}
    	scrollNews(to.replace("news-block", ""));
	});
	
	$('div.profile-description-paged div.prof-desc-pagination a').click(function () {
    	var to = $(this).attr("rel");
    	var leftValue = -1 * (to.replace("block", "") - 1) * 400;
    	$(this).parent().parent().find('div.profile-desc-tape').animate({left: leftValue}, {queue: true, duration: 1});
    	$(this).parent().find('a').removeClass("selected");
    	$(this).addClass("selected");
    });
	showQuestions(1);
});

function initHomepage () {
	$('div.control-block a').click(function () {
    	var to = $(this).attr("rel");
    	scrollBanner(to.replace("page", ""));
    	$('div.control-block a').find("img").removeClass("selected"); //remove gray on all
    	$(this).find("img").addClass("selected"); //gray selected
    });
	$('#slot-pagination a').click(function () {
    	var to = $(this).attr("rel");
    	if (to == null) {
			return false; //you have come to the end of the list
		}
    	scrollSlotPage(to.replace("slot", ""));
    });
	$('div.control-block a').hover(	
		function () {
			$(this).parent().find("div.cap").show();
			$(this).find("img").addClass("grayOut");
		},
		function () {
			$(this).parent().find("div.cap").hide();
			$(this).find("img").removeClass("grayOut");
		}
	);
	$('div#control a.nav').click(function (){
		//check direction - left or right
		var to = '';
		if ($(this).hasClass('up')) {
			to = $('div#slot-pagination a.selected').prev().attr('rel');
		} else {
			to = $('div#slot-pagination a.selected + a').attr('rel');
		}
    	if (to == null) {
			return false; //you have come to the end of the list
		}
		
		scrollSlotPage(to.replace("slot", ""));
	});
}

function scrollBanner(index){
	var topValue = -1 * (index - 1) * 435;
	$('div.tape').animate({top: topValue}, {queue: true, duration: 500});
	showQuestions(index);
}

function showQuestions(index){
	$('div.leftside div.question').hide();
	$('div.leftside div.question span').remove();
	
	var timeDelayed = 1000;
	$('div.img' + index + ' div.leftside div.question').each( function () {
		$(this).prepend('<span class="qTop"></span>');
		$(this).append('<span class="qBottom"></span>');
		$(this).delay(timeDelayed).fadeIn('slow', function(){
				$(this).find('p').addClass('Png');
				$(this).find('span.qTop').attr('class', 'qTopPng');
				$(this).find('span.qBottom').attr('class', 'qBottomPng');
			});
		timeDelayed += 1500;
	});	
}


function scrollSlotPage(index){
	var topValue = -1 * (index - 1) * 71 * 3;
	$('div.control-tape').animate({top: topValue}, {queue: true, duration: 500});
	$('#slot-pagination a').removeClass("selected");
    $('#slot-pagination a[rel=slot'+index+']').addClass("selected");
}
