// ###########################
//
// Javascipt di www.web2net.it
//
// versione:        1.0
// data:        18.01.2004
// autore:        Laurin Moroder
//
// info@web2net.it
//
// ############################

// barra di stato

window.status = "Ski Rental & Service Val Gardena, Gröden - Dolomiten, Dolomiti, Dolomites";


// Per aprire un popup


/*
function oeffnefenster (url) {
 fenster=window.open(url, "fenster1", "width=600,height=450,status=no,scrollbars=no,resizable=no,top=0,left=0");
 fenster.focus();
}

*/
function popup2(file, larghezza, altezza)
{

        var openpopup = window.open(file,"", "width="+larghezza+", height="+altezza+", toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=no,resizable=no");
}


function popup2(file, larghezza, altezza)
{

        var openpopup = window.open(file,"page", "width="+larghezza+", height="+altezza+", toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=no,resizable=no");
}

function popup3(file, larghezza, altezza)
{

        var openpopup = window.open(file,"page", "width="+larghezza+", height="+altezza+", toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars=yes,resizable=no");
}

/*
,"toolbar=no, left=2, top=2"

'toolbar=no,left=2,top=2,status=no,directories=no,menubar=no,scrollbars=no,resizable=no'
*/

var ImageListOff=new Array();
var ImageListOn=new Array();

onload=ImagesPreload;

function ImagesPreload(){
        if(document.images){

// bandieres

                ImageListOff[1]= new Image; ImageListOff[1].src='images/cover/gasthof_somont_willkommen.jpg';
                ImageListOn[1] = new Image; ImageListOn[1].src='images/cover/gasthof_somont_willkommen_a.jpg';
                ImageListOff[2]= new Image; ImageListOff[2].src='images/cover/albergo_somont_benvenuti.jpg';
                ImageListOn[2] = new Image; ImageListOn[2].src='images/cover/albergo_somont_benvenuti_a.jpg';
                ImageListOff[3]= new Image; ImageListOff[3].src='images/cover/hotel_somont_welcome.jpg';
                ImageListOn[3] = new Image; ImageListOn[3].src='images/cover/hotel_somont_welcome_a.jpg';

// menu DEU

                ImageListOff[21]= new Image; ImageListOff[21].src='../images/intern/willkommen.jpg';
                ImageListOn[21] = new Image; ImageListOn[21].src='../images/intern/willkommen_a.jpg';
                ImageListOff[22]= new Image; ImageListOff[22].src='../images/intern/ambiente.jpg';
                ImageListOn[22] = new Image; ImageListOn[22].src='../images/intern/ambiente_a.jpg';
                ImageListOff[23]= new Image; ImageListOff[23].src='../images/intern/zimmer.jpg';
                ImageListOn[23] = new Image; ImageListOn[23].src='../images/intern/zimmer_a.jpg';
                ImageListOff[24]= new Image; ImageListOff[24].src='../images/intern/kueche.jpg';
                ImageListOn[24] = new Image; ImageListOn[24].src='../images/intern/kueche_a.jpg';
   				ImageListOff[25]= new Image; ImageListOff[25].src='../images/intern/lage.jpg';
                ImageListOn[25] = new Image; ImageListOn[25].src='../images/intern/lage_a.jpg';
                ImageListOff[26]= new Image; ImageListOff[26].src='../images/intern/preise.jpg';
                ImageListOn[26] = new Image; ImageListOn[26].src='../images/intern/preise_a.jpg';
                ImageListOff[27]= new Image; ImageListOff[27].src='../images/intern/anfrage.jpg';
                ImageListOn[27] = new Image; ImageListOn[27].src='../images/intern/anfrage_a.jpg';


// menu ENG

                ImageListOff[31]= new Image; ImageListOff[31].src='../images/grafica/juac/menu/eng/welcome.jpg';
                ImageListOn[31] = new Image; ImageListOn[31].src='../images/grafica/juac/menu/eng/welcome_a.jpg';
                ImageListOff[32]= new Image; ImageListOff[32].src='../images/grafica/juac/menu/eng/ambiente.jpg';
                ImageListOn[32] = new Image; ImageListOn[32].src='../images/grafica/juac/menu/eng/ambiente_a.jpg';
                ImageListOff[33]= new Image; ImageListOff[33].src='../images/grafica/juac/menu/eng/restaurant.jpg';
                ImageListOn[33] = new Image; ImageListOn[33].src='../images/grafica/juac/menu/eng/restaurant_a.jpg';
                ImageListOff[34]= new Image; ImageListOff[34].src='../images/grafica/juac/menu/eng/rooms.jpg';
                ImageListOn[34] = new Image; ImageListOn[34].src='../images/grafica/juac/menu/eng/rooms_a.jpg';
   				ImageListOff[35]= new Image; ImageListOff[35].src='../images/grafica/juac/menu/eng/location.jpg';
                ImageListOn[35] = new Image; ImageListOn[35].src='../images/grafica/juac/menu/eng/location_a.jpg';
                ImageListOff[36]= new Image; ImageListOff[36].src='../images/grafica/juac/menu/eng/prices.jpg';
                ImageListOn[36] = new Image; ImageListOn[36].src='../images/grafica/juac/menu/eng/prices_a.jpg';
                ImageListOff[37]= new Image; ImageListOff[37].src='../images/grafica/juac/menu/eng/request.jpg';
                ImageListOn[37] = new Image; ImageListOn[37].src='../images/grafica/juac/menu/eng/request_a.jpg';



}

}

