/* CONFIG */
menuClassName = "menuNavigazione";

/* SCRIPT */

/*************************************************************************
  This code is from Dynamic Web Coding at www.dyn-web.com
  Copyright 2001-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

/*
    pausing scroller - vertical or horizontal 
    version date: March 2005 (revised GeckoTableFix)
*/

// Arguments: id of content layer (inside wn), width and height of scroller (of wn, that is), 
// number of items (repeat 1st one at end!), axis ("v" or "h"),
// set up mouse events? (boolean)
function dw_scroller(id, w, h, num, axis, bMouse) {
    this.id=id; this.el = document.getElementById? document.getElementById(id): null; 
    if (!this.el) return; this.css = this.el.style; 
    this.css.left = this.x = 0; this.css.top = this.y = 0;
    this.w=w; this.h=h; this.num=num; this.axis=axis||"v"; 
    this.ctr=0; // pause onload (for large doc's, may want to set this to 1)
    this.pause=5000; this.speed=60; // defaults
    if (bMouse) dw_scrollers.setMouseEvents(this.el);
    this.lastTime = new Date().getTime(); this.check = 0;
    this.index = dw_scrollers.ar.length;  dw_scrollers.ar[this.index] = this;
    this.active = true;
}

dw_scroller.prototype.setTiming = function(speed, pause) {
    this.speed = speed; this.pause = pause;
}

dw_scroller.prototype.controlScroll = function() {
    if (this.ctr > this.num-1) {
        this.shiftTo(0, 0); this.ctr = 1;
    } else {
        switch (this.axis) {
            case "v" :
                if (this.y > -this.h * this.ctr) { 
                    var ny = this.y + -1 * this.elapsed/1000 * this.speed;
                    ny = Math.max(ny, -this.h * this.ctr);
                    this.shiftTo(0, ny);	
                } else this.doPause();
                break;
            case "h" :
                if (this.x > -this.w * this.ctr) { 
                    var nx = this.x + -1 * this.elapsed/1000 * this.speed;
                    nx = Math.max(nx, -this.w * this.ctr);
                    this.shiftTo(nx, 0);	
                } else this.doPause();
            break;
        }
    }
}

dw_scroller.prototype.doPause = function() {
    this.check += this.elapsed;
    if (this.check >= this.pause) { this.ctr++; this.check = 0; }
}

dw_scroller.prototype.shiftTo = function(x, y) {
    this.css.left = (this.x = x) + "px";
    this.css.top = (this.y = y) + "px";
}

////////////////////////////////////////////////////////////////////////////
// common to all scrollers (pausing or continuous, vertical or horizontal)
dw_scrollers = {};  
dw_scrollers.ar = []; // global access to all scroller instances

dw_scrollers.setMouseEvents = function(obj) {
    obj.onmouseover = dw_scrollers.halt;
    obj.onmouseout = dw_scrollers.resume;
}

dw_scrollers.halt = function() {
    var curObj;
    for (var i=0; curObj = dw_scrollers.ar[i]; i++) 
        if ( curObj.id == this.id ) { curObj.active = false; return; }
}

dw_scrollers.resume = function(e) {
    var curObj;
    for (var i=0; curObj = dw_scrollers.ar[i]; i++) {
        if ( curObj.id == this.id ) {
            e = e? e: window.event;
            var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
            if ( this != toEl && !dw_contained(toEl, this) ) { 
                var now = new Date().getTime();
                curObj.elapsed = now - curObj.lastTime;
                curObj.lastTime = now; curObj.active = true; return; 
            }
        }
    }
}

// Handle all instances with one timer - idea from youngpup.net
dw_scrollers.timer = window.setInterval("dw_scrollers.control()", 10);
dw_scrollers.control = function() {
    var curObj;
    for (var i=0; curObj = dw_scrollers.ar[i]; i++) {
        if ( curObj.active ) {
            var now = new Date().getTime();
            curObj.elapsed = now - curObj.lastTime;
            curObj.lastTime = now; curObj.controlScroll();
        }
    }
}

// remove layers from table for ns6+/mozilla (needed for scrollers inside tables)
// pass id's of scrollers (i.e., div's that contain content that scrolls, usually wn, or wn1, ...)
dw_scrollers.GeckoTableFix = function() {
    var ua = navigator.userAgent;
    if ( ua.indexOf("Gecko") > -1 && ua.indexOf("Firefox") == -1 
        && ua.toLowerCase().indexOf("like gecko") == -1 ) {
        dw_scrollers.hold = []; // holds id's of wndo (i.e., 'the scroller') and its container
        for (var i=0; arguments[i]; i++) {
            var wndo = document.getElementById( arguments[i] );
            var holderId = wndo.parentNode.id;
            var holder = document.getElementById(holderId);
            document.body.appendChild( holder.removeChild(wndo) );
            wndo.style.zIndex = 1000;
            var pos = getPageOffsets(holder);
            wndo.style.left = pos.x + "px"; wndo.style.top = pos.y + "px";
            dw_scrollers.hold[i] = [ arguments[i], holderId ];
        }
        window.addEventListener("resize", dw_scrollers.rePosition, true);
    }
}

