function $ge(id){var obj=document.getElementById(id);if(typeof(obj)==un){obj=false;};return(obj);}

var pic_id=0;var preload_image=new Array();

var mm_pics=new Array();var mm_sections=[];
var mm_pic_id=0;
for(var i=1;i<mm_sections.length;i++){
  mm_pic_id=mm_pics.length;mm_pics[mm_pic_id]=new Image();mm_pics[mm_pic_id].src='/img/mm/'+i+mm_sections[i]+'_a.png';
  mm_pic_id=mm_pics.length;mm_pics[mm_pic_id]=new Image();mm_pics[mm_pic_id].src='/img/mm/'+i+mm_sections[i]+'_o.png';
  mm_pic_id=mm_pics.length;mm_pics[mm_pic_id]=new Image();mm_pics[mm_pic_id].src='/img/mm/'+i+mm_sections[i]+'.png';
}

if(SITEPAGE){
  var images_to_preload=[];
  for(var i=1;i<images_to_preload.length;i++){
    pic_id=preload_image.length;preload_image[pic_id]=new Image();preload_image[pic_id].src='/img/'+SITEPAGE+'/'+images_to_preload[i]+'.png';
    pic_id=preload_image.length;preload_image[pic_id]=new Image();preload_image[pic_id].src='/img/'+SITEPAGE+'/'+images_to_preload[i]+'_a.png';
  }
}

function smm(obj,ev,id){
  var s=document.getElementById('menu'+id+'s');
  var a=document.getElementById('menu'+id+'a');
  var o=document.getElementById('menu'+id+'o');
  if(s.parentNode.id=='mm_act_item'){return;}
  var zs=false;var za=false;
  //var z=document.getElementById('mm_act_item');if(z){for(var i=0;i<z.childNodes.length;i++){if(z.childNodes[i].tagName=='DIV'){if(!zs){zs=z.childNodes[i];}else{za=z.childNodes[i];break;}}}}
  switch(ev.type){
    case'mouseover':o.style.visibility='visible';s.style.visibility='hidden';if(zs&&za){zs.style.visibility='visible';za.style.display='hidden';};break;
    case'mouseout':s.style.visibility='visible';o.style.visibility='hidden';if(zs&&za){za.style.visibility='visible';zs.style.display='hidden';};break;
  }
}

function mouse_png(obj,ev){
  var itm=new Array();
	for(var i=0;i<obj.childNodes.length;i++){if(obj.childNodes[i].tagName=='DIV'){itm[itm.length]=obj.childNodes[i];obj.childNodes[i].style.visibility='hidden';}}
  var a_id=0;var s_id=1;
  switch(ev.type){
		case'click':itm[a_id].style.visibility='visible';break;
    case'mouseover':itm[a_id].style.visibility='visible';break;
		case'mouseout':itm[s_id].style.visibility='visible';break;
  }
}
function mouse_gif(obj,ev){if(obj.tagName=='IMG'){var s=obj.src;var r=0;if(s.substr(s.length-4)=='.gif'){r=4;if(s.substr(s.length-6,2)=='_a'){r+=2;};s=s.substr(0,s.length-r);switch(ev.type){case'mouseover':obj.src=s+'_a.gif';break;case'mouseout':obj.src=s+'.gif';break;}}}}


/* MAIN */
var hats_count=7;
var hat_srcs=[0,0,0,0,0,0,0];
for(var i=1;i<=7;i++){while(1){var hat_id_in_arr=Math.round(Math.random()*6);if(hat_srcs[hat_id_in_arr]==0){hat_srcs[hat_id_in_arr]=i;break;}}}

function redraw_canv(img_id,hide){
  var canv=document.getElementById('canvas'+img_id);canv.width=clWidth();if(hide){canv.parentNode.style.left=clWidth()+'px';}var ctx=canv.getContext('2d');var img=new Image();
  img.onload=function(){var neww=clWidth();var newh=Math.round(img.height*(neww/img.width));var ix=0;//var iy=-1*Math.round((newh-440)/2);
    var iy=0;if(newh<440){newh=440;neww=Math.round(img.width*(newh/img.height));ix=-1*Math.round((neww-clWidth())/2);}
    ctx.drawImage(img,ix,iy,neww,newh);
  }
  img.src='/img/head/020_'+hat_srcs[img_id-1]+'.jpg';
}

function redraw_canv_ie(img_id,hide){
  var canv=document.getElementById('canvas'+img_id);
  canv.style.width=clWidth()+'px';
  if(hide){canv.parentNode.style.left=clWidth()+'px';}
  var img=new Image();
  img.onload=function(){
    var neww=clWidth();
    var newh=Math.round(img.height*(neww/img.width));var ix=0;//var iy=-1*Math.round((newh-440)/2);
    var iy=0;if(newh<440){newh=440;neww=Math.round(img.width*(newh/img.height));ix=-1*Math.round((neww-clWidth())/2);}
    canv.style.width=neww+'px';
    canv.style.height=newh+'px';
    canv.style.left=ix+'px';
    canv.style.top=iy+'px';
    canv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale')";
  }
  img.src='/img/head/020_'+hat_srcs[img_id-1]+'.jpg';
}

