if(DIV_WIDTH == 1){STOP_LEFT = 1;}
else {STOP_LEFT = DIV_WIDTH - 1;}
if(DIV_HEIGHT == 1){STOP_TOP = 1;}
else {STOP_TOP = DIV_HEIGHT - 1;}
function move_div(where)
{
   if(ACTIONS == true)
   {
    sPos = 0;
    DIV = document.getElementById('portfolio');
    ACTIONS = false;
	if(where == 'right'){move_right();}
	else if(where == 'left'){move_left();}
	else if(where == 'top'){move_top();}
	else if(where == 'bottom'){move_bottom();}
   }
}
function move_top()
{
  if(NOW_TOP == STOP_TOP){ACTIONS = true; sPos = 0; close_button('button_top');}
  else
  {
  cStop = 'start'; 
  if(sPos == 180){ACTIONS = true; sPos = 0; cStop = 'stop'}
  else {sPos = sPos + 10;}
  pLus = 10;
  if(cStop == 'start')
  {
   DIV.style.top = (parseInt(DIV.style.top) - pLus) + 'px';
   setTimeout('move_top()',10);
  }
  else
  {
   NOW_TOP = NOW_TOP + 1;
   load_img();
  }
 }
}
function move_left()
{
  if(NOW_LEFT == STOP_LEFT){ACTIONS = true; sPos = 0; close_button('button_left');}
  else
  {
  cStop = 'start'; 
  if(sPos == 431){ACTIONS = true; sPos = 0; cStop = 'stop'}
  else {sPos = sPos + 20;}
  pLus = 20;
  if(sPos == 440){sPos = 431; pLus = 11;}
  if(cStop == 'start')
  {
   DIV.style.left = (parseInt(DIV.style.left) - pLus) + 'px';
   setTimeout('move_left()',10);
  }
  else
  {
   NOW_LEFT = NOW_LEFT + 1;
   load_img();
  }
 }
}              
function move_right()
{
  if(NOW_LEFT == 1){ACTIONS = true; sPos = 0; close_button('button_right');}
  else
  {
  cStop = 'start'; 
  if(sPos == 431){ACTIONS = true; sPos = 0; cStop = 'stop'}
  else {sPos = sPos + 20;}
  pLus = 20;
  if(sPos == 440){sPos = 431; pLus = 11;}
  if(cStop == 'start')
  {
   DIV.style.left = (parseInt(DIV.style.left) + pLus) + 'px';
   setTimeout('move_right()',10);
  }
  else
  {
   NOW_LEFT = NOW_LEFT - 1;
   load_img();
  }
 }
}
function move_bottom()
{
  if(NOW_TOP == 1){ACTIONS = true; sPos = 0; close_button('button_bottom');}
  else
  {
  cStop = 'start'; 
  if(sPos == 180){ACTIONS = true; sPos = 0; cStop = 'stop'}
  else {sPos = sPos + 10;}
  pLus = 10;
  if(cStop == 'start')
  {
   DIV.style.top = (parseInt(DIV.style.top) + pLus) + 'px';
   setTimeout('move_bottom()',10);
  }
  else
  {
   NOW_TOP = NOW_TOP - 1;
   load_img();
  }
 }
}



//
function close_button(img_close)
{
  
 
}
function load_img()
{
if(NOW_TOP == 1){document.getElementById('button_top').style.visibility = 'hidden';}
else {document.getElementById('button_top').style.visibility = 'visible';}
if(NOW_LEFT == 1){document.getElementById('button_left').style.visibility = 'hidden';}
else {document.getElementById('button_left').style.visibility = 'visible';}


if(NOW_TOP == STOP_TOP){document.getElementById('button_bottom').style.visibility = 'hidden';}
else {document.getElementById('button_bottom').style.visibility = 'visible';}
if(NOW_LEFT == STOP_LEFT){document.getElementById('button_right').style.visibility = 'hidden';}
else {document.getElementById('button_right').style.visibility = 'visible';}

 show_img(NOW_LEFT,NOW_TOP);
  if(DIV_WIDTH > 1)
  {
    show_img((NOW_LEFT + 1),NOW_TOP);
  }
 
  if(DIV_HEIGHT > 1)
  {
    show_img(NOW_LEFT, (NOW_TOP + 1));
    if(DIV_WIDTH > 1)
    {
      show_img((NOW_LEFT + 1), (NOW_TOP + 1));
     }  
  }
  
}
function show_img(id_left, id_top)
{
 // document.getElementById('none_'+id_left+'_'+id_top).style.display='none';
  img = document.getElementById('portfolio_'+id_left+'_'+id_top);
  if(img.style.display != 'block')
  {
  src = img.src;
  img.src = '/pf/none.gif';
  img.style.display='block';
  preload(img,src);
  }
}
function preload(elem,url){
    var elem;
    elem.src='/pf/none.gif';
    var img= new Image();
    img.src=url;
    img.onload=function(){
        img.onload=null;
        elem.src=url;
    }
    if(img.complete)
        img.onload();
}




document.onmousemove = moveTip;
function moveTip(e) {
floatTipStyle = document.getElementById("messBox").style;
w = 200; // Ширина слоя
// Для браузера IE
if (document.all) { 
x = mPosition(event).x;
y = mPosition(event).y;
// Для остальных браузеров
} else  { 
x = e.pageX; // Координата X курсора
y = e.pageY; // Координата Y курсора
}
// Показывать слой справа от курсора 
if ((x + w + 10) < document.body.clientWidth) { 
floatTipStyle.left = x + 10 + 'px';
// Показывать слой слева от курсора
} else { 
floatTipStyle.left = x - w + 60 + 'px';
}
// Положение от верхнего края окна браузера
floatTipStyle.top = y + 18	+ 'px';
}
function toolTip(msg) {
floatTipStyle = document.getElementById("messBox").style;
if (msg) {
// Выводим текст подсказки
document.getElementById("messBox").innerHTML = msg;
// Показываем слой
floatTipStyle.display = "block";
} else { 
// Прячем слой
cClick = false;
floatTipStyle.display = "none";
} 
}
function mPosition(event) {
    var x = y = 0;
    if (document.attachEvent != null) { // Internet Explorer & Opera
        x = window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        y = window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    } else if (!document.attachEvent && document.addEventListener) { // Gecko
        x = event.clientX + window.scrollX;
        y = event.clientY + window.scrollY;
    } else {
        // Do nothing
    }
    return {x:x, y:y};
}
