$(document).ready(function(){
	// Initialize FTR announcements width
	var getDivWidth = document.getElementById("ftrannouncements_carousel_container");
	var announcementsWidth = getDivWidth.offsetWidth - 20 - 4; // Minus 4px for left and right borders, 20px for list items padding
	$('.infiniteCarousel .ftrannouncements_wrapper ul li').css('width', announcementsWidth);
	$('.infiniteCarousel .ftrannouncements_wrapper').css('width', announcementsWidth);
	$('.infiniteCarousel .ftrannouncements_wrapper').css('padding', '0 10px');
	$('.ftrannouncements_newstitle a').css('max-width', announcementsWidth - 90);
	
	// Initialize Poker Forum Topics width
	var getDivWidth = document.getElementById("pokerforumtopics_carousel_container");
	var forumtopicsWidth = getDivWidth.offsetWidth - 1 - 4; // Minus 4px for left and right borders, 20px for list items padding
	$('.infiniteCarousel .pokerforumtopics_wrapper ul li').css('width', forumtopicsWidth);
	$('.infiniteCarousel .pokerforumtopics_wrapper').css('width', forumtopicsWidth);
	$('.pokerforumtopics_newstitle a').css('max-width', announcementsWidth - 90);
	
	// Initialize news width
	var getDivWidth = document.getElementById("pokercommunitynews_content_container_id");
	var newsWidth = getDivWidth.offsetWidth;
	$('.infiniteCarousel .pokercommunitynews_wrapper ul li').css('width', newsWidth-20); // 20px for padding
	$('.infiniteCarousel .pokercommunitynews_wrapper').css('width', newsWidth);
	
	// Initialize tabs
	$("#pokerroomrankings_tabs ul").idTabs("!mouseover");
	$("#upcomingevents_tabs ul").idTabs("!mouseover"); 

// Infinite Carousel - for Poker Community News
    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = true;
    
	// Begin FTR Announcements scroll
    $('.ftrannouncementsCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.ftrannouncementsCarousel').trigger('next');
        }
    }, 5000);
	
	// Begin Poker Forum Topics scroll
	$('.pokerforumtopicsCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.pokerforumtopicsCarousel').trigger('next');
        }
    }, 5000);
	
	// Begin Poker Community News scroll
	$('.pokercommunitynewsCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.pokercommunitynewsCarousel').trigger('next');
        }
    }, 8000);
	