function draw_canvases(){
  var canvases=document.getElementById('canvases');
  
  var lbie=(bn.indexOf("msie")!=-1)&&document.all&&bdb&&!bop;
  var lbie6=bie&&(parseFloat(bnv.substring(bnv.indexOf("MSIE")+5))>=5.5);
  
  for(var i=1;i<=hats_count;i++){
    var div=document.createElement('DIV');
    canvases.appendChild(div);
    div.className='canvasdiv';
    if(lbie||lbie6){
      var canvas=document.createElement('DIV');
      div.appendChild(canvas);
      canvas.id='canvas'+i;
      div.style.position='absolute';
      div.style.top='0px';
      div.style.left='0px';
      redraw_canv_ie(i,(i>1));
    }else{
      var canvas=document.createElement('CANVAS');
      div.appendChild(canvas);
      canvas.id='canvas'+i;
      canvas.width=1300;
      canvas.height=440;
      redraw_canv(i,(i>1));
    }
  }
}

/* ABOUT */

var services_active=true;
function switch_services(){
  var sc=document.getElementById('services_cnt');
  var sw1=document.getElementById('services_sw1');
  var sw2=document.getElementById('services_sw2');
  if(services_active){
    sc.style.display='none';
    services_active=false;
    sw1.style.display='none';
    sw2.style.display='block';
  }else{
    sc.style.display='block';
    services_active=true;
    sw1.style.display='block';
    sw2.style.display='none';
  }
}

function move_head_image(dir){
  
}

var gal_all=false;
var gal_cur=false;
var gal_pos=new Array();
var gal_tmr=false;
var gal_moving=false;
var gal_dir=null;
var gal_2mv=false;
var gal_step=30;
var gal_mw=428;
var gal_nw=4;

function collect_gal(id){
  var gal_block=false;
  if(gal_block=$ge(id)){
    var gal=new Array();
    for(var i=0;i<gal_block.childNodes.length;i++){if(gal_block.childNodes[i].tagName=='DIV'){gal[gal.length]=gal_block.childNodes[i];}}
    return(gal.length?gal:false)
  }
  return(false);
}

function move_gal(dir,gal_html_id,w,sc){
  
  if(sc&&!services_active){
    //move_head_image(dir);
    gal_html_id='canvases';
    gal_nw=1;
    gal_mw=clWidth();
    gal_step=Math.round(gal_mw/20);
  }else{
    gal_nw=4;
    gal_mw=w;
    gal_step=30;
  }
  
  if(gal_moving){return;}else{gal_moving=true;}
  if(gal_all=collect_gal(gal_html_id)){
    gal_cur=gal_html_id;
    if(!gal_pos[gal_cur]){gal_pos[gal_cur]=0;}
    gal_dir=dir;
    gal_2mv=new Array();
    var start=0;var count=gal_nw;
    if(gal_dir){var start=-1;var count=gal_nw-1;}

    for(var i=start;i<=count;i++){
      var pos=gal_pos[gal_cur]+i;
      if(pos>(gal_all.length-1)){pos=pos-gal_all.length;}
      else if(pos<0){pos=gal_all.length+pos;}        
      gal_all[pos].style.left=(i*gal_mw)+'px';
      gal_2mv[gal_2mv.length]=gal_all[pos];
    }
    mv_gal();
  }
}

function mv_gal(){var moved=false;
  for(var i=0;i<=gal_nw;i++){var obj=gal_2mv[i];var l=parseInt(obj.style.left);
    if(gal_dir){
      if(l<(i*gal_mw)){l+=gal_step;if(l>(i*gal_mw)){l=(i*gal_mw);}
        obj.style.left=l+'px';moved=true;
      }
    }else{
      if(l>((i-1)*gal_mw)){l-=gal_step;if(l<((i-1)*gal_mw)){l=((i-1)*gal_mw);}
        obj.style.left=l+'px';moved=true;
      }
    }
  }
  if(moved){gal_tmr=setTimeout('mv_gal();',25);}
  else{clearTimeout(gal_tmr);gal_moving=false;gal_tmr=false;
    if(gal_dir){gal_pos[gal_cur]--;if(gal_pos[gal_cur]<0){gal_pos[gal_cur]=(gal_all.length-1);}}else{gal_pos[gal_cur]++;if(gal_pos[gal_cur]>(gal_all.length-1)){gal_pos[gal_cur]=0;}}
    gal_dir=null;
  }
}


/* PHOTO */

