/*                          
_|                                                      _|
_|_|_|     _|_|     _|_|   _|    _|   _|_|_| _|_|_|   _|_|_|_|
_|    _| _|    _| _|    _| _|    _| _|    _| _|    _|   _|
_|    _| _|    _| _|    _| _|    _| _|    _| _|    _|   _|
_|_|_|     _|_|     _|_|     _|_|_|   _|_|_| _|    _|     _|_|
                                 _|
                             _|_|

Description: Booyant Homepage jQuery
Developer: Booyant, Inc.
Website: www.booyant.com
Contact: team@booyant.com  / 978.729.8408
Version: 1.0
	
*/
bannerPosition = 1;

function slider() {
     if (bannerPosition == bannerCount) {
     	bannerPosition = 1;
     	$(".messaging").fadeOut(500);
   		$("#banner_" + bannerPosition).fadeIn(750);
    	$(".pagination > li").removeClass("selected");
    	$("#bannerBtn_"+bannerPosition).addClass("selected");  
     	  // uncomment below to stop at last slide
        clearInterval(bannerInterval);
        return false;
     } else {bannerPosition++;}
 
    $(".messaging").fadeOut(500);
    $("#banner_" + bannerPosition).fadeIn(750);
    $(".pagination > li").removeClass("selected");
    $("#bannerBtn_"+bannerPosition).addClass("selected");                                     
}

bannerInterval = setInterval ( "slider()", 11000 );

$(document).ready(function() {

	bannerCount = $(".messaging").size();
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	// B A N N E R   T A B S
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	
	$(".pagination > li").click(function(){
		clearInterval(bannerInterval);
		var p = $(this).attr("id").split("_");
		$(".pagination > li").removeClass("selected");
		$(this).addClass("selected");
		$(".messaging").fadeOut(500);
		$("#banner_"+p[1]).fadeIn(750);
		bannerPosition=p[1];
		bannerInterval = setInterval ( "slider()", 11000 );
	});
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	// W I D G E T   T A B S
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	
	$(".widget-tab").click(function(){
		var tabid = $(this).attr("id").replace("-tab","");
		$(".widgets").hide();
		$("#"+tabid+"-widget").show();
		
		$(this).parent("li").parent("ul").children("li").removeClass("tab-on");
		$(this).parent("li").addClass("tab-on");
	});
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	// P R O M O   T A B
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	
	$("#promo-tab").click(function(){
		$("#thought_leadership").hide();
		$("#promo").show();
		
		$(this).parent("li").parent("ul").children("li").removeClass("tab-on");
		$(this).parent("li").addClass("tab-on");
	});
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	// T H O U G H T   L E A D E R S H I P   T A B 
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
		
	$("#tl-tab").click(function(){
		$("#promo").hide();
		$("#thought_leadership").show();
		
		$(this).parent("li").parent("ul").children("li").removeClass("tab-on");
		$(this).parent("li").addClass("tab-on");
	});

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>
	// P R E V I O U S / N E X T   B U T T O N S
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>	
	
	$(".previous a").click(function(){
		imgSize = $(this).parent("li").parent("ul").siblings("a").size();
		$(this).parent("li").parent("ul").siblings("a").each(function(){
			if ($(this).children("img").is(":visible")){
				img = $(this).children("img").attr("id").split("_");
			}
		});
		
		$(this).parent("li").parent("ul").siblings("a").children("img").hide();
		
		if (img[1]==1){
			$("#"+img[0]+"_"+imgSize).show();
		} else {
			$("#"+img[0]+"_"+((img[1]*1)-1)).show();
		}
	});

	$(".next a").click(function(){
		imgSize = $(this).parent("li").parent("ul").siblings("a").size();
		$(this).parent("li").parent("ul").siblings("a").each(function(){
			if ($(this).children("img").is(":visible")){
				img = $(this).children("img").attr("id").split("_");
			}
		});
		
		$(this).parent("li").parent("ul").siblings("a").children("img").hide();

		if (img[1]==imgSize){
			$("#"+img[0]+"_1").show();
		} else {
			$("#"+img[0]+"_"+((img[1]*1)+1)).show();
		}
	});
});

