function change_homepage_tab (li_obj, tab_type) {
	$(li_obj).parent().children().removeClass('selected');
	$(li_obj).addClass('selected');

	$('#tab_type').val(tab_type);
	$('#tab_product_id').val('0');
	$('#direction').val('0');

	$.ajax({
		type: 'POST',
		url: 'home_tab_ajax.php',
		data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=' + $('#direction').val(),
		beforeSend: function() {
			$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#home_main_module_main_center_').html(json_arr.content);
				$('#tab_product_id').val(json_arr.product_id);

				i = 1;
				if (json_arr.product3) {
					$('#home_main_module_main_focusbuttons_1').hide()
					$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
					$('#home_main_module_main_focusbuttons_2').hide()
					$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
					$('#home_main_module_main_focusbuttons_3').hide()
					$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

					$.each(json_arr.product3, function() {
						j = i-1;

						$('#home_main_module_main_focusbuttons_' + i).show();
						$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
						$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
						$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

						i++;
					});
				}

				if ($('.button_prod_' + json_arr.product_id).is('a')) {
					$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
				}
			}
		}
	});
}

function homepage_prev () {
	$('#direction').val('prev');

	$.ajax({
		type: 'POST',
		url: 'home_tab_ajax.php',
		data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=' + $('#direction').val(),
		beforeSend: function() {
			$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

			$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
			$('#home_main_module_main_center_tmp').attr('style', 'float:right;');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-left:-576px; float: right;"></div>');
				$('#home_main_module_main_center_').html(json_arr.content);

				$('#home_main_module_main_center_').ready(function() {
					$('#home_main_module_main_center_tmp').animate(
					{marginRight:'-576px'},
					'slow',
					function (i) {
						$('#home_main_module_main_center_tmp').remove();
						$('#home_main_module_main_center_').removeAttr('style');

						$('#tab_product_id').val(json_arr.product_id);

						i = 1;
						if (json_arr.product3) {
							$('#home_main_module_main_focusbuttons_1').hide()
							$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_2').hide()
							$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_3').hide()
							$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

							$.each(json_arr.product3, function() {
								j = i-1;

								$('#home_main_module_main_focusbuttons_' + i).show();
								$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
								$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
								$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

								i++;
							});
						}

						if ($('.button_prod_' + json_arr.product_id).is('a')) {
							$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
						}
					});
				});
			}
		}
	});
}

function homepage_next () {
	$('#direction').val('next');

	$.ajax({
		type: 'POST',
		url: 'home_tab_ajax.php',
		data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=' + $('#direction').val(),
		beforeSend: function() {
			$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
			$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

			$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-right:-576px;"></div>');
				$('#home_main_module_main_center_').html(json_arr.content);

				$('#home_main_module_main_center_').ready(function() {
					$('#home_main_module_main_center_tmp').animate(
					{marginLeft:'-576px'},
					'slow',
					function (i) {
						$('#home_main_module_main_center_tmp').remove();
						$('#home_main_module_main_center_').removeAttr('style');

						$('#tab_product_id').val(json_arr.product_id);

						i = 1;
						if (json_arr.product3) {
							$('#home_main_module_main_focusbuttons_1').hide()
							$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_2').hide()
							$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_3').hide()
							$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

							$.each(json_arr.product3, function() {
								j = i-1;

								$('#home_main_module_main_focusbuttons_' + i).show();
								$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
								$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
								$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

								i++;
							});
						}

						if ($('.button_prod_' + json_arr.product_id).is('a')) {
							$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
						}
					});
				});
			}
		}
	});
}

