$(document).ready(function() {

	var randomnumber = Math.floor(Math.random()*3);	
	switch ( randomnumber ) {
		case 0 :
		$("#mc1").attr("src", "./new_images/main-content-1.png");
		break;
		case 1 :
		$("#mc1").attr("src", "./new_images/main-content-1b.png");
		break;
		case 2 :
		$("#mc1").attr("src", "./new_images/main-content-1c.png");
		break;
	}
	
    $("#tweet").tweet({
        username: "2020research",
        join_text: "auto",
        avatar_size: 32,
        count: 5,
        auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "Loading Twitter Updates..."
    });
	
	$("#banner_content1").fadeIn(300);
	$("#banner_content1").addClass("active");
	
	$(".bannerButton").click(function() {
		var href = $("a", this).attr("href");
		processClick(href);
		return false;
	});
	
	showChatButton('panel@workgroup.chat.2020research.com');
	
});

function processClick(href)
{
	switch ( href ) {
		
		case "1" :
		$(".bannerButton").removeClass("active");
		$("#button1").addClass("active");
		$("#banner #bg").attr("src", "./new_images/main-bg1.jpg");
		$(".banner_content.active").fadeOut(300, function() {
			$("#banner_content1").fadeIn(300);
			$(".banner_content.active").removeClass("active");

			$("#banner_content1").addClass("active");
			
			var randomnumber = Math.floor(Math.random()*3);	
			
			switch ( randomnumber ) {
				case 0 :
				$("#mc1").attr("src", "./new_images/main-content-1.png");
				break;
				case 1 :
				$("#mc1").attr("src", "./new_images/main-content-1b.png");
				break;
				case 2 :
				$("#mc1").attr("src", "./new_images/main-content-1c.png");
				break;
			}

		});
		break;
		
		case "2" :
		$(".bannerButton").removeClass("active");
		$("#button2").addClass("active");
		$("#banner #bg").attr("src", "./new_images/main-bg2.jpg");
		$(".banner_content.active").fadeOut(300, function() {
			$("#banner_content2").fadeIn(300);
			$(".banner_content.active").removeClass("active");
			$("#banner_content2").addClass("active");
		});
		break;
		
		case "3" :
		$(".bannerButton").removeClass("active");
		$("#button3").addClass("active");
		$("#banner #bg").attr("src", "./new_images/main-bg3.jpg");
		$(".banner_content.active").fadeOut(300, function() {
			$("#banner_content3").fadeIn(300);
			$(".banner_content.active").removeClass("active");
			$("#banner_content3").addClass("active");
		});
		break;
		
		case "4" :
		$(".bannerButton").removeClass("active");
		$("#button4").addClass("active");
		$("#banner #bg").attr("src", "./new_images/main-bg4.jpg");
		$(".banner_content.active").fadeOut(300, function() {
			$("#banner_content4").fadeIn(300);
			$(".banner_content.active").removeClass("active");
			$("#banner_content4").addClass("active");
		});
		break;
		
	}
}

var twitter_count = 0;

function postTweet()
{
	$("#feed #tweet a").attr("target", "_twitter");
	showTweets();
	setInterval("showTweets();", 10000);
}

function showTweets()
{
	var total_twitters = $("#feed #tweet ul li").size();
	var old_tweet = twitter_count - 1;
	
	if ( old_tweet < 0 ) {
		old_tweet = total_twitters - 1;
	}
	
	$("#feed #tweet ul li").eq(old_tweet).fadeOut("slow", function() {
		$("#feed #tweet ul li").eq(twitter_count).fadeIn("slow");
	});

	twitter_count = twitter_count + 1;
	
	if ( twitter_count >= total_twitters ) {
		twitter_count = 0;
	}
}

function playInterview()
{
	
	switch ( $("#mc1").attr("src") ) {
		case "./new_images/main-content-1.png":
		$("#temp_container").html("<a href='./new_includes/misc/1.m4v' style='display:block;width:520px;height:330px' id='player'></a>");
		break;
		case "./new_images/main-content-1b.png":
		$("#temp_container").html("<a href='./new_includes/misc/2.m4v' style='display:block;width:520px;height:330px' id='player'></a>");
		break;
		case "./new_images/main-content-1c.png":
		$("#temp_container").html("<a href='./new_includes/misc/3.m4v' style='display:block;width:520px;height:330px' id='player'></a>");
		break;
	}

	$.fn.colorbox({
		href: '#temp_container',
		open: true,
		inline: true,
		transition: 'elastic',
		close: '',
		scrolling: false,
		title: 'Participant Interview',
		onCleanup: function() {
		},
		onComplete: function() {
			flowplayer("player", "./new_includes/flowplayer/flowplayer-3.1.5.swf");
		}
	});

}