/**
 * Author - Onur Şimşek
 */
// Sepete ürün ekleme
$(document).ready(function(){
	
	updateShoppingCart();
	
	$('button[name=addShoppingCart]').click(function(){
		var form		= $(this).parent('form');
		var productID	= form.find('input[name=frmProductID]').val();
		
		$.ajax({
			type	: 'post',
			url		: '../ajax/addShoppingCart.php',
			data	: form.serialize(),
			success	: function(data){
				form.find('button[name=addShoppingCart]').html('Eklendi');
				form.find('button[name=addShoppingCart]').attr('disabled', 'disabled');
				updateShoppingCart();
			}
		});
		return false;
	});
	
	function updateShoppingCart(){
		$.ajax({
			type	: 'post',
			url		: '../ajax/updateShoppingCart.php',
			success	: function(data){
				$('#shoppingCart a').html(data);
			}
		});
	}
	
	                                                                   
	/* MEHMET SOYLU - DÜZENLEME */
	
	$('button[name=deleteShoppingCartProduct]').click(function(){
		var parentDiv				= $(this).parent('div.deleteProductInShoppingCart');
		var parentTr			= $(this).parent('div.deleteProductInShoppingCart');
		var shoppingCartProductID	= parentDiv.find('input[name=shoppingCartProductID]').val();
      
     $.ajax({
			type	: 'post',
			url		: '../ajax/deleteShoppingCartProduct.php',
			data	: 'shoppingCartProductID='+ shoppingCartProductID,
			success	: function(data){
				       window.location.href ='/shoppingCart';
			}
		});
		
		return false;
	});
	
		
	$('button[name=clearShoppingCart]').click(function(){ 
  	 
     var shoppingCartID	= $(this).val(); 
        
     $.ajax({
      			type	: 'post',
      			url		: '../ajax/clearShoppingCart.php',
      			data	: 'shoppingCartID='+ shoppingCartID,
      			success	: function(data){
      				     window.location.href ='/shoppingCart';
      			}
		  }); 
      
		  return false;
	});
	
	 
	$('button[name=arttir]').click(function(){ 
  	 
     var shoppingCartProductID	= $(this).val(); 
     $.ajax({
      			type	: 'post',
      			url		: '../ajax/changeQuantityShoppingCartProduct.php',
      			data	: 'shoppingCartProductID='+shoppingCartProductID+'&changeQuantityValue=1',
      			success	: function(data){
      			          window.location.href ='/shoppingCart';
      			}
		  }); 
		  return false;
	});
	
	$('button[name=azalt]').click(function(){ 
		var shoppingCartProductID	= $(this).val();
		$.ajax({
      			type	: 'post',
      			url		: '../ajax/changeQuantityShoppingCartProduct.php',
      			data	: 'shoppingCartProductID='+shoppingCartProductID+'&changeQuantityValue=-1',
      			success	: function(data){
      			     window.location.href ='/shoppingCart';
      			}
		  });
		  return false;
	});
		

	$('#copyAddress').click(function(){
	
		if ($(this).attr('checked') == 'checked')
			$('#tadres').text($('#fadres').val());
		else
			$('#tadres').text('');
	});

	
	/* Bloklar için sola kayan slider */
	simpleSlide({ 
			}); 
			
			$('.auto-slider').each( function() {
				var related_group = $(this).attr('rel');
				window.setInterval("simpleSlideAction('.right-button', " + related_group + ");", 3000);
			});
			
			
			$('.slideshow').live('mouseover mouseout', 
				function(event) {
					if(event.type == 'mouseover'){
						$(this).children('.left-button, .right-button').stop(true, true).fadeIn();
					}
					else {
						$(this).children('.left-button, .right-button').stop(true, true).fadeOut();
					}
				}
			); 
	
	/* MEHMET SOYLU - DÜZENLEME BITTI */
	
});



