var growthByStep = new Array(60,70, 80, 85, 90, 95, 100);
var stepCount = growthByStep.length;
var realWidth = 100;
var realHeight = 75;

var realWidthORIG = 72;
var realHeightORIG = 54;

var realLeft = 0;
var realTop = 0;
var stepNo = 0;
var dLeft=0;
var dTop=0;
var ImgOnLoad = 0;
var FirstVal = 0;

var AlphaNum = 0;

function show(id){

    //document.getElementById('div'+id).style.display='block';
	document.getElementById('s_div'+id).style.visibility="hidden";
    //document.getElementById(id).style.visibility="hidden";
    showImage(id);
}

function hide(id){

    img=document.getElementById('div'+id);
    clearTimeout(xx);
    img.style.display='none';
    document.getElementById('div'+id).style.display='none';
    document.getElementById('s_div'+id).style.visibility="visible";
    img.style.marginLeft=realLeft+'px';
    img.style.marginTop=realTop+'px';
    stepNo = 0;
    dLeft=0;
    dTop=0;
    FirstVal = 0;
    //document.getElementById(id).style.visibility="hidden";
    //showImage(id);
}

function showImage(id){

img=document.getElementById('div'+id);

    if ((stepCount > stepNo + 1)){

        document.getElementById('div'+id).style.display='block';

        stepNo++;

        img.width = realWidth * growthByStep[stepNo] / 100;

        dLeft=realWidth*growthByStep[stepNo]/200-realWidth*growthByStep[stepNo-1]/200;
        dTop=realHeight*growthByStep[stepNo]/100-realHeight*growthByStep[stepNo-1]/100;

        img.height = realHeight * growthByStep[stepNo] / 100;

        img.style.Left = '0px';
        img.style.Top = '-10px';
		img.style.Left=img.style.Left.substring(0, img.style.Left.length-2)-dLeft+'px';
		img.style.Top=img.style.Top.substring(0, img.style.Top.length-2)-dTop+'px';

  	    xx=setTimeout('showImage("'+id+'")', 10);

		//img.style.opacity = stepNo/10+0.5;
		//img.style.filter = 'alpha(opacity=' + ((stepNo+1)*100/stepCount) + ')';
	}
    var ua = navigator.userAgent.toLowerCase();
    isSafari = (ua.indexOf("safari") != -1);
    if(isSafari) img.style.top = '10px';
}

function resizeImage(id, cordX, cordY, id2, id3){

img=document.getElementById('b_'+id);
div=document.getElementById('div'+id);

        document.getElementById('div'+id).style.display='block';
        //cordX = cordX - 7;
        if(cordX > 71) cordX = 71;
        //if(cordX < 2) cordX = 2;
        if(cordX > 11 && cordX < 13) cordX = 13;
        if(cordY > 53) cordY = 54;
        if(cordY <= 2) cordY = 3;

        if(cordX > 36) w = Math.round(((72 - cordX)/36) * 100); else w = Math.round((cordX/36) * 100);
        if(cordY > 27) h = Math.round(((54 - cordY)/27) * 100); else h = Math.round((cordY/27) * 100);
        q = (h*w)/((h + w) / 2);
        img.width = realWidthORIG+(realWidth-realWidthORIG) * q / 100;
        img.height = realHeightORIG+(realHeight-realHeightORIG) * q / 100;
        //document.getElementById('text').innerHTML = q;

}

document.onmousemove=function(e){
    if (!document.all) { mousex = e.layerX; mousey = e.layerY;}
    if(moveState == true) moveHandler(document.getElementById('rows'), e, widthTab);
    return true
  }

function getCordX(){
    // Получим userAgent браузера и переведем его в нижний регистр
    var ua = navigator.userAgent.toLowerCase();
    // Определим Internet Explorer
    isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
    // Opera
    isOpera = (ua.indexOf("opera") != -1);
    // Gecko = Mozilla + Firefox + Netscape
    isGecko = (ua.indexOf("gecko") != -1);
    // Safari, используется в MAC OS
    isSafari = (ua.indexOf("safari") != -1);
    // Konqueror, используется в UNIX-системах
    isKonqueror = (ua.indexOf("konqueror") != -1);

    if (isIE || isOpera || isKonqueror) {
        mosX = event.x-8;
    }
    if (isGecko || isSafari) {
        mosX = mousex;
    }

    return mosX
}

