// Anfragebox Datum

var mon = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var Datum = new Date();
var weekday = Datum.getDay();
var diff = 6-weekday;
var tt = Datum.getDate() +diff;
//var tt = Datum.getDate() +1;
var btt = tt+7;
var mM = Datum.getMonth() + 1;
var bmM = mM;
var tage31 = true;
var actdays = mon[Datum.getMonth()];
if (btt > actdays) { 
	btt = btt-actdays; bmM++; 
} 
if (tt > actdays) { 
	tt = tt-actdays; mM++; 
} 
var jjjj = Datum.getFullYear();
var bjjjj = Datum.getFullYear();
if (bmM > 12) { bmM = 1; bjjjj++; }
if (mM > 12) { mM = 1; jjjj++; }


// Menu

var menuTimeout = 400;
var menuOffsetWidth = 0;
var menuOffsetHeight = -1;

var menuId = 'menu';
var menuTree = new Array();
var menuSections = new Array();
var menuSectionsCountHide = new Array();
var menuSectionsVisible = new Array();

var menuBrowser = navigator.userAgent.toLowerCase();
var menuBrowserIsOpera = menuBrowser.indexOf('opera') != -1;
var menuBrowserIsIE = menuBrowser.indexOf('msie') != -1 && !menuBrowserIsOpera;
//alert(navigator.userAgent);
    
