jQuery.noConflict(); (function($) { $(function() {

$('html').attr('id', 'js'); // Enabled Javascript Detection

if($("a[rel=external]")){
	$("a[rel=external]").click(function() {
		window.open(this.href);  
		return false;
	});
}

if(!$.fontAvailable('Bookman Old Style')) {
	Cufon.replace('h1, h2, h3, h4, h5', {fontFamily: 'Bookman Old Style'});
}

if(!$.fontAvailable('Freestyle Script')) {
	Cufon.replace('.cake_box_img h3', {fontFamily: 'Freestyle Script'});
}

if ($('#html_mail_form').length){$("#html_mail_form").validate({errorElement: "span"});};

$("#c_like_order").change(function() {
	if ($("#c_like_order").val()!='') {
		if ($("#c_like_order").val()=='Cupcake') {
			$("#c_size").hide();
			$("#c_size_cupcake").show();
			$("#c_size_cake").hide();
			};
		if ($("#c_like_order").val()=='Cake') {
			$("#c_size").hide();
			$("#c_size_cake").show();
			$("#c_size_cupcake").hide();
			};
	} else {
		$("#c_size").show();
		$("#c_size_cake").hide();
		$("#c_size_cupcake").hide();
	}
			
	});


if ($('#cake_box').length){
	var scrollCount = 0;
	$(window).scroll(
		function() {
			scrollCount++;
			setTimeout(moveCupcake, 100);
		}		
	);
}

$('.week_line a').click(
	function(){							
		var target_id = getCupcakeTargetId(this)
		if(target_id == '')
			return false;
		//var td = $(this).parent();
		//selectCupcake(td);
		showCupcake(target_id);
		return false;

});

function getCupcakeTargetId(link)
{
	var href = $(link).attr('href');
	var hash = href.lastIndexOf('#');
	if(hash < 0)
		return '';
	var target_id = href.substring(hash + 1, href.length);	
	return target_id;
}



function showCupcake(cupcake_id)
{
	$('#cake_box div').removeClass('selected');
	$('#' + cupcake_id).addClass('selected');
}




function moveCupcake()
{
	scrollCount--;
	if(scrollCount > 0)
		return;

	var startPos = 350;
	var scrollPos = $(this).scrollTop();
	if(scrollPos > startPos)
	{
		var scrollTo = (scrollPos + 1) - startPos;
		$('#cake_box').animate({'top': scrollTo + 'px'}, 100);
		//$('#right-col-holder').delay(100).css('top', scrollTo + 'px'); 
	}
	else
	{
		//$('#right-col-holder').delay(100).css('top', 0); 
		$('#cake_box').animate({'top': '0px' }, 100);
	}
}


}); })(jQuery);



