/**
*
*/
var JData_UsedNewBook;
$(document).ready(function() {
$(".newused_m_shop").hover(
function(){ $(this).addClass("isShow").css("background","url('../new_include/images/roll_cart2.png') no-repeat"); },
function(){ $(this).removeClass("isShow").css("background","url('../new_include/images/roll_cart1.png') no-repeat"); }
).click(function(){
//$.growlUI($(this).parent().parent().attr("rel") + '已加入暫存清單');
if($("#HIDE_INPUUT_CUST_ISLOGIN").val()!="true"){
$("#ajaxLogin").attr("href", "login_taaze_Ajax.html?keepThis=true&TB_iframe=true&height=420&width=600").trigger("click");
}else{
$.growlUI('已加入暫存清單');
addNextShopping($(this).parent().parent().attr("rel"));
}
});
//usedNewBookView(1);
//next page
$("#newused_button table tr td:eq(3)").click(function(){
var p = parseInt($("#newused_page").text());
p++;
$.history.load("AA"+p);
//usedNewBookView(p);
}).hover(
function(){ $(this).css("background","url('../new_include/images/arrow_right_o.jpg') no-repeat"); },
function(){ $(this).css("background","url('../new_include/images/arrow_right_n.jpg') no-repeat"); }
);
//back page
$("#newused_button table tr td:eq(1)").click(function(){
var p = parseInt($("#newused_page").text());
p--;
$.history.load("AA"+p);
//usedNewBookView(p);
}).hover(
function(){ $(this).css("background","url('../new_include/images/arrow_left_o.jpg') no-repeat"); },
function(){ $(this).css("background","url('../new_include/images/arrow_left_n.jpg') no-repeat"); }
);
});
function newusedEqualHeight(){
var maxHeight = 0;
$('.newused_word div.newused_b').each(function(){
if (maxHeight < $(this).find("ul").height()) {maxHeight = $(this).find("ul").height();}
});
$('.newused_word div.newused_b').each(function(){
$(this).height(maxHeight);
});
}
function usedNewBookView(currentPage){
if(JData_UsedNewBook == null){
$.ajax({
type: "get",
url: "../beta/usedNewBookAgent.jsp",
data: "",
dataType: "text",
async: false,
error: function(err) {  },
success: function(json) {
JData_UsedNewBook = jQuery.parseJSON(json);
//var pCount = JData.length < 10 ? JData.length : 10;
var pCount = (currentPage - 1) * 10;
var aCount = JData_UsedNewBook.length;
var real_page = JData_UsedNewBook.length % 10 == 0 ? JData_UsedNewBook.length/10 :  Math.floor(JData_UsedNewBook.length/10) + 1;
if(currentPage>real_page) currentPage = 1;
if(currentPage<=0) currentPage = real_page;
$("#newused_page").text(currentPage);
$("#newused_pages").text(aCount % 10 == 0 ? aCount/10 :  Math.floor(aCount/10) + 1);
//alert(aCount % 10 == 0 ? aCount/10 :  Math.floor(aCount/10) + 1);
$(".newused_m").each(function(){
if((pCount + 1) > aCount){
//$(this).fadeOut("slow",function(){
$(this).children().eq(0).css({ "background":"url('" + $("#GLOBAL_URL_BOOK").val() + "/showLargeImage.html?sc=10000000000&height=172&width=122') no-repeat center center" }).unbind('mouseenter mouseleave');
$(this).children().eq(1).html("&nbsp;");
$(this).children().eq(2).html("&nbsp;");
$(this).children().eq(3).html("&nbsp;");
$(this).show();
//});
}else{
//alert(JData_UsedNewBook[pCount]["titleMain"]);
var JDataItem = new Array(6);
JDataItem[0] = JData_UsedNewBook[pCount]["orgProdId"];
JDataItem[1] = JData_UsedNewBook[pCount]["titleMain"];
JDataItem[2] = JData_UsedNewBook[pCount]["listPrice"];
JDataItem[3] = JData_UsedNewBook[pCount]["saleDisc"];
JDataItem[4] = JData_UsedNewBook[pCount]["salePrice"];
JDataItem[5] = JData_UsedNewBook[pCount]["prodId"];
$(this).attr("rel",JDataItem[5]);
//$(this).fadeOut("slow",function(){
$(this).children().eq(0).css({ "background":"url('" + $("#GLOBAL_URL_BOOK").val() + "/showLargeImage.html?sc="+JDataItem[0]+"&height=172&width=122') no-repeat center center" })
.hover(
function(){
$(this).children().eq(0).show();
},
function(){
$(this).children().eq(0).hide();
}
).click(function(){
if(!$(this).children().eq(0).hasClass("isShow")) {
window.location = $("#GLOBAL_URL").val() + "/sing.html?pid=" + $(this).parent().attr("rel");
}
});
$(this).children().eq(1).html("<a href='" + $("#GLOBAL_URL").val() + "/sing.html?pid=" + $(this).attr("rel") + "'>" + cutstr(JDataItem[1],40) + "</a>");
$(this).children().eq(2).html("定價" + JDataItem[2] + "元");
//$(this).children().eq(3).html("二手價<span>" + JDataItem[3] + "</span>折<span>" + JDataItem[4] + "</span>元");
$(this).children().eq(3).html(bindString_A(JDataItem[3], JDataItem[4], "二手價"));
$(this).show();
//});
}
pCount++;
//$(this).children().eq(0).css({ "background":"url('http://media.taaze.tw/showLargeImage.html?sc="+pics[p-1]+"&width=124') no-repeat center center" });
});
},
complete: function() {
//newusedEqualHeight();
}
});
newusedEqualHeight();
}else{
//alert(Math.floor(10/10) + 1);
if(perfix=="AA"){
var real_page = JData_UsedNewBook.length % 10 == 0 ? JData_UsedNewBook.length/10 :  Math.floor(JData_UsedNewBook.length/10) + 1;
if(currentPage>real_page) currentPage = 1;
if(currentPage<=0) currentPage = real_page;
var pCount = (currentPage - 1) * 10;
var aCount = JData_UsedNewBook.length;
$("#newused_page").text(currentPage);
$(".newused_m").each(function(){
if((pCount + 1) > aCount){
$(this).fadeOut("slow",function(){
$(this).children().eq(0).css({ "background":"url('" + $("#GLOBAL_URL_BOOK").val() + "/showLargeImage.html?sc=10000000000&height=172&width=122') no-repeat center center" }).unbind('mouseenter mouseleave');
$(this).children().eq(1).html("&nbsp;");
$(this).children().eq(2).html("&nbsp;");
$(this).children().eq(3).html("&nbsp;");
$(this).show();
});
}else{
var JDataItem = new Array(6);
JDataItem[0] = JData_UsedNewBook[pCount]["orgProdId"];
JDataItem[1] = JData_UsedNewBook[pCount]["titleMain"];
JDataItem[2] = JData_UsedNewBook[pCount]["listPrice"];
JDataItem[3] = JData_UsedNewBook[pCount]["saleDisc"];
JDataItem[4] = JData_UsedNewBook[pCount]["salePrice"];
JDataItem[5] = JData_UsedNewBook[pCount]["prodId"];
$(this).attr("rel",JDataItem[5]);
$(this).fadeOut("slow",function(){
$(this).children().eq(0).css({ "background":"url('" + $("#GLOBAL_URL_BOOK").val() + "/showLargeImage.html?sc="+JDataItem[0]+"&height=172&width=122') no-repeat center center" })
.hover(
function(){
$(this).children().eq(0).show();
},
function(){
$(this).children().eq(0).hide();
}
).click(function(){
if(!$(this).children().eq(0).hasClass("isShow")) {
window.location = $("#GLOBAL_URL").val() + "/sing.html?pid=" +$(this).parent().attr("rel");
}
});
$(this).children().eq(1).html("<a href='" + $("#GLOBAL_URL").val() + "/sing.html?pid=" + $(this).attr("rel") + "'>" + cutstr(JDataItem[1],40) + "</a>");
$(this).children().eq(2).html("定價" + JDataItem[2] + "元");
$(this).children().eq(3).html(bindString_A(JDataItem[3], JDataItem[4], "二手價"));
$(this).show();
});
}
pCount++;
//$(this).children().eq(0).css({ "background":"url('http://media.taaze.tw/showLargeImage.html?sc="+pics[p-1]+"&width=124') no-repeat center center" });
});
//$("html,body").animate({scrollTop: $("#newused_top").offset().top}, "slow", function(){newusedEqualHeight();});
if($("#newused_autoview").attr('checked')){
if(perfix=="AA"){
$("html,body").animate({scrollTop: $("#newused_top").offset().top}, "slow", function(){newusedEqualHeight();});
}else{
newusedEqualHeight();
}
}else{
newusedEqualHeight();
}
}//if(perfix=="AA")
}
}