function getCordY(){
    // Получим userAgent браузера и переведем его в нижний регистр
    var ua = navigator.userAgent.toLowerCase();
    // Определим Internet Explorer
    isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
    // Opera
    isOpera = (ua.indexOf("opera") != -1);
    // Gecko = Mozilla + Firefox + Netscape
    isGecko = (ua.indexOf("gecko") != -1);
    // Safari, используется в MAC OS
    isSafari = (ua.indexOf("safari") != -1);
    // Konqueror, используется в UNIX-системах
    isKonqueror = (ua.indexOf("konqueror") != -1);

    if (isIE || isOpera || isKonqueror) {
        mosY = event.y-8;
    }
    if (isGecko || isSafari) {
        mosY = mousey;
    }

    return mosY
}

function menuHover(id, img){

   document.getElementById('menu'+id).src = 'upload/menu/'+img+'_red.gif';
}

function menuOut(id, img){

    document.getElementById('menu'+id).src = 'upload/menu/'+img+'_black.gif';
}

var STEP = 0;

var TIMER = 0;

function imgHoverLight(id, type,imgPath){
    DIVimg = document.getElementById('mainIMG');
    img = document.getElementById(id);

    if(type == 'hide') {
      TIMER = setTimeout('imgHoverLight("'+id+'","'+type+'","'+imgPath+'")', 1);

      img.style.opacity = ((20-STEP)*5)/100;
      img.style.filter = 'alpha(opacity=' + ((20-STEP)*5) + ')';
      if(STEP==20) {
            //document.getElementById('divload2').style.display = 'block';
      //document.getElementById('divNextBack').style.display = 'none';
      document.getElementById('divload').style.display = 'block';


          //if(pairPath == 0)
          if(screen.height <= 1000){
            DIVimg.innerHTML = '<img id="srcimg" style="width:500px;" src="upload/s_big/' + imgPath + '_b.jpg" onload="document.getElementById(\'mainIMG\').style.display = \'block\'; resize(); imgHoverLight(\'mainIMG\',\'show\',\''+imgPath+'\');" alt="" border="0" />';
          }else{
            DIVimg.innerHTML = '<img id="srcimg" src="upload/big/' + imgPath + '_b.jpg" onload="document.getElementById(\'mainIMG\').style.display = \'block\'; resize(); imgHoverLight(\'mainIMG\',\'show\',\''+imgPath+'\');" alt="" border="0" />';
          }
          DIVimg.style.display = 'none';
          clearTimeout(TIMER);STEP=0;
            var ua = navigator.userAgent.toLowerCase();
            isOpera = (ua.indexOf("opera") != -1);
            isKonqueror = (ua.indexOf("konqueror") != -1);
            if (isOpera || isKonqueror) {
                document.getElementById('mainIMG').style.display = 'block';
                resize();
            }
          }
    } else {
      document.getElementById('divload').style.display = 'none';
      //document.getElementById('divNextBack').style.display = 'block';
      //document.getElementById('divload2').style.display = 'none';
      TIMER=setTimeout('imgHoverLight("'+id+'","'+type+'","'+imgPath+'")', 1);

      img.style.opacity = STEP*4/100;
      img.style.filter = 'alpha(opacity=' + (STEP*4) + ')';
      if(STEP==25) {clearTimeout(TIMER);STEP=0;
       num = parseInt(document.getElementById('liveID').value);
       lenta = document.getElementById('divlenta');
       numall2 = document.getElementById('numall').value;

       num_all = (numall2 * 90) + 20;
       gps = (num*90)+10;
       neleft = parseInt(lenta.style.left)*(-1);
       deltaX = (gps - neleft);
        //alert(deltaX);
       if(deltaX <= 99) {
            tmp3 = gps - 189;
            if(tmp3<0)tmp3 = 0;
            //if(gps > (num_all-180)) tmp3 = num_all-828; else tmp3 = gps - 90;

       } else if (deltaX >= 639) {
            tmp3 = gps - 549;
            if(tmp3 > (num_all - 649)) tmp3 = num_all - 649;
       } else tmp3 = neleft;
       //alert(deltaX);
       //lenta.style.left = '-' + tmp3 + 'px';

       avtoMoveLenta(neleft, tmp3, num_all, tmp3 - neleft);
      }
    }
    STEP++;
}

