var base_url = 'http://www.undwein.de/';
var base_url_ajax = 'http://www.undwein.de/ajax/';
var base_url_finish = 'http://www.undwein.de/ajax/?finish=1';
var base_url_pop = 'http://www.undwein.de/popup/';
  	var isExtended = 0;
	var height = 450;
	var width = 200;
	var slideDuration = 1000;
	var opacityDuration = 1500;
// ######################################################################
// DOMREADY
// ######################################################################

 window.addEvent('domready', function(){
 	
	new pageLoader();
	showTips = true;
//	weinAnzeigen('16');
	
 	/* ############################################################# */
 	/* ############################################################# */
 	
	/* ############################################################# */
	/* ############################################################# */

 		
 		initWeinTrigger();
 		initTagButtons();
 		initMinimizeRealcontent();
 		initClearRealcontent();
 		//initThemenButtons();
 		initAutoComplete();
 		initTips();
 		initMainnavi();
 		initVidAusMenu();
		//minimizeRealcontent();
 		//playMovie();
 		//var moosizer = new mooSizer({ bgElement:'bgImg' });
 		//callLoadNewVideo();
 		initStartseite();
 	
 	/* ############################################################# */
 	/* ############################################################# */
 	
 	
 	
 	
 	/* ############################################################# */
 	/* ############################################################# */
 	
 	
 	
 	
	
	//new History();
 	
 }); 
 /* ############################################################# */
  /* ####################### Startseite ############################ */  
  /* ############################################################# */
 function initStartseite() {
 	// Menu: Stichwort
 	
 	// Titel des Startvideos in die Menüzeile setzen.
 	/*
 	var videotitel = $('featuredVidID').get('html');
 	$('videoTitelAnzeige').set('text', videotitel);
 	
 	
 	// Menu: Wein
 	// Titel des ersten Weins in die Menüzeile setzen.
 	$('videoWeinAnzeige').empty();
 	var weintitel = '';
 	$$('.featuredWeinID').each(function(element,index) {
 		weintitel = element.get('html');
 	});
 	$('videoWeinAnzeige').set('text', weintitel);
 	*/
 	
 	
 	// Pause-Button	anzeigen
 	$('playpausebutton').setProperty('src', '/fileadmin/templates/images/menu/pause.png');
 	$('playpausebutton').setProperty('class', 'play');
 	
 	
 	
 	// PLay-Pause Button initialisieren
 	$('playpausebutton').addEvent('click', function(){
 		 togglePlayPause();
 		 callVideoPlayPause();
 		
 		
 		
 		
 	});
 	//eventCall('79');
 	// Movie Starten
 	//playMovie('/fileadmin/vids/google-encoded/003_brotzeit_undwein.flv');
 	//playMovie('/fileadmin/vids/google-encoded/003_weib_undwein.flv');
 
 	// TEst
 	//weinAnzeigen('1');
 } /* ############################################################# */   
 function initVidAusMenu(){
 	
 	vidLinks = $$('.videoLink');
		vidLinks.each(function(el,i){
			
			el.addEvent('click',function(e){
				if(e != undefined){
					new Event(e).stop();
				}
				startVidAusMenu(el);
				// videotitel einsetzen
				//var headline = el.getChildren('.headline').get('html');
				//$('videoTitelAnzeige').set('html', headline + ' und ');
			}.bind(this));
		}.bind(this));
 
 }
  /* ############################################################# */   
 function startVidAusMenu(el){
 	var menu_id = el.get('id').split("videoID_");
 	// videoname in die play-anzeige
 	//setVidWeine(menu_id[1]);
 	
 	// weinname in die play-anzeige
 	//setNameWein(menu_id[1]);
 	
 	
	callLoadNewVideo(el.get('alt'));
 
 
 } 
  
  
  /* ############################################################# */  
 function togglePlayPause(){

 		var trigger = $('playpausebutton').getProperty('class');
 		if(trigger == 'play'){
 			$('playpausebutton').setProperty('src', '/fileadmin/templates/images/menu/play.png');
 			$('playpausebutton').setProperty('class', 'pause');
 		}else{
 			$('playpausebutton').setProperty('src', '/fileadmin/templates/images/menu/pause.png');
 			$('playpausebutton').setProperty('class', 'play');
 		}
 }
 
 /* ############################################################# */  
 /* Beim Wechsel der Bezahlart wird der zugehörige Hinweis eingeblendet  */ 
 /*	und die Auswahl zu Server gesendet, um sie in der Session zu speichern */  
 /* ############################################################# */
 function bezInfo(selectedEL,nosend){
 	/*
 	0: rechnung
 	1: ueberweisung
 	2: kk
 	3: ba
 	4: NN
 	*/
 	//console.log(selectedEL);
 	$$('.hinweise').each(function(element) {
 		element.setStyles({display:'none'});
 	});
 	
 	if(selectedEL == '0'){
 		$('hinweis_re').setStyles({display:'block'});
 		$('hinweis_re').fade('in');
 		$('hinweis_re').highlight('#ddf');
 	}
 	if(selectedEL == '1'){
 		$('hinweis_uw').setStyles({display:'block'});
 		$('hinweis_uw').fade('in');
 		$('hinweis_uw').highlight('#ddf');
 	}
 	if(selectedEL == '2'){
 		$('hinweis_kk').setStyles({display:'block'});
 		$('hinweis_kk').fade('in');
 		$('hinweis_kk').highlight('#ddf');
 	}
 	if(selectedEL == '3'){
 		$('hinweis_ba').setStyles({display:'block'});
 		$('hinweis_ba').fade('in');
 		$('hinweis_ba').highlight('#ddf'); 		
 	}
 	if(selectedEL == '4'){
 		$('hinweis_nn').setStyles({display:'block'});
 		$('hinweis_nn').fade('in');
 		$('hinweis_nn').highlight('#ddf'); 		
 	}
 	if(nosend != '1'){
 		var jsonRequest = new Request.JSON({
			url: base_url_ajax, 
			onComplete: function(oRsp){
				//console.log(oRsp);
				bezInfo(oRsp.result.data.bez,1);
			}
		}).get({'ajax': 1,'chBEZ': selectedEL});
	}
	
 }   
 /* ############################################################# */  
 /* Aufruf der Info-Boxen aus dem Flash-file, uid entspricht der */
 /* UID des Inhaltselements im BE */  
 /* ############################################################# */
 function eventCall(uid){
 		var pop_neu = 'pop_' + uid;
 	 	// wenn die Box mit der id schon angezeigt wird, abbrechen
		if($(pop_neu)){
		
			$('realcontent_right').grab($(pop_neu),'top');

		
			$(pop_neu).highlight('#ff0000');
			return false;
		}else{
			
 		this.popup = new Request({  
			method: 'get',  
			url: base_url_pop,
			
			onRequest: function() {
				var pop = new Element('div', {
					'id': 'poploader_' + uid,
					'class': 'singlewein_loading'
				}).inject('realcontent_right','top');
			},
			onComplete: function(result){
			
				$('poploader_' + uid).destroy();
				var pop = new Element('div', {
					'id': 'pop_' + uid,
					'class': 'singlewein boxfunctionEvent'
				}).inject('realcontent_right','top');
				
				
				var temp = new Element('div').set({ id:'temp', display:'none' }).injectInside(document.body);
				temp.set({html:result});
				
				var target_id = '#uid_' + uid;
				var select =  $('temp').getElement(target_id);
				var value = select.get('html');
				$('temp').destroy();
				$('pop_' + uid).setAttribute('class','singlewein boxfunctionEvent');
				
				
				var oben = new Element('div', {
					'class': 'oben'
				}).inject($('pop_' + uid),'top');

				var boxfunc = new Element('div', {
					'id': 'boxfunctionEvent_' + uid,
					'class': 'boxfunction inline right'	
				}).inject($('pop_' + uid),'bottom');
						
				
				var rand_id = 'dummy_' + Math.round((Math.random() * 1000000));
				var dummy = new Element('div', {
					'id': rand_id
				}).inject($('boxfunctionEvent_' + uid),'top');
						
				var closebut = new Element('div', {
					'id': 'boxfunctionEvent_' + uid,
					'class': 'self_close pointer boxfunctionEventCloseBut',
					'html' : '<img width="16" height="16" title="close" alt="close" src="/fileadmin/templates/images/close.png"/>'
				}).inject($(rand_id),'top');
				
				var mitte = new Element('div', {
					'id': 'mitte_' + uid,
					'class': 'mitte',
					'html' : value
				}).inject($('pop_' + uid),'bottom');
						
				var unten = new Element('div', {
					'class': 'unten'
				}).inject($('pop_' + uid),'bottom');

						
			
				
				// box-destroyer starten
				BoxDestroy('pop_' + uid,30000);
				
				// stop-box-destroyer initialisieren (rollover)
				initStopBoxDestroy('pop_' + uid);		
				
				// closeButton aktivieren
				initCloseButton();
				// pageLoader aktivieren, um links in den boxen abzufangen
				new pageLoader();
			}
				
		}).get({'rand':$random(0, 4096), 'getID':uid});
	}	


 }
 
 /* ############################################################# */
 /* ################### VIDEOFUNKTIONEN ######################### */  
 /* ############################################################# */
 	/* This utility function resolves the string movieName to a Flash object reference based on browser type. */

	function callVideoPlayPause() {
		$('bgFlash').extCallVideoPausePlay();
		return null;
	}
	function callLoadNewVideo(moviePath){
		$('bgFlash').extCallLoadNewVideo(moviePath);
		return null;
	}
		
	
 /* ############################################################# */  
 /* ###################### MAINNAVI ############################# */
 /* ############################################################# */
 function initMainnavi(){
 	// Mainnavi initialization

	$$('.mainnavicontent').fade('hide');
	$$('.mainnaviitem').each(function(element,index) {
	
		element.addEvents({
			'mouseover': function(){
				var contentbox = element.getNext();
				// alle anderen contentboxen ausblenden
				// ausser der eigenen contentbox
				$$('.mainnavicontent').each(function(otherelement) {
					if(contentbox != otherelement){
						otherelement.fade('out');
					}
					
				});

				contentbox.fade('in');
				contentbox.addEvents({
					'mouseleave': function(){
						contentbox.fade('out');
					},
					'mouseover': function(){
						element.removeEvents('mouseleave');
					}
				});

			},
			'mouseleave': function(){
				(function(){element.getNext().fade('out');}).delay(1000);
			}
		});
	
	});
		
 		
		
	}
	

 /* ############################################################# */
 /* Die Tips werden bei rollover in der Weinliste verwendet, nach dem ersten */
 /* Klick werden sie aber nicht mehr angezeigt (showTips= false) */
 /* ############################################################# */
 
 function initTips(){
 	//erstmal alle ollen weg
 	$$('.custom-tip').each(function(element) {
 		element.destroy();
 	});
 	//store titles and text

 	if(showTips){
 		// FILTER
		$$('.ShowTipFilter').each(function(element,index) {
		    //var content = element.get('title').split('::');
		    var content = element.innerHTML;
		    element.store('tip:title', 'Alle Weine mit der Eigenschaft <span class="tip-text">' + content + '</span> anzeigen');
		    element.store('tip:text', '');
		});
		//create the tooltips
		var tipz = new Tips('.ShowTipFilter',{
		    className: 'custom-tip'
		});
		
		// sortierung
		$$('.ShowTipSortierung').each(function(element,index) {
		    //var content = element.get('title').split('::');
		    var content = element.innerHTML;
		    element.store('tip:title', 'Sortieren nach: <span class="tip-text">' + content + '</span>');
		    element.store('tip:text', '');
		});
		
		//create the tooltips
		var tipSort = new Tips('.ShowTipSortierung',{
		    className: 'custom-tip'
		});
		

		tipz.addEvents({
		    'show': function(tip) {
		        tip.fade('in');
		    },
		    'hide': function(tip) {
		        tip.fade('out');
		    }
		});
	}
 
 
 }
  /* ############################################################# */
  /*  ################### Weindaten holen und box anzeigen  ###### */
  /* ############################################################# */
  function weinAnzeigen(id, notimer){
 	 	
 	 	var id_neu = 'wein_' + id;
 	 	var id_bookmark =  'getcontentback_wein_' + id;
 	 	
 	 	
 	 	// wenn der wein mit der id schon angezeigt wird, abbrechen
			if($(id_neu)){
				$('realcontent_right').grab($(id_neu),'top');
				$(id_neu).highlight('#ff0000');
				return false;
			}else{
				// wenn der wein schon in der Bookmarkliste ist, rausholen und bookmark löschen
				if($(id_bookmark)){
					$(id_bookmark).destroy();
					// aber nicht mehr verschwinden lassen
					notimer = '1';
				}

				// einblenden
				
				
				var jsonRequest = new Request.JSON({
					url: base_url_ajax, 
					onRequest: function() {
						var pop = new Element('div', {
							'id': 'weinloader_' + id,
							'class': 'singlewein_loading'
						}).inject('realcontent_right','top');
					},
					onComplete: function(oRsp){
						
						$('weinloader_' + id).destroy();
						var wein = new Element('div', {
							'id': id_neu,
							'class': 'singlewein'
						}).inject('realcontent_right','top');
				
						
						
						var oben = new Element('div', {
							'class': 'oben'
						}).inject(wein,'top');

						var mitte = new Element('div', {
							'id': 'mitte' + id_neu,
							'class': 'mitte',
							'html': oRsp.result.data
						}).inject(wein,'bottom');
						
						var unten = new Element('div', {
							'class': 'unten'
						}).inject(wein,'bottom');
						
						//sendSelektion('form_bestellen_16');
						
						
						if(notimer){
							
							//(function(){minimizeWeinbox(id_neu);}).delay(5000);
						}else{
							// box-destroyer starten
							BoxDestroy(id_neu,30000);
							// stop-box-destroyer initialisieren (rollover)
							initStopBoxDestroy(id_neu);
						}
						
						if($('transferToAngebot')){
							//$('mitte' + id_neu).addClass('mitteAngebot');
							$('mitte' + id_neu).setProperty('class', 'mitteAngebot');
							$('transferToAngebot').destroy();
						}
						
						
						
						// Detail ansicht: 
						initAccordeon();
						// closeButton aktivieren
						initCloseButton();
						initMinimizeWeinboxen();
						initTagButtons();
						initMooze();
						new pageLoader();
					}
				}).get({'showWein': id, 'ajax':'1'});
			}

  }
   

  
 /* ##################### zoomer ########################### */ 
 /* ###### Zoom-funktion der Bilder in den Weinboxen ######' */ 
 /* ############################################################# */
  function initMooze(){
  	$$('a.remooz-element').each(function(element) {
 	
        // Constructor, takes the element and options as arguments
        new ReMooz(element, {
            centered: false, // Zoom the center of the screen
            dragging: false
        });
 		element.set('class', 'remooz-elementOK');
    });
  
  
  
  } 
  
  
  /* ############################################################# */
  /* ### Bestellung - Warenkorb- Funktionen  ################# */ 
  /* ############################################################# */
  
  
  
  
  /* ############################################################# */
  /* ### Anzahl der Weine im WK wird verändert  ################# */ 
  /* ############################################################# */
  function sendChangeWK(el, uid){
  	
  	var jsonRequest = new Request.JSON({
		url: base_url_ajax, 
		onComplete: function(oRsp){
			//console.log(oRsp);
			//warenkorb
			if($('bestelldetails')){
				$('bestelldetails').destroy();
			}
			var bestelldetails = document.createElement("div");
			bestelldetails.setAttribute('id', 'bestelldetails');
			bestelldetails.setAttribute('class','');
			
			bestelldetails.inject('form_bestellen_finish', 'bottom');
			bestelldetails.innerHTML = oRsp.result.data.bestelldetails;
			$('bestelldetails').fade('hide');
			$('bestelldetails').fade('in');

			initWeinTrigger();
			initWarenkorbFunc();
			bezInfo(oRsp.result.data.bez,1);
		}
	}).get({'ajax': 1,'updateWK': 1, 'wein_id': uid, 'anzahl': eval(el.selectedIndex + 1)});
	
  }
  
 /* ############################################################# */  
 /* ###### Bestellformular einblenden, wenn wein ausgewählt #### */
 /* ############################################################# */
 function sendSelektion(formname){
 	
 	// wenn bestellform minimiert ist, anzeigen
 	if($('getbestellformback')){
		removedBestellung.inject('realcontent', 'top');
		$('getbestellformback').destroy();	
 	}
 	
 	// wenn bestellform schon angezeigt wird, keinen neuen divs erzeugen
	if($('bestellung')){
		/*
		if($('getbestellformback')){
			$('getbestellformback').destroy();
		}
		$('bestellung').morph('.class_bestellung');
		*/
	}else{
		
		// erstmal inhalt löschen
		$('realcontent').empty();
		var bestellung = new Element('div', {
			'id': 'bestellung',
			'class': 'class_bestellung'
		}).inject($('realcontent'),'top');
		
		// minimize-button
		var minimize = new Element('div', {
			'id': 'minimize_form',
			'html' : '<img width="16" height="16" title="minimize" alt="minimize" src="/fileadmin/templates/images/minimize.png"/>'
		}).inject($('bestellung'),'top');
		
	}

 	var jsonRequest = new Request.JSON({
		url: base_url_ajax, 
		onComplete: function(oRsp){
			
			// formular
			if(!$('form_bestellen_finish')){
				var formular = new Element('form', {
					'id': 'form_bestellen_finish',
					'class': 'inline checkform',
					'onSubmit': 'return false;'
				}).inject($('bestellung'),'bottom');
				$('form_bestellen_finish').fade('hide');
				$('form_bestellen_finish').fade('in');	
							
			}
			
			// adresse
			if(!$('adresse')){
			
				var adresse = new Element('div', {
					'id': 'adresse',
					'class': '',
					'html': oRsp.result.data.adresse
				}).inject($('form_bestellen_finish'),'bottom');
				$('adresse').fade('hide');
				$('adresse').fade('in');	

			}
			if(!$('lieferadresse')){
				// lieferadresse
				var lieferadresse = new Element('div', {
					'id': 'lieferadresse',
					'class': '',
					'html': oRsp.result.data.lieferadresse
				}).inject($('form_bestellen_finish'),'bottom');
				$('lieferadresse').fade('hide');
				$('lieferadresse').fade('in');
				
			}
			
			//warenkorb
			if($('bestelldetails')){
				$('bestelldetails').destroy();
			}
			
			var bestelldetails = new Element('div', {
				'id': 'bestelldetails',
				'class': '',
				'html': oRsp.result.data.bestelldetails
			}).inject($('form_bestellen_finish'),'bottom');
			$('bestelldetails').fade('hide');
			$('bestelldetails').fade('in');
			
	
			
			
			
			bezInfo(oRsp.result.data.bez,1);
			initMinimizeForm();
			initTagButtons();
			initWeinTrigger();
			
			// löschen-button
			initWarenkorbFunc();
			
			var Check = new FormCheck('form_bestellen_finish', {
				tipsClass: 'fc-tbx',
				submitByAjax : true,	
				submitByAjaxMethode : 'post',	
				submitByAjaxAction: '/ajax/?finish=1',	
				ajaxResponseDiv : 'bestellung',
				display : {
					indicateErrors : 2,
					showErrors : 1
				}
			});	
				
		}
	}).post($(formname));
				
 }
 
 
 /* ############################################################# */  
 /* ###### Löschen-funktion der Weinauswahl initialisieren #### */
 /* ############################################################# */

 function initWarenkorbFunc(){
	$$('.delete').each(function(el){
		el.addEvents({
			'click': function() {
				var delete_id = el.get('id').split("delete_");
				var jsonRequest = new Request.JSON({
					url: base_url_ajax,
					onComplete: function(oRsp){
						$('bestelldetails').innerHTML = oRsp.result.data.bestelldetails;
						initWarenkorbFunc();
					}
				}).get({'delete_id': delete_id[1], 'ajax':'1'});
			}
		});
	});				
 }

 /* ############################################################# */
  /* ################### WEINBOXEN-Links initialisieren ############## */
   /* ############################################################# */
 function initWeinTrigger(){
	$$('.getWeinTrigger').each(function(el){
 		el.addEvents({
			'click': function() {

			var id_string = el.getProperty('id');
			var id = id_string.split("show_wein_");
			var id_neu = 'wein_' + id[1];
			
			weinAnzeigen(id[1]);
				
			}
		});
	});	
 
 }
 
 /* ############################################################# */
 /* ################# MINIMIZE-WARENKORB init ################ */
 /* ############################################################# */
 function initMinimizeForm(){  
 	$('minimize_form').removeEvents('click');
 	$('minimize_form').addEvents({
		'click': function(){
			minimizeForm();
		}
	});

 }
 


 
 /* ############################################################# */
 /* ################# MINIMIZE-WARENKORB  ################ */
 /* ############################################################# */
 function minimizeForm(){
 	
 	// herholen-button machen
	var getbestellformback = new Element('div', {
		'id': 'getbestellformback',
		'class': 'pointer'
	}).inject($('ablage'));
	
	
	removedBestellung = $('bestellung').dispose();
		
		
		$('getbestellformback').addEvents({
			'click': function(){
				// $('bestellung').morph('.class_bestellung');
				//removedBestellung.inject('content', 'top');
				if($('realcontent')){
					minimizeRealcontent();
				}
				removedBestellung.inject('content', 'bottom');
				$('getbestellformback').destroy();		
			}
		});
}
 
 /* ############################################################# */
 /* ################# MINIMIZE-CONTENT init ################ */
 /* ############################################################# */
 function initMinimizeRealcontent(){
 	if($('minimize_content')){
 		$('minimize_content').removeEvents('click');
 		$('minimize_content').addEvents({
			'click': function(){
				minimizeRealcontent();
			}
		});
	}
 }
 
 /* ############################################################# */
 /* ################# MINIMIZE-CONTENT ################ */
 /* ############################################################# */ 
  function minimizeRealcontent(){
  
  
  	// herholen-button machen
  	var getcontentback = new Element('div', {
		'id': 'getcontentback',
		'class': 'pointer'
	}).inject($('ablage'));
	
	
	
	removedContent = $('realcontent').dispose();
		
		
		$('getcontentback').addEvents({
			'click': function(){
				if($('bestellung')){
					minimizeForm();
				}
				// $('bestellung').morph('.class_bestellung');
				//removedBestellung.inject('content', 'top');
				removedContent.inject('content', 'bottom');
				$('getcontentback').destroy();		
			}
		}); 
  
        		
 
 }
