/*!
 * Bloooming Shop Plugin v1.3 Wordpress
 * http://www.bloooming.com/
 *
 * Copyright 2010, Tina Coric
 * All rights reserved
 *
 * Date: Sun Apr 04 22:22:22 2010 -0500
 */


jQuery.fn.bloooming_shop = function(){

	/*********************get cart ****************************/
		$.ajax({
			type : 'GET',
			url : $('#pathtocart').attr('href'),
			success : function (html) {
				$('#items').html(html);

			}
		});

	if (jQuery().sSelect) {
		
		$('.productoptions').sSelect();
		
	}
	
	////// animate cart ///////
	
	$('.productoptions').change(function(){

	
		var selid = $(this).attr('id');
		
		var selprice = $('#'+selid+' option:selected').attr('rel');
		var prid = selid.substr(1);
		var currency = $('#'+prid).attr('rel');
		
		var phtml = currency+' '+selprice;
			
		$('#'+prid+' .price').html(phtml);
		$('#'+prid+' .price').attr('rel',selprice);


		if (Cufon) {
			Cufon.replace('.price');
		}
		
	});


	$('.showdetails').click(function() {
			$(this).next('.details').slideToggle(50);
	});
	
	
	////// animate cart ///////
	
	$('.addtocart').click(function(){

		pid = $(this).attr('id').substring(1);
		
		///animated shadow
		var pcont = $('#' + pid);
        var cart = $('#cart');		
        var shadow = $('#' + pid + '_shadow');
        
        $('body').prepend('<div class="shadow" id="'+pcont.attr('id')+'_shadow"></div>');
          var shadow = $('#'+pcont.attr('id')+'_shadow');

	     shadow.width(pcont.css('width')).height(pcont.css('height')).css('top', pcont.offset().top).css('left', pcont.offset().left).css('opacity', 0.5).show();
    	 shadow.css('position', 'absolute');
		 
		 shadow.animate( {
		  		width: cart.innerWidth(), 
		  		height: cart.innerHeight(), 
		  		top: cart.offset().top, 
		  		left: cart.offset().left 
		  		}, { 
		  		duration: 300 
		  		} )
		    .animate({ 
		    	opacity: 0 
		    },
		    { 
		    duration: 100,
		    complete: function(){
		    	
		    	shadow.remove();
		    	
		    }
		    
		    });
		 
		    
	/// add to cart
	
		var name = $('#' + pid + ' > h3').text();
		var price = $('#' + pid + ' > .price').attr('rel');
		var option = '';
		option = $('#o'+pid+' option:selected').attr('value');
		var oprice = $('#o'+pid).attr('rel');
		
		var formData = 'productid=' + pid + '&productname='+ name + '&productprice=' + price + '&productoption=' + option + '&productoprice=' + oprice; 
		
		$.ajax({
			type : 'POST',
			url : $('#pathtocart').attr('href'),
			data : formData,
			success : function (html) {
				$('#items').html(html);
			}
		});
		

	});
	
	$('.removeitem').live('click', function() {		
		rid = $(this).attr('id');
		rop = $(this).attr('rel');

		var remData = 'removeproduct=' + rid + '&rop=' + rop; 
		
		$.ajax({
			type : 'POST',
			url : $('#pathtocart').attr('href'),
			data : remData,
			success : function (html) {
				$('#items').html(html);
			}
		});
		
	});
	
	$('#gotopayment').click(function(){
			
		$.ajax({
			type : 'GET',
			url : $('#gatewaypath').attr('href'),
			success : function (html) {
				window.location.href = html;
			}
		});
		
	});	

}



		