function ImageOn(NumeroImage,NomeImage){
        if (ImageListOn[NumeroImage])
                document[NomeImage].src=ImageListOn[NumeroImage].src;
}

function ImageOff(NumeroImage,NomeImage){
        if (ImageListOff[NumeroImage])
                document[NomeImage].src=ImageListOff[NumeroImage].src;
}



//image move


function Position(x, y)
{
  this.X = x;
  this.Y = y;
  
  this.Add = function(val)
  {
    var newPos = new Position(this.X, this.Y);
    if(val != null)
    {
      if(!isNaN(val.X))
        newPos.X += val.X;
      if(!isNaN(val.Y))
        newPos.Y += val.Y
    }
    return newPos;
  }
  
  this.Subtract = function(val)
  {
    var newPos = new Position(this.X, this.Y);
    if(val != null)
    {
      if(!isNaN(val.X))
        newPos.X -= val.X;
      if(!isNaN(val.Y))
        newPos.Y -= val.Y
    }
    return newPos;
  }
  
  this.Min = function(val)
  {
    var newPos = new Position(this.X, this.Y)
    if(val == null)
      return newPos;
    
    if(!isNaN(val.X) && this.X > val.X)
      newPos.X = val.X;
    if(!isNaN(val.Y) && this.Y > val.Y)
      newPos.Y = val.Y;
    
    return newPos;  
  }
  
  this.Max = function(val)
  {
    var newPos = new Position(this.X, this.Y)
    if(val == null)
      return newPos;
    
    if(!isNaN(val.X) && this.X < val.X)
      newPos.X = val.X;
    if(!isNaN(val.Y) && this.Y < val.Y)
      newPos.Y = val.Y;
    
    return newPos;  
  }  
  
  this.Bound = function(lower, upper)
  {
    var newPos = this.Max(lower);
    return newPos.Min(upper);
  }
  
  this.Check = function()
  {
    var newPos = new Position(this.X, this.Y);
    if(isNaN(newPos.X))
      newPos.X = 0;
    if(isNaN(newPos.Y))
      newPos.Y = 0;
    return newPos;
  }
  
  this.Apply = function(element)
  {
    if(typeof(element) == "string")
      element = document.getElementById(element);
    if(element == null)
      return;
    if(!isNaN(this.X))
      element.style.left = this.X + 'px';
    if(!isNaN(this.Y))
      element.style.top = this.Y + 'px';  
  }
}

function hookEvent(element, eventName, callback)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
    return;
  if(element.addEventListener)
  {
    element.addEventListener(eventName, callback, false);
  }
  else if(element.attachEvent)
    element.attachEvent("on" + eventName, callback);
}