/* ############################################################# */
 function initWarenkorbWaitButton(){
 	var accordion = new Accordion($$('.toggler_form'),$$('.element_form'), {
		opacity: 0,
		display: 0,
		alwaysHide: true,
		onActive: function(toggler) { 
			//toggler.setAttribute('class','class_bestellung');
			//togglerid = toggler.getAttribute('id');
			//console.log(togglerid);
			//if(togglerid == 'weitershoppen'){
			//	$('weitershoppen').innerHTML = 'Langsam, langsam, ich bin noch nicht fertig - erstmal weiterschauen.';
			//}
		},
		onBackground: function(toggler) { 
			//toggler.setStyle('color', '#ff0000'); 
			//togglerid = toggler.getAttribute('id');
			//console.log(togglerid);
			//if(togglerid == 'weitershoppen'){
			//	$('weitershoppen').innerHTML = 'Jetzt schicke ich Jan zur Post.';
			//}
			
		}

	});
 }

 /* ############################################################# */
 function initAccordeon(){
	var accordion = new Accordion($$('.weindetailshow'),$$('.element'), {
		opacity: 0,
		display: -1,
		alwaysHide: true
		/*
		onActive: function(toggler) { toggler.setStyle('color', '#ff3300'); },
		onBackground: function(toggler) { toggler.setStyle('color', '#ff0000'); }
		*/
	});
 }
 /* ############################################################# */
 function initClearRealcontent(){
 	if($('clear_realcontent')){
		$('clear_realcontent').addEvents({
			'click': function() {
				$('realcontent').empty();

			}
 		});
 	}
 }
 
