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 jzphoto(id,bq,no){
var imgbq=document.getElementById(id).getElementsByTagName(bq);
for(var i=0;i<=imgbq.length;i++){
if((i%4==0)&&(i!=0)){
imgbq[i-1].style.marginRight="0px";
}
}
}

function showLayer(objname,path,id) {
if(objname=="qvpop"){
//$('qvpopiframe').src='include'+id+'.php';
//$('qvpopiframe').src='include.php?main_page=product_info&cPath='+path+'&products_id='+id;
$('qvpopiframe').src='index.php?main_page=popup_include&cPath='+path+'&products_id='+id;
}
$(objname).style.display = "block";
$('body').style.height="100%";
$('body').style.overflow="hidden";
}


function hideLayer(objname,id) {
$(objname).style.display = "none";
$(objname).style.height = "";
document.getElementById('body').style.overflow="";
}




function w(vd){
var ob=document.getElementById(vd);
if(ob.style.display=="block" || ob.style.display==""){
	 ob.style.display="none";
     changeclass('s'+vd,'f');
}
else{
   ob.style.display="block";
    changeclass('s'+vd,'f2');
}
}
function k(vd){
var ob=document.getElementById(vd);
if(ob.style.display=="block" || ob.style.display==""){
     ob.style.display="none";
	 changeclass('s'+vd,'fs');
}
else{
    ob.style.display="block";
	changeclass('s'+vd,'fs2');
}
}

function kn(vd){
var ob=document.getElementById('s'+vd);
if(ob.className=="fs2"){
	 changeclass('s'+vd,'fs');
}
else{
	changeclass('s'+vd,'fs2');
}
}

function injectbuyer(did,sid){
$(did).innerHTML=$(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){
//	clearInterval(din);
for(var i=1;i<=no;i++){
	changediv(par+'tab'+i,0);
	changeclass(par+'taba'+i,"normal");
}
changeclass(par+'taba'+tabid,"select");
//sopen($(par+'tab'+tabid),550,10);
changediv(par+'tab'+tabid,1);
}

function controltabs(par,startid,maxid,no){
var nowtab;
for(var i=1;i<=maxid;i++){
	if($(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)/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 productmove(ob,maximg,limiteimg,pagewidth,sign){
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);
}


			function getlocaltion(){
				var path;
				var tmppath=location;
			if (tmppath.toString().indexOf("bbb")>0){
				path=location;
			}else{
				path=location+'#bbb';
			}		
				$('writea').innerHTML="<a href="+path+">Write a review</a>";
			}
			function getbbb(){
				var pa;
				var tmp=location;
			if (tmp.toString().indexOf("bbb")>0){
				pa=location;
			}else{
				pa=location+'#bbb';
			}		
				$('tobe').innerHTML="<a href="+pa+" class=\"reviewbtn\"></a>";
			}
			function top(){
				var p;
				var top=location;
			if (top.toString().indexOf("top")>0){
				p=location;
			}else{
				p=location+'#top';
			}		
				$('totop').innerHTML="<a href="+p+">back to top</a>";
			}