function showFlash(width,height,src)
{
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=" + width + " height=" + height + "><param name='movie' value='" + src + "'><param name='quality' value='high'><param name='wmode' value='transparent'><embed src='" + src +"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='transparent' width=" + width + " height='" + height + "'></embed></object>");
}

function getids(id) { return document.getElementById(id); }

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
var hkctpsCdc_s=0;
function hkctpsCdc(v){
	if(v){
	hkctpsCdc_s+=3
	}else{
	hkctpsCdc_s-=3
	}
	if(typeof strs1=="undefined") strs1=getids("hkctps_1").innerHTML.split('\n');
	if(typeof strs2=="undefined") strs2=getids("hkctps_2").innerHTML.split('\n');
	if(typeof strs3=="undefined") strs3=getids("hkctps_3").innerHTML.split('\n');
	getids("hkctps_1").innerHTML='';
	getids("hkctps_2").innerHTML='';
	getids("hkctps_3").innerHTML='';
	var vth=strs1.length;
	if(vth<=hkctpsCdc_s || hkctpsCdc_s<0) hkctpsCdc_s=0;
	for(var i = hkctpsCdc_s; i < strs1.length; i++) {
 	getids("hkctps_1").innerHTML+=strs1[i]+'\n';
	getids("hkctps_2").innerHTML+=strs2[i]+'\n';
	getids("hkctps_3").innerHTML+=strs3[i]+'\n';
	}
	hkctpsChange();
//	alert(abc[0]);
	}

