/**
* We use the initCallback callback
* to assign functionality to the controls
*/
function mycarousel_initCallback(carousel) {
  jQuery('#mycarousel-next').bind('click', function() { carousel.next(); return false; });
	jQuery('#mycarousel-prev').bind('click', function() {	carousel.prev(); return false; });
};

// Ride the carousel...
jQuery(document).ready(function() {
	if ($("#mycarousel").length>0)
	{
    jQuery("#mycarousel").jcarousel({
      scroll: 3,
      visible: 3,
      initCallback: mycarousel_initCallback,
      // This tells jCarousel NOT to autobuild prev/next buttons
      buttonNextHTML: null,
      buttonPrevHTML: null
    });
	}

	//to notify not added successfully (needs to be server side really :( )
	if ($("#recipecontentbox").length>0)
	{
		var curl = window.location.href;
		if (curl.match("flag=recipebook"))
		{
			alert("You have successfully added this recipe to your recipe book.");
		}
	}

	//dynamically change the social book marks
	var curUrl = window.location.href;
	$("a[href^='http://www.facebook.com/']")
	   .each(function()
	   {
		  this.href = "http://www.facebook.com/share.php?u="+curUrl;
	   });
	 $("a[href^='http://www.stumbleupon.com/']")
	   .each(function()
	   {
		  this.href = "http://www.stumbleupon.com/submit?url="+curUrl;
	   });
	 $("a[href^='http://delicious.com/']")
	   .each(function()
	   {
		  this.href = "http://del.icio.us/post?url="+curUrl;
	   });
	 $("a[href^='http://www.facebook.com/']")
	   .each(function()
	   {
		  this.href = "http://www.facebook.com/sharer.php?u="+curUrl;
	   });
	 $("a[href^='http://digg']")
	   .each(function()
	   {
		  this.href = "http://digg.com/submit?phase=2&amp;url="+curUrl;
	   });
	   var rawName = $("#accesslink").html();
	   rawName = rawName.replace(/,/, "");
	   $("#accesslink").html(rawName);
	   if ($("#mrbHead").length>0)
		{

		   var lio = rawName.indexOf("/")
		   if (rawName.match("Log out"))
		   {
				$("#mrbHead span").html(" "+rawName.substring(12,lio));
		   }
		}
		if ($("#myrecipebook").length>0)
		{
			$("#myrecipebook p.title")
		   .each(function()
			   {
				var newtext = this.innerHTML.replace(/,/, "");
				  this.innerHTML = newtext;
			   });

		}

		//var anaCode = '<script type="text/javascript">';
		//var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		//var anaCode = unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E");

		//var oldCode = $("#footer").html();
		//$("#footer").html(oldCode+anaCode);



			//try {
			//var pageTracker = _gat._getTracker("UA-10977073-1");
			//pageTracker._trackPageview();
			//}
			//catch(err) {};


});

