var calculator = false;
var print_flash = false;

// functions
function init() {
  if (calculator) {
	for (i=0; i<13; i++) {
		//document.getElementById("cb"+i).checked = false;
		getCheckbox(i).checked = false;
	}
	//для примера, пометим некоторые чекбоксы
	//getCheckbox(0).checked = true;
	//getCheckbox(3).checked = true;
	//getCheckbox(4).checked = true;
	//getCheckbox(9).checked = true;
	//document.getElementById("cb"+0).checked = true;
	//document.getElementById("cb"+3).checked = true;
	//document.getElementById("cb"+4).checked = true;
	//document.getElementById("cb"+9).checked = true;
  }
  //updateFlashSize();
}

function onScreenSent(result) {
    //alert("onScreenSent >> " + result);
    f = result.replace("result=","")+".jpg";
    $("#flashscreen img").attr("src","/flashscreen/i/"+f);
    //$("#flash").toggle();
    //$("#flashscreen").toggle();
    setTimeout("window.print()",3000)
}

function isIE() {
  return (navigator.appName.indexOf("Microsoft") != -1);
} 

function getWindowWidth() {
  var w = 0;
  if (typeof(window.innerWidth) == 'number') {
    w = window.innerWidth;
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    w = document.documentElement.clientWidth;
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    w = document.body.clientWidth;
  }

  return w;
}

function updateFlashSize() { 
  var div = getObject("flash");
  var padding = (calculator) ? 630:380;
  var w_window = getWindowWidth() - padding;     
  var k = getWindowWidth()/screen.width; // [0, 1]    
  var w = Math.max((calculator)?370:540, w_window * k);  
  var h = Math.floor(w * (0.4+0.17*(1-k)));
  
  if (!print_flash)
  div.style.height = h+"px";    

  var flash = getObject("shindler");
  if (!flash) {   
      showFlash(); 
  }    

}

// flash content
function showFlash() {
  if (print_flash)
  var so = new SWFObject("/sites/all/themes/shindler/flash/shindler_print.swf", "shindler", "1", "1", "9");
  else
  var so = new SWFObject("/sites/all/themes/shindler/flash/shindler.swf", "shindler", "100%", "100%", "9");
  so.addParam("allowScriptAccess", "always");
  so.addParam("bgColor", "#ffffff");
  so.addParam("scaleMode", "noScale");
  so.addParam("menu", "false");
  so.addParam("id", "shindler");
  so.addParam("name", "shindler");
  so.addParam("wmode", "transparent");
  if (calculator) {
    if (print_flash)
    {
        so.addVariable("defaultEnabled", flash_actives);
        so.addVariable("extraErrorDelay", 20000);
        so.addVariable("sendScreen", "true");
        so.addVariable("sendScreenUrl", "/flashscreen/swf_to_jpg.php");
    }
    else
    so.addVariable("defaultEnabled", "0");
    so.addVariable("animation_mode", "off"); 
  } else {
    so.addVariable("animation_mode", "on"); 
    so.addVariable("extraErrorDelay", -1); // -1 - no additional breakages, 1-100000...000 - time between additional breakages
  }
  so.write("flash");
}

function enableHardware(index) {
  var checked = getCheckbox(index).checked;//document.getElementById("cb"+index).checked;
  //alert(index+"-"+checked);
  getObject("shindler").enableHardware(index, checked);
}

function getCheckbox(index) {
  return getObject("cb"+index);
}

function getObject(movieName) { 
  return document.getElementById(movieName); 
}