var startimg=1;
var nowimg=1;
var maximg=4;

var dsimg=1;
var dnimg=1;
var dmimg=3;

var productimgcurrent=0;

function Nround(v,e){
var t=1;
for(;e>0;t*=10,e--);
for(;e<0;t/=10,e++);
return Math.round(v*t)/t;
}

function int(I,k) {  
var ff=0;  
var j;  
j=Math.round(I/k)-I/k;  
if (j>=0.5)  
ff=Math.round(I/k)-1;  
if (j<=0)  
ff=Math.round(I/k);  
return ff;  
}

function $(id) {
	return document.getElementById(id);
}

function changediv(divid,type){
switch(type){
case 0:document.getElementById(divid).style.display="none";break;
case 1:document.getElementById(divid).style.display="block";break;
}
}
function changeclass(divid,classname){
document.getElementById(divid).className=classname;
}

function menujs(id,sign){
if(sign==1){
changeclass('l'+id,'select');
$('i'+id).src='/includes/templates/kingex/images/img/menu_arr_c.gif';
changediv('c'+id,1);
}
else{
changeclass('l'+id,'normal');
$('i'+id).src='/includes/templates/kingex/images/img/menu_arr_g.gif';
changediv('c'+id,0);
}
}

function sign(id,sign){
if(sign==1){
changeclass('ls'+id,'select');
$('is'+id).src='/includes/templates/kingex/images/img/menu_arr_c.gif';
}
else{
changeclass('ls'+id,'normal');
$('is'+id).src='/includes/templates/kingex/images/img/menu_arr_g.gif';
}
}




function jzphoto(id,bq,no){
var imgbq=document.getElementById(id).getElementsByTagName(bq);
for(var i=0;i<=imgbq.length;i++){
if((i%no==0)&&(i!=0)){
imgbq[i-1].style.marginRight="0px";
}
}
}





function injectbuyer(did,sid){
document.getElementById(did).innerHTML=document.getElementById(sid).innerHTML;
}


function buyimg(no,did,sname){
if(no==0){
if (nowimg>startimg){
nowimg--;
}
else{
nowimg=maximg;
}
}
else{
if(nowimg<maximg){
nowimg++;
}
else{
nowimg=startimg;
}
}
injectbuyer(did,sname+nowimg);
}

function buyimg2(no,did,sname){
if(no==0){
if (dnimg>dsimg){
dnimg--;
}
else{
dnimg=dmimg;
}
}
else{
if(dnimg<dmimg){
dnimg++;
}
else{
dnimg=dsimg;
}
}
injectbuyer(did,sname+dnimg);
}

function showtabs2(par,tabid,no){
//	clearInterval(din);
for(var i=1;i<=no;i++){
	changediv(par+'tab'+i,0);
	changeclass(par+'taba'+i,"normal");
}
changeclass(par+'taba'+tabid,"select");
changediv(par+'tab'+tabid,1);
}

function showtabs(par,tabid,no,height,speed){
//	clearInterval(din);
for(var i=1;i<=no;i++){
	changediv(par+'tab'+i,0);
	changeclass(par+'taba'+i,"");
}
changeclass(par+'taba'+tabid,"select");
sopen(document.getElementById(par+'tab'+tabid),height,speed);
//changediv(par+'tab'+tabid,1);
}

function controltabs(par,startid,maxid,no){
var nowtab;
for(var i=1;i<=maxid;i++){
	if(document.getElementById(par+'taba'+i).className=='select'){
		nowtab=i;
	}
}
if(no==0){
if (nowtab>startid){
nowtab--;
}
else{
nowtab=maxid;
}
}
else{
if(nowtab<maxid){
nowtab++;
}
else{
nowtab=startid;
}
}
showtabs(par,nowtab,maxid);
}

//var din=setInterval("controltabs('d',1,3,1)",5000);


function sopen(obj,height,speed){
  var h=obj.offsetHeight;
  var maxh=height;
  function dmove(){
    h+=speed; 
    if(h>=maxh){
      obj.style.height=maxh+'px';
      clearInterval(iIntervalId);
    }else{
      obj.style.display='block';
      obj.style.height=h+'px';
    }
  }
  iIntervalId=setInterval(dmove,2);
}


function sclose(obj,speed){
  var h=obj.offsetHeight;
  function dmove(){
    h-=speed;
    if(h<=0){
      obj.style.display='none';
      clearInterval(iIntervalId);
    }else{
      obj.style.display='block';
      obj.style.height=h+'px';
    }
  }
  iIntervalId=setInterval(dmove,2);
}


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)/40);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/40);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/60);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/60);
    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(){
 var focusBtnList = document.getElementById('flashcontrol').getElementsByTagName('a');
 for(var i=0; i<focusBtnList.length; i++) {
  focusBtnList[i].className='';
 }
}
function focusChange() {
 var focusBtnList = document.getElementById('flashcontrol').getElementsByTagName('a');
  focusBtnList[0].onmouseover = function() {
   moveElement('flash',0,0,5);
   classNormal();
   focusBtnList[0].className='select';
  }
  focusBtnList[1].onmouseover = function() {
   moveElement('flash',0,-460,5);
   classNormal();
   focusBtnList[1].className='select';
  }
  focusBtnList[2].onmouseover = function() {
   moveElement('flash',0,-460*2,5);
   classNormal();
   focusBtnList[2].className='select';
  }
  focusBtnList[3].onmouseover = function() {
   moveElement('flash',0,-460*3,5);
   classNormal();
   focusBtnList[3].className='select';
  }
}
function autoFocusChange() {
 var focusBtnList = document.getElementById('flashcontrol').getElementsByTagName('a');
 for(var i=0; i<focusBtnList.length; i++) {
  if (focusBtnList[i].className == 'select') {
   var currentNum = i;
  }
 }
 if (currentNum==0 ){
  moveElement('flash',0,-460,5);
  classNormal();
  focusBtnList[1].className='select';
 }
 if (currentNum==1 ){
  moveElement('flash',0,-460*2,5);
  classNormal();
  focusBtnList[2].className='select';
 }
 if (currentNum==2 ){
  moveElement('flash',0,-460*3,5);
  classNormal();
  focusBtnList[3].className='select';
 } 
 if (currentNum==3 ){
  moveElement('flash',0,0,5);
  classNormal();
  focusBtnList[0].className='select';
 }
}


function productmove(ob,maximg,limiteimg,pagewidth,sign){
//var ob=document.getElementById(obj);
var productimgmax=maximg;
var productimglimite=limiteimg;
var productimgmaxcan=Math.ceil(productimgmax/productimglimite);
var productimgper=pagewidth;
if(sign==0){
if (productimgcurrent>-productimgmaxcan+1){
productimgcurrent--;
}else{
productimgcurrent=0;
}
}
else{
if (productimgcurrent<0){
productimgcurrent++;
}
else{
productimgcurrent=-productimgmaxcan+1;
}
}
moveElement(ob,productimgcurrent*pagewidth,0,2);
}






