
var FeaturedBook = function(name,topNo,objName){
	this.divName = name;
    this.topNo   = topNo;
	this.objName = objName;
	
	this.featuredBook_list = "";
  
 this.list = function (pageno){
	if(!this.featuredBook_list) {
		return false;
		alert(this.objName+'featuredBook_list not exist!');
	}
	
	var divName = this.divName;
	var countItems = this.featuredBook_list.length;	//得到精選新書 (中文新書)Array的長度
	var items=5;

	//alert(this.featuredBook_list.length);
	//计算页码
	if(countItems % items==0)		pages = parseInt(countItems/items);
	else						pages=parseInt(countItems/items)+1;
	//alert("countItems="+countItems+ "    pages =="+pages);
	
	document.getElementById(divName).innerHTML="";
	
	//左邊箭頭和前一頁的設置
	if(pageno==1)
		document.getElementById(divName).innerHTML += "<div id=\"arrowLeft\"> </div>";
	else
		document.getElementById(divName).innerHTML += "<div id=\"arrowLeft\"><a href=\"javascript:"+this.objName+".list("+(pageno*1-1)+")\"><img src=\"image/gimg/frontBannerImg/arrow_left.gif\" width=\"12\" height=\"23\" border=\"0\" /></a></div>";
	
	var start = (pageno*1-1) * items;
	var end = items;
	
	//如果是最後一頁，並且數組長度 % 每頁顯示數!=0,  則....
	if(pageno == pages && (countItems % items!=0))		end = countItems%items;
	
	var BookPic;
	var ProductID;
	
	//alert("end  =="+end);
	for(i=0; i<end; i++){
		id=(i*1+start*1);
		
		//alert('i == '+i+"   id=="+id+"\n"+this.featuredBook_list[0][0]);
		
		document.getElementById(divName).innerHTML += "<div id=\"BookInfo\"><a href=\"http://www.cp1897.com.hk/product_info.php?BookId="+this.featuredBook_list[id][0]+"\" target=\"_blank\"><img src=\""+this.featuredBook_list[id][3]+"\" width=\"80\" border=\"0\" onmousemove=\""+this.objName+".showBookInfo("+id+", "+i+", "+this.topNo+");\"></a>";
	}
	
	//右邊箭頭和下一頁的設置
	if(pageno==pages)
		document.getElementById(divName).innerHTML=document.getElementById(divName).innerHTML+"<div id=\"arrowRight\"> </div>";
	else
		document.getElementById(divName).innerHTML=document.getElementById(divName).innerHTML+"<div id=\"arrowRight\"><a href=\"javascript:"+this.objName+".list("+(pageno*1+1)+")\"><img src=\"image/gimg/frontBannerImg/arrow_right.gif\" width=\"12\" height=\"23\" border=\"0\" /></a></div>";
		
}
 
 this.showBookInfo = function (id, leftNo, topNo){
	if(!js_lg.buy) alert('js_lg語言文件沒有裝入！');
		
	window_left('bookShowDiv', leftNo); 
	window_top('bookShowDiv', topNo);
	
	document.getElementById('bookShowDiv').style.display="";
	document.getElementById('bookShowDiv').focus();

	document.getElementById('BookName').innerHTML="";
	document.getElementById('AuthorPublisher').innerHTML="";
	document.getElementById('BookPrice').innerHTML="";
	document.getElementById('OrderStatus').innerHTML="";
	document.getElementById('BookName').innerHTML="<a href='product_info.php?BookId="+this.featuredBook_list[id][0]+"' >"+this.featuredBook_list[id][2]+"</a>";
	
	
	//顯示作者
	if(this.featuredBook_list[id][4]!="")
		document.getElementById('AuthorPublisher').innerHTML=document.getElementById('AuthorPublisher').innerHTML+'<div id="BookAuthor">'+js_lg.author+js_lg.TEXT_COLON+this.featuredBook_list[id][4]+"</div>";
	
	//顯示出版社
	if(this.featuredBook_list[id][5]!="")
		document.getElementById('AuthorPublisher').innerHTML=document.getElementById('AuthorPublisher').innerHTML+'<div id="Publisher">'+js_lg.publisher+js_lg.TEXT_COLON+this.featuredBook_list[id][5]+"</div>";
	
	//如果有特價
	if(this.featuredBook_list[id][8] && this.featuredBook_list[id][8]!=""){
		document.getElementById('BookPrice').innerHTML=document.getElementById('BookPrice').innerHTML+'<font color="#FF0000"><span class="defaultPrice"><b>HKD'+this.featuredBook_list[id][8]+"</b></span></font>";
		if(this.featuredBook_list[id][7]!=""){
			document.getElementById('BookPrice').innerHTML='<span class=\"oldPrice\">HKD'+this.featuredBook_list[id][7]+" </span> &nbsp; "+document.getElementById('BookPrice').innerHTML;
		}
	}
	//沒有特價
	else{
			document.getElementById('BookPrice').innerHTML += '<span class="newPrice">HKD'+this.featuredBook_list[id][7]+" </span> &nbsp; ";
	}

	//暫存架
	document.getElementById('OrderStatus').innerHTML = "<a onclick=\"add_to_tmpcart('"+this.featuredBook_list[id][0]+"','favor"+id+"');\" name='Save' href=\"javascript:void(0);\"><img src=\"image/gimg/tempShelf.gif\" alt="+js_lg.hold+" width='27' height='27' border='0' class='BookInfo_Icon' title="+js_lg.hold+" ><span class=\"toolsLabel\">"+js_lg.hold+"</span></a> ";
	
	
	if(this.featuredBook_list[id][9]=="Y")
		document.getElementById('OrderStatus').innerHTML += '&nbsp; <a href="javascript:showdiv(' +this.featuredBook_list[id][1]+');" target="_self"><img src="image/gimg/shoppingCart.gif" alt="'  +js_lg.buy+"\" width='27' height='27' border=0 class='BookInfo_Icon' title=\"" +js_lg.buy+'" ><span class="toolsLabel">'+js_lg.buy+"</span></a>";
	}

}	//Object END......


function window_left(popUpDivVar, leftNo) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	// window_width=window_width/2-281;//281 is half popup's width
	window_width=39+20+leftNo*120;//205 is half popup's width  (window_width-947)/2+
	popUpDiv.style.left = window_width + 'px';
}
function window_top(popUpDivVar, topNo) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
//	popUpDiv_height=blanket_height/2-15-(topNo*1)*162;//150 is half popup's height
	popUpDiv_height=276+(topNo*1-1)*215;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
	//popUpDiv.style.top = '100px';
	//popUpDiv.style.top = '150px';
}