// JavaScript Document

$(document).ready(function(){
	
	var maxicon = "/CMSTmpSupport/images/social_maximize.png";
	var minicon = "/CMSTmpSupport/images/social_minimize.png";
	
	/* Show the minimize button if JS is on */
	$("#minbutton").show();
	
	/* Set up functions for showing and hiding bar, and setting up cookies to remember state */
	
		function closeIcons (){
			/* Change the min/max button */
			$("#minbutton a img").attr("title","Show Berry Social Media Channel"); /* Change mouseover title */
			$("#minbutton a img").attr("src", maxicon); /* Change the image to an up arrow */
		
			/* Hide the bottom bar */
			$("#bottom").stop().animate({
				bottom: "-35px"
			},100);
			
			/* Remember that the bar is hidden */
			$.cookie("showsocialmedia", "false", { expires: 30, path: "/", domain: "berry.edu" });
		}
		
		function openIcons (){
			/* Change the min/max button */
			$("#minbutton a img").attr("title","Hide Social Media Icons"); /* Change mouseover title */
			$("#minbutton a img").attr("src", minicon); /* Change the image to a down arrow */
		
			/* Show bottom bar */
			$("#bottom").stop().animate({
				bottom: "-3px"
			},75);
			
			/* Remember that the bar is shown */
			$.cookie("showsocialmedia", "true", { expires: 30, path: "/", domain: "berry.edu" });
		}




	/*********** Set starting conditions based on cookie ************/
	if ($.cookie("showsocialmedia") != "false"){
		
		/*********** If the bar should be shown ... ************/
		
			/* Hide and show based on click - FIRST CLICK HIDES */
			$("#hideshow").toggle(
				function(e){
					closeIcons();
					/*e.preventDefault();*/
					return false;
				},
				function(e){
					openIcons ();
					/*e.preventDefault();*/
					return false;
				}
			);
		
	} else {
		
		
		/*********** If the bar should be hidden ... ************/
		
			/* Change the minbutton icon to an up arrow */
			$("#minbutton a img").attr("src", maxicon);
			
			/* Hide the social media icons */
			$("#bottom").css("bottom","-35px");
		
		
			/* Hide and show based on click - FIRST CLICK SHOWS */
			$("#hideshow").toggle(
				function(e){
					openIcons ();
					e.preventDefault();
				},
				function(e){
					closeIcons();
					e.preventDefault();
				}
			);
		
	}
	
	/*********** Track which social media icons are clicked with Google Analytics ************/

	$("#bottom a").click(function(){
		var socialname = $(this).find("img").attr("title");
		pageTracker._trackEvent("FrontPage", "SocialClick", socialname);
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
});