function homepage_jump (product_id, number) {
	$('#direction').val('jump');
	$('#tab_product_id').val(product_id);

	var direction = 'right';
	if ($('#home_main_module_main_focusbuttons_1').hasClass('home_main_module_main_focusbutton_sel')) {
		direction = 'left';
		if (number == 3) {
			direction = 'mega_left';
		}
	}
	if ($('#home_main_module_main_focusbuttons_2').hasClass('home_main_module_main_focusbutton_sel')) {
		if (number > 2) {
			direction = 'left';
		}
		if (number < 2) {
			direction = 'right';
		}
	}
	if ($('#home_main_module_main_focusbuttons_3').hasClass('home_main_module_main_focusbutton_sel')) {
		direction = 'right';
		if (number == 1) {
			direction = 'mega_right';
		}
	}

	if (direction == 'left') {
		$.ajax({
			type: 'POST',
			url: 'home_tab_ajax.php',
			data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=' + $('#direction').val(),
			beforeSend: function() {
				$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
				$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
				$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

				$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-right:-576px;"></div>');
					$('#home_main_module_main_center_').html(json_arr.content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_main_module_main_center_tmp').animate(
						{marginLeft:'-576px'},
						'slow',
						function (i) {
							$('#home_main_module_main_center_tmp').remove();
							$('#home_main_module_main_center_').removeAttr('style');

							$('#tab_product_id').val(json_arr.product_id);

							i = 1;
							if (json_arr.product3) {
								$('#home_main_module_main_focusbuttons_1').hide()
								$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_2').hide()
								$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_3').hide()
								$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

								$.each(json_arr.product3, function() {
									j = i-1;

									$('#home_main_module_main_focusbuttons_' + i).show();
									$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
									$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
									$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

									i++;
								});
							}

							if ($('.button_prod_' + json_arr.product_id).is('a')) {
								$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
							}
						});
					});
				}
			}
		});
	}
	else if (direction == 'mega_left') {
		$.ajax({
			type: 'POST',
			url: 'home_tab_ajax.php',
			data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=mega_next',
			beforeSend: function() {
				$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-right:-576px;"></div>');
					$('#home_main_module_main_center_').html(json_arr.middle_content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_main_module_main_center_tmp').animate(
						{marginLeft:'-576px'},
						'slow',
						function (i) {
							$('#home_main_module_main_center_tmp').remove();
							$('#home_main_module_main_center_').removeAttr('style');
							$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');

							$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-right:-576px;"></div>');
							$('#home_main_module_main_center_').html(json_arr.content);

							$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

							i = 1;
							if (json_arr.product3) {
								$('#home_main_module_main_focusbuttons_1').hide()
								$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_2').hide()
								$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_3').hide()
								$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

								$.each(json_arr.product3, function() {
									j = i-1;

									$('#home_main_module_main_focusbuttons_' + i).show();
									$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
									$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
									$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

									i++;
								});
							}

							if ($('.button_prod_' + json_arr.middle_product_id).is('a')) {
								$('.button_prod_' + json_arr.middle_product_id).addClass('home_main_module_main_focusbutton_sel');
							}

							$('#home_main_module_main_center_').ready(function() {
								$('#home_main_module_main_center_tmp').animate(
								{marginLeft:'-576px'},
								'slow',
								function (i) {
									$('#home_main_module_main_center_tmp').remove();
									$('#home_main_module_main_center_').removeAttr('style');

									$('#tab_product_id').val(json_arr.product_id);

									$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
									$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
									$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

									i = 1;
									if (json_arr.product3) {
										$('#home_main_module_main_focusbuttons_1').hide()
										$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
										$('#home_main_module_main_focusbuttons_2').hide()
										$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
										$('#home_main_module_main_focusbuttons_3').hide()
										$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

										$.each(json_arr.product3, function() {
											j = i-1;

											$('#home_main_module_main_focusbuttons_' + i).show();
											$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
											$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
											$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

											i++;
										});
									}

									if ($('.button_prod_' + json_arr.product_id).is('a')) {
										$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
									}
								});
							});
						});
					});
				}
			}
		});
	}
	else if (direction == 'mega_right') {
		$.ajax({
			type: 'POST',
			url: 'home_tab_ajax.php',
			data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=mega_prev',
			beforeSend: function() {
				$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
				$('#home_main_module_main_center_tmp').attr('style', 'float:right;');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-left:-576px; float: right;"></div>');
					$('#home_main_module_main_center_').html(json_arr.middle_content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_main_module_main_center_tmp').animate(
						{marginRight:'-576px'},
						'slow',
						function (i) {
							$('#home_main_module_main_center_tmp').remove();
							$('#home_main_module_main_center_').removeAttr('style');
							$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
							$('#home_main_module_main_center_tmp').attr('style', 'float:right;');

							$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-left:-576px; float: right;"></div>');
							$('#home_main_module_main_center_').html(json_arr.content);

							$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
							$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

							i = 1;
							if (json_arr.product3) {
								$('#home_main_module_main_focusbuttons_1').hide()
								$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_2').hide()
								$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_3').hide()
								$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

								$.each(json_arr.product3, function() {
									j = i-1;

									$('#home_main_module_main_focusbuttons_' + i).show();
									$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
									$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
									$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

									i++;
								});
							}

							if ($('.button_prod_' + json_arr.middle_product_id).is('a')) {
								$('.button_prod_' + json_arr.middle_product_id).addClass('home_main_module_main_focusbutton_sel');
							}

							$('#home_main_module_main_center_tmp').animate(
							{marginRight:'-576px'},
							'slow',
							function (i) {
								$('#home_main_module_main_center_tmp').remove();
								$('#home_main_module_main_center_').removeAttr('style');

								$('#tab_product_id').val(json_arr.product_id);

								$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

								i = 1;
								if (json_arr.product3) {
									$('#home_main_module_main_focusbuttons_1').hide()
									$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
									$('#home_main_module_main_focusbuttons_2').hide()
									$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
									$('#home_main_module_main_focusbuttons_3').hide()
									$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

									$.each(json_arr.product3, function() {
										j = i-1;

										$('#home_main_module_main_focusbuttons_' + i).show();
										$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
										$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
										$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

										i++;
									});
								}

								if ($('.button_prod_' + json_arr.product_id).is('a')) {
									$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
								}
							});
						});
					});
				}
			}
		});
	}
	else {
		$.ajax({
			type: 'POST',
			url: 'home_tab_ajax.php',
			data: 'tab_type=' + $('#tab_type').val() + '&tab_product_id=' + $('#tab_product_id').val() + '&direction=' + $('#direction').val(),
			beforeSend: function() {
				$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
				$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
				$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

				$('#home_main_module_main_center_').attr('id', 'home_main_module_main_center_tmp');
				$('#home_main_module_main_center_tmp').attr('style', 'float:right;');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_main_module_main_center_tmp').after('<div id="home_main_module_main_center_" style="margin-left:-576px; float: right;"></div>');
					$('#home_main_module_main_center_').html(json_arr.content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_main_module_main_center_tmp').animate(
						{marginRight:'-576px'},
						'slow',
						function (i) {
							$('#home_main_module_main_center_tmp').remove();
							$('#home_main_module_main_center_').removeAttr('style');

							$('#home_main_module_main_center_').html(json_arr.content);
							$('#tab_product_id').val(json_arr.product_id);

							i = 1;
							if (json_arr.product3) {
								$('#home_main_module_main_focusbuttons_1').hide()
								$('#home_main_module_main_focusbuttons_1').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_2').hide()
								$('#home_main_module_main_focusbuttons_2').removeClass('home_main_module_main_focusbutton_sel');
								$('#home_main_module_main_focusbuttons_3').hide()
								$('#home_main_module_main_focusbuttons_3').removeClass('home_main_module_main_focusbutton_sel');

								$.each(json_arr.product3, function() {
									j = i-1;

									$('#home_main_module_main_focusbuttons_' + i).show();
									$('#home_main_module_main_focusbuttons_' + i).addClass('button_prod_' + this.id);
									$('#home_main_module_main_focusbuttons_' + i).attr('onClick', 'homepage_jump(\'' + eval(this.id) + '\', \'' + i + '\'); return false;');
									$('#home_main_module_main_focusbuttons_' + i).children('.text').text(this.text);

									i++;
								});
							}

							if ($('.button_prod_' + json_arr.product_id).is('a')) {
								$('.button_prod_' + json_arr.product_id).addClass('home_main_module_main_focusbutton_sel');
							}
						});
					});
				}
			}
		});
	}
}