/* ############################################################# */
 function initCloseButton(){
	$$('.self_close').each(function(el){
 		el.addEvents({
			'click': function() {
				// wir müssen 3 ebenen hoch. 
				id = el.getParent('div').get('id');
				id_parent = $(id).getParent('div').get('id');
				id_parent_parent = $(id_parent).getParent('div').get('id');
				$(id_parent_parent).destroy();
				/*
				$(id_parent_parent).set('tween', {
					onComplete: function(e) {
						$(id_parent_parent).destroy();
					}	
				});
				*/
				// höhe beibehalten
				//$(id_parent_parent).setStyle('height', $(id_parent).getStyle('height'));
				// inhalt löschen
				/*
				$(id_parent_parent).empty();
				$(id_parent_parent).tween({'width': '0', 'height': '0'});
				*/
			}
		});
 	});
 }
 
/* ############################################################# */
 function initMinimizeWeinboxen(){
 
 	$$('.self_minimize').each(function(el){
 		
 		el.addEvents({
			'click': function() {
				// wir müssen 3 ebenen hoch, um das richtige div zu erwischen
				var id = el.getParent('div').get('id');
				var id_parent = $(id).getParent('div').get('id');
				var id_parent_parent = $(id_parent).getParent('div').get('id');
				
				minimizeWeinbox(id_parent_parent);

			}
		});
 	}); 
 }
  /* ############################################################# */
 function minimizeWeinbox(id){
 	var id_get = id.split("wein_");
 	//console.log(id);
 	
	fnChain = new Chain();  
	fnChain.chain(  
		function(){
			$(id).fade('out');
			(function(){fnChain.callChain();}).delay(500);
		},
		function(){
			// herholen-button machen
			var getcontentback = new Element('div', {
				'id': 'getcontentback_' + id,
				'class': 'wein_bm pointer',
				'html' : $('name_' + id_get[1]).get('html').substr(0,10) + '...</h1>'
			}).inject($('ablage_weine'));
			
			$('getcontentback_' + id).fade('hide');
			$('getcontentback_' + id).fade('in');
			

				
			$('getcontentback_' + id).addEvents({
				'click': function(){
					weinAnzeigen(id_get[1], '1');
					if($('getcontentback_' + id)){
						$('getcontentback_' + id).destroy();
					}
				}
			});
			(function(){fnChain.callChain();}).delay(500);
		},
		function(){
			$(id).dispose();
		}
	);			
	fnChain.callChain();
 }
 
 
 /* ############################################################# */
 function initTagButtons(){
	$$('.weintag').each(function(el){
		
 		el.addEvents({
			'click': function() {
				tag = el.get('tag');
				
				var jsonRequest = new Request.JSON({
					url: base_url, 
					onComplete: function(oRsp){
						//console.log(oRsp.result.uidarr);
						oRsp.result.uidarr.each(function(item, index){
    						weinAnzeigen(item);
						});
						
						
					}
				}).get({'showWeineByTag': tag, 'ajax':'1'});
			}
		});
 	}); 
 }
 
 /* ############################################################# */
 	function BoxDestroy(id,wait){
 		objectNameFade = 'fadeOut_' + id;
 		objectNameDestroy = 'destroy_' + id;
		objectNameFadeName = false;
 		objectNameDestroyName = false;

 		var objectNameFade = function(){ 
 			if(!objectNameFadeName){

 				$(id).set('tween', {
					onComplete: function(e) {
						$(id).destroy();
					}	
				});
				$(id).setStyle('height', $(id).getStyle('height'));
				// inhalt löschen
				$(id).empty();
				// schrumpfen
				$(id).tween('width', '0');
 			
 			
 				
 			}
 		};
 		
		var objectNameDestroy = function(){ 
			if(!objectNameDestroyName){
				//$clear(processName);
				$(id).destroy(); 
				
			}
		};
		
		objectNameFade.delay(wait); 
		//objectNameDestroy.delay(wait + 500); 
		
		
 	}
 	
 	/* ############################################################# */
 	/* Bei Rollover über die Box wird der destroy-timer gestoppt */
 	function initStopBoxDestroy(id){
 	
 		$(id).addEvents({
    		'mouseover': function(){
        		//alert('mouseover');
        		objectNameFadeName = 'fadeOut_' + id;
 				objectNameDestroyName = 'destroy_' + id;
 				
 				objectNameFadeName = true;
 				objectNameDestroyName = true;
    		}

		});
 	}
 /* #################################################### */
	function startTimer(timer_id){
		var timer_id = 'wein_1';
		
		var size = $('timer_' + timer_id).getSize();
		var newSize = (size.x + 3);
		
		
		$('timer_' + timer_id).setStyle('width', newSize);
		//$('countdown_' + show_question).innerHTML = ( (updateinterval/1000) - countdowntimer )+" sec";
		
		
		// if(DEBUG==1) console.log($('timer_' + show_question).getStyle('width'));
	}
