
function doAjax(targetURL, targetContainer){
	
	$.ajax({
		url: targetURL,
		cache: false,
		success: function(html){
			$("#"+targetContainer).html(html);
  		}
	});}

function doAjaxPost(sourceForm, targetContainer){

	var dataString = $('#'+sourceForm).serialize();
	
	$.post($('#'+sourceForm).attr('action'), $('#'+sourceForm).serialize(), function(data) { $('#'+targetContainer).html(data); } , 'text');

	return true;
}

function send_tooltip_ajax(form_name,ajax_link,banner,container,products_id) {
    
    // Create the variable for the tooltip container
    obj = $('#j-tooltip');
    
    // Refernce for current form selected
    oForm = obj.find('#'+ form_name);
    
    // fix's a problem when dynamically called.
    ajax_link.replace(/&amp;/g, "&"); 

    // hide form
    oForm.fadeOut('fast');
    
    // Send form via ajax
    $.post(ajax_link, oForm.serialize(), function(data){
        obj.find('.captureCart').html(data).fadeIn('fast');
        $('#captureCart' + products_id).html(data);
    });


    // We remove the form from the dom from the obj and from its hidden
    // counter part hidden that was copied to the obj so its not copied back over later
    // if users mouse back over. 
    obj.find('#'+ form_name).remove();
    $('#'+ form_name).remove();
    
    // Make sure the information that was updated is now visible for future mouse over
    $('#captureCart' + products_id).show();
}

function send_form_ajax(form_name,ajax_link,banner,container)
{
	var container = container;
	var form_name = form_name; // also servs as the ID for the form.
	var ajax_link = ajax_link;
	ajax_link   = ajax_link.replace(/&amp;/g, "&"); // fix's a problem when dynamically called.

	var ogAction = $('#'+form_name).attr('action'); // grabs original action for replacement later
	
	$('#'+form_name).attr('action',ajax_link);
		
	// track this with google analytics
//	pageTracker._trackPageview(ajax_link+'#add-to-cart');
	
	if (doAjaxPost(form_name, container) == true) {
		if (banner == true) {
			$('#cartUpdate').fadeIn("slow");
			$('#' + form_name).attr('action', ogAction);
			setTimeout("$('#cartUpdate').fadeOut('slow')", 10000);
		}
	}
}




$().ready(function() {
	if($("#frontFeatureBox").length)
	{
		$("#frontFeatureBox").after('<div id="cycle-nav"></div>').cycle({
			fx: "fade",
			pager: "#cycle-nav",
			pagerAnchorBuilder: function(idx, slide) 
			{ 
		        return '<a href="#">&bull;</a>'; 
		    }
		});
	}
	
   
    var shelf_items = $(".scrollable").scrollable({  circular: true }).navigator();
	var i = 0;

	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	$("a[rel]").overlay({

		mask: 'black',
		effect: 'apple',

		onBeforeLoad: function() {

			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");

			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}

	});

	$('.tooltip-holder').tooltip({ 

		// use div.tooltip as our tooltip
		tip: '.tooltip',

		// use the fade effect instead of the default
		effect: 'fade',

		// make fadeOutSpeed similar to the browser's default
		fadeOutSpeed: 10,

		// the time before the tooltip is shown
		predelay: 500,
		delay: 10,

		// tweak the position
		position: "bottom right",
		offset: [-200, -30]
	}).dynamic({ right: { direction: 'left', bounce: true } }).hover(function(){
	    $('#j-tooltip').html($(this).parent().parent().parent().find('.product-information').html());
	}, function(){});

	// superfish menu
    $("ul.sf-menu").superfish({ 
        animation: {height:'show'},   // slide-down effect without fade-in 
        delay:     1200               // 1.2 second delay on mouseout 
    }); 

});



















