$(document).ready(function(){

	// GLOBAL - TipTip - Tooltip plug-in
	$("section#socialBar ul.socialLinks a, body#home section#businessHeadlines a.rss, body#mediacenter a.rss").tipTip({
		defaultPosition: "top",
		delay:100
	});
	
	// HOME - Main Marketing Slider
	function paginate(ind, el){
		if (ind == 0) return '<a href="#" title="" class="defaultSlide">2012 Competitiveness Agenda</a>';
		else if (ind == 1) return '<a href="#" title="" class="navSlideOne">Comprehensive<br />Tax Reform</a>';
		else if (ind == 2) return '<a href="#" title="" class="navSlideTwo">Economic<br />Development</a>';
		else if (ind == 3) return '<a href="#" title="" class="navSlideThree">Environment<br />&amp; Energy</a>';
		else if (ind == 4) return '<a href="#" title="" class="navSlideFour">Government<br />Restructuring</a>';
		else if (ind == 5) return '<a href="#" title="" class="navSlideFive">Infrastructure</a>';
		else if (ind == 6) return '<a href="#" title="" class="navSlideSix">Workforce<br />Development</a>';
	}
	
	
	$('body#home section#mainMarketing div.features').cycle({
		activePagerClass: 'active',
		fx: 'scrollVert',
		manualTrump: false,
		pager: 'body#home section#mainMarketing section#mainMarketingNav',
		pagerAnchorBuilder: paginate,
		pauseOnPagerHover: 1,
		speed: 2000,
		timeout: 8000
	});
	
	// HOME - Chamber Events Scroll
	var scrollTimeout,
    scrolled = $("#chamberEventsList");
	// selecting both
	$("a.viewNewer,a.viewOlder").bind("mouseenter", function (e) {
	    var direction = $(this).is(".viewOlder") ? 1 : -1;
	    
	    function moveit() {
	        scrolled.scrollTop( direction + scrolled.scrollTop() );
	        scrollTimeout = setTimeout( moveit, jQuery.fx.interval );
	    }
	    moveit();
	    
	}).bind("mouseleave", function (e) {
	    clearTimeout( scrollTimeout );
	});
	
	$('section#chamberEvents section#chamberEventsControls a.viewNewer, section#chamberEvents section#chamberEventsControls a.viewOlder').click(function() {
	  return false;
	});
	
	// INTERNAL - Wrap all internal page images and grab longdesc if exists to use for caption
	$("body.internalTemplate div#mainContent div#pageContent img").each(function() {	
		var imgWidth = $(this).width();
		var attr = $(this).attr("longdesc");
		var floatStatus = $(this).css("float");
		if (typeof attr !== 'undefined' && attr !== false && attr !== '') {			
			$(this).wrap('<div class="figure group">');
			$(this).after(String('<div class="figcaption">' + attr + '</div>'));
			$(this).parent().css("max-width",imgWidth);
			$(this).parent().css("float",floatStatus);
		}
		if ($(this).is('.htmlContentImageCenter')) {
			$(this).parent().css("margin","20px auto");
		}
    });

    //Check for cookie to hide social bar.
    var socialBarCookie = $.cookie('HideSocialSession');
    if (socialBarCookie != null && socialBarCookie === 'true') {
        $('body > section#socialBar').hide();
    }

});

$(window).load(function () {

    // HOME - Set thumbs height to match mainContent
    var mainHeightHome = $("body#home div#mainContent").height();
    $("body#home div#mainContent > section#thumbsUpDown").css('min-height', mainHeightHome);

    // INTERNAL - Set aside height to match mainContent
    var mainHeight = $("div#mainContent").height();
    $("div#mainContent > aside").css('min-height', mainHeight);

    // Close Social Bar
    $('body > section#socialBar a#closeSocialBar').click(function () {
        //Set Cookie for to hide on future loads
        $.cookie('HideSocialSession', 'true', {path: '/' });
        $('body > section#socialBar').hide();
        return false;
    });

});
