//Global Mega Options AJAX product submit with validation
//Joseph De Araujo 2010 www.alreadymade.com

$(document).ready(function() {
	$('#add_to_cart').removeAttr('onclick');
	$('#add_to_cart').click(function () {

    var submitted = $('#product :input').serialize();
    var options = {
        beforeSend:  function() { return $('#product').validate().form(); },
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#image').offset();
    		var cart  = $('#module_cart').offset();

    		$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});
	
	$('#side_add1').removeAttr('onclick');
	$('#side_add1').click(function () {

    var submitted = $('#sides1 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image1').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image1').before('<img src="' + $('#side_image1').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add2').removeAttr('onclick');
	$('#side_add2').click(function () {

    var submitted = $('#sides2 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image2').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image2').before('<img src="' + $('#side_image2').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add3').removeAttr('onclick');
	$('#side_add3').click(function () {

    var submitted = $('#sides3 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image3').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image3').before('<img src="' + $('#side_image3').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add4').removeAttr('onclick');
	$('#side_add4').click(function () {

    var submitted = $('#sides4 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image4').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image4').before('<img src="' + $('#side_image4').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add5').removeAttr('onclick');
	$('#side_add5').click(function () {

    var submitted = $('#sides5 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image5').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image5').before('<img src="' + $('#side_image5').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add6').removeAttr('onclick');
	$('#side_add6').click(function () {

    var submitted = $('#sides6 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image6').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image6').before('<img src="' + $('#side_image6').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add7').removeAttr('onclick');
	$('#side_add7').click(function () {

    var submitted = $('#sides7 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image7').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image7').before('<img src="' + $('#side_image7').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add8').removeAttr('onclick');
	$('#side_add8').click(function () {

    var submitted = $('#sides8 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image8').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image8').before('<img src="' + $('#side_image8').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add9').removeAttr('onclick');
	$('#side_add9').click(function () {

    var submitted = $('#sides9 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image9').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image9').before('<img src="' + $('#side_image9').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

	$('#side_add10').removeAttr('onclick');
	$('#side_add10').click(function () {

    var submitted = $('#sides10 :input').serialize();
    var options = {
        url:           'index.php?route=module/cart/callback',
        type:          'post',
        data:          submitted,
        datatype:      'html',
        success: function (html) {
				    $('#module_cart .middle').html(html);
		         },
    	complete: function () {
    		var image = $('#side_image10').offset();
    		var cart  = $('#module_cart').offset();

    		$('#side_image10').before('<img src="' + $('#side_image10').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

    		params = {
    			top : cart.top + 'px',
    			left : cart.left + 'px',
    			opacity : 0.0,
    			width : $('#module_cart').width(),
    			heigth : $('#module_cart').height()
    		};

    		$('#temp').animate(params, 'slow', false, function () {
    			$('#temp').remove();
    		});
    	}

    };

    $.ajax(options);

});

});