// Load for main image
function showMainImage(id, imgPath, pairPath, intra2) {

    DIVimg = document.getElementById('mainIMG');
    //alert(DIVimg.style.display);
    if( DIVimg.style.display == 'block' ) {
        if(TIMER!=0) {clearTimeout(TIMER);STEP=0;}
        tmp1 = parseInt(document.getElementById('liveID').value);
        document.getElementById('eye_'+tmp1).style.display = 'none';

        imgHoverLight('mainIMG','hide',imgPath);

           // else DIVimg.innerHTML = '<table id="tableHID" width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="50%" align="center" valign="top"><table cellpadding="0" cellspacing="0" align="center"><tr><td width="15" height="15" style="background-image:url(\'img/shade/l_t.jpg\'); background-repeat:no-repeat;"></td><td rowspan="2" colspan="2" width="250"><img id="srcimg" src="upload/big/' + imgPath + '_b.jpg" width="300" onload="document.getElementById(\'mainIMG\').style.display = \'block\'; document.getElementById(\'sh1\').height = parseInt(document.getElementById(\'srcimg\').height)-15+\'px\';" alt="" border="0" /></td></tr><tr><td width="15" id="sh1" ><div style="background-image:url(\'img/shade/l_c.jpg\'); height:100%; background-repeat:repeat-y;"></div></td></tr><tr><td width="15" height="15" style="background-image:url(\'img/shade/l_d.jpg\'); background-repeat:no-repeat;"></td><td width="250" height="15" style="background-image:url(\'img/shade/d_c.jpg\'); background-repeat:repeat-x;"></td><td width="15" height="15" style="background-image:url(\'img/shade/d_r.jpg\'); background-repeat:no-repeat;"></td></tr></table></td><td width="50%" align="center" valign="top"><table cellpadding="0" cellspacing="0" align="center"><tr><td width="15" height="15" style="background-image:url(\'img/shade/l_t.jpg\'); background-repeat:no-repeat;"></td><td rowspan="2" colspan="2" width="250"><img id="srcimg2" src="upload/big/' + pairPath + '_b.jpg" width="300" onload="document.getElementById(\'mainIMG\').style.display = \'block\'; document.getElementById(\'sh2\').height = parseInt(document.getElementById(\'srcimg2\').height)-15+\'px\'; imgHoverLight(\'mainIMG\',\'show\');" alt="" border="0" /></td></tr><tr><td width="15" id="sh2" ><div style="background-image:url(\'img/shade/l_c.jpg\'); height:100%; background-repeat:repeat-y;"></div></td></tr><tr><td width="15" height="15" style="background-image:url(\'img/shade/l_d.jpg\'); background-repeat:no-repeat;"></td><td width="250" height="15" style="background-image:url(\'img/shade/d_c.jpg\'); background-repeat:repeat-x;"></td><td width="15" height="15" style="background-image:url(\'img/shade/d_r.jpg\'); background-repeat:no-repeat;"></td></tr></table></td></tr></table>';

    }

}

function live(num){
   document.getElementById('liveID').value = num;
   //if(neleft > (num_all-370)) neleft = num_all;
   //tmpcoe = neleft / (num_all-590);
   //avtoMoveRows(parseInt(rows2.style.left), tmpcoe*597);
   //rows2.style.left = tmpcoe*597 + 'px';
   //pol.style.left = ((tmpcoe*597)+13) + 'px';

   document.getElementById('eye_'+num).style.display = 'block';
   num_all = parseInt(document.getElementById('numall').value);
        if(num >= 2) {document.getElementById('row_left').style.display = 'block';}
        if(num >= num_all) {document.getElementById('row_right').style.display = 'none';}
        if(num <= 1) {document.getElementById('row_left').style.display = 'none';}
        if(num < num_all) {document.getElementById('row_right').style.display = 'block';}
}