function best_seller_prev () {
	if (parseInt($('#start').val()) > 0) {
		$('#start').val(parseInt($('#start').val())-3);

		$.ajax({
			type: 'POST',
			url: 'best_sell_ajax.php',
			data: 'start=' + $('#start').val(),
			beforeSend: function() {
				$('#home_bestsell_module_center_').attr('id', 'home_bestsell_module_center_tmp');
				$('#home_bestsell_module_center_tmp').attr('style', 'float:right;');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_bestsell_module_center_tmp').after('<div id="home_bestsell_module_center_" style="margin-left:-614px; float: right;"></div>');
					$('#home_bestsell_module_center_').html(json_arr.content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_bestsell_module_center_tmp').animate(
						{marginRight:'-614px'},
						'slow',
						function (i) {
							$('#home_bestsell_module_center_tmp').remove();
							$('#home_bestsell_module_center_').removeAttr('style');
						});
					});
				}
			}
		});


	}
}

function best_seller_next () {
	if (parseInt($('#start').val()) < parseInt($('#total').val())-3) {
		$('#start').val(parseInt($('#start').val())+3);

		$.ajax({
			type: 'POST',
			url: 'best_sell_ajax.php',
			data: 'start=' + $('#start').val(),
			beforeSend: function() {
				$('#home_bestsell_module_center_').attr('id', 'home_bestsell_module_center_tmp');
			},
			success: function(msg){
				if(msg != '') {
					var json_arr = eval("(" + msg + ")");

					$('#home_bestsell_module_center_tmp').after('<div id="home_bestsell_module_center_" style="margin-right:-614px;"></div>');
					$('#home_bestsell_module_center_').html(json_arr.content);

					$('#home_main_module_main_center_').ready(function() {
						$('#home_bestsell_module_center_tmp').animate(
						{marginLeft:'-614px'},
						'slow',
						function (i) {
							$('#home_bestsell_module_center_tmp').remove();
							$('#home_bestsell_module_center_').removeAttr('style');
						});
					});
				}
			}
		});


	}
}




