// Set default state for bar
var societalBarState = 'expanded';

$(document).ready(function() {
	
	// Use for standard implementation
	//$('body').css({'paddingBottom' : '60px'});
	
		// OR...
	
	// Use when the body bg color is breaking where societal begins
	$('body').append($('<div id="societal-body-lift">&nbsp;</div>'));
	
	
	// Initialize cookie for bar state.
	if ($.cookie('societalBarState')) societalBarState = $.cookie('societalBarState');


	// Check for expanded state and make settings adjustments
	// if ($.cookie('societalBarState') == 'expanded') { // check cookie state
	// 	$('a.minimize-societal').removeClass('hide'); // show the minimize button
	// 	$('a.maximize-societal').addClass('hide'); // hide the maximize button
	// 	$('div#societal-bar').show(); // show the bar
	// }
	
	// Minimize function
	$('a.minimize-societal').click(function() {
		$.cookie('societalBarState', 'collapsed', {path:'/'}); // set cookie to "collapsed" and the path to root
		$(this).parent().parent().find('div.societal-content').hide(); // hide before slide animation begins
		$(this).parent().parent().find('div#societal-bar').animate({ // slide duration 600
				width: 'toggle'
			}, {
				duration: 600, 
				specialEasing: {
					width: 'linear'
				}, 
				complete: function() { // when animation completes, hide the minimize button and show the maximize button
					$('a.minimize-societal').hide(); // hide minimize button
					$('a.maximize-societal').show(); // show maximize button
				}
			});
		
		
	});

	
	// Check for collapsed state and make settings adjustments
	if ($.cookie('societalBarState') == 'collapsed') { // check cookie state
		$('a.minimize-societal').hide(); // hide the minimize button
		$('a.maximize-societal').show(); // show the maximize button
		$('div.societal-content').hide(); // hide this in case the bar is expanded on a differnt page
		$('div#societal-bar').hide(); // hide the bar itself
	}
	
	//Maximize function
	$('a.maximize-societal').click(function() { 
		$.cookie('societalBarState', 'expanded', {path:'/'}); //set cookie to expanded and the path to root
		$(this).parent().parent().find('div#societal-bar').animate({ //slide duration 600
				width: 'toggle'
			}, {
				duration: 600, 
				specialEasing: {
					width: 'linear'
				}, 
				complete: function() { // when animation completes, show the minimize button, hide the maximize button and fade in bar content
					$('a.minimize-societal').show(); // show the minimize button
					$('a.maximize-societal').hide(); // hide the maximize button
					$(this).parent().parent().find('div.societal-content').fadeIn('slow'); // fade in bar content
				}
			});
	});
	

	// Tooltip - Minimize
	$("a.minimize-societal[title]").tooltip({ 

	    // place tooltip on the right edge 
	    position: "center right", 

	    // a little tweaking of the position 
	    offset: [-33, -17],

	    // use the built-in fadeIn/fadeOut effect 
	    //effect: "fade", 
	
		// positioning
	    relative: "false",

	    // use this single tooltip element 
	    tip: '#societal-controller-minimize-message' 

	});
	
	
	// Tooltip - Maximize
	$("a.maximize-societal[title]").tooltip({ 

	    // place tooltip on the right edge 
	    position: "center left", 

	    // a little tweaking of the position 
	    offset: [-33, 10], 

	    // use the built-in fadeIn/fadeOut effect 
	    //effect: "fade", 
	
		// positioning 
	    relative: "false",

	    // use this single tooltip element 
	    tip: '#societal-controller-maximize-message' 

	});
	
	
	// Tooltip - Social Share
	$("#societal-share-page").tooltip({ 
		
		// place tooltip on the right edge 
	    position: "top center",
	
		// slide
		//effect: 'fade',
		
		// positioning 
	    relative: "false",
		
		//use this single tooltip element
		tip: '#societal-share-tooltip'
	});
	
	
	// Select Box
	$('div.societal-select-box').hover(function() {
			$(this).children('.societal-select-box-selections:hidden').fadeIn(200); // fade in the box options
			$(this).children('a:first').addClass('select-home-hover'); // change class on root anchor
			$(this).parent('.societal-select-box-wrap').addClass('hover'); // change class on box itself
			$(this).addClass('hover'); // remove hover class
		},
		function() {
			$(this).children('.societal-select-box-selections:visible').fadeOut(50); // fade out box options
			$(this).children('a:first').removeClass('select-home-hover'); // remove hover class
			$(this).parent('.societal-select-box-wrap').removeClass('hover'); // remove hover class
			$(this).removeClass('hover'); // remove hover class
		}
	);
});