/* ######################################################################### */
function showImage(){
	$('bg').innerHTML = '<img id="bgImg" width="997" height="748" border="0" title="" alt="" src="fileadmin/templates/images/bg_IMG_0003.JPG" />';

	var moosizer = new mooSizer({ bgElement:'bgImg' });
}
/* ######################################################################### */

function playMovie(moviePath, menuid){
	/*
	if(menuid){
		setVidWeine(menuid);
		setNameWein(menuid);
	}
	*/
	var obj = new Swiff('/fileadmin/player/flvPlayr.swf', {
    	id: 'bgFlash',
    	movieName: 'flvPlayr',
    	width: '100%',
    	height: '100%',
    	container: $('bg'),
    	params: {
       		wmode: 'transparent',
        	bgcolor: '#ff3300'
    	},
    	vars: {
        	flv: moviePath
    	}, 
    	callBacks: {
        	load: weinAnzeigen
    	}
	});
	
	// Sprungmarker

	//var sprungmarkerPath = moviePath.replace(/.flv/g, ".xml");
 	//showSprungmarker(sprungmarkerPath);
 	
	//var moosizer = new mooSizer({ bgElement:'bgImg' });
}

function setVidWeine(id){
	var inhalt = eval('vidtowein_' + id) + alleWeine;	
	$('weinimvideo').set('html', '');
	$('weinimvideo').set('html', inhalt);	
	
	// videotitel einsetzen
	//var videotitelid = 'vid_titel' + id;
	//console.log($(videotitelid).get('html'));
	//$('videoTitelAnzeige').set('html',$(videotitelid).get('html'));
	
}