function update_cart (product_id) {
	$.ajax({
		type: 'GET',
		url: 'ajax_cart.php',
		data: 'product_id=' + product_id + '&action=update_cart',
		success: function(msg){
			$('#header_register_or_cart').html(msg);
		}
	});
}

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function update_cart_visual (product_id, buy_button) {
	$.ajax({
		type: 'GET',
		url: 'ajax_cart.php',
		data: 'product_id=' + product_id + '&action=update_cart',
		success: function(msg){
			var to_effect = '#header_register_or_cart';
			var to_effect_id = 'header_register_or_cart';
			if ($('#header_cart').is('a')) {
				to_effect = '#header_cart';
				to_effect_id = 'header_cart';
			}
			
			cart_pos = $('#' + to_effect_id).position().top;
			button_pos = $(buy_button).position().top;
			
			var pos_delta = 0;
			if (cart_pos > button_pos) {
				pos_delta = cart_pos - button_pos;
			}
			else {
				pos_delta = button_pos - cart_pos;
			}
			
			speed = 700;
			speed_plus = pos_delta * 1.5;

			$(buy_button).effect(
			'transfer',
			{
				to: to_effect, className: 'ui-effects-transfer', easing: 'linear'
			},
			speed + speed_plus,
			function () {
				$('#header_register_or_cart').html(msg);
				
				if ($('#header_cart').is('a')) {
					if ($('#cart_scrolleddown').is('input')) {
						if ($('#cart_scrolleddown').val() == 'true') {
							top_window_position = $(window).scrollTop();
							cart_pos = $('#header_register_or_cart').position().top;
			
							if (top_window_position > cart_pos) {
								$('#header_cart').addClass('scrolleddown');
							}
							else {
								$('#header_cart').removeClass('scrolleddown');
							}
						}
					}
				}
			}
			);
		}
	});
}


