// Javascript for the Accordion Effect, Hover and Active State of Citizenship landing page

(function($$) {
$$.fn.orphans = function(){
    var txt = [];
    this.each(function(){$$.each(this.childNodes, function() {
        if (this.nodeType == 3 && $$.trim(this.nodeValue)) txt.push(this)
    })}); 
    return $$(txt);
};

$$.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
$$.fn.slideFadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
};
})

$$(function() {
	//hover states for .expand
	$$('.expand1').hover(function(){
		$$(this).parent('div:parent').addClass('hover_gradient');
		$$(this).siblings('#thumb_container_citizenship_top').addClass('hover_gradient_top');
	  }, function() {
		$$(this).parent('div:parent').removeClass('hover_gradient');
		$$(this).siblings('#thumb_container_citizenship_top').removeClass('hover_gradient_top');
	});
	
	//click states for .expand
    $$('.collapse').hide(); 
    $$('.expand1').click(function(){
		//Collapse and remove classes for all open div's first, if the div is clicked twice in the row, the div just closes
		var clickedTwice = $$(this).parent("div:parent").hasClass("active_gradient");
		$$('.collapse').slideUp();
		$$('.active_gradient').removeClass('active_gradient');
		$$('.active_gradient_top').removeClass('active_gradient_top');
		
		//If the div hasn't been clicked twice in a row, on the current div, open it, give it the proper class, etc...
		if(clickedTwice==0)
		{
    	    $$(this).next('.collapse').slideToggle();
			$$(this).parent("div:parent").toggleClass("active_gradient");
			$$(this).siblings("#thumb_container_citizenship_top").toggleClass("active_gradient_top");
		}
    });

});