function setNameWein(id){
	//console.log('play_wein_headline_' + id);
	var inhalt = $('play_wein_headline_' + id).get('html');	
	$('videoWeinAnzeige').set('html', inhalt);	
	
	var neueBreite = $('videoWeinAnzeige').getStyle('width');
	
	$$('.dynamic').each(function(el) {
 		//el.setStyle('width', neueBreite);
 		var breiteID = el.getChildren().getChildren('.headline');
 		//el.get('id')
 		breiteID.each(function(item, index){
    		//alert(index + " = " + item);
    		//console.log(item.offsetWidth);
		}); 
 		//var textWidth = document.getElementById("play_wein_headline_2").offsetWidth;
		//console.log(textWidth);
 		//console.log(el.getChildren().getChildren('.headline'));
 		//console.log(el.getStyle('width'));
 	});
	
	
	//console.log($('videoWeinAnzeige').getStyle('width'));
	
}
/* ######################################################################### */
/* E-Mailadresse Syntax-Check */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
/* ######################################################################### */
 /* ############################################################# */
  /* Momentan nicht benutzt, da kein suchfeld  */
 function initAutoComplete(){
 	// Autocomplete initialization
	if($('weinsucheform')){
	
 	/*$('suchfelder').setStyle('display', 'none');
 	$('suchfelder').fade('hide');
 	$('suchlabel').addEvents({
		'click': function(){
			$('suchfelder').setStyle('display', 'block');
			$('suchfelder').fade('in');
			$('suchlabel').removeClass('pointer');
		}
	});*/
		
 		$('suchfeld').addEvents({
			'mouseover': function(){
				//console.log('xxx');
				$('suchfeld').morph('.big');
			},
			'mouseleave': function(){
				if($('suchfeld').getProperty('value') == ''){
					$('suchfeld').morph('.small');
				}
			}
		});
 	
		new Autocompleter.Request.JSON($('suchfeld'), '/weine/suche/1/', {
			'indicatorClass': 'autocompleter-loading',
			'onRequest': function(el) {
				$('suchfeld').addClass('loader');
			},
			'onComplete': function(el) {
				$('suchfeld').removeClass('loader');
			}
		});
		
		
		// submit abfangen in pageLoader.js
	
	}
 
 
 
 }
 