// Setup other boxes
	//Initialize pager container width and position
	$('.ftrannouncementsCarousel .pager_container').css('width', ((10 * 22) + 5) + 'px'); // 10x
	$('.pokerforumtopicsCarousel .pager_container').css('width', ((10 * 22) + 5) + 'px'); // 10x
	
	// Initialize news height
	var getDivHeight = document.getElementById("pokercommunitynews_carousel_list");
	var newsHeight = getDivHeight.offsetHeight;
	
	$('.pokercommunitynews_content_container').css('height', newsHeight + 30 + 22 + 10 + 'px'); // footer 30px, pager 20px, margin 10px
	$('.pokercommunitynews_wrapper').css('height', (newsHeight + 22) + 'px');
	$('.pokercommunitynews_content_footer').css('margin-top', newsHeight + 22 + 10 + 'px');
	$('.pokercommunitynews_wrapper').css('margin-top', '-' + (newsHeight + 10) + 'px');
	
	// Initialize FTR announcements box
	var getDivHeight = document.getElementById("id_importantannouncements_content_container"); // Get Important Announcements height info
	var getFTRHeight = document.getElementById("ftrannouncements_carousel_list"); // Get FTR Announcements height info
	
	var ftrannouncementsListHeight = getFTRHeight.offsetHeight;
	var ftrannouncementsContainerHeight = getDivHeight.offsetHeight;
	
	// Minimum height of FTR announcements box in pixels
	var ftrannouncementsMinimumHeight = 120;
	if (ftrannouncementsContainerHeight <= ftrannouncementsMinimumHeight) {
		ftrannouncementsContainerHeight = ftrannouncementsMinimumHeight;
	}
	
	var ftrannouncementsHeight = ftrannouncementsContainerHeight - 2; // minus 2px from the width due to 2px bottom border
	var ftrannouncementsPadding = (ftrannouncementsHeight - ftrannouncementsListHeight) / 2;
	var ftrannouncementsPagerMargin = (ftrannouncementsHeight - 22 - ftrannouncementsPadding);
	var ftrannouncementsWrapperMargin = (ftrannouncementsHeight - 2*ftrannouncementsPadding - 22 + (ftrannouncementsHeight - ftrannouncementsListHeight)/2);

	// If Important Announcements height is below minimum height, set Important Announcements height equal to FTR Announcements height
	if (ftrannouncementsContainerHeight <= ftrannouncementsMinimumHeight) {
		$('.importantannouncements_content_container').css('height', (ftrannouncementsHeight - 20) + 'px'); // Minus Important Announcements padding-top and padding-bottom
	}
	
	$('.ftrannouncements_wrapper').css('height', ftrannouncementsListHeight + 'px');
	$('.ftrannouncements_content_container').css('height', ftrannouncementsHeight + 'px');
	$('.ftrannouncementsCarousel .pager_container').css('margin-top', (0.1 * ftrannouncementsPagerMargin) + 'px');
	$('.ftrannouncements_wrapper').css('margin-top', '-' + ftrannouncementsWrapperMargin + 'px');
	
	// Initialize Poker Forum Topics box
	var getDivHeight = document.getElementById("pokerforumtopics_carousel_list"); // Get Important Announcements height info
	
	var pokerforumtopicsListHeight = getDivHeight.offsetHeight;
	var pokerforumtopicsHeight = pokerforumtopicsListHeight + 22 + 10; // 22px pager height, 10px spacing
	var pokerforumtopicsPadding = (pokerforumtopicsHeight - pokerforumtopicsListHeight) / 2;
	var pokerforumtopicsWrapperMargin = ((pokerforumtopicsHeight - 22 -  pokerforumtopicsListHeight)/2 + pokerforumtopicsListHeight);
	
	$('.pokerforumtopics_content_container').css('padding-top',  pokerforumtopicsPadding + 'px');
	$('.pokerforumtopics_content_container').css('height', pokerforumtopicsHeight + 'px');
	$('.pokerforumtopicsCarousel .pager_container').css('margin-top', (0.1 * pokerforumtopicsHeight) + 'px');
	$('.pokerforumtopics_wrapper').css('height', pokerforumtopicsListHeight + 'px'); 
	$('.pokerforumtopics_wrapper').css('margin-top', '-' + pokerforumtopicsWrapperMargin + 'px'); 
	
	// Initialize What is FTR? Height
	var getNFHeight = document.getElementById("upcomingevents_box");
	var NFHeight = getNFHeight.offsetHeight + 10;
	
	var getTPNHeight = document.getElementById("toppokernetworks_box");
	var TPNHeight = getTPNHeight.offsetHeight + 10;
	
	var getPGHeight = document.getElementById("photogallery_box");
	var PGHeight = getPGHeight.offsetHeight + 10;
	
	var getPCNHeight = document.getElementById("pokercommunitynews_box");
	var PCNHeight = getPCNHeight.offsetHeight + 10;
	
	var getPFTHeight = document.getElementById("pokerforumtopics_box");
	var PFTHeight = getPFTHeight.offsetHeight + 10;
	
	var WIFHeight = NFHeight + TPNHeight + PGHeight + PFTHeight - PCNHeight - (10+35+13+13+30) - 2;
	$('.whatisftr_text_container').css('height', WIFHeight);
});

$(window).resize(function() {
	// Resize What is FTR? Height
	var getNFHeight = document.getElementById("upcomingevents_box");
	var NFHeight = getNFHeight.offsetHeight + 10;
	
	var getTPNHeight = document.getElementById("toppokernetworks_box");
	var TPNHeight = getTPNHeight.offsetHeight + 10;
	
	var getPGHeight = document.getElementById("photogallery_box");
	var PGHeight = getPGHeight.offsetHeight + 10;
	
	var getPCNHeight = document.getElementById("pokercommunitynews_box");
	var PCNHeight = getPCNHeight.offsetHeight + 10;
	
	var getPFTHeight = document.getElementById("pokerforumtopics_box");
	var PFTHeight = getPFTHeight.offsetHeight + 10;
	
	var WIFHeight = NFHeight + TPNHeight + PGHeight + PFTHeight - PCNHeight - (10+35+13+13+30) - 2;
	$('.whatisftr_text_container').css('height', WIFHeight);
});