function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y) {
		return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

function classNormal(hkctpsBtnID,hkctpsTxID){
	var hkctpsBtns= getids(hkctpsBtnID).getElementsByTagName('li');
	var hkctpsTxs = getids(hkctpsTxID).getElementsByTagName('li');
	for(var i=0; i<hkctpsBtns.length; i++) {
		hkctpsBtns[i].className='normal';
		hkctpsTxs[i].className='normal';
	}
}

function classCurrent(hkctpsBtnID,hkctpsTxID,n){
	var hkctpsBtns= getids(hkctpsBtnID).getElementsByTagName('li');
	var hkctpsTxs = getids(hkctpsTxID).getElementsByTagName('li');
	hkctpsBtns[n].className='current';
	hkctpsTxs[n].className='current';
}

function hkctpsChange() {
	if(!getids('hkctps')) return false;
	if(!getids("hkctps_1").innerHTML) return false;
	getids('hkctps').onmouseover = function(){atuokey = true};
	getids('hkctps').onmouseout = function(){atuokey = false};
	var hkctpsBtns = getids('hkctps_btn').getElementsByTagName('li');
	var listLength = hkctpsBtns.length;
	hkctpsBtns[0].onmouseover = function() {
		moveElement('hkctps_piclist',0,0,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',0);
	}
	if (listLength>=2) {
		hkctpsBtns[1].onmouseover = function() {
			moveElement('hkctps_piclist',0,-230,5);
			classNormal('hkctps_btn','hkctps_tx');
			classCurrent('hkctps_btn','hkctps_tx',1);
		}
	}
	if (listLength>=3) {
		hkctpsBtns[2].onmouseover = function() {
			moveElement('hkctps_piclist',0,-460,5);
			classNormal('hkctps_btn','hkctps_tx');
			classCurrent('hkctps_btn','hkctps_tx',2);
		}
	}
	if (listLength>=4) {
		hkctpsBtns[3].onmouseover = function() {
			moveElement('hkctps_piclist',0,-690,5);
			classNormal('hkctps_btn','hkctps_tx');
			classCurrent('hkctps_btn','hkctps_tx',3);
		}
	}
}
setInterval('autohkctps()',5000);
var atuokey = false;
function autohkctps() {
	if(!getids('hkctps')) return false;
	if(atuokey) return false;
	var focusBtnList = getids('hkctps_btn').getElementsByTagName('li');
	var listLength = focusBtnList.length;
	for(var i=0; i<listLength; i++) {
		if (focusBtnList[i].className == 'current') var currentNum = i;
	}
	if (currentNum==0&&listLength!=1 ){
		moveElement('hkctps_piclist',0,-230,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',1);
	}
	if (currentNum==1&&listLength!=2 ){
		moveElement('hkctps_piclist',0,-460,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',2);
	}
	if (currentNum==2&&listLength!=3 ){
		moveElement('hkctps_piclist',0,-690,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',3);
	}
	if (currentNum==3 ){
		moveElement('hkctps_piclist',0,0,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',0);
	}
	if (currentNum==1&&listLength==2 ){
		moveElement('hkctps_piclist',0,0,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',0);
	}
	if (currentNum==2&&listLength==3 ){
		moveElement('hkctps_piclist',0,0,5);
		classNormal('hkctps_btn','hkctps_tx');
		classCurrent('hkctps_btn','hkctps_tx',0);
	}
}
addLoadEvent(hkctpsChange);
function del_box(){
	$('div.alert').fadeOut();
	$('div.alert').remove()
}
function del_box_car(){
	$('.cart_alert').hide('300');
}
function font_14(){
	document.getElementById('dread').style.fontSize="14px";
	}
function font_16(){
	document.getElementById('dread').style.fontSize="16px";
	$("#dread").siblings().css("font-size","16px");
	}
	
function alertbox(msg){
	del_box();
		bodyTop = document.documentElement.scrollTop + document.body.scrollTop+250;
		$("div.baby_top").append('<div class="alert" style="top:'+bodyTop+'px" ><p>系統提示：<img src="images/c.gif" onclick="del_box()"/></p><div>'+msg+'</div></div>');
		$('div.alert').fadeIn();
		setTimeout("del_box()",3000);
		}
function ealertbox(msg){
	del_box();
		bodyTop = document.documentElement.scrollTop + document.body.scrollTop+250;
		$("div.baby_top").append('<div class="alert" style="top:'+bodyTop+'px" ><p>系統提示：<img src="images/c.gif" onclick="del_box()"/></p><div>'+msg+'</div></div>');
		$('div.alert').fadeIn();
		setTimeout("del_box()",3000);
}
function cart_alert(msg){
	del_box_car();
	$(function(){
		$('.cart_alert').show('300');
		$('.cart_alert p').html('商品已'+msg);
		setTimeout("del_box_car()",3000);
							 });
}

function SpareClick(id,url,msg,hurl,type) {
if(!hurl) hurl='cart';
str='';
if(id && url){
if(id.indexOf(',')>0){
id=id.split(',');
url=url.split(',');
for(i=0;i<url.length;i++){
if(i) str =str+'&';
str = str+url[i]+'='+id[i];
}}else{
str=url+"="+id;
}}
php=".php?";
$.ajax({
type: "get",
url: hurl+php,
data:str,
global: false,
beforeSend: function(data, status, settings) {
if(hurl=='address') tb_remove();
$("#"+hurl).html("<div style='width:100%;text-align:center'><img src='images/cart.gif' style='padding:50px 0'></div>");
},
success: function(data, status, settings) {
$("#"+hurl).html(data);
if(msg=='加入購物車') {
	cart_alert(msg);
}else if(msg) alertbox(msg);
},
complete: function(data, status, settings) {
if(msg) tb_remove();
},
error: function(data, status, settings) {
		
if(msg) ealertbox(msg);
}
});
};

function loginClick(id,url,hurl) {
if(!hurl) hurl='cart';
str='';
if(id && url){
if(id.indexOf(',')>0){
id=id.split(',');
url=url.split(',');
for(i=0;i<url.length;i++){
if(i) str =str+'&';
str = str+url[i]+'='+id[i];
}}else{
str=url+"="+id;
}}
php=".php?";
$.ajax({
type: "get",
url:"../"+hurl+php,
data:str,
global: false,
beforeSend: function(data, status, settings) {
$('iframe').contents().find("#m_login").html('正在驗證，請稍等！');
},
success: function(data, status, settings) {
if(data.length<5){
		$('iframe').contents().find("#m_login").html('帳戶密碼錯誤');
}else if(data.length<10){
		$('iframe').contents().find("#m_login").html('請輸入正確帳戶和密碼');
}else{	
$("#"+hurl).html(data);
$.cookie('ifloginto','1');
siemg=$.cookie('emsg_book_login');
if(!siemg) siemg="en";
tb_remove();
var vidf=$.cookie('logingotohref');
if(vidf=='emag') {
	emsg_book_content(siemg); 
}else if(vidf=='shop'){
	window.location.href='shopping.php';
}else if(vidf!='' && vidf) {
	window.location.href=vidf;
}
$.cookie('logingotohref',null);
}
},
complete: function(data, status, settings) {
},
error: function(data, status, settings) {
}
});
};

function book_content(si){
				var siv=0;
				if(si){
				siv=si;
				var si=si.attr("name");
				}else{
				var si=$("#book_cont a:first").attr("name");	
				siv=$("#book_cont a:first");	
				}
				var vid=$('#book_cont_d');
				$("#book_cont a").removeClass('book_cont');
				siv.attr('class','book_cont');
				$("#book_cont_d div").hide();
				$('#'+si).slideDown(300);	   
 }
function tb_remove(){
	 $.fancybox.close();		
}
