$(function(){
	$(window).resize(function(){
        var w=$(window).width();
		var m=w-1070;
        var fm=w-1280;
		var o=$('.header').offset();
		if(o != null){
			$('div.content').css('marginLeft',m>0?m/2:o.left-45);
	        $('div.footer').css('marginLeft',fm>0?fm/2:o.left-155);
			$('div.shoppingcart_listmenu').css('left',o.left+650);
		}
		
	});
	//$(document).ready(function(){
        var w=$(window).width();
		var m=w-1070;
        var fm=w-1280;
        var o=$('.header').offset();
        if(o != null){
			$('div.content').css('marginLeft',m>0?m/2:o.left-45);
	        $('div.footer').css('marginLeft',fm>0?fm/2:o.left-155);
			$('div.shoppingcart_listmenu').css('left',o.left+650);
        }
		//$('div.content').show();
	//});
});
/*
$(function(){
	$('a[id^="sub_"]').click(function(){
		var listItem = $(this).parent();
		var itemIndex = $('#mainbtn > li').index(listItem)+1;
		var targetColor = '';
		
		switch(itemIndex)
		{
			case 1:	targetColor = '#c20001';break;
			case 2:	targetColor = '#ff3399';break;
			case 3:	targetColor = '#99ffcc';break;
			case 4:	targetColor = '#006699';break;
			case 5:	targetColor = '#009900';break;
			case 6:	targetColor = '#ffff00';break;
			case 7:	targetColor = '#ff6600';break;
			case 8:	targetColor = '#6633cc';break;
			default: targetColor = '#c20001';
		}
		
		$('#mainbtn > li').each(function(index){
			$(this).css('border-color',targetColor);
		});

		$('#mainbtn > li > div.marker').hide();	
		$('#mainbtn > li').removeClass('active');
		$('ul#mainbtn > li:nth-child('+itemIndex+') > div').show();
		$('ul#mainbtn > li:nth-child('+itemIndex+')').addClass('active');
		$('div#submenu_grp > ul').removeClass('active');
		$('div#submenu_grp > #submenu_'+itemIndex).addClass('active');
	});
});
*/

$(function(){
	$('a.selectbtn').click(function(){
		$('ul#booktype_submenu').slideToggle();
	});
	$('ul#booktype_submenu > li > a').click(function(){
		$(this).parent().parent().slideToggle();
	});
});

$(function(){
	$('#my_shoppingcart').click(function(){
		$('#shoppingcart_listmenu').slideToggle();
	});
	$('#shoppingcart_listmenu > table > tbody > tr > td > a').click(function(){
		$('#shoppingcart_listmenu').slideToggle();
	});
});


$(function(){
	$('#member_info_tab1').click(function(){
		$(this).addClass('active');
		$('#member_info_tab2').removeClass('active');
		$('#member_content_1').addClass('active');
		$('#member_content_2').removeClass('active');
	});
	$('#member_info_tab2').click(function(){
		$(this).addClass('active');
		$('#member_info_tab1').removeClass('active');
		$('#member_content_2').addClass('active');
		$('#member_content_1').removeClass('active');
	});
});




$(function(){
	var divAccordion = $("#accordion");
	if(divAccordion.size()>0) {
		var imgROOT;
		var imgs = $('#accordion > h3 img');
		if(imgs.size()>0) {
			var imgSrc = imgs.eq(0).attr("src");
			var index = imgSrc.lastIndexOf("/");
			if(index!=-1) imgROOT = imgSrc.substring(0, index); 
		}
		if(imgROOT==null) imgROOT = "images";

		$('#accordion > h3').click(function(){
			$(this).parent().children('.book_block3').each(function(index){
				if($(this).css('display')!='none')
				{
					$(this).slideToggle(300);
					$('#accordion > h3').children().children('img').attr("src",imgROOT+'/sidemenu-tab-arrow-03.gif');
				}
			});
			$(this).next().slideToggle(300);
			$(this).children().children('img').attr("src",imgROOT+'/sidemenu-tab-arrow-02.gif');
		});
	}
});


$(function(){
	$('#classify_accordion > ul > li.citem').click(function(){
		$(this).parent().children('.csubmenu').each(function(index){
			if($(this).css('display')!='none')
			{
				$(this).slideToggle(300);
			}
		});
		$(this).next().slideToggle(300);
	});
});


$(function(){
	$('.showCouponStatus').click(function(){
		$(this).html()=="▼"?$(this).html("▲"):$(this).html("▼");
		$(this).parent().parent().next('.couponStatusBox').toggle();
	});
});


$(function(){
	  
	var imgRotateSecond = $("input[name='rotateSecond'][type='hidden']").val();
	//alert(imgRotateSecond);
	$('#promo_data')
	.after('<div class="pagenation" id="promo_page">')
		.cycle({
			fx:'scrollUp',
			//speed:'slow',
			speed: imgRotateSecond,
			pager: '#promo_page',
			pause: 1,
			pauseOnPagerHover: 1	  
		});

	
});

$(function(){
	$('#about_us_roller')
	.cycle({
		fx:'scrollUp',
		speed:'slow'
	});
});


$(function(){
	$('#product_detail_tab > li > a[id^="p_tab_"]').click(function(){
		var listItem = $(this).parent()
		var itemIndex = $('#product_detail_tab > li').index(listItem)+1;
		
		//alert($(this).html());
		//alert(listItem.html());
		//alert(itemIndex);
		//$(this).attr(id);
		$('#product_detail_tab > li').removeClass('active');
		$(this).parent().addClass('active');
		$('div.product_detail_container > div').removeClass('active');
		$('div#p_content_'+itemIndex).addClass('active');
	});
});