/* ######################################################################### */
 /* NICHT mehr benutzt  */
function playMovieSWF(moviePath){

	var so = new SWFObject("/fileadmin/player/flvPlayr.swf","flvPlayr", "100%", "100%", "9", "#FFFF00");
				
	so.addParam( "allowScriptAccess", "sameDomain" );
	so.addParam( "scale", "noscale" );
	so.addParam( "flv", moviePath );
	so.write( "bg" );
}


 
 
 
 /* ################### sprungmarker ######################### */ 
  /* NICHT mehr benutzt, weil die sprungmarker jetzt in der zeitleste sind */
 function showSprungmarker(file){
 
 	var jsonRequest = new Request.JSON({
		url: base_url_ajax, 
		'ajax':'1',
		onComplete: function(oRsp){
			var sprungmarker = document.createElement("ul");
      			sprungmarker.setAttribute('class','wein_im_video_thumbs');
      			sprungmarker.setAttribute('id','sprungmarker');
				sprungmarker.inject($('navi'), 'bottom');
				$('sprungmarker').set('html', oRsp.result.data); 		

		}
	}).get({'showSprungmarker': file, 'ajax':'1'});
 
 
 }
  /* ############################################################# */  

  /* ############################################################# */  
  function extendContract(){
	
	if(isExtended == 0){
		
		sideBarSlide(0, height, 0, width);
		
		sideBarOpacity(0, 1);
	
		isExtended = 1;
		
		// make expand tab arrow image face left (inwards)
		//$('minifunc').childNodes[0].src = $('minifunc').childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');
		
	}
	else{
		
		sideBarSlide(height, 0, width, 0);
		
		sideBarOpacity(1, 0);
		
		isExtended = 0;
		
		// make expand tab arrow image face right (outwards)
		
		//$('minifunc').childNodes[0].src = $('minifunc').childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');
	}

}

