function cart_add(product_data, quantity)
{
	$('#shopping_cart_items').html($('#shopping_cart_loading').html());
	$.ajax({url: '/ajax-cart-add',
			method: 'post',
		    data: {data: product_data, quantity: quantity?quantity:1},
		    success: function(html){
		         $('#shopping_cart').html(html);
		    }
	});
	return false;
		ajax_update = new Ajax.Updater('shopping_cart', 
								'/ajax-cart-add',
								{evalScripts: true, method: 'post', parameters: {data: product_data, quantity: quantity?quantity:1},
								onLoading:function(){$('shopping_cart_items').hide(); $('shopping_cart_loading').show();},  
								onSuccess:function(){$('shopping_cart_items').show(); $('shopping_cart_loading').hide();}
						
							   });
}
function cart_remove(product_data, product_name)
{
	if (!confirm("Are you sure you want to remove this item from your cart?"))
		return false;
	
	$('#shopping_cart_items').html($('#shopping_cart_loading').html());
	$.ajax({url: '/ajax-cart-remove',
			method: 'post',
		    data: {data: product_data},
		    success: function(html){
		         $('#shopping_cart').html(html);
		    }
	});
	return false;
	
	ajax_update = new Ajax.Updater('shopping_cart', 
								   '/ajax-cart-remove', 
								   {evalScripts: true, method: 'post', parameters: {data: product_data},
									onLoading:function(){$('shopping_cart_items').hide(); $('shopping_cart_loading').show();},  
									onSuccess:function(){$('shopping_cart_items').show(); $('shopping_cart_loading').hide();}
	
								   });
	return true;
}

function pop_return_policy()
{
	win = window.open('/return-policy', 'returnpolicy','scrollbars=1,width=700,height=336');
}

function toggleShipSameAsBilling(form, checkbox)
{
	if (checkbox.checked == true)
	{
		form.elements['shipping[first_name]'].value = form.elements['billing[first_name]'].value
		form.elements['shipping[last_name]'].value = form.elements['billing[last_name]'].value
		form.elements['shipping[address]'].value = form.elements['billing[address]'].value
		form.elements['shipping[address_cont]'].value = form.elements['billing[address_cont]'].value
		form.elements['shipping[city]'].value = form.elements['billing[city]'].value
		form.elements['shipping[state]'].selectedIndex = form.elements['billing[state]'].selectedIndex
		form.elements['shipping[zip]'].value = form.elements['billing[zip]'].value
		form.elements['shipping[phone]'].value = form.elements['billing[phone]'].value
	}
	else
	{
		form.elements['shipping[first_name]'].value = "";
		form.elements['shipping[last_name]'].value = "";
		form.elements['shipping[address]'].value = "";
		form.elements['shipping[address_cont]'].value = "";
		form.elements['shipping[city]'].value = "";
		form.elements['shipping[zip]'].value = "";
		form.elements['shipping[phone]'].value = "";
	}
}

function switch_preview(hide, show)
{
	$('sc_preview['+hide+']').hide();
	Effect.Appear('sc_preview['+show+']', { duration: 1.0 });
	
}


/************
 SOCIAL BOOKMARK FUNCTIONS
 ************/

function social_digg()
{
	url = location.href;
	title = document.title;
	new_window = window.open('http://digg.com/submit?media=MEDIA&topic=TOPIC&url=?'+encodeURIComponent(url)+'&title='+encodeURIComponent(title),'digg');
	req = new Ajax.Request('/api-social-bm/digg/'+encodeURIComponent(url));
	return false;
}
	
function social_stumble()
{
	url = location.href;
	title = document.title;
	new_window = window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(url));
	req = new Ajax.Request('/api-social-bm/stumbleupon/'+encodeURIComponent(url));
	return false;
}
	
function social_facebook() 
{
	url = location.href;
	title = document.title;
	new_window = window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
	req = new Ajax.Request('/api-social-bm/facebook/'+encodeURIComponent(url));
	return false;
}

function social_twitter(title) 
{
	url = location.href;
	
	if (title == undefined || title == "")
		title = "Bell Curves";
	
	new_window = window.open('http://twitter.com/home/?status='+encodeURIComponent(url)+' '+encodeURIComponent(title));
	req = new Ajax.Request('/api-social-bm/twitter/'+encodeURIComponent(url));
	
	return false;
}
	
function social_delicious() 
{
	url = location.href;
	
	title = document.title;
	
	new_window = window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title), 'delicious','toolbar=no,width=550,height=550');
	req = new Ajax.Request('/api-social-bm/delicious/'+encodeURIComponent(url));
	
	return false;
}

/************
 TOOLTIP FUNC
 ************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var tipobj = null;

function startToolTip()
{
	if (ie||ns6)
		tipobj=document.all? document.all["dhtml_mouseover_box"] : document.getElementById? document.getElementById("dhtml_mouseover_box") : ""
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function popTooltip(thetext, thewidth){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px"
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.visibility="visible"
	}
}

function hideTooltip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove=positiontip

/**
 * END TOOLTIP
 */


/**** Image Slide Show By Michael Yudin
	  Requires scriptaculous for Effect.Appear 

	  If you dont want to use scriptaculous,  just replace 
	  Effect.Appear lines with document.getElementById(this.images[this.current_index]).style.display = "block"; 
****/
var imageSlideShow = function(image_id_array)
{
	var _self = this;
	
	this.slide_show = setInterval(function(){
			_self.nextImage();
			}, 5000);
	
	this.current_index = 0;
	
	this.images = image_id_array;
	
	this.nextImage = function()
	{
		
		document.getElementById(this.images[this.current_index]).style.display = "none";
		
		this.current_index++;
		
		if (this.current_index >= this.images.length)
			this.current_index = 0;
			
		Effect.Appear(this.images[this.current_index], { duration: 1 });
	}
	
	this.prevImage = function()
	{
		document.getElementById(this.images[this.current_index]).style.display = "none";
		
		this.current_index--;
		
		if (this.current_index <= 0)
			this.current_index = this.images.length - 1;
			
		Effect.Appear(this.images[this.current_index], { duration: .5 });
	}
	
	this.stopSlideShow = function()
	{
		clearInterval(this.slide_show);
	}
	this.startSlideShow = function()
	{
		var _self = this;
		
		this.slide_show = setInterval(function(){
			_self.nextImage();
			}, 1000);
	}
	
}
     