var openKuzovPhoto_img=false;
var openKuzovPhoto_viewer=false;
var openKuzovPhoto_opened=false;
function openKuzovPhoto(obj,ev){if(openKuzovPhoto_opened){return;}
  var shade=document.getElementById('photo_shade');
  var viewer=document.getElementById('photo_viewer');
  var frame=document.getElementById('photo_frame');
  var cnt=document.getElementById('photo_cnt');
  var img=document.getElementById('photo_img');
  
  var parts=obj.getAttribute('alt').split('|');
  parts[1]=parseInt(parts[1]);
  parts[2]=parseInt(parts[2]);

  if(shade&&viewer&&frame&&cnt&&img){
    frame.style.width=(parts[1]+14)+'px';
    frame.style.height=(parts[2]+14)+'px';
    frame.style.left=Math.round((732-parts[1])/2)+'px';
    
    cnt.style.width=(parts[1])+'px';
    cnt.style.height=(parts[2])+'px';
    cnt.style.display='block';
    
    img.width=parts[1];
    img.height=parts[2];
    img.style.width=parts[1]+'px';
    img.style.height=parts[2]+'px';
    
    img.src=parts[0];
    
    shade.style.display='block';
    shade.style.height=pageHeight()+'px';
    viewer.style.display='block';
    
    openKuzovPhoto_opened=true;
  }
  
}

function closeKuzovPhoto(obj,ev){
  if(openKuzovPhoto_opened){
    var cnt=document.getElementById('photo_cnt');cnt.style.display='none';
    var shade=document.getElementById('photo_shade');shade.style.display='none';
    var viewer=document.getElementById('photo_viewer');viewer.style.display='none';
    var img=document.getElementById('photo_img');img.src='';
    openKuzovPhoto_opened=false;
  }
}


var photo_frame=false;var photo_cnt=false;var photo_img=false;var photo_pos=false;var photo_gp_loading_left=false;var photo_gp_loading_right=false;
var pg_image;var pg_next_w=0;var pg_next_h=0;var pg_next_pos='';var pg_posed=false;var pg_img_loaded=false;

function galleryImageLoaded(){photo_img.src=pg_image.src;photo_img.style.width=pg_next_w+'px';photo_img.style.height=pg_next_h+'px';pg_img_loaded=true;if(!pg_moving&&!pg_posed){photo_cnt.style.display='block';photo_gp_loading_left.style.display='none';photo_gp_loading_right.style.display='none';photo_pos.innerHTML=pg_next_pos;pg_posed=true;}}

var gallery_pos_obj=0;
function openGallery(obj,section){var shade=document.getElementById('photo_shade');var viewer=document.getElementById('photo_viewer');
  if(shade&&viewer){shade.style.display='block';shade.style.height=pageHeight()+'px';viewer.style.display='block';
    photo_frame=document.getElementById('photo_frame');photo_cnt=document.getElementById('photo_cnt');photo_img=document.getElementById('photo_img');photo_pos=document.getElementById('gallery_position');photo_gp_loading_left=document.getElementById('gp_loading_left');photo_gp_loading_right=document.getElementById('gp_loading_right');
    if(section!='photo'){var gallery_total=document.getElementById('gallery_total');var pt=0;var pt_obj=false;var gallery_count_images=0;
      while(pt_obj=document.getElementById('pt'+pt)){for(var i=0;i<pt_obj.childNodes.length;i++){if((pt_obj.childNodes[i].tagName=='DIV')){gallery_count_images++;}}
        pt++;}
      gallery_total.innerHTML=gallery_count_images;
    }
    if(photo_frame&&photo_cnt&&photo_img){
      var parts=obj.getAttribute('alt').split('|');pg_posed=pg_img_loaded=false;photo_cnt.style.display='none';photo_gp_loading_left.style.display='block';photo_gp_loading_right.style.display='block';
      photo_frame.style.width='0px';photo_frame.style.height='0px';photo_cnt.style.width='0px';photo_cnt.style.height='0px';
      gallery_pos_obj=obj;pg_next_w=parseInt(parts[1]);pg_next_h=parseInt(parts[2]);pg_next_pos=parseInt(parts[3]);pg_center=true;gallery_resize();
      
      var gallery_image_title=document.getElementById('gallery_image_title');
      if(gallery_image_title){
        if(parts[5]){
          gallery_image_title.setAttribute("title",parts[4]);
          gallery_image_title.src=parts[5];
          gallery_image_title.width=parts[6];
          gallery_image_title.height=parts[7];
          gallery_image_title.style.display='block';
        }else{gallery_image_title.style.display='none';}}
      
      pg_image=new Image();pg_image.onload=galleryImageLoaded;pg_image.src=parts[0];
    }
  }
}

