/*
 * Author: Noah Ottenstein <http://tnintegratedsolutions.com>
 * Date: January 2011
 * Site: Caseus
 */


// change class on label to "clicked" when clicked, remove the class when clicked outside
function label_click_bind() {
	$(".bigLinks .label").bind('click', function() {
			
			// for firefox and no-csstransitions
			$(this).removeAttr("style")
			$(this).parent(".no-csstransitions .container").switchClass('','clicked','slow', function() {
				$(this).removeAttr("style");
			});
			
		$(this).parent().addClass('clicked');
		$(this).parent().bind('clickoutside', function(event) {
			$(".clicked").removeClass('clicked');
			$(this).unbind('clickoutside');
			
			// exception for when another label is clicked directly
			target = $(event.target);
			if (target.is(".container *")) {
				target.parents('.container').addClass('clicked');
			}
		});
		
		
		
		// remove hover events for clicked label
		$(this).unbind('mouseenter');
		$(this).unbind('mouseleave');
	});
};

function verifyGiftCertificate() {
	if ($('#gift-certificate input[name="amount"]').val() >= 25) {
		return true;
	} else {
		alert("Please enter an amount above $25.00");
		return false;
	}
}

/* accordian menus */
function initMenu() {
	$('.accordian ul').hide();
	$('.accordian li .toggle').click(
		function() {
			if ($(this).text() == 'View More') {
				$(this).text('Hide');
			} else {
				$(this).text('View More');
			}
			$(this).parent().next('ul').slideToggle('normal');
		}
	);
}
	
	
$(document).ready(function() {
	// fade in labels when all images are loaded
	$('.label .front img, img.bg').imagesLoaded(function() {
        $(".label").fadeIn('slow');
		$(".labels").removeClass('labelHide');
		
		// FF fix - preload animation states (otherwise first :hover event does not animate)
		$(".no-csstransitions .label").animate({width: '150%', height: '150%', 'margin-left': '-25%', 'margin-top': '-25%'}, 1).animate({width: '100%', height: '100%', 'margin-left': '0', 'margin-top': '0'}, 1);
    });
	
	label_click_bind();
	
	// close button
	$(".close").bind('click', function(event) {
		event.stopPropagation();
		$(".clicked .label").unbind('clickoutside');
		$(".clicked").removeClass('clicked');
	});
	
	
	// animation for when css transitions are not supported
	$(".no-csstransitions .label").hover(
    	function(){$(this).stop().animate({width: '150%', height: '150%', 'margin-left': '-25%', 'margin-top': '-25%'}, 'fast').css('overflow','visible');},        
    	function(){$(this).stop().animate({width: '100%', height: '100%', 'margin-left': '0', 'margin-top': '0'}, 'fast').css('overflow','visible');
	});
	
	/* Hide mailing list signup form */
	$('#mailingListSignup form').hide();
	$("#mailingListSignup .joinLink").bind('click', function() {
		$(this).fadeOut('fast');
		$('#mailingListSignup form').fadeIn('slow');
	});
	
	/* initialize accordian menus */
	initMenu();

 });




