function avtoMoveLenta(ot2, do2, num_all, delta){
    lenta = document.getElementById('divlenta');
    rows2 = document.getElementById('rows');
    pol = document.getElementById('pole');
    if(ot2<do2) {
       ot2++;
       //if (Math.Abs(delta) > 30) {}
       TIMER2 = setTimeout('avtoMoveLenta('+ot2+', '+do2+', '+num_all+', '+delta+')', 1);

       lenta.style.left = '-' + ot2 + 'px';
       tmpcoe = ot2 / (num_all-650);
       rows2.style.left = tmpcoe*577 + 'px';
       //pol.style.left = ((tmpcoe*597)+13) + 'px';
       pol.style.left = tmpcoe*577 + 'px';
    }
    if(ot2>do2) {
       ot2--;
       TIMER2 = setTimeout('avtoMoveLenta('+ot2+', '+do2+', '+num_all+', '+delta+')', 1);
       lenta.style.left = '-' + ot2 + 'px';
       tmpcoe = ot2 / (num_all-650);
       rows2.style.left = tmpcoe*577 + 'px';
       pol.style.left = tmpcoe*577 + 'px';
    }
    if(ot2==do2 && ot2 != 0 && do2 != 0){
      clearTimeout(TIMER2);
      //alert(TIMER2);
    }
     //Static move
    /*lenta.style.left = '-' + do2 + 'px';
    tmpcoe = do2 / (num_all-650);
    rows2.style.left = tmpcoe*597 + 'px';
    pol.style.left = ((tmpcoe*597)+13) + 'px';*/

}


function showBigPhoto(id){
    AlphaNum++;
    grey_div = document.getElementById('opa_div2');
    mov_enable = pano[parseInt(document.getElementById('liveID').value)];
    if(AlphaNum <=16){

    grey_div.style.display = 'block';
    xx5=setTimeout('showBigPhoto()', 5);

	grey_div.style.opacity = AlphaNum/20;
	grey_div.style.filter = 'alpha(opacity=' + (AlphaNum * 5) + ')';
    } else {clearTimeout(xx5); AlphaNum=0;
       if(mov_enable == 1) showDivMov(); else showDivPhoto();}

}


function showDivPhoto(){

    document.getElementById('forlist2').style.display = 'block';
    grey_div = document.getElementById('whitelist2');
    op_div = document.getElementById('opa_div2');
    grey_div.style.display = 'block';
     grey_div.style.width = 100 + '%';
    pathimg = img_s[parseInt(document.getElementById('liveID').value)];
    //document.getElementById(\'whitelist2\').style.width = parseInt(document.getElementById(\'v_photo\').width) + 40 + \'px\';
    grey_div.innerHTML = '<img id="v_photo" src="upload/v_big/' + pathimg + '_b.jpg" style="border:10px solid #fff;" onClick="closePhoto();" onLoad="document.getElementById(\'opa_div2\').style.height = (document.getElementById(\'v_photo\').height > document.body.clientHeight) ? document.getElementById(\'v_photo\').height + 60 + \'px\' : document.body.clientHeight;">';

    //var height23 = 100 + '%';
    //op_div.style.height = 1500 + 'px';
    //alert(document.getElementById('whitelist2').style.offsetheight);


}

function showDivMov(){

    document.getElementById('forlist2').style.display = 'block';
    document.getElementById('opa_div2').style.display = 'block';
    grey_div = document.getElementById('whitelist2');
    grey_div.style.display = 'block';
    grey_div.style.width = 100+'%';
    pathimg = img_s[parseInt(document.getElementById('liveID').value)];
    //document.getElementById(\'whitelist2\').style.width = parseInt(document.getElementById(\'v_photo\').width) + 40 + \'px\';
    //grey_div.innerHTML = '<img id="v_photo" src="upload/v_big/' + pathimg + '_b.jpg" style="border:10px solid #fff;" onClick="closePhoto();" onLoad="document.getElementById(\'opa_div2\').style.height = (document.getElementById(\'v_photo\').height > document.body.clientHeight) ? document.getElementById(\'v_photo\').height + 60 + \'px\' : document.body.clientHeight;">';
    htmlText  = '<div class="div_mov" style=""><OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="1280" height="960" codebase="http://www.apple.com/qtactivex/qtplugin.cab">'
     + '<param name="src" value="/upload/mov/' + pathimg + '.mov"><param name="autoplay" value="false"><param name="controller" value="true">'
     + '<param name="loop" value="false">'
     + '<EMBED src="/upload/mov/' + pathimg + '.mov" onClick="closePhoto();" width="1280" height="960" autoplay="false" controller="true" loop="false" bgcolor="#000" pluginspage="http://www.apple.com/quicktime/download/">'
     + '</EMBED></OBJECT></div>';
    grey_div.innerHTML = htmlText;

}

