// JavaScript Document



 /* EXAMPLES */

  /* IE only */
  DD_roundies.addRule('.button', '4px');



   DD_roundies.addRule('.searchBox','4px');

   
   


$(function() {


///////// Change the Headline Timer here ////////////
///////// 1000 = 1 second////////////////////////////
var timerDuration = 6000;
///////// Change the Headline Timer here ////////////



/*

$(".tweet").tweet({
            username: "fsroundtable",
            join_text: "auto",
            avatar_size: 32,
            count: 5,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
        });
*/



$.jGFeed('http://www.smartbrief.com/servlet/rss?b=FSR',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    
    $('#industryNewsList').append('<li class="industryNewsItem"><a href="'+entry.link+'" target="_blank" >'+entry.title+' <span class="subText">'+entry.publishedDate+'</span></a></li>');
  }
}, 4);











var tweetName = 'fsroundtable';
var tweetCount = 5;
getTweets(tweetName,tweetCount);

function getTweets(tweetName, tweetCount)
{
    $.getJSON(
        'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + tweetName + '&count='+ tweetCount +'&callback=?',
        {},
        showTweets,
        'jsonp'
    );
}



function parseDate(str) {
  var v=str.split(' ');
  return new Date(Date.parse(v[1]+" "+v[2]+", "+v[5]+" "+v[3]+" UTC"));
} 


function showTweets(tweets)
{


    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
    var str = '<ul>';
    
    
    var i = 0;
    
    
    $.each(tweets, function(index,value)
    {
		
		
        if(i == tweetCount)  return;
        //var dt = new Date(value.created_at);
		
		//alert(dt);
		
		
		var dt=parseDate(value.created_at);
		
        str+= '<li><p>';
        str+= value.text;
        str+= '</p>';
        str+='<span class="subText">';
        str+= dt.getDate() + '-' + months[dt.getMonth()] + '-' + dt.getFullYear();
        str+= ' at ' + dt.getHours() + ':' +dt.getMinutes();
        str+= ' From ' + value.source;
        str+= '</span></li>';
        i++;
    });
    str+= '</ul>';
    
    
    $('#tweetBox').html(str);
    $('#tweetBox > ul > li:odd').addClass('odd');
    $('#tweetBox > ul > li:even').addClass('even');
}




/*
$.jGFeed('http://twitter.com/statuses/user_timeline/97239626.rss',
function(feeds){
  // Check for errors
  if(!feeds){
    // there was an error
    return false;
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    
    $('#tweets').append('<li class="tweet"><a href="'+entry.link+'" target="_blank" >'+entry.title+' <span class="subText">'+entry.publishedDate+'</span></a></li>');
  }
}, 5);

*/



var rand=Math.random()*Math.random();

