$(function(){
	//masonry
	$('#flavors-pricing ul li').not('#flavors-pricing ul li ul li').addClass('cascade');
	$('#flavors-pricing ul').masonry({
   		columnWidth: 128, 
   		itemSelector: '.cascade' 
	});
});

$(function(){
	//set global variables
	if( $('div').hasClass('fondant-thin')){
		var section = $('.fondant-thin .section');
		var sectionHeight = section.height();
		var imageHeight = 177;
	}
	else if( $('div').hasClass('fondant-full')){
		var section = $('.fondant-full .content');
		var sectionHeight = section.height();
		var imageHeight = 177;
	}
	else if( $('div').hasClass('parchment-full')){
		var section = $('.parchment-full .section');
		var sectionHeight = section.height();
		var imageHeight = 412;
	}
	else{
		return false;
	}
	//function to calculate the desired height for seemless flow
	function calculate_height(repeatNumber){
		repeatNumber /= imageHeight;
		repeatNumber = Math.ceil(repeatNumber);
		return height = imageHeight * repeatNumber;
	}
	//if more than image height add a style for correct height
	if(sectionHeight >= imageHeight){
		calculate_height(sectionHeight);
		section.css({
			'height' : height + 'px'
		});
	}
	
	//sidebar images
	var aside_img = $('.aside img');
	if (aside_img.length == 0) {
		return false;
	}else {
		$('.aside li:nth-child(even)').addClass('left');
		$('.aside li:nth-child(odd)').addClass('right');
	}
	
	$('.aside img:nth-child(even)').addClass('right');
	$('.aside img:nth-child(odd)').addClass('left');
	

	//home button functionality
	$('#home ul li.wedding p a').each(function(){
		$(this).attr('href', '/wedding-cakes/');
	});
	$('#home ul li.specialty p a').each(function(){
		$(this).attr('href', '/specialty-cakes/');
	});
	$('#home ul li.sinful p a').each(function(){
		$(this).attr('href', '/sinful-desserts/');
	});
	$('#home ul li.sweetblooms p a').each(function(){
		$(this).attr('href', '/sweet-blooms/');
	});
});

$(function(){
	//gallery scripts
	$('.gallery li a').attr('rel', 'gallery'); //for photo credit
	$('.gallery li a img').each(function(){
		var title_img = $(this).attr('title');
		$(this).parent().attr('title', title_img);
	});
	
	$('.gallery li p a').add('.parchment-full a:has(img)').fancybox({ //for fancybox
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'speedIn': 600,
		'speedOut': 200,
		'titlePosition': 'inside'
	});
	
	$('.article .gallery li:even').addClass('right'); //for adding .right and .left classes
	$('.article .gallery li:odd').addClass('left');
});