function show_register () {
	$('#client_not_yet').addClass('active');
	$('#client_already').removeClass('active');

	$('#coordonees_title').show();
	$('#addressdata').show();

	$('.checkout_register_error').remove();
	$('.checkout_login_error').remove();
}
function show_login () {
	$('#client_already').addClass('active');
	$('#client_not_yet').removeClass('active');

	$('#coordonees_title').hide();
	$('#addressdata').hide();

	$('.checkout_register_error').remove();
	$('.checkout_login_error').remove();
}
function checkout_login() {
	$.ajax({
		type: 'POST',
		url: 'checkout_ajax.php',
		data: 'action=login&email=' + $('#email_address').val() + '&password=' + $('#password').val(),
		beforeSend: function() {
			$('.checkout_login_error').remove();
			$('.checkout_register_error').remove();
		},
		success: function(msg){
			if (msg == 'ok') {
				$('#login').remove();
				display_checkout_full();
			}
			else {
				stackit(msg, "Erreurs");
				/*$('#login').after('<div class="checkout_login_error">' + msg + '</div>');*/
			}
		}
	});
}
function checkout_register() {
	var livraison = 0;
	if ($('#livraison').is('input:checked')) {
		livraison = 1;
	}
	var newsletter = 0;
	if ($('#newsletter').is('input:checked')) {
		newsletter = 1;
	}
	var conditions = 0;
	if ($('#conditions_val').is('input:checked')) {
		conditions = 1;
	}

	$.ajax({
		type: 'POST',
		url: 'checkout_ajax.php',
		data: 'action=register&gender=m&firstname=' + $('#firstname_val').val() + '&lastname=' + $('#lastname_val').val() + '&dob=01/02/1970&email_address=' + $('#email_val').val() + '&newsletter=' + newsletter + '&password=' + $('#pass_val').val() + '&confirmation=' + $('#pass2_val').val() + '&company=&street_address=' + $('#adresse_val').val() + '&suburb=' + $('#adresse_2_val').val() + '&postcode=' + $('#postcode_val').val() + '&city=' + $('#city_val').val() + '&country=73&telephone=' + $('#phone_val').val() + '&livraison=' + livraison + '&shipping_adresse=' + $('#shipping_adresse').val() + '&shipping_adresse_2=' + $('#shipping_adresse_2').val() + '&shipping_postcode=' + $('#shipping_postcode').val() + '&shipping_city=' + $('#shipping_city_val').val() + '&conditions=' + conditions + '&company=' + $('#company_val').val(),
		beforeSend: function() {
			$('.checkout_register_error').remove();
			$('.checkout_login_error').remove();
		},
		success: function(msg){
			if (msg == 'ok') {
				$('#login').remove();
				$('#coordonees_title').remove();
				$('#addressdata').remove();
				display_checkout_full();
			}
			else {
				stackit(msg, "Erreurs");
				/*$('#addressdata').before('<div class="checkout_register_error">' + msg + '</div>');*/
			}
		}
	});
}
function display_checkout_full () {
	$.ajax({
		type: 'POST',
		url: 'checkout_ajax.php',
		data: 'action=display_full',
		success: function(msg){
			if (msg != '') {
				$('#addressdata').remove();
				$('#cart').after(msg);
			}
			else {

			}
		}
	});
}
function display_city (postcode_input) {
	var postcode = $(postcode_input).val();
	var city = $(postcode_input).next().val();

	$.ajax({
		type: 'POST',
		url: 'postcode_ajax.php',
		data: 'postcode='  + postcode + '&fieldname=' + $(postcode_input).attr('name') + '&city=' + city,
		success: function(msg){
			$(postcode_input).next().remove();
			$(postcode_input).after(msg);
			$(postcode_input).next().focus();
		}
	});
}

function login_register() {
	var newsletter = 0;
	if ($('#newsletter').is('input:checked')) {
		newsletter = 1;
	}
	var conditions = 0;
	if ($('#conditions_val').is('input:checked')) {
		conditions = 1;
	}



	$.ajax({
		type: 'POST',
		url: 'login_ajax.php',
		data: 'action=register&gender=m&firstname=' + $('#firstname_val').val() + '&lastname=' + $('#lastname_val').val() + '&dob=01/02/1970&email_address=' + $('#email_val').val() + '&newsletter=' + newsletter + '&password=' + $('#pass_val').val() + '&confirmation=' + $('#pass2_val').val() + '&company=&street_address=' + $('#adresse_val').val() + '&suburb=' + $('#adresse_2_val').val() + '&postcode=' + $('#postcode_val').val() + '&city=' + $('#city_val').val() + '&country=73&telephone=' + $('#phone_val').val() + '&conditions='  + conditions + '&company=' + $('#company_val').val(),
		beforeSend: function() {
			$('.login_register_error').remove();
		},
		success: function(msg){
			var json_arr = eval("(" + msg + ")");

			if (json_arr['result'] == 'ok') {
				document.location = json_arr['url'];
			}
			else {
				stackit(json_arr['error'], "Erreurs");
				/*$('#addressdata').before('<div class="login_register_error">' + json_arr['error'] + '</div>');*/
			}
		}
	});
}




function prod_info1_prev () {
	$.ajax({
		type: 'POST',
		url: 'product_info_ajax.php',
		data: 'action=random&products_id=' + $('#cat_prod_1').val(),
		beforeSend: function() {
			$('#product_suggestions_1_center_').attr('id', 'product_suggestions_1_center_tmp');
			$('#product_suggestions_1_center_tmp').attr('style', 'float:right;');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#product_suggestions_1_center_tmp').after('<div id="product_suggestions_1_center_" style="margin-left:-278px; float: right;"></div>');
				$('#product_suggestions_1_center_').html(json_arr.content);

				$('#product_suggestions_1_center_').ready(function() {
					$('#product_suggestions_1_center_tmp').animate(
					{marginRight:'-278px'},
					'slow',
					function (i) {
						$('#product_suggestions_1_center_tmp').remove();
						$('#product_suggestions_1_center_').removeAttr('style');
					});
				});
			}
		}
	});
}

