var Page={
	createTag:function(tagName, Att, Value){
		var s='';
		if(!tagName)tagName='';
		if(!Value)Value='';
		if(Att)s='<'+tagName+' '+Att;
		else s='<'+tagName;
		switch(tagName){
			case 'img': s=s+' />'+Value; break;
			case 'input': s=s+' />'+Value; break;
			case 'br': s=s+' />'+Value; break;
			case 'hr': s=s+' />'+Value; break;
			case 'meta': s=s+' />'+Value; break;
			case 'col': s=s+' />'+Value; break;
			case 'link': s=s+' />'+Value; break;
			case 'base': s=s+' />'+Value; break;
			case '': s=Value; break;
			default: s=s+'>'+Value+'</'+tagName+'>'; break;
			}
		return(s);
		},
	navSelectedItem:null,
	HTMLEncode:function(s){
		return(s.replace(/</g,'&lt;').replace(/>/g,'&gt;'));
		},
	toggleContent:function(Obj, Case){
		Obj=Obj.nextSibling;
		while(Obj){
			if(!Case){
				if(Obj.style)if(Obj.style.display=='none'){Obj.style.display='block'}else{Obj.style.display='none'};
				}
			else
				{
				if(Obj.style)Obj.style.display=Case;
				}
			Obj=Obj.nextSibling;
			}
		},
    toggleWine:function(Obj, id){
        Page.navSelectedItem.className='';
        Obj.className='selected';
        Page.navSelectedItem=Obj;
        var wineBox=document.getElementById('wineLabel');
        var o=wineBox.getElementsByTagName('div');
        var wineName=Obj.firstChild.data;
        for(var i=0;i<o.length;i++){
            if(o[i].id==id)o[i].style.display='block';
            else o[i].style.display='none';
            }
        },
	setHeadlineEvent:function(Obj){
		var tagName='', tagNameSelf=Obj.tagName;
		for(var i=0;i<Obj.length;i++){
			var oH=Obj[i];
			oH.title='Inhalt ein/ausblenden';
			oH.style.cursor='pointer';
			oH.onclick=function(){
				var Obj=this.nextSibling;
				while(Obj){
					tagName=Obj.tagName
					if(tagName==tagNameSelf)break;
					if(Obj.style)if(Obj.style.display=='none'){Obj.style.display='block'}else{Obj.style.display='none'};
					Obj=Obj.nextSibling;
					}
				}
			}
		}
	};

//<yui 3.1.0>
YUI().use('node',
	function(Y){
	    //<var>
        //</var>
		Y.on('contentready', function(){
	        var o=document.getElementById('wineLabel');
	        var navMain=document.getElementById('nav-main').getElementsByTagName('li');
	        var menuName=o.getElementsByTagName('h2')[0].firstChild.data;
	        var selectedItem, s='', hl, bstNr, text, Geschmack, Rebe, aWineName=[];
	        for(var i=0;i<navMain.length;i++){
	            if(menuName==navMain[i].firstChild.firstChild.data){
	                selectedItem=navMain[i];
	                break;
	                }
	            }
            o=o.getElementsByTagName('div');
            for(var i=0;i<o.length;i++){
                hl=o[i].getElementsByTagName('h3')[0];
	            bstNr=getBstNr(o[i]);
	            Geschmack=bstNr.Geschmack;
	            bstNr=bstNr.BestNr;
                o[i].id='wine_'+bstNr;
                o[i].title=menuName;
                Rebe=hl.firstChild.data;
                text=Rebe;
                if(!Geschmack=='')text+='<br />- '+Geschmack;
                s+=(
                    '<li title="'+Rebe+'">'+
                    '<a href="#doc" onclick="Page.toggleWine(this,\'wine_'+bstNr+'\')">'+text+'</a>'+
                    '</li>'+
                    '');
                }
            if(s!='' && selectedItem){
                o=document.createElement('ul');
                o.innerHTML=s;
                selectedItem.appendChild(o);
                }
            //<nested>
            function getBstNr(o){
                var bstNr=o.getElementsByTagName('p'), a=['Geschmack','BestNr'];
                for(var i=0;i<bstNr.length;i++){
                    if(bstNr[i].className=='BstNr'){
                        a.BestNr=bstNr[i].firstChild.data.split(': ')[1];
                        }
                    else if(bstNr[i].className=='Geschmack'){
                        a.Geschmack=bstNr[i].firstChild.data;
                        if(!a.Geschmack || a.Geschmack.length<2)a.Geschmack='';
                        }
                    }
                return a;
                }
            //</nested>
		    },
		    '#wineLabel'
		    );
		Y.on('available', function(){
		    var node=Y.one('#SocialNetworks');
		    var url=window.location.href.split('?')[0].split('#')[0]
		    node.append('<p><iframe src="http://www.facebook.com/plugins/like.php?href='+encodeURIComponent(url)+'&amp;layout=button_count&amp;show_faces=false&amp;width=300&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100%; height:20px"></iframe></p>');
		    },
		    '#SocialNetworks'
		    );
		Y.on('available', function(){
            var dtm=new Date().toLocaleString(), o=document.getElementById('datetime');
	        o.firstChild.data=dtm;
	        o.title=dtm;
	        window.setInterval(function(){var o=document.getElementById('datetime'),dtm=new Date().toLocaleString();o.firstChild.data=dtm;o.title=dtm}, 1000);
            return false;
		    },
		    '#datetime'
		    );
		Y.on('available', function(){
	        var navMain=document.getElementById('nav-main').getElementsByTagName('li');
	        var url=window.location.href.split('?')[0].split('#')[0];
	        var link;
	        for(var i=0;i<navMain.length;i++){
	            link=navMain[i].getElementsByTagName('a')[0];
	            if(url==link.href){
	                Page.navSelectedItem=link;
	                link.className='selected';
	                break;
	                }
	            }
		    },
		    '#nav-main'
		    );
    });
//</yui 3.1.0>
//</script>


function encode_utf8(rohtext){
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,'\n');
	var utftext='';
	for(var n=0; n<rohtext.length; n++){
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
			utftext+=String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)){
			utftext+=String.fromCharCode((c>>6)|192);
			utftext+=String.fromCharCode((c&63)|128);
			}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else{
			utftext+=String.fromCharCode((c>>12)|224);
			utftext+=String.fromCharCode(((c>>6)&63)|128);
			utftext+=String.fromCharCode((c&63)|128);
			}
		}
	return utftext;
	}
function decode_utf8(utftext){
	var plaintext=''; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length){
		c=utftext.charCodeAt(i);
		if (c<128){
			plaintext+=String.fromCharCode(c);
			i++;
			}
		else if((c>191) && (c<224)){
			c2=utftext.charCodeAt(i+1);
			plaintext+=String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
			}
		else{
			c2=utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext+=String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
			}
		}
	return plaintext;
	}