$.jGFeed('http://fsround.org/rss/fsroundNews.xml?'+rand,
function(feeds){


  // Check for errors
  if(!feeds){
    // there was an error
    return false;
    
  }
  // do whatever you want with feeds here
  for(var i=0; i<feeds.entries.length; i++){
    var entry = feeds.entries[i];
    // Entry title
    
    $('#latestNews').append('<li><a href="'+entry.link+'" >'+entry.title+' <span class="subText">'+entry.publishedDate+'</span></a></li>');
  }
}, 5);




	var youtubeWidth = 220;
	var currYoutubeSlide = 0;
	var maxYoutubeSlides = 4;

    $.getJSON('http://gdata.youtube.com/feeds/users/fsround/uploads?alt=json-in-script&callback=?&max-results=4', function(data) { 
        $.each(data.feed.entry, function(i, item) {
	    var title = item['title']['$t'];
	    var video = item['id']['$t'];
	    var thumb = item['media$group']['media$thumbnail'][3]['url'];
	    video = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/watch?v=');
	    $('#youtube').append('<li><a href="'+video+'">'+'<img width="200" height="140" src="'+thumb+'" /img>'+'</a><p>'+title+'</p></li>');
	    
	    var ytItem = $('#youtube-page').append('<li class="youtubeItem" id="yt'+i+'">&nbsp;&nbsp;&nbsp;&nbsp;</li>');
	    
	    $('#yt'+i).click(function(){
	    	gotoPage(i);
	    	clearYoutubeNav();
	    	 $(this).removeClass("hover").addClass("selected");
	    	
	    	});
	     $('#yt'+i).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
	    
	    if(i==0){
	    	$('#yt'+i).addClass("selected");
	    }
	    
	    
        });
    });
    
    
    $('.youtube-arrow-rt').click(function(){goNext();});
    $('.youtube-arrow-rt').hover(function(){$(this).addClass("hoverRt")},function(){$(this).removeClass("hoverRt")});
    $('.youtube-arrow-lt').click(function(){goBack();});
    $('.youtube-arrow-lt').hover(function(){$(this).addClass("hoverLt")},function(){$(this).removeClass("hoverLt")});
    
    $('.youtube-arrow-lt').addClass("disabledLt");
    
    
    function gotoPage(pageNum){
    	currYoutubeSlide=pageNum;
    	$('#youtubeThumbs').animate({'left':(youtubeWidth*currYoutubeSlide)*(-1)});
    	
    	if(currYoutubeSlide>=maxYoutubeSlides-1)
	    	{
	    		$('.youtube-arrow-rt').addClass("disabledRt");
	    		$('.youtube-arrow-lt').removeClass("disabledLt");
	    	}
	    	else if(currYoutubeSlide==0)
	    	{
	    		$('.youtube-arrow-lt').addClass("disabledLt");
	    		$('.youtube-arrow-rt').removeClass("disabledRt");
	    	}
	    	
	    	else
	    	{
	    		$('.youtube-arrow-rt').removeClass("disabledRt");
	    		$('.youtube-arrow-lt').removeClass("disabledLt");
	    	}
	    	
	    	
    
    }
	
	function clearYoutubeNav(){
		$('.youtubeItem').removeClass("selected");
	}
	    
    function goNext(){
    	if(currYoutubeSlide<maxYoutubeSlides-1)
    	{
    		clearYoutubeNav();
	    	currYoutubeSlide++;
	    	$('#yt'+currYoutubeSlide).removeClass("hover").addClass("selected");
	    	$('#youtubeThumbs').animate({'left':(youtubeWidth*currYoutubeSlide)*(-1)})
	    	
	    	if(currYoutubeSlide>=maxYoutubeSlides-1)
	    	{
	    		$('.youtube-arrow-rt').addClass("disabledRt");
	    	}
	    	else
	    	{
	    		$('.youtube-arrow-lt').removeClass("disabledLt");
	    	}
	    	
	    	
    	}
    }
    
     function goBack(){
     if(currYoutubeSlide>0)
    	{
    		clearYoutubeNav();
	    	currYoutubeSlide--;
	    	$('#yt'+currYoutubeSlide).removeClass("hover").addClass("selected");
	    	$('#youtubeThumbs').animate({'left':(youtubeWidth*currYoutubeSlide)*(-1)});
	    	
	    	
	    	if(currYoutubeSlide==0)
	    	{
	    		$('.youtube-arrow-lt').addClass("disabledLt");
	    	}
	    	
	    	else
	    	{
	    		$('.youtube-arrow-rt').removeClass("disabledRt");
	    	}
	    	
	    	
	    }
	    	
    }
    
    
    
    
    
  ///////////////////////////     publication slider start /////////////////////////////////
	
	var currPubPage=0;
	var containerWidth=0;
	
	 $('#publicationArrowLt, #publicationArrowRt').hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
	 
	 
	$('#publicationList li').each(function(i,e){
			containerWidth += $(e).outerWidth(true);
			
	});

	$('.publicationContainer').css({'width':containerWidth,'visibility':'visible'});
	
	var pubSlideWidth=$('.publicationContent').width();
	var totalPubPages=Math.floor(containerWidth/pubSlideWidth);
	 $('#publicationArrowLt').addClass("disabled");
	
	function gotoPub(pubNum){
		
		currPubPage=pubNum;
		
		$('.publicationContainer').animate({'left':(pubNum*pubSlideWidth)*-1});	
		clearPublicationPages();
		$('#publication'+pubNum).removeClass("hover").addClass("selected");
		
		if(pubNum==totalPubPages){
			$('#publicationArrowLt, #publicationArrowRt').removeClass("disabled");
			  $('#publicationArrowRt').addClass("disabled");
			  
		}
		
		else if(pubNum==0){
			$('#publicationArrowLt, #publicationArrowRt').removeClass("disabled");
			  $('#publicationArrowLt').addClass("disabled");
		 }
		 
		 else{
			  $('#publicationArrowLt, #publicationArrowRt').removeClass("disabled");
		 }
	};
	
	 $('#publicationArrowRt').click(function(){
		 
		 if(currPubPage<totalPubPages){
		 	gotoPub(currPubPage+1);
			
		 }
		 
	});
	
	
	$('#publicationArrowLt').click(function(){
		
		 if(currPubPage>0){
		 	gotoPub(currPubPage-1);
		 }
		 
	});
	 
	for(var i=0;i<=totalPubPages; i++){
		
		var ti=i;
		createPubItem(i);
	}
	
	function createPubItem(i)
	{
		$('#publicationPageList').append('<li class="publicationPage" id="publication'+i+'">&nbsp;&nbsp;&nbsp;&nbsp;</li>');
	
		
		$('#publication'+i).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
    	
    	$('#publication'+i).click(function(){
			
	    	gotoPub(i);
			
	    	
	    	 
	    	
	    });
	}
	
	
	function clearPublicationPages(){
		
    	$('.publicationPage').removeClass("hover").removeClass("selected");
    }
	
	 $('#publication0').addClass("selected");
	
	
	 $.each($('.publicationSlide'), function(i, val) {
		 
			var tempPub = $('#publicationCompleteListing').append('<li id="pub'+i+'"><p>'+$(val).text()+'</p></li>'); 
	 		$(val).find('img').clone().appendTo('#pub'+i);
			$('#pub'+i).wrapInner('<a href="'+$(val).find('a').attr('href')+'" />');
	 });
	
  ///////////////////////////     publication slider end /////////////////////////////////
	
	
    
    
    /************ headlines *******************/
    
    
    
    var currHeadlineNum=0;
    var maxHeadline = 5;
    var headlineWidth = 660;
	var isPlaying = true;
	
	
     var headlineTimer = setInterval(function(){
    
    
    	nextHeadline();
    
    },timerDuration);
	
	
	$('#headlinePlay').addClass('isPlaying');
	
	$('#headlinePlay').click(
		function(){
			if(isPlaying)
			{
				clearInterval(headlineTimer);
				$('#headlinePlay').removeClass('isPlaying').addClass('isPaused');
				isPlaying = false;
			}
			
			else
			{
				isPlaying=true;	
				$('#headlinePlay').removeClass('isPaused').addClass('isPlaying');
				resetTimer();
				
				
			}
			
		}
	)

	
    $('#headlinePages li, #headlineArrowRt, #headlineArrowLt').hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
    
    
    $('#headlineArrowRt').click(function(){nextHeadline();});
    $('#headlineArrowLt').click(function(){prevHeadline();});
    
    $.each($('.headlineSlide'), function(i, val) {
    	$('#headlineList').append('<li class="headlinePage" id="headline'+i+'"></li>');
    	
    	$('#headline'+i).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
    	
    	$('#headline'+i).click(function(){
	    	gotoHeadline(i);
	    	clearHeadlinePages();
	    	 $(this).removeClass("hover").addClass("selected");
	    	
	    });
	    
	    if(i==0){
	    	$('#headline'+i).removeClass("hover").addClass("selected");
	    }
	    	
    });
    
    
    $('#headlineArrowLt').addClass("disabled");
    
    function clearHeadlinePages(){
    	$('.headlinePage').removeClass("selected");
    }
    
    function gotoHeadline(slideNum){
		resetTimer();
    	currHeadlineNum=slideNum;
    	$('.headlineContainer').animate({'left':(headlineWidth*currHeadlineNum)*(-1)});
    	
    	if(currHeadlineNum>=maxHeadline-1)
	    	{
	    		$('#headlineArrowRt').addClass("disabled");
	    		$('#headlineArrowLt').removeClass("disabled");
	    	}
	    	else if(currHeadlineNum==0)
	    	{
	    		$('#headlineArrowLt').addClass("disabled");
	    		$('#headlineArrowRt').removeClass("disabled");
	    	}
	    	
	    	else
	    	{
	    		$('#headlineArrowRt').removeClass("disabled");
	    		$('#headlineArrowLt').removeClass("disabled");
	    	}
	    	
	    	
	    	
    }
    
    function nextHeadline(){
		resetTimer();
		
	    if(currHeadlineNum<maxHeadline-1)
	    {
	    	currHeadlineNum++;
	    	
	    	clearHeadlinePages();
	    	$('#headline'+currHeadlineNum).removeClass("hover").addClass("selected");
	    	
	    	
	    	$('.headlineContainer').animate({'left':(headlineWidth*currHeadlineNum)*(-1)});
	    	
	    	
	    	if(currHeadlineNum>=maxHeadline-1)
	    	{
	    		$('#headlineArrowRt').addClass("disabled");
	    		$('#headlineArrowLt').removeClass("disabled");
	    	}
	    	else
	    	{
	    		$('#headlineArrowLt').removeClass("disabled");
	    	}
	    	
	    	
	    	
	    }
		
		else
		{
			currHeadlineNum = 0;
			clearHeadlinePages();	
			$('#headline'+currHeadlineNum).removeClass("hover").addClass("selected");
	    	$('.headlineContainer').animate({'left':(headlineWidth*currHeadlineNum)*(-1)});
			$('#headlineArrowLt').addClass("disabled");
	    		$('#headlineArrowRt').removeClass("disabled");
	    	
		}
		
		
    }
    
    function prevHeadline(){
		resetTimer();
     	if(currHeadlineNum>0)
	    {
	    	currHeadlineNum--;
	    	
	    	clearHeadlinePages();
	    	$('#headline'+currHeadlineNum).removeClass("hover").addClass("selected");
	    	



	    	$('.headlineContainer').animate({'left':(headlineWidth*currHeadlineNum)*(-1)});
	    	
	    	
	    	if(currHeadlineNum==0)
	    	{
	    		$('#headlineArrowLt').addClass("disabled");
	    		$('#headlineArrowRt').removeClass("disabled");
	    	}
	    	
	    	else
	    	{
	    		$('#headlineArrowRt').removeClass("disabled");
	    	
	    	}
	    	
	    	
    	}
    }
    
    
	
	function resetTimer(){
		if(isPlaying)
		{
			clearInterval(headlineTimer);
			 headlineTimer = setInterval(function(){
			
			
				nextHeadline();
			
			},timerDuration);
		}
		
	}
    
   
    
    
    
    
    /************ end headlines *****************/
    
    
    
    
    
    
    
    
    
    
    /******* affiliates ***********/
   
    
    var affliateWidth = 440;
    var affiliateCounter = 0 ;
    
    
    var affiliatePageTotal = Math.floor($('#affiliateList').width()/affliateWidth);
    
    $('#affiliateArrowRt').click(function(){nextAffiliate();});
    $('#affiliateArrowLt').click(function(){prevAffiliate();});
    
    
     $('#affiliateArrowRt, #affiliateArrowLt').hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
     
     
     $('#affiliateArrowLt').addClass("disable");
     
     
    
    function nextAffiliate(){
    	if(affiliateCounter<affiliatePageTotal-1)
    	{
	    	affiliateCounter++;
	    	$('#affiliateContainer').animate({'left':(affliateWidth*affiliateCounter)*(-1)});
	    	
	    	
	    	if(affiliateCounter>=affiliatePageTotal-1)
	    	{
	    		$('#affiliateArrowRt').addClass("disable");
	    		$('#affiliateArrowLt').removeClass("disable");
	    	}
	    	else
	    	{
	    		$('#affiliateArrowLt').removeClass("disable");
	    	}
	    	
	    	
	    	
		}
    }
    
    function prevAffiliate(){
    	if(affiliateCounter>0)
    	{
    		affiliateCounter--;
    		$('#affiliateContainer').animate({'left':(affliateWidth*affiliateCounter)*(-1)});
    		
    		
    		if(affiliateCounter==0)
	    	{
	    		$('#affiliateArrowLt').addClass("disable");
	    		$('#affiliateArrowRt').removeClass("disable");
	    	}
	    	else
	    	{
	    		$('#affiliateArrowRt').removeClass("disable");
	    	}
	    	
	    	
    	}
    }
    
    
    
    /******* end affiliates ***********/
    
    
    
	
	
	
    
    $('.subMenu').hide();
    
    $('.menuItem').hover(
		function()
		{
			$(this).find('.subMenu').show(); 
			$(this).find('.menuIndicator').show(); 
			$(this).find('.menuTitle').addClass('hoverMain');
		},
		function()
		{
			$(this).find('.subMenu').hide(); 
			$(this).find('.menuTitle').removeClass('hoverMain');
			$(this).find('.menuIndicator').hide(); 
		}
	);
	
	
	$('li:last-child').css({'border-bottom':'none'});
	
	
	
	
	/************ core value ***************/
	
	var coreValueHeight = $('#coreValueContainer').height()+20;
	var coreExpanded = false;
	$('.expandCoreValue').click(function()
		{	
			if(coreExpanded==false)
			{
				$('#coreValueContainer').animate({'height':$('.coreValueList').height()});	
				coreExpanded=true;	
				$('.expandCoreValue').text('- MINIMIZE');	
			}
			else
			{
				$('#coreValueContainer').animate({'height':coreValueHeight});	
				coreExpanded=false;	
				$('.expandCoreValue').text('+ EXPAND');	
			}
	
	
		}
	);
	
	if($('.mediaList').length){
	makeExpandable($('.mediaList'),600);
	}
	
	function makeExpandable(target,targetHeight){
		
		
		target.wrap('<div class="expandContainer" style="height:'+targetHeight+'px; overflow:hidden">').wrap('<div class="expandContent">');
		
		var toggleButton = target.parent().parent().parent().find('.expandButton');
		
		
		target.parent().parent().parent().find('.expandButton').click(function(){
			
			if($(this).hasClass('expanded'))
			{
				
				 target.parent().parent().animate({height:targetHeight},2000);
				 toggleButton.text('expand');
				 toggleButton.removeClass('expanded');
			}
			else
			{
			toggleButton.addClass('expanded');
			toggleButton.text('minimize');
			
			 target.parent().parent().animate({height:target.parent().height()},2000);
			}
		});
	}
	
	
	
	
	
	
	$('#pressReleases').paginate();
	
	
	
    
});