function prod_info1_next () {
	$.ajax({
		type: 'POST',
		url: 'product_info_ajax.php',
		data: 'action=random&products_id=' + $('#cat_prod_1').val(),
		beforeSend: function() {
			$('#product_suggestions_1_center_').attr('id', 'product_suggestions_1_center_tmp');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#product_suggestions_1_center_tmp').after('<div id="product_suggestions_1_center_" style="margin-right:-278px;"></div>');
				$('#product_suggestions_1_center_').html(json_arr.content);

				$('#product_suggestions_1_center_').ready(function() {
					$('#product_suggestions_1_center_tmp').animate(
					{marginLeft:'-278px'},
					'slow',
					function (i) {
						$('#product_suggestions_1_center_tmp').remove();
						$('#product_suggestions_1_center_').removeAttr('style');
					});
				});
			}
		}
	});
}

function prod_info2_prev () {
	$.ajax({
		type: 'POST',
		url: 'product_info_ajax.php',
		data: 'action=random&products_id=' + $('#cat_prod_2').val(),
		beforeSend: function() {
			$('#product_suggestions_2_center_').attr('id', 'product_suggestions_2_center_tmp');
			$('#product_suggestions_2_center_tmp').attr('style', 'float:right;');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#product_suggestions_2_center_tmp').after('<div id="product_suggestions_2_center_" style="margin-left:-278px; float: right;"></div>');
				$('#product_suggestions_2_center_').html(json_arr.content);

				$('#product_suggestions_2_center_').ready(function() {
					$('#product_suggestions_2_center_tmp').animate(
					{marginRight:'-278px'},
					'slow',
					function (i) {
						$('#product_suggestions_2_center_tmp').remove();
						$('#product_suggestions_2_center_').removeAttr('style');
					});
				});
			}
		}
	});
}

function prod_info2_next () {
	$.ajax({
		type: 'POST',
		url: 'product_info_ajax.php',
		data: 'action=random&products_id=' + $('#cat_prod_2').val(),
		beforeSend: function() {
			$('#product_suggestions_2_center_').attr('id', 'product_suggestions_2_center_tmp');
		},
		success: function(msg){
			if(msg != '') {
				var json_arr = eval("(" + msg + ")");

				$('#product_suggestions_2_center_tmp').after('<div id="product_suggestions_2_center_" style="margin-right:-278px;"></div>');
				$('#product_suggestions_2_center_').html(json_arr.content);

				$('#product_suggestions_2_center_').ready(function() {
					$('#product_suggestions_2_center_tmp').animate(
					{marginLeft:'-278px'},
					'slow',
					function (i) {
						$('#product_suggestions_2_center_tmp').remove();
						$('#product_suggestions_2_center_').removeAttr('style');
					});
				});
			}
		}
	});
}

function sort_avis (product_id, order) {
	$.ajax({
		type: 'POST',
		url: 'product_info_ajax.php',
		data: 'action=avis&products_id=' + product_id + '&order=' + order,
		beforeSend: function() {

		},
		success: function(msg){
			if(msg != '') {
				$('#product_main_tabs_3_content').html(msg);
			}
		}
	});
}


function fullcap(field) {
	field.value = field.value.toUpperCase();
}

function initialCap(field) {
	field.value = field.value.substr(0, 1).toUpperCase() + field.value.substr(1);
}

function open_close_note (div_obj) {


	$(div_obj).toggleClass('active');

}



function stackit(message, messagetitle){

	$("#virtpop_top_title").html(messagetitle);
	$("#virtpop_content").html(message);
	tb_show('TB', '#TB_inline?width=766&inlineId=virtpop&modal=true')

}
function stackit2() {
	tb_show('TB', '#TB_inline?width=550&inlineId=virt2pop&modal=true');
	$('#TB_window').css('margin-top','-280px');
	$('#write_avis_errors').html('');
}

function ajax_search (input_obj) {
	var word = $(input_obj).val();
	if (word.length > 2) {
		$.ajax({
			type: 'POST',
			url: 'search_ajax.php',
			data: 'keywords=' + word,
			success: function(msg){
				if(msg != '') {
					$('#search_world_complete').html(msg);
					$('#search_world_complete').show();
					$('body').click(function (i) {
						$('#search_world_complete').fadeOut('slow');
						$('body').unbind('click');
					});
				}
				else {
					$('#search_world_complete').fadeOut('slow');
				}
			}
		});
	}
}