function unhookEvent(element, eventName, callback)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
    return;
  if(element.removeEventListener)
    element.removeEventListener(eventName, callback, false);
  else if(element.detachEvent)
    element.detachEvent("on" + eventName, callback);
}

function cancelEvent(e)
{
  e = e ? e : window.event;
  if(e.stopPropagation)
    e.stopPropagation();
  if(e.preventDefault)
    e.preventDefault();
  e.cancelBubble = true;
  e.cancel = true;
  e.returnValue = false;
  return false;
}

function getMousePos(eventObj)
{
  eventObj = eventObj ? eventObj : window.event;
  var pos;
  if(isNaN(eventObj.layerX))
    pos = new Position(eventObj.offsetX, eventObj.offsetY);
  else
    pos = new Position(eventObj.layerX, eventObj.layerY);
  return correctOffset(pos, pointerOffset, true);
}

function getEventTarget(e)
{
  e = e ? e : window.event;
  return e.target ? e.target : e.srcElement;
}

function absoluteCursorPostion(eventObj)
{
  eventObj = eventObj ? eventObj : window.event;
  
  if(isNaN(window.scrollX))
    return new Position(eventObj.clientX + document.documentElement.scrollLeft + document.body.scrollLeft, 
      eventObj.clientY + document.documentElement.scrollTop + document.body.scrollTop);
  else
    return new Position(eventObj.clientX + window.scrollX, eventObj.clientY + window.scrollY);
}

function dragObject(element, attachElement, lowerBound, upperBound, startCallback, moveCallback, endCallback, attachLater)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
      return;

  var cursorStartPos = null;
  var elementStartPos = null;
  var dragging = false;
  var listening = false;
  var disposed = false;

  function dragStart(eventObj)
  {
    if(dragging || !listening || disposed) return;
    dragging = true;

    if(startCallback != null)
      startCallback(eventObj, element);

    cursorStartPos = absoluteCursorPostion(eventObj);

    elementStartPos = new Position(parseInt(element.style.left), parseInt(element.style.top));

    elementStartPos = elementStartPos.Check();

    hookEvent(document, "mousemove", dragGo);
    hookEvent(document, "mouseup", dragStopHook);

    return cancelEvent(eventObj);
  }

  function dragGo(eventObj)
  {
    if(!dragging || disposed) return;

    var newPos = absoluteCursorPostion(eventObj);
    newPos = newPos.Add(elementStartPos).Subtract(cursorStartPos);
    newPos = newPos.Bound(lowerBound, upperBound)
    newPos.Apply(element);
    if(moveCallback != null)
      moveCallback(newPos, element);

    return cancelEvent(eventObj);
  }

  function dragStopHook(eventObj)
  {
    dragStop();
    return cancelEvent(eventObj);
  }

  function dragStop()
  {
    if(!dragging || disposed) return;
    unhookEvent(document, "mousemove", dragGo);
    unhookEvent(document, "mouseup", dragStopHook);
    cursorStartPos = null;
    elementStartPos = null;
    if(endCallback != null)
      endCallback(element);
    dragging = false;
  }

  this.Dispose = function()
  {
    if(disposed) return;
    this.StopListening(true);
    element = null;
    attachElement = null
    lowerBound = null;
    upperBound = null;
    startCallback = null;
    moveCallback = null
    endCallback = null;
    disposed = true;
  }
  
  this.GetLowerBound = function()
  { return lowerBound; }
  
  this.GetUpperBound = function()
  { return upperBound; }

  this.StartListening = function()
  {
    if(listening || disposed) return;
    listening = true;
    hookEvent(attachElement, "mousedown", dragStart);
  }

  this.StopListening = function(stopCurrentDragging)
  {
    if(!listening || disposed) return;
    unhookEvent(attachElement, "mousedown", dragStart);
    listening = false;

    if(stopCurrentDragging && dragging)
      dragStop();
  }

  this.IsDragging = function(){ return dragging; }
  this.IsListening = function() { return listening; }
  this.IsDisposed = function() { return disposed; }

  if(typeof(attachElement) == "string")
    attachElement = document.getElementById(attachElement);
  if(attachElement == null)
    attachElement = element;

  if(!attachLater)
    this.StartListening();
}