$(function(){
	$('#block_tabs_1 > li > a[id^="b_tab_"]').click(function(){
		var listItem = $(this).parent();
		var itemIndex = $('#block_tabs_1 > li').index(listItem)+1;
		
		//alert($(this).html());
		//alert(listItem.html());
		//alert(itemIndex);
		//$(this).attr(id);
		$('#block_tabs_1 > li').removeClass('active');
		$(this).parent().addClass('active');
		$('div[id^="b_tab_content_"]').removeClass('active');
		var obj =  document.getElementById("b_tab_content_1");
		var obj2 =  document.getElementById("b_tab_content_2");
		
		if(itemIndex==1){
			
			//$('div[id^="b_tab_content_1"]').addStyly('display:none');
			//$('div[id^="b_tab_content_2"]').addStyly('display:');
			document.getElementById("b_tab_content_1").style.display="";
			document.getElementById("b_tab_content_2").style.display="none";
			//$('div[id^="b_tab_content_1"]').style.display="";
			//$('div[id^="b_tab_content_2"]').style.display="none";
			
		}else{
			document.getElementById("b_tab_content_2").style.display="";
			document.getElementById("b_tab_content_1").style.display="none";
			
			
		}
		$('div#b_tab_content_'+itemIndex).addClass('active');
	});
});


$(function(){
	$('a[id^="oinfo_tab"]').click(function(){
		var listItem = $(this).parent().parent();
		var itemIndex = $('#oinfo_tab_list > li').index(listItem)+1;
		
		//alert($(this).html());
		//$(this).attr(id);
		$('#oinfo_tab_list > li').removeClass('active');
		$(this).parent().parent().addClass('active');
		$('div.info_block').removeClass('active');
		$('div#info_'+itemIndex).addClass('active');
	});
});



$(function(){
	$('.product_inside > div.product_content').cycle({
		fx:'scrollHorz',
		speed:200,
		timeout:0,
		prev:'.prev_arrow',
		next:'.next_arrow'
	});
});

$(function(){
	$('.also_buy_list > div.also_buy_list_group').cycle({
		fx:'scrollHorz',
		speed:200,
		timeout:0,
		cleartypeNoBg:1,
		prev:'.prev_arrow',
		next:'.next_arrow'
	});
});


$(function(){
	$("#send_method_way_2").hide();
	
	$('#big_tab_btn_1').click(function(){
		$(this).parent().parent().children("li").removeClass("active");
		$(this).parent().addClass("active");
		$("#big_tab_content_2").hide();
		$("#big_tab_content_1").show();
	});
	$('#big_tab_btn_2').click(function(){
		$(this).parent().parent().children("li").removeClass("active");
		$(this).parent().addClass("active");
		$("#big_tab_content_1").hide();
		$("#big_tab_content_2").show();
	});
});

$(function(){
	$("#gift_reciver").hide();
	$("#bill_reciver").hide();
	
	$('#show_gift_box').click(function(){
		if($("#gift_reciver").css('display') == 'none'){
			$("#gift_reciver").show();
		}else{
			$("#gift_reciver").hide();
		}
	});
	
	$('#show_bill_box').click(function(){
		if($("#bill_reciver").css('display') == 'none'){
			$("#bill_reciver").show();
		}else{
			$("#bill_reciver").hide();
		}
	});
});

$(function(){
	$('.question_list > li > p > span.question').click(function(){
		$('.question_list > li > p > span.question').removeClass('active');
		$('.question_list > li > div.answer_block').hide();
		
		if($(this).hasClass('active'))
		{
			$(this).removeClass('active');
		}
		else
		{
			$(this).addClass('active');
		}
		$(this).parent().next('.answer_block').slideToggle();
	});
});

 $(function() {
	var ver = $.browser.version;
	if(ver=="6.0" || ver=="7.0"){
		$("a#showmail").colorbox({
			speed:350,
			opacity:0.7,
			width:"775px",
			scrolling:false,
			inline:true,
			href:"#service_center_response_mail_block"
		});
		$("a#order_more_mag").colorbox({
			speed:250,
			opacity:0.7,
			width:"775px",
			height:"300px",
			scrolling:false,
			iframe:true
		});
	}
	else
	{
		$("a#showmail").colorbox({
			speed:350,
			opacity:0.7,
			innerWidth:"775px",
			inline:true,
			href:"#service_center_response_mail_block"
		});
		$("a#order_more_mag").colorbox({
			speed:250,
			opacity:0.7,
			innerWidth:"760px",
			innerHeight:"150px",
			scrolling:false,
			iframe:true
		});
	}
	
	$(".choice_books_sent_to_one").colorbox({
		speed:250,
		opacity:0.7
	});
	
	$(".storeinstore_login").colorbox({
		speed:250,
		opacity:0.7
	});
});


$(function(){
	$('.popup_cheerup_info').mouseover(function(){
		$(".popup_info").show();
	});
	$('.popup_cheerup_info').mouseout(function(){
		$(".popup_info").hide();
	});
});

$(function() {
	var ver = $.browser.version;
	if(ver=="6.0" || ver=="7.0"){
		$("a#lightbox").colorbox({
			speed:350,
			opacity:0.7,
			width:"775px",
			scrolling:false,
			inline:true,
			href:"#showlightbox"
		});
	}
	else{
		$("a#lightbox").colorbox({
			speed:350,
			opacity:0.7,
			innerWidth:"775px",
			inline:true,
			href:"#showlightbox"
		});
	}
});