var avis_msg = '';
function write_avis_submit () {
	var rating = $('#rating').val();
	var comment = $('#avis_comment').val();
	var firstname = $('#avis_firstname').val();
	var lastname = $('#avis_lastname').val();
	var products_id = $('#avis_product_id').val();
	var region = $('#avis_region').val();

	$.ajax({
		type: 'POST',
		url: 'avis_write_ajax.php',
		data: 'rating=' + rating + '&comment=' + comment + '&products_id=' + products_id + '&firstname=' + firstname + '&lastname=' + lastname + '&region=' + region,
		beforeSend: function () {
			$('#write_avis_errors').html('');
		},
		success: function(msg){
			if(msg != '') {
				if (msg == 'OK') {
					$('#rating').val('0');
					$('#avis_comment').val('');
					$('#avis_firstname').val('');
					$('#avis_lastname').val('');
					$('div.write_avis_stars_center').children().each(function (i) {
						$(this).removeClass('write_avis_star_on');
						$(this).addClass('write_avis_star_off');
					});

					$.ajax({
						type: 'POST',
						url: 'product_info_ajax.php',
						data: 'action=avis&products_id=' + products_id + '&order=desc',
						beforeSend: function() {

						},
						success: function(msg){
							if(msg != '') {
								tb_remove();
								$('#product_main_tabs_3_content').html(msg);
							}
						}
					});
				}
				else {
					$('#write_avis_errors').html('<ul>' + msg + '</ul>');
					//avis_msg = msg;
					//tb_remove();
					//setTimeout("stackit(avis_msg, 'Erreur')",1000);
				}
			}
		}
	});
}

function set_avis_rating(rating) {
	$('#rating').val(rating);

	$('div.write_avis_stars_center').children().each(function (i) {
		$(this).removeClass('write_avis_star_off');
		$(this).removeClass('write_avis_star_on');

		if (i < rating) {
			$(this).addClass('write_avis_star_on');
		}
		else {
			$(this).addClass('write_avis_star_off');
		}
	})
}

function view_avis_rating_on(rating) {
	$('div.write_avis_stars_center').children().each(function (i) {
		$(this).removeClass('write_avis_star_off');
		$(this).removeClass('write_avis_star_on');

		if (i < rating) {
			$(this).addClass('write_avis_star_on');
		}
		else {
			$(this).addClass('write_avis_star_off');
		}
	})
}
function view_avis_rating_out() {
	rating = $('#rating').val();

	$('div.write_avis_stars_center').children().each(function (i) {
		$(this).removeClass('write_avis_star_off');
		$(this).removeClass('write_avis_star_on');

		if (i < rating) {
			$(this).addClass('write_avis_star_on');
		}
		else {
			$(this).addClass('write_avis_star_off');
		}
	})
}

$(document).ready(function(){
	if ($('#write_avis_flag').is('div')) {
		$('#product_main_tabs_3 a').click();
	}
});



function display_step4 () {
	step2 = $('input[name="step2"]:checked').val();
	step3 = $('input[name="step3"]:checked').val();
	$('.step4_' + step2 + '_' + step3).show();
}


$(document).ready(function(){
	$('#mainmenu_1').hover(function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeIn();
	}, function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeOut();
	});

	$('#mainmenu_2').hover(function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeIn();
	}, function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeOut();
	});

	$('#mainmenu_3').hover(function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeIn();
	}, function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeOut();
	});

	$('#mainmenu_4').hover(function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeIn();
	}, function(){
		$(this).children('dl').children('dd').children('div.panel_').fadeOut();
	});
});


function shopping_cart_submit () {
	var param_str = $('#cart_quantity').serialize();

	$.ajax({
		type: 'GET',
		url: 'checkout_ajax.php',
		data: param_str,
		success: function(msg){
			if (msg.search('shopping_cart.html') >= 0) {
				document.location = msg;
			}
			else {
				var json_arr = eval("(" + msg + ")");
				if (json_arr.cart) {
					$('#cart').html(json_arr.cart);
				}
				if (json_arr.summup) {
					$('#summup').html(json_arr.summup);
				}
				if (json_arr.payment) {
					$('#payment').html(json_arr.payment);

					if (json_arr.payment == 'hide') {
						$('#payment_choice').hide();
						$('#payment').hide();
					}
					else {
						$('#payment_choice').show();
						$('#payment').show();
					}
				}
				if (json_arr.top_cart) {
					$('#header_register_or_cart').html(json_arr.top_cart);
				}
			}
		}
	});
}
function shopping_cart_remove (product_id) {
	$('input[name^=products_id]').remove();
	$('input[name^=cart_quantity]').remove();
	$('#cart_quantity').prepend('<input type="hidden" name="cart_delete" value="1" /><input type="hidden" name="products_id" value="' + product_id + '" />');
	shopping_cart_submit();
}

