/**
*
*/
var JData;
$(document).ready(function() {
$("#newbooks_button table tr td:eq(0) div").click(function(){
if($(this).attr("rel")=="true"){
$("#newbooks_button table tr td:eq(0)").css("background","url('../new_include/images/top_icon_off.jpg') no-repeat");
$(this).attr("rel","false").css("float","right");
}else{
$("#newbooks_button table tr td:eq(0)").css("background","url('../new_include/images/top_icon_on.jpg') no-repeat");
$(this).attr("rel","true").css("float","left");
}
});
$(".newbooks_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"));
}
});
//focusNewBookView(1);
$("#newbooks_button table tr td:eq(4)").click(function(){
var p = parseInt($("#newbooks_page").text());
p++;
$.history.load("AB"+p);
//focusNewBookView(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"); }
);
$("#newbooks_button table tr td:eq(2)").click(function(){
var p = parseInt($("#newbooks_page").text());
p--;
$.history.load("AB"+p);
//focusNewBookView(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"); }
);
//newbookEqualHeight();
});
function newbookEqualHeight(){
var maxHeight = 0;
$('.newbooks_word div.newbook_b').each(function(){
if (maxHeight < $(this).find("ul").height()) {maxHeight = $(this).find("ul").height();}
});
$('.newbooks_word div.newbook_b').each(function(){
$(this).height(maxHeight);
});
}
function focusNewBookView(currentPage){
if(JData==null){
$.ajax({
type: "get",
url: "../beta/focusNewBookAgent.jsp",
//url: "usedNewBookAgent.html",
data: "",
dataType: "text",
async: false,
error: function(err) { },
success: function(json) {
JData = jQuery.parseJSON(json);
//var pCount = JData.length < 10 ? JData.length : 10;
var pCount = (currentPage - 1) * 10;
var aCount = JData.length;
var real_page = JData.length % 10 == 0 ? JData.length/10 :  Math.floor(JData.length/10) + 1;
if(currentPage>real_page) currentPage = 1;
if(currentPage<=0) currentPage = real_page;
$("#newbooks_page").text(currentPage);
$("#newbooks_pages").text(aCount % 10 == 0 ? aCount/10 :  Math.floor(aCount/10) + 1);
$(".newbooks_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[pCount]["orgProdId"];
JDataItem[1] = JData[pCount]["titleMain"];
JDataItem[2] = JData[pCount]["listPrice"];
JDataItem[3] = JData[pCount]["saleDisc"];
JDataItem[4] = JData[pCount]["salePrice"];
JDataItem[5] = JData[pCount]["prodId"];
//$(this).fadeOut("slow",function(){
$(this).attr("rel",JDataItem[5]);
$(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" });
});
newbookEqualHeight();
},
complete: function() { }
});
}else{
//alert(JData.length);
if(perfix=="AB"){
var real_page = JData.length % 10 == 0 ? JData.length/10 :  Math.floor(JData.length/10) + 1;
if(currentPage>real_page) currentPage = 1;
if(currentPage<=0) currentPage = real_page;
var pCount = (currentPage - 1) * 10;
var aCount = JData.length;
$("#newbooks_page").text(currentPage);
$(".newbooks_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[pCount]["orgProdId"];
JDataItem[1] = JData[pCount]["titleMain"];
JDataItem[2] = JData[pCount]["listPrice"];
JDataItem[3] = JData[pCount]["saleDisc"];
JDataItem[4] = JData[pCount]["salePrice"];
JDataItem[5] = JData[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" });
});
//if($("#newbook_autoview").attr('checked')){
if($("#newbooks_button table tr td:eq(0) div").attr("rel")=="true"){
if(perfix=="AB"){
$("html,body").animate({scrollTop: $("#newbooks_top").offset().top}, "slow", function(){newbookEqualHeight();});
}else{
newbookEqualHeight();
}
}else{
newbookEqualHeight();
}
}
}
}

