
var img_x=0;
var img_y=0
var tmr;
var el_arr = new Array();

// проговариваем текст
function start_speach(txt){
    if(voice_on){
		document.getElementById('TTS_Text').innerHTML=txt;
		document.getElementById('tts').innerHTML=txt;
		document.getElementById('StartSpeech').click();
	}
}
function end_speach(){
	document.getElementById('StopSpeech').click();
}
function callback_speach(){
	//alert('');
}
function update(){
	document.getElementById('UpdateContent').click();
}
function volume(vol){
	document.getElementById('TTS_Tone').innerHTML=vol;
}

function img_preload(){
    for(var i=0;i<arrImages.length;i++){
        if(arrImages[i][0] != ''){
	        var pic = new Image();
	        pic.src=arrImages[i][0];
        }
    }
}

function hide_all(){
    //document.getElementById('imgCont').innerHTML='';

    for(var i=0; i<arrImages.length; i++){
    	if(arrImages[i][4]!='')document.getElementById('sh_img_'+i).style.display='none';    }



}


function get_command(txt){
   document.getElementById('command_tts').innerHTML='<a href="javascript:void(0);" onclick="speac_txt(\''+txt+'\');" class="command_act2">'+txt+'</a>';
   update();
}

function speac_txt(txt){
	document.getElementById('command_tts').innerHTML='<a href="javascript:void(0);" onclick="speac_txt(\''+txt+'\');" class="command_noact">'+txt+'</a>';
	document.getElementById('TTS_Text').innerHTML=txt;
	document.getElementById('StartSpeech').click();
}

function show_img(num){
    for(var i=0; i<arrImages.length; i++){
    	if(arrImages[i][4]!='')document.getElementById('sh_img_'+i).style.display=(num==i)?'block':'none';
    }

		var tmp=get_position('absolute', 'main_img');
	    var x=arrImages[num][1]+tmp.left;
	    var y=arrImages[num][2]+tmp.top;

	    document.getElementById('sh_img_'+num).style.top=y+'px';
	    document.getElementById('sh_img_'+num).style.left=x+'px';

	    //document.getElementById('imgCont').innerHTML+="<img src='"+arrImages[num][0]+"' alt='' style='border:0px;position:absolute;top:"+y+"px;left:"+x+"px;z-index:10;' />";
        document.getElementById('popup_tbl').style.zIndex='1001';

}

function show_img2(img,xx,yy){
    for(i=1;i<=4;i++) document.getElementById('sh_img_'+i).style.display='none';
    //if(current_book==0)
	var tmp=get_position('absolute', 'main_img');
    var x=xx+tmp.left;
    var y=yy+tmp.top;
    document.getElementById('sh_img_'+current_book).style.top=y+'px';
	document.getElementById('sh_img_'+current_book).style.left=x+'px'
    //document.getElementById('imgCont').innerHTML+="<img src='"+img+"' alt='' style='border:0px;position:absolute;top:"+y+"px;left:"+x+"px;z-index:1;' />";
    document.getElementById('popup_tbl').style.zIndex='1001';
}

function get_position(pos, elemId){
    var elem = document.getElementById(elemId);
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    var l = 0;
    var t = 0;
    if(pos=='absolute'){
        while (elem){
            l += elem.offsetLeft;
            t += elem.offsetTop;
            elem = elem.offsetParent;
        }
    }else{
        if(navigator.userAgent.indexOf('Gecko') > -1){
            t=elem.style.top;
            l=elem.style.left;
            t=Number(t.replace("px", ''));
            l=Number(l.replace("px", ''));
        }else{
            t=Number(elem.style.pixelTop);
            l=Number(elem.style.pixelLeft);
        }
    }

    return {'left':l, 'top':t, 'width': w, 'height':h};
}

function setElementPosition(elemId,left,top,width,height){
    var elem = document.getElementById(elemId);
    if(navigator.userAgent.indexOf('Gecko') > -1){
       elem.style.top=top+'px';
       elem.style.left=left+'px';
       if(width>0)elem.style.width=width+'px';
       if(height>0)elem.style.height=height+'px';
   }else{
       elem.style.pixelTop=top;
       elem.style.pixelLeft=left;
       if(width>0)elem.style.pixelWidth=width;
       if(height>0)elemelem.style.pixelHeight=height;
   }
}


