var oldCSS, total_cost=0, total_rur,ps;
var fe, fp;

function runActiveContent(what) {
	document.write(what);
}

function doUpdateTotalCost(){
  total_rur = total_cost.toString();
  total_rur = total_rur.replace(".", ",");
  ps = total_rur.indexOf(",");
  if(ps>0&&ps<total_rur.length-1) total_rur = total_rur+"0";
  else if (ps<0) total_rur = total_rur+",00";
  document.forms['orderFrm'].elements['cost_total'].value = total_rur+" р.";  
}

function decrease(what) {
  fe = document.forms['orderFrm'].elements['qty'+what];
  fp = document.forms['orderFrm'].elements['price'+what];
  if(fe.value!="0") {
    fe.value = parseInt(fe.value)-1;
    total_cost = total_cost-parseFloat(fp.value);
  }
  doUpdateTotalCost();
}

function increase(what) {
  fe = document.forms['orderFrm'].elements['qty'+what];
  fp = document.forms['orderFrm'].elements['price'+what];
  fe.value = parseInt(fe.value)+1;
  total_cost = total_cost+parseFloat(fp.value);
  doUpdateTotalCost();
}

function doHighlight(what, color){
  oldCSS = what.style.cssText;
  what.style.cssText = "background-color: "+color;
}

function doBlur(what){
  what.style.cssText = oldCSS;
}

function openCartWindow(url){ 
  if(url=="") url = dp+'cart/';
  if(url=="!") url = "";
  window.open(url, 'cart', 'width=650, height=350, scrollbars=yes, resizable=yes');
}

function doAddToCart(id, params){
  if(total_cost==0) alert("Пожалуйста выберите хотя бы одну позицию для добавления в корзину!");
  else {
    document.forms['orderFrm'].elements['a1'].value = "add";
    openCartWindow("!");
    document.forms['orderFrm'].submit();
  }
}

var img1, img2, img3;
var dots = new Array();
var dots_count;
var current_item=1, previous_item;

function scanDots(){
  for (i=1; i<=10; i++) {
    img1 = document.images['dot'+i.toString()];
	if(typeof(img1)!="undefined") {
           dots[i-1] = img1.offsetTop;
	//  alert(dots[i-1]);
	}
	else break;
  }
  dots_count = i-1;
  //alert("count="+dots_count);
}

var dt, dt1, sa, sd, int1, stopped;

stopped = false;

function startMarquee(){
  if(!stopped) {
    clearInterval(int1);
    document.all['newsMarquee'].start();
  }
}

function setStop(){
  if(navigator.appName=="Microsoft Internet Explorer") stopped = true;
  else document.all['newsMarquee'].stop();
}

function setStart(){
  if(navigator.appName=="Microsoft Internet Explorer") stopped = false;
  else document.all['newsMarquee'].start();
}

function checkMarquee(){
  img1 = document.all['newsMarquee'];
  img2 = dots[current_item-1];
  previous_item = current_item-1;
  if(previous_item<1) previous_item=dots_count;
  img3 = dots[previous_item-1];  
  //alert(img1.scrollTop);
  dt =Math.abs(img2-img1.scrollTop);
  dt1 = Math.abs(img1.scrollTop-img3);
  if(dt<3) {
    current_item++;
	if(current_item>dots_count) current_item=1;
	img1.stop();
	int1 = setInterval("startMarquee()", 2000);

  } else {
    if(dt1>140) sa = Math.abs(Math.round(dt/15));
	else sa = Math.abs(Math.round(dt1/5));
	if(sa<1) sa = 1;
	if(sa>5) sa = 5;
	sd = Math.abs(Math.round(100/sa));
	if(sd<1) sd = 1;
	
	img1.scrollAmount=sa;
	img1.scrollDelay=sd;


  }
  //clearInterval(int);
}

function doStart(){
  if(navigator.appName=="Microsoft Internet Explorer") int = setInterval("checkMarquee()", 100);
  else {
    document.all['newsMarquee'].scrollAmount = 1;
    document.all['newsMarquee'].scrollDelay = 8;
  }
  document.all['newsMarquee'].start();
}