function sideBarSlide(fromHeight, toHeight, fromWidth, toWidth){
		var myEffects = new Fx.Morph('minifuncContents', {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.start({
			 'height': [fromHeight, toHeight],
			 'width': [fromWidth, toWidth]
		});
}

function sideBarOpacity(from, to){
		var myEffects = new Fx.Morph('minifuncContents', {duration: opacityDuration, transition: Fx.Transitions.linear});
		myEffects.start({
			 'opacity': [from, to]
		});
}
 

 /* ############################################################# */
 function initThemenButtons(){
 	$$('.singletag').each(function(el){
 		el.addEvents({
			'click': function() {
				//$('tags').innerHTML = el.innerHTML;
				//$('taglist').morph('.taglist_hide');
				//$('realcontent').morph('.realcontent_hide');
				playMovie('/fileadmin/vids/001_Hochzeit_undwein_320x240.flv');
				//console.log(this);
				//minimizeRealcontent();
			}
		});
 		/* el.setAttribute('class', 'singletagTrue pointer'); */
 		el.removeClass('singletag');
 		el.addClass('singletagTrue');

 	});
 
 
 }
 /* ##################### felder für lieferadresse einblenden  ########################### */
 	
 	function showHideLieferadresse(element){ 		
 		//console.log(element);
 		$$('.lieferadresse').each(function(el){
 			el.morph('.lieferadresse_show');
 		});
 	
 	}