//-----------------
var ccnntt=0;
function go_fade(){
    the_opacity=the_opacity - 0.05;
    if(the_opacity <= 0){
        document.getElementById("container").style.display='none';
        //alert(ccnntt);
    	return;
    }
    ccnntt++;
    setElementOpacity('container', the_opacity);
    setTimeout('go_fade()',100);
    //set_pic_img(img_x,img_y);
}

function gouz(){// запуск по загрузке
	setTimeout('go_fade()',2000);
	set_pic_img(img_x,img_y);
}


function setElementOpacity(sElemId, nOpacity)
{
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);
  if (!elem || !opacityProp) return;
  if (opacityProp=="filter")
  {
    nOpacity *= 100;
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
  }
  else elem.style[opacityProp] = nOpacity;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) return 'filter';
  return false; //нет прозрачности
}

function set_pic_img(x,y){// x и y - смещение от позиции реальной картинки
	img_x=x;
	img_y=y;
	var elem = get_position('absolute', 'main_img');// куда нужно двигать
    elem.left += x;
    elem.top += y;
    document.getElementById("pic_img").style.left = elem.left + 'px';
    document.getElementById("pic_img").style.top = elem.top + 'px';
}

function zoom_img(id,todo,sz){
    var tmp = el_arr.length;
    for(var i=0;i<el_arr.length;i++)if(el_arr[i][0]==id)tmp = i;
    step=(todo==1)?50:-50;
    var pos = get_position('absolute', id);
	var c_h = getClientHeight();
	var c_w = getClientWidth();
	if(todo==1){
		if((c_w/2)>pos.left){
			document.getElementById(id).style.left='0px';
			document.getElementById(id).style.right='';
		}else{
			document.getElementById(id).style.left='';
			document.getElementById(id).style.right='0px';
		}
		if((c_h/2)>(pos.top-getBodyScrollTop())){
			document.getElementById(id).style.top='0px';
			document.getElementById(id).style.bottom='';
		}else{
			document.getElementById(id).style.top='';
			document.getElementById(id).style.bottom='0px';
		}
		document.getElementById(id).style.border="1px solid gray";
		document.getElementById(id+'_1').style.zIndex="100";
	}else{		document.getElementById(id+'_1').style.zIndex="0";	}
    el_arr[tmp] = new Array(id, sz, step, pos.width);

    tmr=setTimeout('zoom_img_tmr()',10);
}

function zoom_img_tmr(){
    var get_next=false;
    for(var i=0;i<el_arr.length;i++){
    	if(el_arr[i][2]!=0){
	        if((el_arr[i][2]<=0)&&(el_arr[i][3]<=el_arr[i][1])){
                el_arr[i][2]=0;
                el_arr[i][3]=el_arr[i][1];
                document.getElementById(el_arr[i][0]).style.border="";
	    	}else if((el_arr[i][2]>=0)&&(el_arr[i][3]>=el_arr[i][1])){
                el_arr[i][2]=0;
                el_arr[i][3]=el_arr[i][1];
	    	}else{
	    		get_next=true;
	    		el_arr[i][3]+=el_arr[i][2];
	    	}
            if(((el_arr[i][2]>=0)&&(el_arr[i][3]>=el_arr[i][1])) || ((el_arr[i][2]<=0)&&(el_arr[i][3]<=el_arr[i][1])))el_arr[i][3]=el_arr[i][1];
            document.getElementById(el_arr[i][0]).style.width=el_arr[i][3]+'px';
    	}
    }
    if(get_next)tmr=setTimeout('zoom_img_tmr()',10);
}

function getClientWidth(){
  return (document.compatMode=='CSS1Compat')?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return (document.compatMode=='CSS1Compat')?document.documentElement.clientHeight:document.body.clientHeight;
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}