
/**
	 * Create popup message window
	 *
	 * @param content		= Message content
	 * @param type			= error or success
	 */
	function createPopUp(content, type)
	{

		
		if(type == 'error')
		{
			var $title = '<h3 class="dinot">Error</h3>';
			createGrowl( true, '<span class="qtip-error">' + content + '</span>', $title );
		}
		else
		{
			var $title = '<h3 class="dinot underline">Success</h3>';
			createGrowl( true, '<span class="qtip-success">' + content + '</span>', $title );
		}
	}



$(document).ready(function(){
	
	$(".fancy").click(function(){
		$(".content").find("#which_one").remove();
		$(".content").append("<input type='hidden' id='which_one' value='"+$(this).attr("href")+"'>");
	})
	
	$(".contact_send_f").click(function(){
		$(".content").find("#which_one").remove();
		$(".content").append("<input type='hidden' id='which_one' value='contact'>");
	})
	
	window.createGrowl = function(persistent, content, title) {

  		// Use the last visible jGrowl qtip as our positioning target
  		var target = $('.qtip.jgrowl:visible:last');
	 
      	// Create your jGrowl qTip...
      	$(document.body).qtip({
	         // Any content config you want here really.... go wild!
	         content: {
	            text: content,
	            title: {
	               text: title,
	               button: true
	            }
	         },
	         position: {
	         	at: 'center center',
	         	my: 'center center',
	         	viewport: $(window), // Keep the tooltip on-screen at all times
	         	effect: false, // Disable positioning animation
	         	target: $(window),
	         	adjust: {
	                //y: 300
	             }
      		 },
	         show: {
      			modal: true,
	            event: false, // Don't show it on a regular event
	            ready: true, // Show it when ready (rendered)
	            effect: function() { $(this).stop(0,1).fadeIn(400); }, // Matches the hide effect
	            delay: 0, // Needed to prevent positioning issues
	            
	            // Custom option for use with the .get()/.set() API, awesome!
	            persistent: persistent
	         },
	         hide: {
	            event: false, // Don't hide it on a regular event
	            effect: function(api) { 
	               // Do a regular fadeOut, but add some spice!
	               $(this).stop(0,1).fadeOut(400).queue(function() {
	                  // Destroy this tooltip after fading out
	                  api.destroy();
	 
	                  // Update positions
	                  updateGrowls();
	               })
	            }
	         },
	         style: {
	            tip: false, // No tips for this one (optional ofcourse)
	         	classes: 'ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded qtip-custom-messages',
	         	width: '480'
	         },
	         events: {
	            render: function(event, api) {
	               // Trigger the timer (below) on render
	               timer.call(api.elements.tooltip, event);
	               var elem = api.elements.overlay;
	            }
	         }
      	})
      	.removeData('qtip');
   };
 
   // Make it a window property see we can call it outside via updateGrowls() at any point
   window.updateGrowls = function() {
      // Loop over each jGrowl qTip
      var each = $('.qtip.jgrowl:not(:animated)');
      each.each(function(i) {
         var api = $(this).data('qtip');
 
         // Set the target option directly to prevent reposition() from being called twice.
         api.options.position.target = !i ? $(document.body) : each.eq(i - 1);
         api.set('position.at', (!i ? 'top' : 'bottom') + ' right');
      });

   };
   
   
   // Setup our timer function
   function timer(event) {
      var api = $(this).data('qtip'),
         lifespan = 3000; // 2 second lifespan
      
      // If persistent is set to true, don't do anything.
      if(api.get('show.persistent') === true) { return; }
 
      // Otherwise, start/clear the timer depending on event type
      clearTimeout(api.timer);
      if(event.type !== 'mouseover') {
         api.timer = setTimeout(api.hide, lifespan);
      }
   }
 
   // Utilise delegate so we don't have to rebind for every qTip!
   $(document).delegate('.qtip.jgrowl', 'mouseover mouseout', timer);
	
	if($(".popup_message").length > 0)
	{
		var $div = $(".popup_message");
		if($div.hasClass('error'))
		{
			createPopUp($div.html(), 'error');
		}
		else
		{
			createPopUp($div.html(), 'success');
		}

		
	}
	
	
	if ($("a.fancy").length>0)
	{
		$("a.fancy").fancybox({
	
			'transitionIn'		: 'none',
	
			'transitionOut'		: 'none',
	
			'autoScale': false
	
		});
	}
	
	if ($("#y_recipe").length>0)
	{
		$("#y_recipe").val($(".mainHeading h1").text());
		$(".wrapper ul li").each(function() {
			$("#shopping_list form").append("<input type='hidden' name='y_ingredients[]' value='"+$(this).text()+"'>");
		})
	}
	
	$("#send_to_friend").live("click", function() {
		//y_type = $(this).parent().parent().find("[name='type']").val();
	 	//y_email = $(this).parent().parent().find("[name='y_email']").val();
	 	
		$(this).parent().append("<input type='hidden' name='content1' value='"+escape($(".image").html())+"' />");
		$(this).parent().append("<input type='hidden' name='content2' value='"+escape($(".copy").html())+"' />");
			
	 	if($('.breadcrumbs li:nth-child(2)').text()=="Products")
	 		$(this).parents('form').append("<input type='hidden' name='product_c' value='yes'/>");
	 	
	 	if ($("#which_one").val()=="#shopping_list")
			{$("#my_form2").submit(); return false;}
	    else if ($("#which_one").val()=="contact")
	   		{$("#contact_form").submit(); return false;}	
	    else
			{$("#my_form").submit(); return false;}
		return false;
	})
	
	$("#newsletter_submit").live("click", function() {
		//y_type = $(this).parent().find("[name='type']").val();
	 	//y_email = $(this).parent().find("[name='email']").val();
	 	/*$.ajax({
		   type: "POST",
		   data: {
				type 	: y_type,
				email   : y_email,
			},
		   url: "http://oriental.leadingedgehosting.com.au/home/temp/",
		   success: function(msg){
				$("#news_form").submit(); return false;
			     
		   },
			error: function( msg ){
			   $("#news_form").submit(); return false;
		   }
		});*/
	 	/*if ($("#which_one").val()=="#shopping_list")
	 		{$("#my_form2").submit(); return false;}
	 	else if ($("#which_one").val()=="contact")
   			{$("#contact_form").submit(); return false;}	
	 	else
	 		{$("#my_form").submit(); return false;}*/
	 	//$("#news_form").attr("action", "partial/news_submit");
		$("#news_form").submit();
		return false;
	})
	
	

});
