$(document).ready(function(){
	
	
	
	//IE png fix
	$(document).pngFix(); 
	
   /*//scroll to top			
   var defaults = {
   containerID: 'moccaUItoTop', // fading element id
   containerHoverClass: 'moccaUIhover', // fading element hover class
   scrollSpeed: 2000,
   easingType: 'linear' 
   };
   $().UItoTop({ easingType: 'easeOutQuart' });*/
   
   		
   //fix navigation dropdown menu hover for IE
   sfHover = function() {
   var sfEls = document.getElementById("navigation").getElementsByTagName("li");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
         this.className+=" hover";
      }
      sfEls[i].onmouseout=function() {
         this.className=this.className.replace(new RegExp(" hover\\b"), "");
      }
      }
      }
     if (window.attachEvent) window.attachEvent("onload", sfHover);

	//start accordion
	$("#st li img").hide();
	
	$("a.sense").hover(function() {
		var $hidden = $("a.sense img");
    	if($hidden.is(':hidden')) {
			$(this).animate({width:'200px'},{queue:false, duration:400});
			$hidden.show();
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'0px'},{queue:false, duration:400});
	 } else {
		 	$hidden.hide();
        	$(this).animate({width:'88px'},{queue:false, duration:400});
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'56px'},{queue:false, duration:400});
			}
	 return false;
	 });
	 
	 $("a.think").hover(function() {
		var $hidden = $("a.think img");
    	if($hidden.is(':hidden')) {
			$(this).animate({width:'250px'},{queue:false, duration:400});
			$hidden.show();
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'0px'},{queue:false, duration:400});
	 } else {
		 	$hidden.hide();
        	$(this).animate({width:'110px'},{queue:false, duration:400});
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'56px'},{queue:false, duration:400});
			}
	 return false;
	 });
	 
	 $("a.act").hover(function() {
		var $hidden = $("a.act img");
    	if($hidden.is(':hidden')) {
			$(this).animate({width:'249px'},{queue:false, duration:400});
			$hidden.show();
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'0px'},{queue:false, duration:400});
	 } else {
		 	$hidden.hide();
        	$(this).animate({width:'125px'},{queue:false, duration:400});
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'56px'},{queue:false, duration:400});
			}
	 return false;
	 });
	 
	
	$("a.resolve").hover(function() {
		var $hidden = $("a.resolve img");
    	if($hidden.is(':hidden')) {
			$(this).animate({width:'268px'},{queue:false, duration:400});
			$hidden.show();
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'0px'},{queue:false, duration:400});
	 } else {
		 	$hidden.hide();
        	$(this).animate({width:'124px'},{queue:false, duration:400});
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'56px'},{queue:false, duration:400});
			}
	 return false;
	 });
	 
	 $("a.tell").hover(function() {
		var $hidden = $("a.tell img");
    	if($hidden.is(':hidden')) {
			$(this).animate({width:'256px'},{queue:false, duration:400});
			$hidden.show();
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'0px'},{queue:false, duration:400});
	 } else {
		 	$hidden.hide();
        	$(this).animate({width:'110px'},{queue:false, duration:400});
			$("a.think, a.act, a.resolve, a.tell").animate({marginLeft:'56px'},{queue:false, duration:400});
			}
	 return false;
	 });
	 

	
	//slider homepage
	$(".slider.activatedbrands").jCarouselLite({
	btnNext: ".activatedbrands.next",
    btnPrev: ".activatedbrands.prev",
    visible: 1,
    speed: 600
	});
	
	$(".slider.practice").jCarouselLite({
	btnNext: ".practice.next",
    btnPrev: ".practice.prev",
	auto: 800,
	visible: 1,
    speed: 1500
	});
	
	$(".slider.insights").jCarouselLite({
	btnNext: ".insights.next",
    btnPrev: ".insights.prev",
    visible: 3,
    speed: 300
	});
	
	//meet activiste thumbnails
    $('.boxgrid').hover(function() {
        $('.boxcover', this).slideDown(200);
    }, function() {
        $('.boxcover', this).slideUp(200);
    });
	
	//images link hover effect
	 $('a img').hover(function() {
     	$(this).fadeTo('slow', 0.8);
     }, function() {
        $(this).fadeTo('slow', 1);
 	 });
	 
	//banner fade in
	$('.banner').fadeIn(1200);
	
	//background resize
	var theWindow    = $(window),
        $bg          = $("#bgimg"),
        aspectRatio  = $bg.width() / $bg.height();
    $bg.removeAttr("width");
    $bg.removeAttr("height");
	function resizeBg() {
		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                    .removeClass()
                    .addClass('bgheight');
                } else {
                    $bg
                    .removeClass()
                    .addClass('bgwidth');
                }
                if ($bg.width() < theWindow.width()) $bg.addClass('bgwidth');
                if ($bg.height() < theWindow.height()) $bg.addClass('bgheight');
				}
		theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");

	//slider for case studies
	$('#slider').nivoSlider({
        effect:'slideInLeft', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:200, //Slide transition speed
        pauseTime:3000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:true, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:true, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:true, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
		lastSlide: function(){}, //Triggers when last slide is shown
		afterLoad: function(){} //Triggers when slider has loaded
    });
	
	//slideshow for workshop
	$('#slideshow').nivoSlider({
        effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:4000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:false, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
	
	//slideshow for workshop homepage
	$('#slideshow-practice').nivoSlider({
        effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:4000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
	
	
	
	//form textarea auto resize
	$('textarea#message').autoResize({
    // On resize:
    onResize : function() {
        $(this).css({opacity:0.8});
    },
    // After resize:
    animateCallback : function() {
        $(this).css({opacity:1});
    },
    animateDuration : 300,
	animate:false,
    extraSpace : 12
	}).trigger('change');
	
	$("#form").submit(function() {
                
		//Change response text to 'Sending...'
		$('#response').html('Sending...').show();

		//Make AJAX request
		$.post($(this).attr("action"), $(this).serialize(), function(data) {
			$('#response').html(data);
			if (data.indexOf("success") > -1) {
				$("#form").children("label, input, textarea, span").hide();
			}
		});

		//Cancel default action
		return false;
                
	});

});