function save_checkout_comment (textarea_obj) {
	comment = $(textarea_obj).val();

	$.ajax({
		type: 'POST',
		url: 'checkout_ajax.php',
		data: 'action=save_comment&comment=' + comment,
		success: function(msg){

		}
	});
}


function checkout_display_change_shipping () {
	/*
	$('#recapitulatif_title').hide();
	$('#summup').hide();
	$('#change_shipping_link').hide();
	$('#order_comments').hide();
	$('#payment_choice').hide();
	$('#payment').hide();
	*/

	$('#addressdata').show();
}

function checkout_change_shipping () {
	$.ajax({
		type: 'POST',
		url: 'checkout_ajax.php',
		data: 'action=change_shipping&shipping_adresse=' + $('#shipping_adresse').val() + '&shipping_adresse_2=' + $('#shipping_adresse_2').val() + '&shipping_postcode=' + $('#shipping_postcode').val() + '&shipping_city=' + $('#shipping_city_val').val() + '&lastname=' + $('#lastname_val').val() + '&firstname=' + $('#firstname_val').val(),
		beforeSend: function() {
			$('.checkout_register_error').remove();
			$('.checkout_login_error').remove();
		},
		success: function(msg){
			var json_arr = eval("(" + msg + ")");

			if (json_arr.result == 'success') {
				$('#addressdata').hide();

				if (json_arr.sendto) {
					$('#summup_box_content_address').html(json_arr.sendto);
				}
				
				/*
				$('#recapitulatif_title').show();
				$('#summup').show();
				$('#change_shipping_link').show();
				$('#order_comments').show();
				$('#payment_choice').show();
				$('#payment').show();
				*/

				$('#shipping_adresse').val('Rue');
				$('#shipping_adresse_2').val('Complement (optionnel)');
				$('#shipping_city_val').val('Ville');
				$('#shipping_postcode').val('Code Postal');
			}
			else {
				stackit(json_arr.error, "Erreurs");
				/*$('#addressdata').before('<div class="checkout_register_error">' + msg + '</div>');*/
			}
		}
	});
}


$(document).ready(function(){
	if ($('#header_cart').is('a')) {
		if ($('#cart_scrolleddown').is('input')) {
			if ($('#cart_scrolleddown').val() == 'true') {
				top_window_position = $(window).scrollTop();
				cart_pos = $('#header_register_or_cart').position().top;

				if (top_window_position > cart_pos) {
					$('#header_cart').addClass('scrolleddown');
				}
				else {
					$('#header_cart').removeClass('scrolleddown');
				}
			}
		}
	}

	$(window).scroll(function () {
		if ($('#header_cart').is('a')) {
			if ($('#cart_scrolleddown').is('input')) {
				if ($('#cart_scrolleddown').val() == 'true') {
					top_window_position = $(window).scrollTop();
					cart_pos = $('#header_register_or_cart').position().top;

					if (top_window_position > cart_pos) {
						$('#header_cart').addClass('scrolleddown');
					}
					else {
						$('#header_cart').removeClass('scrolleddown');
					}
				}
			}
		}
	});
	

	add_focus_to_input();
});

function add_focus_to_input () {
	if ($('#addressdata').is('div')) {
		$('#addressdata').find('input[type="text"], input[type="password"]').focus(function () {
			$(this).addClass('input_black');
		});
	}
	if ($('#account_edit').is('div')) {
		$('#account_edit').find('input[type="text"], input[type="password"]').focus(function () {
			$(this).addClass('input_black');
		});
	}
	if ($('#pass_edit_').is('div')) {
		$('#pass_edit_').find('input[type="text"], input[type="password"]').focus(function () {
			$(this).addClass('input_black');
		});
	}
}

function close_cart_and_remember () {
	$('#header_cart').removeClass('scrolleddown');

	$.ajax({
		type: 'GET',
		url: 'ajax_cart.php',
		data: 'action=close_and_remember'
	});
	
	if ($('#cart_scrolleddown').is('input')) {
		$('#cart_scrolleddown').val('false');
	}
}