$(document).ready(function() {
    		
/* Set default open/close settings */
$('.acc_container').hide(); /* Hide/close all containers */
$('.acc_trigger:first').addClass('active').next().show(); 

$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { 
		$('.acc_trigger').removeClass('active').next().slideUp(); 
		$(this).toggleClass('active').next().slideDown(); 
	}
	return false; /* Prevent the browser jump to the link anchor */
});			
    		  		/* Scrollable Thumbnails */
    		$(".scrollable").scrollable(); 
    		
    		/* Add the toggle function to hide/show the change environments box w/ thumbnails */
    		$("#tab").hover(function() { $(this).click(); }, function(){ });
    		$("#ce-slide-box").hover(function(){ }, function() { $("#tab").click(); });
    		$("#ce-slide-box img").hover(function(){ $(this).addClass('imgHover'); }, function() { $(this).removeClass("imgHover"); });
    		
    		$('#tab').click(function() {
					$('#ce-slide-box').slideToggle(400);
					
					if($("#change-environment").css("top") == "-30px")
            $("#change-environment").stop().animate({"top":"-95px"}, 400);
          else
          {
            $("#change-environment").stop().animate({"top":"-30px"}, 400);
					}
					return false;
				});
				
				$("#change-environment .items img").click(function(){
           setCookie("cleanearth-bg", $(this)[0].id, 365);
           window.location.href = window.location.href;
				});
				
				/* Add the toggle function to hide/show the forms and downloads ul 
				$('#forms-and-downloads').hover(function() {
					$('#forms-and-downloads ul').stop().css("display", "block").animate({"height":"200px"}, 400);
				},
				function(){
				  $('#forms-and-downloads ul').stop().animate({"height":"0px"}, 400, "swing", function(){
            $(this).css("display", "none");
				  });
				});*/
				
				$('#nav li').hover(function(){
				  $(this).addClass('over');
				}, function(){
				  $(this).removeClass('over');
				});
				
				 
			   /* QTips */
    		 // Make sure to only match links to wikipedia with a rel tag
			   $('div.city').each(function()
			   {

			      // We make use of the .each() loop to gain access to each element via the "this" keyword...
			      $(this).qtip(
			      {
			         content: {
			            // Set the text to an image HTML string with the correct src URL to the loading image you want to use
			            text: '<img class="throbber" src="<?=base_url()?>images/throbber.gif" alt="Loading..." />',
			            ajax: {
			               url: $(this).attr('rel'), // Use the rel attribute of each element for the url to load
			               once: true
			            },
			            title: {
			               text: $(this).text(), // Give the tooltip a title using each elements text
			               button: true
			            }
			         },
			         position: {
			            at: 'bottom center', // Position the tooltip above the link
			            my: 'top center',
			            viewport: $(window) // Keep the tooltip on-screen at all times
			         },
			         show: {
			            event: 'mouseover',
			            solo: true // Only show one tooltip at a time
			         },
			         hide: 'unfocus',
			         style: {
			            classes: 'ui-tooltip-wiki ui-tooltip-dark ui-tooltip-shadow'
			         }
			      })
					 
			   })
			 
			   // Make sure it doesn't follow the link when we click it
			   .click(function(event) { event.preventDefault(); });
							

    	});
			
    	/* Supersized Options (Move to linked js file? Seems most options are duplicate) */
    	jQuery(function($){
    	  var bgCookie = getCookie("cleanearth-bg");
    	  
    	  var startingSlide = 0;
    	  var autoPlay = 1;
    	  
    	  if(bgCookie != null && bgCookie != "")
    	  {
          startingSlide = bgCookie.split('_')[1];
          autoPlay = 0;
        }
				$.supersized({
				  
					//Functionality
					slideshow               :   1,		//Slideshow on/off
					autoplay				:	autoPlay,		//Slideshow starts playing automatically
					start_slide             :   startingSlide,		//Start slide (0 is random)
					random					: 	0,		//Randomize slide order (Ignores start slide)
					slide_interval          :   5000,	//Length between transitions
					transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
					transition_speed		:	1000,	//Speed of transition
					new_window				:	1,		//Image links open in new window/tab
					pause_hover             :   0,		//Pause slideshow on hover
					keyboard_nav            :   1,		//Keyboard navigation on/off
					performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
					image_protect			:	1,		//Disables image dragging and right click with Javascript
					image_path				:	'img/', //Default image path

					//Size & Position
					min_width		        :   0,		//Min width allowed (in pixels)
					min_height		        :   0,		//Min height allowed (in pixels)
					vertical_center         :   1,		//Vertically center background
					horizontal_center       :   1,		//Horizontally center background
					fit_portrait         	:   1,		//Portrait images will not exceed browser height
					fit_landscape			:   1,		//Landscape images will not exceed browser width
					
					//Components
					navigation              :   1,		//Slideshow controls on/off
					thumbnail_navigation    :   1,		//Thumbnail navigation
					slide_counter           :   1,		//Display slide numbers
					slide_captions          :   1,		//Slide caption (Pull from "title" in slides array)
					slides 									:  	[		//Slideshow Images
														{image : 'http://www.cleanearthinc.com/images/bgs/1.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/2.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/3.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/4.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/5.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/6.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/7.jpg'},
														{image : 'http://www.cleanearthinc.com/images/bgs/8.jpg'}  													
												]												
					}); 
		    });
		    
		    function setCookie(c_name,value,exdays)
        {
        var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie=c_name + "=" + c_value;
        }
        function getCookie(c_name)
        {
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
        {
          x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
          y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
          x=x.replace(/^\s+|\s+$/g,"");
          if (x==c_name)
            {
            return unescape(y);
            }
          }
        }