var pg_trg_w=0;var pg_trg_h=0;var pg_step=30;var pg_step_h=0;var pg_moving=false;var pg_center=false;
function gallery_resize(){pg_trg_w=pg_next_w+14;pg_trg_h=pg_next_h+14;pg_moving=true;pg_step_h=Math.round(pg_step*(pg_next_h/pg_next_w));gallery_resize_r();}
function gallery_resize_r(){var moved=false;
  var cw=parseInt(photo_frame.style.width);var ch=parseInt(photo_frame.style.height);
  var wdir=(pg_trg_w>cw);var hdir=(pg_trg_h>ch);
  if(wdir){if(cw<pg_trg_w){moved=true;cw+=pg_step;if(cw>pg_trg_w){cw=pg_trg_w;}}}
  else{if(cw>pg_trg_w){moved=true;cw-=pg_step;if(cw<pg_trg_w){cw=pg_trg_w;}}}
  if(hdir){if(ch<pg_trg_h){moved=true;ch+=pg_step_h;if(ch>pg_trg_h){ch=pg_trg_h;}}}
  else{if(ch>pg_trg_h){moved=true;ch-=pg_step_h;if(ch<pg_trg_h){ch=pg_trg_h;}}}
  photo_frame.style.width=cw+'px';photo_frame.style.height=ch+'px';photo_frame.style.left=Math.round((732-cw)/2)+'px';
  if(pg_center){var th=66+(pg_trg_h-ch)/2;if(th<66){th=66;};photo_frame.style.top=th+'px';}
  cw-=14;if(cw<0){cw=0;};ch-=14;if(ch<0){ch=0;};
  photo_cnt.style.width=cw+'px';photo_cnt.style.height=ch+'px';
  if(moved){setTimeout("gallery_resize_r();",25);}else{pg_moving=false;pg_center=false;if(pg_img_loaded&&!pg_posed){photo_cnt.style.display='block';photo_gp_loading_left.style.display='none';photo_gp_loading_right.style.display='none';photo_pos.innerHTML=pg_next_pos;pg_posed=true;}}
}
function gallery_next(dir,event,section){if(pg_moving){return;};var items=new Array();var cid=0;var iid=0;var obj=false;
  if(section=='photo'){var phpvs=document.getElementById('phpvs');
    if(phpvs){for(var i=0;i<phpvs.childNodes.length;i++){if((phpvs.childNodes[i].tagName=='DIV')){iid=items.length;items[iid]=phpvs.childNodes[i];if(items[iid]==gallery_pos_obj){cid=iid;}}}}
  }else{
    var pt=0;var pt_obj=false;
    while(pt_obj=document.getElementById('pt'+pt)){
      for(var i=0;i<pt_obj.childNodes.length;i++){
        if((pt_obj.childNodes[i].tagName=='DIV')){
          iid=items.length;
          items[iid]=pt_obj.childNodes[i];
          if(items[iid]==gallery_pos_obj){cid=iid;}
        }
      }
      pt++;
    }
  }
  if(!items.length){return;}
  cid+=(dir?1:-1);if(cid>items.length-1){cid=0;}else if(cid<0){cid=items.length-1;};obj=items[cid];
  if(obj){photo_frame=document.getElementById('photo_frame');photo_cnt=document.getElementById('photo_cnt');photo_img=document.getElementById('photo_img');photo_pos=document.getElementById('gallery_position');photo_gp_loading_left=document.getElementById('gp_loading_left');photo_gp_loading_right=document.getElementById('gp_loading_right');
    if(photo_frame&&photo_cnt&&photo_img){var parts=obj.getAttribute('alt').split('|');pg_posed=pg_img_loaded=false;photo_cnt.style.display='none';photo_gp_loading_left.style.display='block';photo_gp_loading_right.style.display='block';
      gallery_pos_obj=obj;pg_next_w=parseInt(parts[1]);pg_next_h=parseInt(parts[2]);pg_next_pos=parseInt(parts[3]);gallery_resize();
      
      var gallery_image_title=document.getElementById('gallery_image_title');
      if(gallery_image_title){
        if(parts[5]){
          gallery_image_title.setAttribute("title",parts[4]);
          gallery_image_title.src=parts[5];
          gallery_image_title.width=parts[6];
          gallery_image_title.height=parts[7];
          gallery_image_title.style.display='block';
        }else{gallery_image_title.style.display='none';}}
      
      pg_image=new Image();pg_image.onload=galleryImageLoaded;pg_image.src=parts[0];
    }
  }
  cancelEvent(event);
}
function closeGallery(event,section){
  var shade=document.getElementById('photo_shade');var viewer=document.getElementById('photo_viewer');
  if(shade&&viewer){viewer.style.display='none';shade.style.display='none';gallery_pos_obj=false;}
}

/* INIT */
function mInit(section){DL=true;
  //var purl=window.location.toString().split('#');
}
