$(function() {
	
	// Newsletter
	$('#newsletter-signup :submit').hide();
	$('.submit-scissors').click(function() {
		$(this).prev().submit();
		return false;
	});
	
});

$(window).load(function() {
	
	// jFlow
	$('.slide_controller').each(function() {
		var $$ = $(this);
		var id = $$.attr('rel');
		var first_media = $("#slides_"+id+" img:first");
		$$.jFlow({
					slides: "#slides_"+id,
					controller: ".jFlowControl_"+id, // must be class, use . sign
					slideWrapper : "#jFlowSlide_"+id, // must be id, use # sign
					selectedWrapper: "jFlowSelected_"+id,  // just pure text, no sign
					prev: ".jFlowPrev_"+id, // must be class, use . sign
					next: ".jFlowNext_"+id, // must be class, use . sign
					autoSlide: true,
					interval: 3000,
					width: first_media.width()+"px",
					height: first_media.height()+"px"
		});	
		$$.find('.jFlowPrev, .jFlowNext').css('bottom', first_media.height()/2-30+'px');
	});
	
	// Masonry
	if ($('#news-articles').size()>0) {
		$('#news-articles').masonry({
	    columnWidth: 240, 
	    itemSelector: '.news-article:not(.invisible)',
	    animate: true,
	    animationOptions: {
	      duration: 1000,
	      queue: false
	    }
		});
	}
	if ($('#salon-boxes').size()>0) {
		$('#salon-boxes').masonry({
	    columnWidth: 240, 
	    itemSelector: '.salon-box'
		});
	}
	
	// Filtering Masonry
	function reveal(href) {
		$('#filters li').removeClass('selected-filter');
		$('#filters a[href='+href+']').parent().addClass('selected-filter');
		
		var tag_class = href.replace('#','.filter-');
		var content = $('#news-articles')

    if(tag_class=='.filter-all') {
				content.children().removeClass('top-news-article').first().addClass('top-news-article');
        content.children('.invisible').toggleClass('invisible').fadeIn();
    } else {    
        content.children().removeClass('top-news-article').not(tag_class).not('.invisible').toggleClass('invisible').fadeOut();
        content.children(tag_class+'.invisible').toggleClass('invisible').fadeIn();
				content.children(':not(.invisible)').first().addClass('top-news-article');
    }
    content.masonry();
	}
	
	$('#filters .spot').click(function() {$(this).next().click();});
	$('#filters a').click(function(){
		var href =$(this).attr('href');
		window.location.hash = href;
			
	  reveal(href);

	  return false;
	});
	
	var hash = window.location.hash;
	if (hash!='' && hash!='#') reveal(hash);
	
	// How to steps
	var step_index = 0;
	$('.step-btn:eq(0)').addClass('stephover');
	$('.step-btn').mouseover(function() {
		var index = $('.step-btn').index($(this));
		if (index!=step_index) {
			$('.step-btn').removeClass('stephover');
			$(this).addClass('stephover');
			$('.step').hide().eq(index).fadeIn();
			step_index = index;
		}
	});
	
});

