/**
 * 
 */

		var outletMoveFlag = false;
		var nowOutletPosInt = 0;
		var outletPicLength = 10;
		
		var nextOutletCheck = 'outlet';
		
		var outletList = {};
		
		$(document).ready(function() {
			//Size Buttom Event
			$('div#outlet_sizeBtn').bind('mouseenter', function() {
				$('#outlet_sizeBtnOn').fadeIn(300);
				outlet_sizeBtnClickHandler(false);
			});
			$('div#outlet_sizeBtn').bind('mouseleave', function() {
				$('#outlet_sizeBtnOn').fadeOut(300);
				outlet_sizeBtnClickHandler(true);
			});
			//Color Buttom Event
			$('div#outlet_colorBtn').bind('mouseenter', function() {
				$('#outlet_colorBtnOn').fadeIn(300);
				outlet_colorBtnClickHandler(false);
			});
			$('div#outlet_colorBtn').bind('mouseleave', function() {
				$('#outlet_colorBtnOn').fadeOut(300);
				outlet_colorBtnClickHandler(true);
			});
			//Brand Buttom Event
			$('div#outlet_wishBtn').bind('mouseenter', function() {
				$('#outlet_wishBtnOn').fadeIn(300);
				outlet_wishBtnClickHandler(false);
			});
			$('div#outlet_wishBtn').bind('mouseleave', function() {
				$('#outlet_wishBtnOn').fadeOut(300);
				outlet_wishBtnClickHandler(true);
			});
			
			$('#outlet-container #exit_outlet_btn_ro').bind('click', function() {
				leftOutletBtnClickHandler();
			});
			
			$('#checkout-container #exit_outlet_btn_ro').bind('click', function() {
				leftOutletBtnClickHandler();
			});
			
			genUnwishList();
			//getOutlet();
			
		});
		
		function gen_outlet_information() {
			if (window.location.hash != "") {
				$.getJSON('./json/gen_shoping_cart.json.php', function(data) {
					if (data.ShippingInfo !== undefined) {
						$('#bill_fullName').html(data.ShippingInfo.fullName);
						$('#bill_address').html(data.ShippingInfo.address);
						$('#bill_city').html(data.ShippingInfo.city);
						$('#bill_zip').html(data.ShippingInfo.zip);
						$('#bill_state').html(data.ShippingInfo.state);
						$('#bill_country').html(data.ShippingInfo.country);
						$('#bill_contactno').html(data.ShippingInfo.contactno);
						$('#bill_email').html(data.ShippingInfo.email);
					}
				});
				
				$.get('./gen_content/gen_cart_row.php', {shop_mode:"outlet"}, function(data) {
					
					//store
					$('div#outlet_table_div').html(data);
					$("div#outlet_table_div img.store_remove_btn").unbind();
					$("div#outlet_table_div img.store_remove_btn").click(function () {
						removeFromOutlet(this);
					});
					if ($('#outlet_table_div table.cart_row').length > 8) {
						$('#outlet_table_div').css('height', '264px');
						$('#outlet_arrow').css('display', 'block');
					} else {
						$('#outlet_table_div').css('height', 'auto');
						$('#outlet_arrow').css('display', 'none');
					}
					//checkout
					$('div#checkout_table_div').html(data);
					$("div#checkout_table_div img.store_remove_btn").unbind();
					$("div#checkout_table_div img.store_remove_btn").click(function () {
						removeFromOutletCheckout(this);
					});
					if ($('#checkout_table_div table.cart_row').length > 8) {
						$('#checkout_table_div').css('height', '264px');
						$('#checkout_arrow').css('display', 'block');
					} else {
						$('#checkout_table_div').css('height', 'auto');
						$('#checkout_arrow').css('display', 'none');
					}
					
					calOutletTotalPrice();
					//update total price
					//getOutletSubTotal();
					//getOutletShippingFee();
					//getOutletTotal();
				});
			}
		}
		
		
		function genUnwishList() {
			
			$.getJSON("./json/get_unwishlist.json.php",
			  {
				action: "unwishlist"
			  },
			  function(data) {
				  if (data.unwish.length > 0) {
					  $.each(data.unwish, function(i, getUnwish) {
						  if (getUnwish.blnChecked) {
							  $('#un_'+getUnwish.outletUnwishCategoryId).attr('checked', true);
							  $('#un_'+getUnwish.outletUnwishCategoryId).dgCheck('#un_span_'+getUnwish.outletUnwishCategoryId);
							  //alert('checked: ' + getUnwish.outletUnwishCategoryId);
						  } else {
							  $('#un_'+getUnwish.outletUnwishCategoryId).attr('checked', false);
							  $('#un_'+getUnwish.outletUnwishCategoryId).dgUncheck('#un_span_'+getUnwish.outletUnwishCategoryId);
							  //alert('unchecked: ' + getUnwish.outletUnwishCategoryId);
						  }
						  
					});
				  }
			  });
						
		}
		
		function update_unwishlist() {
			
			var total_wish = $('input[name="wish"]').length;
			
			var unwish_data = [];
			$.each($('input[name="wish"]:checked'), function() {
				unwish_data.push($(this).val()); 
			});
		
			$.post("./json/update_unwish.json.php", {unwish_data: unwish_data});
			
		}
		
		function getOutlet() {
			
			outletList = {};
			
			for(oo = 1;oo<=5;oo++) {
				$('#outlet_th_'+oo).css('display', 'none');	
			}
			
			$('#outlet_productText_open #desc').html('');
			$('#outlet_productText_open #price').html('');
			$('#outlet_size_ul li').remove();
			$('#outlet_color_ul li').remove();
			
			$('#outletHint1_open').css('display', 'none');
			
			$('#outlet_img_slide').css('display', 'none');
			
			$.getJSON("./json/get_outlet.json.php",
			  {
				action: "getOutlet"
			  },
			  function(data) {
				  if (data.outlets.length > 0) {
					  //alert(data.outlets.length);
					  $('#outlet_img_slide').css('display', 'block');
					  addNewOutlet(data.outlets);
					  if (data.outlets[0] !== undefined) {
						  genOutletContent(0, data.outlets);
						  $('#outlet_th_1').attr('src', 'outlet/m/'+data.outlets[0].colorlist[0].thumbnailPath);
						  $('#outlet_th_1').css('display', 'block');
					  } else {
						  $('#outlet_th_1').css('display', 'none');
					  }
					  if (data.outlets[1] !== undefined) {
						  $('#outlet_th_2').attr('src', 'outlet/m/'+data.outlets[1].colorlist[0].thumbnailPath);
						  $('#outlet_th_2').css('display', 'block');
					  } else {
						  $('#outlet_th_2').css('display', 'none');
					  }
					  if (data.outlets[2] !== undefined) {
						  $('#outlet_th_3').attr('src', 'outlet/m/'+data.outlets[2].colorlist[0].thumbnailPath);
						  $('#outlet_th_3').css('display', 'block');
					  } else {
						  $('#outlet_th_3').css('display', 'none');
					  }
					  if (data.outlets[3] !== undefined) {
						  $('#outlet_th_4').attr('src', 'outlet/m/'+data.outlets[3].colorlist[0].thumbnailPath);
						  $('#outlet_th_4').css('display', 'block');
					  } else {
						  $('#outlet_th_4').css('display', 'none');
					  }
					  if (data.outlets[4] !== undefined) {
						  $('#outlet_th_5').attr('src', 'outlet/m/'+data.outlets[4].colorlist[0].thumbnailPath);
						  $('#outlet_th_5').css('display', 'block');
					  } else {
						  $('#outlet_th_5').css('display', 'none');
					  }
				  } else {
					$('#outletHint1_open').css('display', 'block');
				  }
			  });
						
		}
		
		function genOutletContent(i, outlet) {
			  $('#outlet_img_slide #outlet_centerPicContainer #outlet_centerPic').attr('src', 'outlet/'+outlet[i].colorlist[0].imagePath);
			  $('#outlet_productText_open #desc').html(outlet[i].description);
			  $('#outlet_productText_open #price').html("HK $ "+outlet[i].price);
			  $('#current_outletId').val(outlet[i].outletId);
			  $('#outlet_size_ul li').remove();
			  if (outlet[i].sizelist.length > 0) {
				  var maxsize = outlet[i].sizelist.length - 1;
				  $.each(outlet[i].sizelist, function(i,size){
					  if (i < maxsize) {
						  $('#outlet_size_ul').append('<li class="clearfix"><span class="radio" style="width:19px;"><input type="radio" value="'+size.outletSizeId+'" name="size"></span><label>'+size.name+'</label></li>');
					  } else {
						  $('#outlet_size_ul').append('<li class="last clearfix"><span class="radio" style="width:19px;"><input type="radio" value="'+size.outletSizeId+'" name="size"></span><label>'+size.name+'</label></li>');
					  }
				  });
				  $("#outlet_size_ul .radio").dgStyle();
			  }
			  $('#outlet_color_ul li').remove();
			  if (outlet[i].colorlist.length > 0) {
				  var maxcolor = outlet[i].colorlist.length - 1;
				  $.each(outlet[i].colorlist, function(i,color){
					  if (i < maxcolor) {
						  $('#outlet_color_ul').append('<li><span class="radio" style="width:19px;"><input type="radio" value="'+color.outletColorId+'" name="color"></span><label>'+color.name+'</label></li>');
					  } else {
						  $('#outlet_color_ul').append('<li class="last"><span class="radio" style="width:19px;"><input type="radio" value="'+color.outletColorId+'" name="color"></span><label>'+color.name+'</label></li>');
					  }
				  });
				  $("#outlet_color_ul .radio").dgStyle();
					$('#outlet_color_ul .radio').bind('click', function() {
						var getIndex = $('#outlet_color_ul .radio').index(this);
						$('#outlet_img_slide #outlet_centerPicContainer').fadeOut(300, function() {
							$('#outlet_img_slide #outlet_centerPicContainer #outlet_centerPic').attr('src', 'outlet/'+outlet[i].colorlist[getIndex].imagePath);
							$('#outlet_img_slide #outlet_centerPicContainer').fadeIn(300);
						});
					});
			  }
			$('#outlet_centerPic').fadeIn(0, function(){
				var minusX = -480;
				
				$('#outlet_centerPicContainer').animate({'left': '0'}, 1);
				$('#outlet_otherPicContainer').animate({'left': minusX + "px"}, 1);
				
//				document.getElementById("centerPicContainer").style.left = "0";
//				document.getElementById("otherPicContainer").style.left = minusX + "px";
				
				$('#outlet_productText_open').fadeIn(300);
			});
		}
		
		function addNewOutlet(data) {
			outletList = data;
		}
		
		//-------------------------------photoSlide--------------------------------
		var nowOutletPicMoveType = "next";
		function nextOutletBtnClickHandler(){
			
			$('#outlet_sizeBtn').animate({top: '558px', height: '23px'}, 200);
			$('#outlet_colorBtn').animate({top: '558px', height: '23px'}, 200);
			$('#outlet_wishBtn').animate({top:'16px', height: '23px'}, 200);

			
			if (outletList.length > 1) {
			
				if ($('#outletHint1_open').css('display') == 'block') {
				  $('#outletHint1_open').fadeOut(300);
				}
				
				if ( !outletMoveFlag ){
					outletMoveFlag = true;
					nowOutletPosInt++;
					if (nowOutletPosInt > outletList.length - 1){
						nowOutletPosInt = 0;
					}
					
					divHidden('#outlet_productText_open');
					
					nowOutletPicMoveType = "prev";
					picOutletLoadHandler();
				}
				
			}
		}
		
		
		function prevOutletBtnClickHandler(){
			
			$('#outlet_sizeBtn').animate({top: '558px', height: '23px'}, 200);
			$('#outlet_colorBtn').animate({top: '558px', height: '23px'}, 200);
			$('#outlet_wishBtn').animate({top:'16px', height: '23px'}, 200);

			if (outletList.length > 1) {
				if ($('#outletHint1_open').css('display') == 'block') {
				  $('#outletHint1_open').fadeOut(300);
				}
				
				if (!outletMoveFlag){
					outletMoveFlag = true;
					nowOutletPosInt--;
					if (nowOutletPosInt < 0){
						nowOutletPosInt = outletList.length - 1;
					}
	
					divHidden('#outlet_productText_open');
	
					nowOutletPicMoveType = "next";
					picOutletLoadHandler();
				}
			}
		}
		
		
		var nextOutletPositionInt = 0;
		var prevOutlerPositionInt = 0;
		var loadImgOutletChecSetInterval;
		function picOutletLoadHandler(){
			
			clearInterval( loadImgOutletChecSetInterval );
			
			if (nowOutletPicMoveType == "next"){
				nextOutletPositionInt = nowOutletPosInt;
				if( prevOutlerPositionInt > outletList.length - 1 ){
					nextOutletPositionInt = outletList.length + nextOutletPositionInt;
				}
								
				document.getElementById("outlet_otherPic").setAttribute("src", 'outlet/'+outletList[nextOutletPositionInt].colorlist[0].imagePath);
				if (document.getElementById("outlet_otherPic").complete == true) {
					picOutletMoveHandler();
				} else {
					loadImgOutletChecSetInterval = setInterval( picOutletLoadHandler, 500 );
				}
				
			}else{
				
				prevOutlerPositionInt = nowOutletPosInt;
				if( nextOutletPositionInt < 0 ){
					prevOutlerPositionInt = prevOutlerPositionInt - outletList.length;
				}
				
				document.getElementById("outlet_otherPic").setAttribute("src", 'outlet/'+outletList[prevOutlerPositionInt].colorlist[0].imagePath);
				if (document.getElementById("outlet_otherPic").complete == true) {
					picOutletMoveHandler();
				} else {
					loadImgOutletChecSetInterval = setInterval( picOutletLoadHandler, 500 );
				}
				
			}
		}
		
		var picOutletMoveSetIntervalHandler;
		function picOutletMoveHandler(){
			var plusX = 480;
			var minusX = -480;
			
			if (nowOutletPicMoveType == "next") {
				$('#outlet_centerPicContainer').animate({left: String( plusX ) + 'px'}, 500);
				
				document.getElementById("outlet_otherPicContainer").style.left = String( minusX ) + "px";
				$('#outlet_otherPicContainer').animate({left: '0'}, 500, function(){
					document.getElementById("outlet_centerPic").setAttribute("src", '');														   
				});
				
				picOutletMoveSetIntervalHandler = setInterval( picOutletMoveCompHandler, 600 );
			}else{
				
				$('#outlet_centerPicContainer').animate({left: String( minusX ) + 'px'}, 500);
				
				document.getElementById("outlet_otherPicContainer").style.left = String( plusX ) + "px";
				$('#outlet_otherPicContainer').animate({left: '0'}, 500, function(){
					document.getElementById("outlet_centerPic").setAttribute("src", '');														   
				});
				
				picOutletMoveSetIntervalHandler = setInterval( picOutletMoveCompHandler, 600 );
			}
		}
		
		function picOutletMoveCompHandler(){
			
			$('#outlet_centerPic').fadeIn(0);
			
			clearInterval( picOutletMoveSetIntervalHandler );
			outletMoveFlag = false;
				
			/*var minusX = -480;
			
			document.getElementById("outlet_centerPicContainer").style.left = "0";
			document.getElementById("outlet_otherPicContainer").style.left = minusX + "px";*/
			
			genOutletContent(nowOutletPosInt, outletList);
			
			divShow('#outlet_productText_open');
			
			document.getElementById("outlet_centerPic").setAttribute("src", 'outlet/'+outletList[nowOutletPosInt].colorlist[0].imagePath);
	
			/*if (nowOutletPicMoveType == "next") {
				document.getElementById("outlet_centerPic").setAttribute("src", 'outlet/'+outletList[nowOutletPosInt].colorlist[0].imagePath);
			}else{
				document.getElementById("outlet_centerPic").setAttribute("src", 'outlet/'+outletList[nowOutletPosInt].colorlist[0].imagePath);
			}*/
		}


		//-------------------------------leftOutletBtnClickHandler--------------------------------
		
	function getUnwishList() {
		
		var data = { 'wish[]' : []};
		$('input[name="wish"]:checked').each(function() {
		  data['wish[]'].push($(this).val());
		});
		$.post("./json/get_outlet_unwish_check.json.php?action=updateUnwish", data);
		
	}
	
	function check_empty_outlet_cart() {
		
		if ($('#outlet_table_div table.cart_row').length > 0) {
			processCheckOutOutletBtnClickHandler();
		}
		
		return false;
	}
		
	var processCheckOutOutletContainerMoveSetIntervalHandler;
	function processCheckOutOutletBtnClickHandler() {
		if (outletMoveFlag == false) {
			outletMoveFlag = true;
			
			nowSituation = 'checkout';
			nextOutletCheck = 'checkout';
			
			window.location = '#checkout';
			
			getUnwishList();
									
			$('#outlet-confirm-container').animate({
				top: '-600px'
			}, 500);
			$('#outlet-container').animate({
				top: '-600px'
			}, 500);
			processCheckOutOutletContainerMoveSetIntervalHandler = setInterval(processCheckOutOutletContainerFadeOutCompHandler, 900);
		}
	}
	
	
	function processCheckOutOutletContainerFadeOutCompHandler() {
		
		clearInterval( processCheckOutOutletContainerMoveSetIntervalHandler );
		document.getElementById( "outlet-confirm-container" ).style.display = "none";
		document.getElementById( "outlet-container" ).style.display = "none";
		
		$('#acc_for_store').css('display', 'none');
		$('#acc_for_outlet').css('display', 'block');
		
		//about
		document.getElementById( "checkout-container" ).style.top = String( -620 ) + "px";
		document.getElementById( "checkout-container" ).style.display = "block";
		var stageHeight = document.documentElement.clientHeight;
		var containerY = ( stageHeight - 600) / 2;
		$('#checkout-container').animate({top: containerY + 'px' }, 500);
		processCheckOutOutletContainerMoveSetIntervalHandler = setInterval(processCheckOutOutletContainerFadeInCompHandler, 510);
	}
	
	
	function processCheckOutOutletContainerFadeInCompHandler() {
		outletMoveFlag = false;

		clearInterval( processCheckOutOutletContainerMoveSetIntervalHandler );
		clearInterval( outletTimer );
		mins = 5;
		seconds = 0;
	}
	

		//-------------------------------leftOutletBtnClickHandler--------------------------------
		
	var leftOutletContainerMoveSetIntervalHandler;
	function leftOutletBtnClickHandler(){		
		if (outletMoveFlag == false) {
			outletMoveFlag = true;
			
			$('#storeBtn').fadeIn(300);
			$('#aboutBtn').fadeIn(300);
			//$('#supportBtn').fadeIn(300);
			$('#contactBtn').fadeIn(300);

			$('#outlet-messageBox').fadeOut(300);
			
			$('#checkout-container #terms_btn').css('display', 'block');
			$('#checkout-container #privacy_btn').css('display', 'block');
			$('#checkout-container #returns_btn').css('display', 'block');
			$('#checkout-container #terms_btn_ro').css('display', 'none');
			$('#checkout-container #privacy_btn_ro').css('display', 'none');
			$('#checkout-container #returns_btn_ro').css('display', 'none');
			
			if (nowSituation == "store" || nowSituation == "checkout" || nowSituation == "about" || nowSituation == "support" || nowSituation == "contact") {
				if (nowSituation == "checkout") {
					$('#store-title').fadeOut(300);
					$('#storeBtn').delay(300).animate({width: '40px',right: '545px'}, 200);
				}
				if (nowSituation != "checkout") {
					$('#'+nowSituation+'-title').fadeOut(300);
					$('#'+nowSituation+'Btn').delay(300).animate({width: '40px',right: '545px'}, 200);
				}
			}
			
			if(nextOutletCheck == 'outlet') {
				var stageHeight = document.documentElement.clientHeight;
				$('#outlet-confirm-container').animate({
					top: '-'+stageHeight+'px'
				}, 500);
				$('#outlet-container').animate({
					top: '-600px'
				}, 500);
			} else {
				if(nextOutletCheck == 'checkout') {
					$('#checkout-container').animate({
						top: '-600px'
					}, 500);
				}
			}
			leftOutletContainerMoveSetIntervalHandler = setInterval(leftOutletContainerFadeOutCompHandler, 900);
		}
	}
	
	
	function leftOutletContainerFadeOutCompHandler(){
		
		$('#'+nowSituation+'-container #terms_brn_ro').css('display', 'none');
		$('#'+nowSituation+'-container #privacy_brn_ro').css('display', 'none');
		$('#'+nowSituation+'-container #returns_brn_ro').css('display', 'none');
		
		clearInterval( leftOutletContainerMoveSetIntervalHandler );
		
		if(nextOutletCheck == 'outlet') {
			document.getElementById( "outlet-confirm-container" ).style.display = "none";
			document.getElementById( "outlet-container" ).style.display = "none";
		} else {
			document.getElementById( "checkout-container" ).style.display = "none";
		}
		
		if (nowSituation=='checkout') {
			nowSituation = 'store';
		}
		
		gen_information();
		update_unwishlist();
		
		document.getElementById( nowSituation+"-container" ).style.top = String( -620 ) + "px";
		document.getElementById( nowSituation+"-container" ).style.display = "block";
		var stageHeight = document.documentElement.clientHeight;
		var containerY = ( stageHeight - 600) / 2;
		$('#'+nowSituation+'-container').animate({top: containerY + 'px' }, 500);
		leftOutletContainerMoveSetIntervalHandler = setInterval(leftOutletContainerFadeInCompHandler, 510);
	}
	
	
	function leftOutletContainerFadeInCompHandler(){
		outletMoveFlag = false;

		clearInterval( leftOutletContainerMoveSetIntervalHandler );
		clearInterval(outletTimer);

		//reset timer
		mins = 5;
		seconds = 0;
		$('#outlet-timer-box').html('time left: '+ mins+":0"+seconds);

		if (nowSituation == "store" || nowSituation == "checkout" || nowSituation == "about" || nowSituation == "support" || nowSituation == "contact") {
			if (nowSituation == "checkout") {
				$('#storeBtn .grey-btn').css('display','none');
				$('#storeBtn .white-btn').css('display','block');
				$('#storeBtn').animate({right: '465px', width: '120px'}, 200);
				$('#w-store-title').fadeIn(300);
			}
			
			if (nowSituation == "store" || nowSituation == "checkout" || nowSituation == "support") {
				accInit();
			}
			
			if (nowSituation != "checkout") {
				$('#'+nowSituation+'Btn .grey-btn').css('display','none');
				$('#'+nowSituation+'Btn .white-btn').css('display','block');
				$('#'+nowSituation+'Btn').animate({right: '465px', width: '120px'}, 200);
				$('#w-'+nowSituation+'-title').fadeIn(300);
			}
			if (nowSituation == "support") {
				liveTimer = setInterval(genLiveSupport, totalWaitLiveTime);
			} else {
				genLiveSupport();
			}
		}
	}
	

		
		//-------------------------------confirmOutletBtnClickHandler--------------------------------
		function confirmOutletBtnClickHandler(){
			$('#outlet-confirm-container').fadeOut(300);
			$('#outlet-messageBox').fadeOut(300);
			//$.get('./json/update_outlet_accesstime.json.php', {action:"updateAccessTime"});
			outletTimer = setInterval(timer, 1000);
		}
		
		var outletTimer;
		 function timer() { 
			if (seconds != 0) {
				 seconds--;
			} else {
				if (mins != 0) {
					seconds = 59;
					mins--;
				} else {
					if (seconds != 0) {
						seconds--;
					} 
				}
			}
			if (seconds < 10) {
				$('#outlet-timer-box').html('time left: '+ mins+":0"+seconds);
			} else {
				$('#outlet-timer-box').html('time left: '+ mins+":"+seconds);
			}
			if (mins == 0 && seconds == 0) {
				clearInterval(outletTimer);
				leftOutletBtnClickHandler();
			}
		 }
	
		
		
		//-------------------------------outlet_wishBtnClickHandler--------------------------------
		
		var outlet_wishBtnOpened = false;
		function outlet_wishBtnClickHandler(outlet_wishBtnFlag){
			var getTotal = $('#outlet_wishBtn li').length;
			if (outlet_wishBtnFlag == false) {
				var totalHeight = String((getTotal * 20) + 23);
				if (!outlet_wishBtnOpened) {
					$('#outlet_wishBtn').animate({
						top: '16px',
						height: totalHeight + 'px'
					}, (getTotal * 100), function(){outlet_wishBtnOpened=true;});
				}
			} else{
				if (outlet_wishBtnOpened) {
					$('#outlet_wishBtn').animate({
						top:'16px',
						height: '23px'
					}, (getTotal * 100), function() {outlet_wishBtnOpened = false;});
				}
			}
		}
		
		
		//-------------------------------outlet_sizeBtnClickHandler--------------------------------
		
		var outlet_sizeBtnOpened = false;
		function outlet_sizeBtnClickHandler(outlet_sizeBtnFlag){
			if (!outletMoveFlag) {
				var getTotal = $('#outlet_size_ul li').length;
				if (outlet_sizeBtnFlag == false) {
					var totalHeight = String((getTotal * 20) + 23);
					var totalTop = String(558 - (getTotal * 20));
					if (!outlet_sizeBtnOpened) {
						$('#outlet_sizeBtn').animate({
							top: totalTop + 'px',
							height: totalHeight + 'px'
						}, (getTotal * 100), function(){outlet_sizeBtnOpened=true;});
					}
				} else{
					if (outlet_sizeBtnOpened) {
						$('#outlet_sizeBtn').animate({
							top: '558px',
							height: '23px'
						}, (getTotal * 100), function() {outlet_sizeBtnOpened = false;});
					}
				}
			}
		}
		
		
		
		//-------------------------------outlet_colorBtnClickHandler--------------------------------
		
		var outlet_colorBtnOpened = false;
		function outlet_colorBtnClickHandler(outlet_colorBtnFlag){
			if (!outletMoveFlag) {
				if (outlet_colorBtnFlag == false) {
					var getTotal = $('#outlet_color_ul li').length;
					var totalHeight = String((getTotal * 20) + 23);
					var totalTop = String(558 - (getTotal * 20));
					if (!outlet_colorBtnOpened) {
						$('#outlet_colorBtn').animate({
							top: totalTop + 'px',
							height: totalHeight + 'px'
						}, 200, function(){outlet_colorBtnOpened=true;});
					}
				} else{
					if (outlet_colorBtnOpened) {
						$('#outlet_colorBtn').animate({
							top: '558px',
							height: '23px'
						}, 200, function() {outlet_colorBtnOpened = false;});
					}
				}
			}
		}
		
		
		//---------------------------add_to_cart---------------------------------------------
		
		function addToOutletHandler() {
			
			if (!outletMoveFlag) {
			
				outletMoveFlag = true;
				var blnSuccess = true;
				
				if (outletList.length > 0) {
					if ($('#outlet_color_ul input[name="color"]:checked').val() === undefined && $('#outlet_size_ul input[name="size"]:checked').val() === undefined) {
						  if ($('#outletHint1_open').css('display') == 'block') {
							  $('#outletHint1_open').fadeOut(300);
						  }
						  $('#outletHint1_open img').attr('src', 'img/store/cho_size_color.gif');
						  $('#outletHint1_open').fadeIn(300);
						  blnSuccess = false;
						  outletMoveFlag = false;
					} else {
						if ($('#outlet_color_ul input[name="color"]:checked').val() !== undefined && $('#outlet_size_ul input[name="size"]:checked').val() === undefined) {
						  if ($('#outletHint1_open').css('display') == 'block') {
							  $('#outletHint1_open').fadeOut(300);
						  }
						  $('#outletHint1_open img').attr('src', 'img/store/size_add_cart.gif');
						  $('#outletHint1_open').fadeIn(300);
						  blnSuccess = false;
						  outletMoveFlag = false;
						}
						if ($('#outlet_color_ul input[name="color"]:checked').val() === undefined && $('#outlet_size_ul input[name="size"]:checked').val() !== undefined) {
						  if ($('#outletHint1_open').css('display') == 'block') {
							  $('#outletHint1_open').fadeOut(300);
						  }
						  $('#outletHint1_open img').attr('src', 'img/store/color_add_cart.gif');
						  $('#outletHint1_open').fadeIn(300);
						  blnSuccess = false;
						  outletMoveFlag = false;
						}
					}
				} else {
					blnSuccess = false;
					outletMoveFlag = false;
				}
				
				if (blnSuccess) {
					
					openLoadingBar();
					
					$.get('gen_content/cart_row.php', 
						  
						  {
							  action: 'addToCart',
							  outletId: $('#current_outletId').val(),
							  colorId: $('#outlet_color_ul input[name="color"]:checked').val(),
							  sizeId: $('#outlet_size_ul input[name="size"]:checked').val(),
							  shop_mode: "outlet"
						  
						  }, function(data) {
							  
							  if (data != "") {
							  
								  if ($('#outletHint1_open').css('display') == 'block') {
									  $('#outletHint1_open').fadeOut(300);
								  }
																	
								//outlet page
								$('div#outlet_table_div').append(data);
																		
								var lastIndex = $('#outlet_table_div table.cart_row').length - 1;
								
								$('#outlet_table_div table.cart_row:eq('+lastIndex+')').fadeIn(300);;
								
								$('#outlet_table_div table.cart_row:eq('+lastIndex+')').removeAttr('style');
							
								$("#outlet_table_div table.cart_row img.store_remove_btn").unbind();
								
								$("#outlet_table_div table.cart_row img.store_remove_btn").click(function () {
																		  
									removeFromOutlet(this);
									
								});
											
								if ($('#outlet_table_div table.cart_row').length > 8) {
									$('#outlet_table_div').css('height', '264px');
									$('#outlet_arrow').css('display', 'block');
								} else {
									$('#outlet_table_div').css('height', 'auto');
									$('#outlet_arrow').css('display', 'none');
								}
								
								//check out page
								$('div#checkout_table_div').append(data);
																		
								var lastIndex = $('#checkout_table_div table.cart_row').length - 1;
								
								$('#checkout_table_div table.cart_row:eq('+lastIndex+')').fadeIn(300);
								
								$('#checkout_table_div table.cart_row:eq('+lastIndex+')').removeAttr('style');
							
								$("#checkout_table_div table.cart_row img.store_remove_btn").unbind();
								
								$("#checkout_table_div table.cart_row img.store_remove_btn").click(function (e) {
																		  
									removeFromOutletCheckout(this);
									
								});
											
								if ($('#checkout_table_div table.cart_row').length > 8) {
									$('#checkout_table_div').css('height', '264px');
									$('#checkout_arrow').css('display', 'block');
								} else {
									$('#checkout_table_div').css('height', 'auto');
									$('#checkout_arrow').css('display', 'none');
								}
									
								calOutletTotalPrice();
								//getOutletSubTotal();
								//getOutletShippingFee();
								//getOutletTotal();
								outletMoveFlag = false;
								closeLoadingBar();
							
							} else {
								
								$('#outletHint1_open img').attr('src', 'img/store/product_hint1.gif');
								$('#outletHint1_open').fadeIn(300);
	
								outletMoveFlag = false;
								closeLoadingBar();
							}
					});
				}
			
			}
						
		}
		
		function removeFromOutlet(obj) {
			
			openLoadingBar();
			
			$.getJSON('./json/update_cart.json.php', {action:'removeProduct', index:obj.getAttribute('alt')}, function(data) {
			
				var index = $("#outlet_table_div table.cart_row img.store_remove_btn").index(obj);
				
				$('#outlet_table_div table.cart_row:eq('+index+')').fadeOut(300, function() {
														   
					$('#outlet_table_div table.cart_row:eq('+index+')').remove();
					$('#checkout_table_div table.cart_row:eq('+index+')').remove();
	
					if ($('#outlet_table_div table.cart_row').length <= 8) {
						$('#outlet_table_div').css('height', 'auto');
						$('#checkout_table_div').css('height', 'auto');
						$('#outlet_arrow').css('display', 'none');
						$('#checkout_arrow').css('display', 'none');
					}
					
					calOutletTotalPrice();
					//getOutletSubTotal();
					//getOutletShippingFee();
					//getOutletTotal();
					closeLoadingBar();
				});
				
				
			});
												
		}
			
		function removeFromOutletCheckout(obj) {
			
			openLoadingBar();
			$.getJSON('./json/update_cart.json.php', {action:'removeProduct', index:obj.getAttribute('alt')}, function(data) {
			
				var removeIndex = $("#checkout_table_div table.cart_row img.store_remove_btn").index(obj);
				
				if (removeIndex < 0) {
					
					var removeIndex = $("#checkout_table_div table.cart_row input.s_input_qty").index(obj);
				
				}
					
				$('#checkout_table_div table.cart_row:eq('+removeIndex+')').fadeOut(300, function() {
														   
					$('#outlet_table_div table.cart_row:eq('+removeIndex+')').remove();
					$('#checkout_table_div table.cart_row:eq('+removeIndex+')').remove();
					
					if ($('#checkout_table_div table.cart_row').length <= 8) {
						$('#outlet_table_div').css('height', 'auto');
						$('#checkout_table_div').css('height', 'auto');
						$('#outlet_arrow').css('display', 'none');
						$('#checkout_arrow').css('display', 'none');
					}
					
					calOutletTotalPrice();
					//getSubTotal();
					//getShippingFee();
					//getTotal();
					closeLoadingBar();
				});
				
				
			});
												
		}
		
		/*function removeFromOutletCheckout(obj) {
			
			var index = $("img.store_remove_btn").index(obj);
			
			$('#checkout_table_div table.checkout_row:eq('+index+')').fadeOut(300, function() {
													   
				$('#outlet_table_div table.cart_row:eq('+index+')').remove();
				$('#checkout_table_div table.checkout_row:eq('+index+')').remove();
				
				if ($('#checkout_table_div table.checkout_row').length <= 8) {
					$('#outlet_table_div').css('height', 'auto');
					$('#checkout_table_div').css('height', 'auto');
					$('#outlet_arrow').css('display', 'none');
					$('#checkout_arrow').css('display', 'none');
				}
				
			});
												
		}*/
		
		function initCheckoutContainer() {
			
			$('.checkout_row').removeAttr('style');
			
			if ($('#checkout_table_div table.checkout_row').length > 8) {
				$('#checkout_table_div').css('height', '264px');
				$('#checkout_arrow').css('display', 'block');
			} else {
				$('#checkout_table_div').css('height', 'auto');
				$('#checkout_arrow').css('display', 'none');
			}
			$("img.store_remove_btn").unbind();
			
			$("img.store_remove_btn").click(function () {
				removeFromCheckout(this);
			});
			
		}
		
		function calOutletTotalPrice() {
			if (window.location.hash != "") {
				$.ajax({
					 type: "GET",
					 url: './json/get_total.json.php',
					 data: {action:'updateTotal', shop_mode:"outlet"},
					 async: false,
					 beforeSend: function(x) {
					  if(x && x.overrideMimeType) {
					   x.overrideMimeType("application/j-son;charset=UTF-8");
					  }
				 },
				 dataType: "json",
				 success: function(data){
					$('#outlet_subtotal').html("$"+data.sub_total);								 
					$('#checkout_subtotal').html("$"+data.sub_total);					 
					$('#checkout_shippingFee').html(data.shipping_fee);
					$('#shipping_fee_needed').html(data.shipping_fee_need);
					$('#checkout_total').html("$"+data.total);					 
				 }
				});				
			}
		}
			
		function getOutletSubTotal() {
			if (window.location.hash != "") {
				$.getJSON('./json/get_total.json.php', {action:'subtotal', shop_mode:"outlet"}, function(data) {
					$('#outlet_subtotal').html("$"+data.sub_total);								 
					$('#checkout_subtotal').html("$"+data.sub_total);					 
				});
			}
		}
			
		function getOutletShippingFee() {
			if (window.location.hash != "") {
				$.getJSON('./json/get_total.json.php', {action:'shippingFee', shop_mode:"outlet"}, function(data) {

					$('#checkout_shippingFee').html(data.shipping_fee);
					$('#shipping_fee_needed').html(data.shipping_fee_need);
					
				});
			}
		}
			
		function getOutletTotal() {
			if (window.location.hash != "") {
				$.getJSON('./json/get_total.json.php', {action:'total', shop_mode:"outlet"}, function(data) {
					$('#checkout_total').html("$"+data.total);					 
				});
			}
		}
			

