var Imgi = new Array();
function preload(url) {
   if (document.images) {
      var i = Imgi.length;
      Imgi[i] = new Image();
      Imgi[i].src = url;
   }
}
window.onload = function(){
  preload('images/polska.gif');
  preload('images/wielkabrytania.gif');
  preload('images/niemcy.gif');
}

function GetScrollTop(){
  if(!document.body.scrollTop && !document.documentElement.scrollTop)
    return(0);
  if(!document.body.scrollTop && document.documentElement.scrollTop)
    return(document.documentElement.scrollTop);
  return(document.body.scrollTop);
}
function GetScrollLeft(){
  if(!document.body.scrollLeft && !document.documentElement.scrollLeft)
    return(0);
  if(!document.body.scrollLeft && document.documentElement.scrollLeft)
    return(document.documentElement.scrollLeft);
  return(document.body.scrollLeft);
}
var qx = 0;
var qy = 0;
function GetMouseMove(e){
  if(!e) var e = window.event;
  qx = e.clientX;
  qy = e.clientY;
  document.getElementById("foggy_one").style.left=qx+document.body.scrollLeft+4+'px';
  document.getElementById("foggy_one").style.top=qy+GetScrollTop()+8+'px';
}
function AttachOnMouse(oEl, sText, src){
  if(!(src === null)){
    var url = oEl.src;
    oEl.src = src;
  }else{
    var url = null;
  }
  var oDiv = document.createElement("div");
  oDiv.id = 'foggy_one';
  oDiv.style.position = 'absolute';
  oDiv.style.left = qx + document.body.scrollLeft + 4 + 'px';
  oDiv.style.top = qy + GetScrollTop() + 8 + 'px';
  oDiv.style.border = "solid 1px #1E5207";
  oDiv.style.background = "#49B128";
  oDiv.style.color = "white";
  oDiv.style.visibility = 'visible';
  oDiv.style.padding = '4px';
  oDiv.innerHTML = sText;
  document.body.appendChild(oDiv);
  oEl.onmousemove = GetMouseMove;
  oEl.onmouseout = function(){HideOnMouse(oEl, url);};
}
function ShowOnMouse(oEl, sText){
  if(document.getElementById('foggy_one'))
    document.body.removeChild(document.getElementById('foggy_one'));
  AttachOnMouse(oEl, sText);
}
function HideOnMouse(oEl, url){
  if(!(url === null)){
    oEl.src = url;
  }
  oDiv = document.getElementById('foggy_one');
  if(oDiv)
    document.body.removeChild(oDiv);
  if(oEl !== null){
    oEl.onmouseout = '';
    oEl.onmousemove = null;
  }
}

function openWindow(url, width, height){
  var left = Math.floor((screen.width - width)/2);
  var top = Math.floor((screen.height - height)/2);
  var winParms = "menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no,top="+top+",left="+left+",height="+height+",width="+width;
  var win = window.open(url, 'window', winParms);
  win.window.focus();
}
function openPhoto(id, width, height){
  openWindow('enlarge.php?url=photos/'+id+'.jpg', width, height);
}

var Images = new Array();
function SwapImages(array){
  Images = array;
  document.getElementById('ImageSwap').innerHTML = '<img src="offerimages/'+Images[0][0]+'/small/0.jpg" onmouseover="AttachOnMouse(this, \'Kliknij, by powiększyć\', null)" onclick="openWindow(\'enlarge.php?url=offerimages/'+Images[0][0]+'/0.jpg\', '+Images[0][1]+', '+Images[0][2]+')" />';
  setTimeout(function(){SetImage(1);}, 5000);
}
function SetImage(id){
  id = id%(Images.length);
  var oEl = document.getElementById('ImageSwap');
  OpToZero(oEl, 1, id);
}
function OpToZero(oEl, op, id){
  oEl.style.opacity = op;
  oEl.style.filter ="progid:DXImageTransform.Microsoft.Alpha(Opacity="+100*op+"%)";
  if(op < 0){
    HideOnMouse(null, null);
    Change(oEl, id);
  }
  else
    setTimeout(function(){OpToZero(oEl, op-0.2, id)}, 100);
}
function Change(oEl, id){
  oEl.innerHTML = '<img src="offerimages/'+Images[id][0]+'/small/'+id+'.jpg" onmouseover="AttachOnMouse(this, \'Kliknij, by powiększyć\', null)" onclick="openWindow(\'enlarge.php?url=offerimages/'+Images[id][0]+'/'+id+'.jpg\', '+Images[id][1]+', '+Images[id][2]+')" />';
  OpToOne(oEl, 0.1, id);
}
function OpToOne(oEl, op, id){
  oEl.style.opacity = op;
  oEl.style.filter ="progid:DXImageTransform.Microsoft.Alpha(Opacity="+100*op+"%)";
  if(op >= 1)
    setTimeout(function(){SetImage(id+1);}, 5000);
  else
    setTimeout(function(){OpToOne(oEl, op+0.2, id)}, 100);
}