// ns6+/mozilla need to reposition layers onresize when scrollers inside tables.
dw_scrollers.rePosition = function() {
    if (dw_scrollers.hold) {
        for (var i=0; dw_scrollers.hold[i]; i++) {
            var wndo = document.getElementById( dw_scrollers.hold[i][0] );
            var holder = document.getElementById( dw_scrollers.hold[i][1] );
            var pos = getPageOffsets(holder);
            wndo.style.left = pos.x + "px"; wndo.style.top = pos.y + "px";
        }
    }
}

function getPageOffsets(el) {
    var left = el.offsetLeft;
    var top = el.offsetTop;
    if ( el.offsetParent && el.offsetParent.clientLeft || el.offsetParent.clientTop ) {
        left += el.offsetParent.clientLeft;
        top += el.offsetParent.clientTop;
    }
    while ( el = el.offsetParent ) {
        left += el.offsetLeft;
        top += el.offsetTop;
    }
    return { x:left, y:top };
}

// returns true if oNode is contained by oCont (container)
function dw_contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

// avoid memory leak in ie
dw_scrollers.unHook = function() {
  var i, curObj;
  for (i=0; curObj = dw_scrollers.ar[i]; i++) {
    if ( curObj.el ) { 
      curObj.el.onmouseover = null;
      curObj.el.onmouseout = null;
      curObj.el = null;
    }
  }
}

if ( window.addEventListener ) window.addEventListener( "unload", dw_scrollers.unHook, true);
else if ( window.attachEvent ) window.attachEvent( "onunload", dw_scrollers.unHook );

/*************************************************************************
  This code is from Dynamic Web Coding at www.dyn-web.com
  Copyright 2001-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/
function initScroller()
        {
            var scr1 = new dw_scroller('cnt', 180, 280, 17, 'v', true);
            scr1.setTiming(100, 7000);
        }

/* copyright Gianluca Troiani... */

function closeSub(menu) {
	for (var i=0; i<menu.childNodes.length; i++)
		if (menu.childNodes[i].nodeName.toLowerCase()=="li") {
			li = menu.childNodes[i];
			li.onmouseover = li.onactivate = li.onfocus = function() { if (this.subMenu) this.subMenu.className = this.subMenu.className.replace(/subMenu-off/g,"subMenu-on") };
			li.onmouseout = li.ondeactivate = li.onblur = function() { if (this.subMenu) closeSub(this.subMenu) };
			for (j=0; j<li.childNodes.length; j++)
				if (li.childNodes[j].nodeName.toLowerCase()=="ul" || li.childNodes[j].nodeName.toLowerCase()=="ol") closeSub(li.subMenu = li.childNodes[j]);
		}
	menu.className = menu.className.replace(/\s?subMenu-on/g,"")+" subMenu-off";
}

/*   dw_banners.js   version date: April 2005  */

/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2001-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

dw_Banner.restartDelay = 500; // delay onmouseout to restart rotation

dw_Banners = {}; // globally accessible reference to object 
function dw_Banner(id, delay, bMouse) {
    this.id = id; this.delay = delay; this.items = []; this.ctr = 0; this.timer = null;
    dw_Banners[this.id] = this; this.animString = "dw_Banners." + this.id;
    if (bMouse) dw_Banner.setMouseEvents(this.id); // set up pause/resume onmouseover/out
};

dw_Banner.prototype.addItem = function(sHtml) {
 	this.items[this.items.length] = sHtml;
};

dw_Banner.prototype.rotate = function() {
    clearTimeout(this.timer); this.timer = null;
    var el = document.getElementById(this.id);
    if ( el && typeof el.innerHTML != "undefined" ) {
        el.innerHTML = this.items[this.ctr];
        if (this.ctr < this.items.length-1) this.ctr++;
        else this.ctr = 0;
        this.timer = setTimeout(this.animString + ".rotate()", this.delay);
    }
};

dw_Banner.setMouseEvents = function(id) {
    var el = document.getElementById(id);
    if (el) {
        el.onmouseover = dw_Banner.pause;
        el.onmouseout = dw_Banner.resume;
    }
};