function gallery(id,cat,imgs,lang){
	url = "/gallery.php?id="+id+"&cat="+cat+"&imgs="+imgs+"&lang="+lang;
	width = "450";
	height = "350";
	newwindow=window.open(url,name,'height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
}

function menuInit() {
    menuMakeIds(document.getElementById(menuId).childNodes, menuTree, menuId, 0, 0, 0);
    for (var i = 0; i < menuSections.length; i++) {
        menuSectionsCountHide[menuSections[i]] = 0;
    }
    for (var i = 0; i < menuSections.length; i++) {
        menuInitSection(menuSections[i], menuGetTreeById(menuSections[i]));
    }
}

function menuMakeIds(nodes, tree, id, lastOW, lastBLW, lastBRW) {
    for (var i = 0; i < nodes.length; i++) {
        switch (nodes[i].className) {
            case "top":
            case "box-right":
                id = id + "-" + tree.length;
                nodes[i].id = id;
                if (menuBrowserIsIE && document.compatMode && document.compatMode != "BackCompat") {
                    if (nodes[i].className == "box-right" && nodes[i].currentStyle) {
                        var tmp;
                        tmp = lastBLW + lastBRW;
                        if (tmp) {
                            tmp = Math.floor(tmp / 2) + 1;
                        }
                        nodes[i].style.width = lastOW - ( parseInt(nodes[i].currentStyle.paddingLeft) + parseInt(nodes[i].currentStyle.paddingRight) ) - tmp;
                    }
                }
                tree[tree.length] = new Array();
                tree = tree[tree.length - 1];
                break;
            case "box":
                nodes[i].id = id + "-" + tree.length;
                tree[tree.length] = new Array();
                break;
        }
        var className = new String(nodes[i].className);
        if (menuBrowserIsIE && !(document.compatMode && document.compatMode != "BackCompat")) {
            if (className == "box" || className == "box-hover") {
                nodes[i].style.width = "100%";
            }
        }
        if (className == "section") {
            if (!menuBrowserIsIE) {
                nodes[i].style.width = "100%";
            }
            nodes[i].style.left = (lastOW + menuOffsetWidth) + "px";
            nodes[i].style.top = menuOffsetHeight + "px";
        }
        if (className.substr(0, 7) == "section") {
            menuSections[menuSections.length] = id;
            nodes[i].id = id + "-section";
            lastOW = nodes[i].offsetWidth;
            if (nodes[i].currentStyle) {
                lastBLW = parseInt(nodes[i].currentStyle.borderLeftWidth);
                lastBRW = parseInt(nodes[i].currentStyle.borderRightWidth);
            }
        }
        if (nodes[i].childNodes) {
            menuMakeIds(nodes[i].childNodes, tree, id, lastOW, lastBLW, lastBRW);
        }
    }
}

function menuInitSection(id_section, tree) {
    eval("document.getElementById('"+id_section+"').onmouseover = function() {"+
        "menuShow('"+id_section+"');"+
        "if (document.getElementById('"+id_section+"').className == 'box-right') {"+
            "document.getElementById('"+id_section+"').className = 'box-right-hover';"+
        "}"+
    "}");
    eval("document.getElementById('"+id_section+"').onmouseout = function() {"+
        "setTimeout(\"menuTryHide('"+id_section+"', \"+menuSectionsCountHide['"+id_section+"']+\")\", menuTimeout);"+
        "if (document.getElementById('"+id_section+"').className == 'box-right-hover') {"+
            "document.getElementById('"+id_section+"').className = 'box-right';"+
        "}"+
    "}");
    for (var i = 0; i < tree.length; i++) {
        var id = id_section + "-" + i;
        if (tree[i].length == 0) {
            eval("document.getElementById('"+id+"').onmouseover = function() {"+
                "menuShow('"+id_section+"');"+
                "document.getElementById('"+id+"').className = 'box-hover';"+
            "}");
            eval("document.getElementById('"+id+"').onmouseout = function() {"+
                "setTimeout(\"menuTryHide('"+id_section+"', \"+menuSectionsCountHide['"+id_section+"']+\")\", menuTimeout);"+
                "document.getElementById('"+id+"').className = 'box';"+
            "}");
        }
    }
}

function menuShow(id_section) {
    var sections = menuGetIdParentsArrById(id_section, true);
    for (var i = 0; i < sections.length; i++) {
        menuSectionsCountHide[sections[i]]++;
    }
    for (var i = 0; i < menuSectionsVisible.length; i++) {
        if (!menuArrayContains(sections, menuSectionsVisible[i])) {
            menuHide(menuSectionsVisible[i]);
        }
    }
    document.getElementById(id_section + "-section").style.zIndex = 99;
    document.getElementById(id_section + "-section").style.visibility = 'visible';
    menuSectionsVisible = sections;
}

function menuTryHide(id_section, count) {
    if (count == menuSectionsCountHide[id_section]) {
        var sections = menuGetIdParentsArrById(id_section, true);
        if (menuArraysEqual(sections, menuSectionsVisible)) {
            for (var i = 0; i < sections.length; i++) {
                menuHide(sections[i]);
            }
        } else {
            menuHide(id_section);
        }
    }
}

function menuHide(id_section) {
    document.getElementById(id_section + "-section").style.visibility = 'hidden';
    document.getElementById(id_section + "-section").style.zIndex = -1;
}

function menuGetTreeById(id) {
    var a = id.split("-");
    a.shift();
    var s = "";
    for (var i = 0; i < a.length; i++) {
        s += ("[" + a[i] + "]");
    }
    return eval("menuTree" + s);
}

function menuGetIdParentsArrById(id, includeSelf) {
    var a = id.split("-");
    var ret = new Array();
    if (includeSelf) {
        ret[ret.length] = id;
    }
    while (a.length > 2) {
        a.pop();
        ret[ret.length] = a.join("-");
    }
    return ret;
}

function menuArrayContains(a, s) {
    var found = false;
    for (var i = 0; i < a.length; i++) {
        if (a[i] == s) {
            found = true;
            break;
        }
    }
    return found;
}

function menuArraysEqual(a1, a2) {
    if (a1.length != a2.length) {
        return false;
    }
    for (var i = 0; i < a1.length; i++) {
        if (a1[i] != a2[i]) {
            return false;
        }
    }
    return true;
}


//ncm smooth transition slideshow with randomizer
//ver 2.0, (c) stevi
//allgemeine einstellungen:
var rSlideShowSpeed = 5000;
var rCrossFadeDuration = 3;

// so lassen
var zuf = true;
var rPic = new Array()
var rRandom = new Array();
var rImages = new Array();
var rPreLoad = new Array();
var rNum, rT, rJ = 0;
var i,y,z;
var duplicate=false;
var cat = "";

function init(category) {
	init(category, false);
}

function init(category, zufall) {
	zuf = zufall;
	cat = category;
	switch (category) {
		case 'index': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; rPic[5]='6.jpg'; rPic[6]='7.jpg'; rPic[7]='8.jpg'; rPic[8]='9.jpg'; rPic[9]='10.jpg'; break;
		case 'winter': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; rPic[5]='6.jpg'; rPic[6]='7.jpg'; rPic[7]='8.jpg'; rPic[8]='9.jpg'; break;
		case 'zimmer': rPic[0]='1.jpg'; rPic[1]='2.jpg'; break;
		case 'bar': rPic[0]='1.jpg'; rPic[1]='2.jpg'; break;
		case 'terrasse': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; break;
		case 'koeche': rPic[0]='1.jpg'; rPic[1]='2.jpg'; break;
		case 'badestrand': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; rPic[5]='6.jpg'; rPic[6]='7.jpg'; break;
		case 'kochkurse': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; rPic[5]='6.jpg'; break;
		case 'speisekarte': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; break;
		case 'sport': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; break;
		case 'trinken': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; break;
		case 'vinothek': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; break;
		case 'augenweiden': rPic[0]='1.jpg'; rPic[1]='2.jpg'; rPic[2]='3.jpg'; rPic[3]='4.jpg'; rPic[4]='5.jpg'; rPic[5]='6.jpg'; rPic[6]='7.jpg'; rPic[7]='8.jpg'; rPic[8]='9.jpg'; rPic[9]='10.jpg'; rPic[10]='11.jpg'; rPic[11]='12.jpg'; rPic[12]='13.jpg'; rPic[13]='14.jpg'; rPic[14]='15.jpg'; rPic[15]='16.jpg'; rPic[16]='17.jpg'; rPic[17]='18.jpg'; rPic[18]='19.jpg'; rPic[19]='20.jpg'; break;
	}
	rNum = rPic.length;
	randomize();
	for (i = 0; i < rImages.length; i++){
	   rPreLoad[i] = new Image()
	   rPreLoad[i].src = rImages[i]
	}
	document.write("<img src='http://www.seehotel-lackner.at/images/slideshow/" + rImages[0] + "' width='350' height='250' align='left' name='rSlide'>");
}

function randomize(){
	z=0;
	while (z!=(rNum)){
		y=Math.floor(Math.random()*(rNum));
		for(i=0;i<rRandom.length;i++){	if (y==rRandom[i]){	duplicate=true;	}
	}
	if (duplicate==true){ duplicate=false;	continue; }
	else
		if (duplicate==false){	rRandom[z] = y;	z+=1;	}
	}
	if(zuf) { 
		for(i=0; i<rRandom.length; i++) { rImages[i] = "http://www.seehotel-lackner.at/images/slideshow/" + cat + "/"  + rPic[rRandom[i]]; }	//hier korrekten pfad zu unterverzeichnis der slideshow eintragen
	}
	else {
		for(i=0; i<rPic.length; i++) { rImages[i] = "http://www.seehotel-lackner.at/images/slideshow/" + cat + "/"  + rPic[i]; }	//hier	
	}
}

function runRandomSlideShow(){
   if (document.all){
      document.images.rSlide.style.filter='blendTrans(duration='+rCrossFadeDuration+')'
      document.images.rSlide.filters.blendTrans.Apply()      
   }
   document.images.rSlide.src = rPreLoad[rJ].src
   if (document.all){
      document.images.rSlide.filters.blendTrans.Play()
   }
   rJ = rJ + 1
   if (rJ > (rImages.length-1)) rJ=0
   rT = setTimeout('runRandomSlideShow()', rSlideShowSpeed)
}
