/*
 * jQuery Atarimarket Customize Series vol.2
 * 
 *
 * Copyright (c) 2009 Atarimarket
 *
 * Date: 2009-08-30
 * 
 */
jQuery.extend({
});
jQuery.fn.extend({
	//Visible Cart
	cartonLoad: function(){
		var obj=$(this);
		if(flashvars['items']==0 || flashvars['items']==undefined){
			//カート内にアイテムがないか、もしくは取得エラーの場合
			//非表示
			obj.hide();
		}else{
			//表示
			if(obj.is(':hidden')){
				obj.show();
			}
			//
			var swffile="/common/swf/shoppingcart.swf";
			var expfile="/common/js/plugin/expressInstall.swf";
			swfobject.embedSWF(swffile, "cart", "820", "40", "8.0.0", expfile, flashvars, params);
		}
	},
	//Visible mini Cart
	mini_cartonLoad: function(){
		var obj=$(this);
		if(flashvars['items']==0 || flashvars['items']==undefined){
			//カート内にアイテムがないか、もしくは取得エラーの場合
			//非表示
			obj.hide();
		}else{
			//表示
			if(obj.is(':hidden')){
				obj.show();
			}
			//
			var swffile="/common/swf/minicart.swf";
			var expfile="/common/js/plugin/expressInstall.swf";
			swfobject.embedSWF(swffile, "mini_cart", "402", "40", "8.0.0", expfile, flashvars, params);
		}
	},
	//Visible Cart Timer
	cart_timeronLoad: function(){
		var obj=$(this);
		if(flashvars['items']==0 || flashvars['items']==undefined){
			//カート内にアイテムがないか、もしくは取得エラーの場合
			//非表示
			obj.hide();
		}else{
			//表示
			obj.show();
			//
			var swffile="/common/swf/carttimer.swf";
			var expfile="/common/js/plugin/expressInstall.swf";
			swfobject.embedSWF(swffile, "cart_timer", "234", "40", "8.0.0", expfile, flashvars, params);
		}
	},
	change_cart: function(id){
		var i=0;
		$(this).change(function () {
			$('option:selected',this).each(function () {
				i=$(this).attr("value");
			});
		});
	
		if(i>=1){
			add_cart(id, i);
			return true;
		}else if(i<=1){
			reduce_cart(id, -(i));
			return true;
		}else{
			return false;
		}
	},
	//吹き出し表示処理
	addPop: function(t) {
		var obj= $(this);
		var pos= obj.offset();
		var addTop=0;
		var addLeft=0;
		//表示要素がある場合
		
		if($('.pop_position')){
			$('.pop_position').remove();	
		}
		
		$(this).formatPop(t);
		
		addTop=($('.pop_position').outerHeight());
		addLeft=(obj.outerWidth()/2);
		
		$('.pop_position').css({'top':pos.top,'left':pos.left+addLeft-20,'zIndex':10011});
		
		$('.pop_position').animate({'height':'show','top':pos.top-addTop+10},750,'easeInOutCirc',function(){
			$(this).oneTime(2000, function() {
				$('.pop_position').removePop();
			});	
		});
		return false;
	},
	//吹き出し型生成
	formatPop: function(t) {
		var obj=t;
		var upper="<div class='pop_position'><table id='pop_table' cellpadding='0' cellspacing='0' width='170'><tr><td id='pop_tl'></td><td id='pop_top'></td><td id='pop_tr'></td></tr><tr><td id='pop_body' colspan='3'><div class='pop-inner'>";
		var under="</div></td></tr><tr><td id='pop_bl'></td><td id='pop_bottom'></td><td id='pop_br'></td></tr></table></div>";
		$(this).after(upper+obj+under);
		return true;
	},
	//吹き出しの削除処理
	removePop: function() {
		var obj=this;
		obj.slideUp(400,function(){
			$(this).remove();
		});
	},
	checkSetUp: function() {
		var obj=$(this);
		
		//初期化
		obj.each(function(){
			var id=$(this).attr('id');
			var target=$("#"+id+"_option");
			if($(this).is(":checked")){
				target.show();
			}else{
				target.hide();
			}
		});
		//クリック時の処理
		obj.click(function(){
			var id=$(this).attr('id');
			var option=$("#"+id+"_option");
			var price=$("#"+id+"_price");
			if($(this).is(":checked")){
				option.show();
				$('.checked',price).show();
				$('.nocheck',price).hide();
			}else{
				option.hide();
				$('.checked',price).hide();
				$('.nocheck',price).show();
			}		
		});	
	},
	pantsSelect:function(){
		var obj=$(this);
		$('input.radio',$(this)).click(function(){
			var loc=$(this).parent().parent().parent().get(0);
			var set = $(this).attr('value');
			if($(this).is(":checked")){
				switch(set){
					case '1':
					//シングルの場合
					$('.pants_type div' , loc).hide();
					$('.pants_type .single' , loc).show();
					break;
					case '2':
					//ダブルの場合
					$('.pants_type div' , loc).hide();
					$('.pants_type .double' , loc).show();
					break;
					default:
					//エラー
					alert(set);
					alert("裾上げ選択エラー");
					break;
				}
			}
		});
	},
	wrappingSelect:function(){
		var obj=$(this);
		if($('input.yes',$(this)).is(":checked")){
			$('#wrapping_option').show();
		}else{
			$('#wrapping_option').hide();
		}
		$('input.no',$(this)).click(function(){
			if($(this).is(":checked")){
				$('#wrapping_option').hide();
			}
		});
		$('input.yes',$(this)).click(function(){
			if($(this).is(":checked")){
				$('#wrapping_option').show();
			}
		});
	}	
});


