var photomove = 0;
var ax = ay = 0;
var ox = oy = 0;
function loadHTML(file, dest, param, add) 
{
  $.ajax(
  {
     url: file + param,
     beforeSend: function()
     {
       if ( add != "+" && add != "-" && add != "s")
       {
         $("#"+dest).html("<img src='/images/wait.gif'/>")
                    .slideDown(700);;
       }
     },
     success: function(answ)
     {
       if ( add == "+" )
       {
         $("#"+dest).hide()  
                     .append(answ)
                     .slideDown(700);
       }
       else
       {
         if ( answ != '' )
         {
            $("#"+dest).hide()  
                        .html(answ)
                        .slideDown(700);
         }
         else
         {
            $("#"+dest).slideUp(700)
                       .html(answ)
                       ;
         }
         if ( add == 's' )
         {
            $("#"+dest).slideUp(700);
         }
       }
     }
  }
  );
}


function show(id)
{
  block = document.getElementById(id).style
  if ( block.display == 'none' )
  {
    block.display = '';
  }
  else
  {
    block.display = 'none';
  }
}

function hide( id )
{
   $("#"+id).hide();
}

function getkamen(id)
{
   loadHTML('/getkamen.php', 'korzina', '?id='+id, ''); 
}
function clean(id)
{
   loadHTML('/getkamen.php', 'korzina', '?action=clean', ''); 
}

function showpic(id, x, y)
{
   
   div = id;
   if ( !photomove )
   {
      $("#"+id).animate({ width: x, height: y }, 0);
      $("#"+id).attr("class", "photo greyborder");
   }
   photomove = 1;
   
   needx = ox*1.0 + x*1.0;
   needy = oy*1.0 + y*1.0;
   
   leftpos = ax*1.0+20
   toppos = ay*1.0+20

   if ( getClientWidth() >  needx )
   {
      leftpos = ax*1.0 + 20
   }
   else 
   {
      leftpos = ax*1.0 - x*1.0 - 10
   }
   
   if ( getClientHeight() >  needy )
   {
      toppos = ay*1.0 + 20;
   }
   else
   {
      toppos = ay*1.0 - (y - (getClientHeight() - oy));
   }
   
   $("#"+id).attr("style", "left:"+leftpos+"px;top:"+toppos+"px;");

}
function hidepic(id, x, y)
{
   $("#"+id).animate({ width: 0, height: 0 }, 0);
   $("#"+id).attr("class", "hide");
   setTimeout('photomove = 0;', 40);
}

document.onmousemove = mouseMove
 
function mouseMove(event){ 
    event = fixEvent(event)
    ax = event.pageX
    ay = event.pageY
    ox = event.x
    oy = event.y

    if ( event.clientX != null ) 
    {
       ox = event.clientX
       oy = event.clientY
    }
}

function fixEvent(e) {
    // получить объект событие для IE
    e = e || window.event
 
    // добавить pageX/pageY для IE
    if ( e.pageX == null && e.clientX != null ) {
        var html = document.documentElement
        var body = document.body
        e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
        e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
    }
    else
    {
      
    }

    // добавить which для IE
    if (!e.which && e.button) {
        e.which = e.button & 1 ? 1 : ( e.button & 2 ? 3 : ( e.button & 4 ? 2 : 0 ) )
    }
 
    return e
}
    
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

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