function closePhoto(){
  //document.getElementById('close').style.display = 'none';
  //document.getElementById('contakt_text').style.display = 'none';
  //document.getElementById('whitelist').style.width = '1px';
  document.getElementById('whitelist2').style.display = 'none';
  document.getElementById('opa_div2').style.display = 'none';
  document.getElementById('forlist2').style.display = 'none';

  AlphaNum=0;
}

function closeGrey(){
  document.getElementById('close').style.display = 'none';
  document.getElementById('contakt_text').style.display = 'none';
  document.getElementById('whitelist').style.width = '1px';
  document.getElementById('whitelist').style.display = 'none';
  document.getElementById('opa_div').style.display = 'none';

  AlphaNum=0;
}

function showContakt(){
    AlphaNum++;
    grey_div = document.getElementById('opa_div');
    if(AlphaNum <=16){

    grey_div.style.display = 'block';
    xx4=setTimeout('showContakt()', 5);

	grey_div.style.opacity = AlphaNum/20;
	grey_div.style.filter = 'alpha(opacity=' + (AlphaNum * 5) + ')';
    } else {clearTimeout(xx4); AlphaNum=0; showWhiteDiv();}

}
function showWhiteDiv(){
    AlphaNum++;
    document.getElementById('forlist').style.display = 'block';
    if(AlphaNum <=50){
    grey_div = document.getElementById('whitelist');
    grey_div.style.display = 'block';
    xx5=setTimeout('showWhiteDiv()', 5);

	grey_div.style.width = parseInt(grey_div.style.width)+10+'px';
    } else {clearTimeout(xx5); AlphaNum=0; showContaktText();}

}
function showContaktText(){
    AlphaNum++;
    if(AlphaNum <=20){
    grey_div = document.getElementById('contakt_text');
    grey_div.style.display = 'block';
    document.getElementById('close').style.display = 'block';
    xx6=setTimeout('showContaktText()', 5);

	grey_div.style.opacity = AlphaNum/20;
	grey_div.style.filter = 'alpha(opacity=' + (AlphaNum * 5) + ')';
    } else {clearTimeout(xx6); AlphaNum=0;}

}

function resize(){
    document.getElementById('srcimg').style.width = (screen.height <= 850)?'500px':'640px';
    document.getElementById('mainIMG').style.width = (screen.height <= 850)?'540px':'640px';
    document.getElementById('tableImage').style.height = (screen.height <= 850)?'375px':'480px';
    document.getElementById('divNextBack').style.width = document.getElementById('srcimg').style.width;
    document.getElementById('divNextBack').style.height = document.getElementById('tableImage').style.height;
}

function photoNext(){
    live_cou = parseInt(document.getElementById('liveID').value);
    num_all = parseInt(document.getElementById('numall').value);
    next = live_cou + 1;
    //alert(live_cou);
    showMainImage(id_s[next],img_s[next],0);
    live(next);
    if(next >= 2) {document.getElementById('row_left').style.visibility = 'visible';}
    if(next >= num_all) {document.getElementById('row_right').style.visibility = 'hidden';}
}

function photoBack(){
    live_cou = document.getElementById('liveID').value;
    num_all = document.getElementById('numall').value;
    next = live_cou - 1;
    showMainImage(id_s[next],img_s[next],0);
    live(next);
    if(next <= 1) {document.getElementById('row_left').style.visibility = 'hidden';}
    if(next < num_all) {document.getElementById('row_right').style.visibility = 'visible';}
}