// these 2 functions called onmouseover/out of banner el
dw_Banner.pause = function() { 
    var curObj = dw_Banners[this.id];
    if (curObj) { clearTimeout(curObj.timer); curObj.timer = null; }
};
 
dw_Banner.resume = function(e) {
    e = e? e: window.event;
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( this != toEl && !dw_contained(toEl, this) ) {
        var curObj = dw_Banners[this.id];
        if (curObj)
            curObj.timer = setTimeout(curObj.animString + ".rotate()", dw_Banner.restartDelay);
    }
};

// returns true of oNode is contained by oCont (container)
function dw_contained(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
    return false;
};

var imageHandler = { 
    path:"", imgs:[], preload:function() { for(var i=0;arguments[i];i++) {
    var img=new Image(); img.src=this.path+arguments[i]; this.imgs[this.imgs.length]=img;}}
};
/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2001-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// preload images
imageHandler.path = "images/";
imageHandler.preload("bisanum.jpg", "bannaranci.gif", "euro.gif");

function initBanner() {
    if ( !document.getElementById ) return;
    // arguments: id, delay (amount of time in milliseconds you linger on each item)
    var ban1 = new dw_Banner('txtBanner', 8000);
    // add as many items as you like
    // ban1.addItem('DHTML rotating banner from <a href="http://www.dyn-web.com">Dynamic Web Coding</a>');
    // ban1.addItem('Find many more quality DHTML scripts at <a href="http://www.dyn-web.com">dyn-web.com</a>');
    // ban1.addItem('Simple demo documents to help you implement the code ');
    
    var ban2 = new dw_Banner('imgBanner', 8000);
    // put your items here
    ban2.addItem('<a href="http://www.bisanumviaggi.it" target="_blank"><img src="Images/Bisanum.jpg" width=468" height="60" alt="Bisanum Viaggi - Per le tue vancanze a Vieste e sul Gargano" /></a>');
    ban2.addItem('<a href="http://www.eurocasaimm.it" target="_blank"><img src="Images/euro.gif" width=468" height="60" alt="La scelta per le tue vancanze a Vieste e sul Gargano" /></a>');
    ban2.addItem('<a href="http://www.hotelaranci.it" target="_blank"><img src="Images/bannaranci.gif" width=468" height="60" alt="Un successo che non conosce ecclissi..." /></a>');
    

    
    dw_Banner.setPartners(ban1, ban2);
    ban1.rotate();  
    ban2.rotate(); 
}

dw_Banner.setPartners = function(p1, p2) {
    p1.el = document.getElementById(p1.id);
    p2.el = document.getElementById(p2.id);

    if (p1.el && p2.el) {
        p1.el.onmouseover = dw_Banner.tandemHalt;
        p2.el.onmouseover = dw_Banner.tandemHalt;
        p1.el.onmouseout = dw_Banner.tandemResume;
        p2.el.onmouseout = dw_Banner.tandemResume;
        p1.partner = p2; p2.partner = p1;
    }
}

dw_Banner.tandemHalt = function() {
    var curObj = dw_Banners[this.id];
    if ( curObj && curObj.partner ) {
        clearTimeout(curObj.timer); curObj.timer = null;
        clearTimeout(curObj.partner.timer); curObj.partner.timer = null; 
    }
}

dw_Banner.tandemResume = function(x) {
    x = x? x: window.event;
    var toEl = x.relatedTarget? x.relatedTarget: x.toElement;
    if ( this != toEl && !dw_contained(toEl, this) ) { 
        var curObj = dw_Banners[this.id];
        if ( curObj && curObj.partner ) {
            curObj.timer = setTimeout(curObj.animString + ".rotate()", dw_Banner.restartDelay);
            curObj.partner.timer = setTimeout(curObj.partner.animString + ".rotate()", dw_Banner.restartDelay);        
        }
    }     
}

/* ON LOAD */
window.onload = function(e) 
{
	if(tags_ = document.getElementsByTagName('ul'))
		for(i=0; i<tags_.length; i++) 
			if (tags_[i].className==menuClassName) closeSub(tags_[i]);
	if(tags_ = document.getElementsByTagName('ol'))
		for(i=0; i<tags_.length; i++) 
			if (tags_[i].className==menuClassName) closeSub(tags_[i]);
			
	initScroller();
	initBanner();
}


/*
(c) 2004 Gianluca Troiani < g.troiani@constile.org > some rights reserved.
This code is licensed under Creative Commons Attribution-ShareAlike License 
< http://creativecommons.org/licenses/by-sa/2.0/ >

*/



