var myShow = '';
var myShow1 = '';

function startShow(x){
	if(x=='myShow'){
		myShow.pause(1);
	}else if(x=='myShow1'){
		myShow1.pause(1);
	}
}
/* GoogleMaps Funktion */
//map ausserhalb deklarieren damit global ferfuegbar
var map				= '';
var marker		= '';
var gmarkers	= [];

function newCenter(x,y,zoom){
	map.setCenter(new GLatLng(x, y), zoom);
}

var oldStandort = '';
var oldX				= '';
var oldY				= '';

//erstellt einen Marker auf der Karte mit Click Event
function createMarker(latlng,html,markerOptions,lat,lng,category,window) {
	//alert(latlng+','+html+','+markerOptions+','+lat+','+lng+','+category);
	var marker = new GMarker(latlng,markerOptions);
	marker.category = category;

  GEvent.addListener(marker, "click", function(){
  	map.openInfoWindowHtml(latlng, html);
  });
	
	gmarkers.push(marker);
	return marker;
}

function blink(el){
	var myEffect = new Fx.Morph(el, {duration: '200', transition: Fx.Transitions.Sine.easeOut});
	rel = $(el).getProperty('rel');
	if(rel<4){
		rel2 = rel*1+1;
		$(el).setProperty('rel',rel*1+1);
	}else{
		rel2 = 1;
		$(el).setProperty('rel',1);
	}
	
	myEffect.start({
		'background-image':['url(images/casual/'+rel+'.jpg)','url(images/casual/'+rel2+'.jpg)']
	})
	//if(element.getStyle('visibility') == 'visible') element.setStyle('visibility', 'hidden');
	//else element.setStyle('visibility', 'visible');
}

function setBack(back){
	arrRel=back.split('|');
	if(arrRel.length<3){
		document.write('www<strong><!-- 2808789 -->.</strong><!-- 9863247 --><strong>'+arrRel[1]+'</strong><!-- 1254632 --><strong>.</strong><!-- 45628712 -->'+arrRel[0]+'');
	}else{
		document.write('www<strong><!-- 2808789 -->.</strong><!-- 286387 --><strong>'+arrRel[2]+'.</strong><!-- 9863247 --><strong>'+arrRel[1]+'</strong><!-- 1254632 --><strong>.</strong><!-- 45628712 -->'+arrRel[0]+'');
	}
}
function inputCounter(field,count){
	var len = $(field).value.length;
	if(len<=count){
		p = $(field).getNext('p');
		s = p.getChildren('strong');
		s.set('text', (count*1-len*1));
	}else{
		xValue = $(field).value; 
		$(field).value = xValue.substr(0,800);
		
		var myEffectsD = new Fx.Morph(field, {duration: 200, transition: Fx.Transitions.Sine.easeOut});
			myEffectsD.start({
		 		'background-color': ['#fff','#900'],
				'color':['#000','#fff']
			}).chain(function(){
			myEffectsD.start({
		 		'background-color': ['#900','#fff'],
				'color':['#fff','#000']
			});
		});
	}
	
	if(len>=count){
		$(field).value = $(field).value.substr(0);
	}
}

window.addEvent('domready', function(){
	//Nachricht -> vorschau.php, vorschau_club.php
	$$('.msgBtn').each(function(el){
		el.addEvents({
			'click': function(){
				if (this.hasClass('off') == false) {
					alert('Hier in der Anzeigenvorschau ist dieser Link deaktiviert, sonst wird an dieser Stelle das Nachrichtenformular angezeigt.');
				}
			}
		});
	});
	
	//Nachrichten -> anzdetail.php, anzdetail_club.php, vorschau.php
	if($('sendMessage')){
		//*
		$('sendMessage').addEvent('click',function(){
			if (this.hasClass('off') == false) {
				var overlay = new Overlay($(document.body)).open();
				var ekBox	= new Element('div',{ 'id':'ekBox' });
				ekBox.injectInside($(document.body));
				ekBox.setStyles({})
			
				new Request.HTML({url:myServer+'nachrichtSenden.php',
				onSuccess: function(html){
					var myFx = new Fx.Scroll(window).toTop();
	  		//Inject the new DOM elements into the results div.
					$('ekBox').adopt(html);
					$$('.ekClose').each(function(el){
						el.addEvent('click',function(){
							overlay.close();
							ekBox.destroy();
						});
					});
					
					$('ekEmailForm').addEvent('submit', function(e) {
						//alert('submit');
						e.stop();
						err = ekValidate('ekNachrichtSenden');
						
						if(err==0){
							loader('sendMsg');
							this.set('send', {
								onComplete: function(r){
									//gleicheNachricht, userSperre, adminSperre, nachrichtGesendet, noPayKde, noPayAnz, msgPending
									
									var erg = r.search(/|.+/);
									if(erg!=-1){
										var arrRes = r.split('|');
										r = arrRes[0];
										
										var msgCount = arrRes[2];
										
										if(r=='noPayKde'){
											var text = $('payKde').get('text');
											$('payKde').innerHTML = '<a href="index.php?site=message&msg='+arrRes[1]+'&c='+msgCount+'">'+text+'</a>';
										}else if(r=='noPayAnz'){
											if(arrRes[1]==1){
												var text = $('payAnz').get('text');
												$('payAnz').innerHTML = '<a href="'+arrRes[2]+'">'+text+'</a>';
											}else{
												//infotext entfernen
												$('payAnz').destroy();
												//loginformular einblenden
												$('ekLogin').removeClass('dnone');
												//link in Form speichern
												$('anzU').value = arrRes[2];
												//alle Button raus
												$('msgButtonBar').destroy();
											}
										}else if(r=='kdeNoAnz'){
											//alle Button raus
											$('msgButtonBar').destroy();
										}
									}
									
									unloader();
									var arrNachricht = new Array('gleicheNachricht','userSperre','adminSperre','nachrichtGesendet','noPayKde','noPayAnz','msgPending','kdeNoAnz');
									for(var i=0; i<arrNachricht.length; i++){
										if (arrNachricht['i'] == r) {
											$(arrNachricht['i']).addClass('dnone');
										}else{
												if($(r)) $(r).removeClass('dnone');
												if($('formMsgBox')) $('formMsgBox').addClass('dnone');
												if($('labelAgbDatenschutz')) $('labelAgbDatenschutz').addClass('dnone');
												if($('ekRngAgbDatenschutz')) $('ekRngAgbDatenschutz').addClass('dnone');
												if($('msgButtonSend')) $('msgButtonSend').addClass('dnone');
												if($('msgButtonClose')) $('msgButtonClose').value='Schliessen';
											}
										}
										if(r!='noPayAnz' && r!='noPayKde' && r!='kdeNoAnz'){
											//alert(r);
											var myFn = function(){
												overlay.close();
												ekBox.destroy();
											}.delay('6000');
										}
									}
								});
								this.send();
							}
						});
					
					
						$('anzSchalten').addEvent('click',function(){
							top.location.href='index.php?site=login&link=newinsert';
						});
//msgButtonSend
						$('msgSenden').addEvent('click',function(){
							new Request({
								url: myServer + 'banner/ajax.php',
								method: 'post',
								onComplete:function(r){
									//alert(r);
									if(r==0){
										$('ekEmailForm').send();
										$('kdeNoAnz').addClass('dnone');
									}else{
										alert('Es ist ein Fehler aufgetrteten, bitte versuchen Sie es erneut.');
										
										overlay.close();
										ekBox.destroy();
									}
								}
							}).send('act=deleteKdeNoAnz&mail='+$('ekEmail').value);
						});
					
					
						//Zeichen in Nachrihten feld zaehlen
						$('ekNachricht').addEvents({
			  			'keyup': function(){
			  				inputCounter('ekNachricht', 800);
			  			},
							'click':function(){
								if(this.value=='+++ ACHTUNG +++ Tragen Sie keine Telefonnummern, Handynummern, E-Mail, Domain und Chat Adressen in den Nachrichtentext ein sonst wird die Nachricht sofort geloescht.') this.value='';
							},
							'focus':function(){
								if(this.value=='+++ ACHTUNG +++ Tragen Sie keine Telefonnummern, Handynummern, E-Mail, Domain und Chat Adressen in den Nachrichtentext ein sonst wird die Nachricht sofort geloescht.') this.value='';
							}
			  		});
						
						//ekTelefon auf richtige Zeichen pruefen
						if($('ekTelefon')){
							$('ekTelefon').addEvents({
								'keyup':function(){
									if(!this.value.match(/^[\d\/\s+-]+$/)){
										//this.value = this.value.substr(0,this.value.length-1);
										this.value = '';
									}
								}
							});
						}
						//ekTelefon auf richtige Zeichen pruefen
						if($('ekHandy')){
							$('ekHandy').addEvents({
								'keyup':function(){
									if(!this.value.match(/^[\d\/\s+-]+$/)){
										//this.value = this.value.substr(0,this.value.length-1);
										this.value = '';
									}
								}
							});
						}
						/*
						var myEffectsD = new Fx.Morph('ekBox', {duration: 200, transition: Fx.Transitions.Sine.easeOut});
			 			myEffectsD.start({
			   			'': 
						});
						*/
					
					},
					//Our request will most likely succeed, but just in case, we'll add an
					//onFailure method which will let the user know what happened.
					onFailure: function() {
						$('ekFormBox').set('text', 'The request failed.');
					}
				}).get({'anzid':this.getProperty('rel')});
			}
		});
		//*/
	}
	//Nachrichten -> anzdetail.php, anzdetail_club.php, vorschau.php
	if($('sendMessageC')){
		//*
		$('sendMessageC').addEvent('click',function(){
			if (this.hasClass('off') == false) {
				var overlay = new Overlay($(document.body)).open();
				var ekBox	= new Element('div',{ 'id':'ekBox' });
				ekBox.injectInside($(document.body));
				ekBox.setStyles({})
			
				new Request.HTML({url:myServer+'nachrichtSenden.php',
				onSuccess: function(html){
					var myFx = new Fx.Scroll(window).toTop();

	  		//Inject the new DOM elements into the results div.
					$('ekBox').adopt(html);
					$$('.ekClose').each(function(el){
						el.addEvent('click',function(){
							overlay.close();
							ekBox.destroy();
						});
					});
					
					$('ekEmailForm').addEvent('submit', function(e) {
						e.stop();
						err = ekValidate('ekNachrichtSenden');
						
						if(err==0){
							loader('sendMsg');
							this.set('send', {
								onComplete: function(r){
									//gleicheNachricht, userSperre, adminSperre, nachrichtGesendet							
									unloader();
									var arrNachricht = new Array('gleicheNachricht','userSperre','adminSperre','nachrichtGesendet');
									for(var i=0; i<arrNachricht.length; i++){
										if (arrNachricht['i'] == r) {
											$(arrNachricht['i']).addClass('dnone');
										}else{
												$(r).removeClass('dnone');
												if($('formMsgBox')) $('formMsgBox').addClass('dnone');
												if($('labelAgbDatenschutz')) $('labelAgbDatenschutz').addClass('dnone');
												if($('ekRngAgbDatenschutz')) $('ekRngAgbDatenschutz').addClass('dnone');
												if($('msgButtonSend')) $('msgButtonSend').addClass('dnone');
												if($('msgButtonClose')) $('msgButtonClose').value='Schliessen';
											}
										}
										var myFn = function(){
											overlay.close();
											ekBox.destroy();
										}.delay('8000');
									}
								});
								this.send();
							}
						});
					
						//Zeichen in Nachrihten feld zaehlen
						$('ekNachricht').addEvents({
			  			'keyup': function(){
			  				inputCounter('ekNachricht', 800);
			  			},
							'click':function(){
								if(this.value=='Tragen Sie keine E-Mail, Domain und Chat Adressen in den Nachrichtentext ein sonst wird die Nachricht sofort geloescht. Bitte Verfassen Sie Ihren Nachrichtentext individuell zur Anzeige.') this.value='';
							},
							'focus':function(){
								if(this.value=='Tragen Sie keine E-Mail, Domain und Chat Adressen in den Nachrichtentext ein sonst wird die Nachricht sofort geloescht. Bitte Verfassen Sie Ihren Nachrichtentext individuell zur Anzeige.') this.value='';
							}
			  		});
					
						/*
						var myEffectsD = new Fx.Morph('ekBox', {duration: 200, transition: Fx.Transitions.Sine.easeOut});
			 			myEffectsD.start({
			   			'': 
						});
						*/
					
					},
					//Our request will most likely succeed, but just in case, we'll add an
					//onFailure method which will let the user know what happened.
					onFailure: function() {
						$('ekFormBox').set('text', 'The request failed.');
					}
				}).get({'anzid':this.getProperty('rel')});
			}
		});
		//*/
	}
		
	//back-lk
	$$('.back').each(function(el){
		el.addEvents({
			'click':function(){
				if (this.hasClass('off') == false) {
					arrRel = this.getProperty('rel').split('|');
					//ekWindow(mypage,myname,w,h,pos,infocus)
					if(arrRel.length<3){
						ekWindow('http://www.' + arrRel[1] + '.' + arrRel[0], '', 1024, 768, '', '');
					}else{
						ekWindow('http://www.' + arrRel[2] + '.' + arrRel[1] + '.' + arrRel[0], '', 1024, 768, '', '');
					}
					
					//backClick,anzid(anz_anzeige)
					var arrID = document.URL.split('=');
					var anzID = arrID[2];
					
					//alert(arrID[2]);
					//*
					new Request({
						url: myServer + 'banner/ajax.php',
						method: 'post'
					}).send('act=backClick&anzid='+anzID);
					//*/
				}
			},
			'mouseenter':function(){
				if(this.hasClass('off')==false){
					this.addClass('backact');
				}
			},
			'mouseleave':function(){
				if (this.hasClass('off') == false) {
					this.removeClass('backact');
				}
			}
		});
	});
	
	//woob (img zoom)
	$$('.galerie dd a img').each(function(el) {
		if(el.getProperty('rel')!='old'){
			var fx = new Fx.Morph(el, {
				duration: 100,
				link: 'cancel'
			});
			el.addEvents({
				'mouseenter': function(e) {
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','none');
					e.stop();
					fx.start({
						'width':146,
						'height':146,
						'margin':'-10px 0 0 -10px'
					});
				},
				'mouseleave': function(e) {
					e.stop();
					fx.start({
						'width':124,
						'height':124,
						'margin':0
					});
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','');
				}
			});
		}
	});
	
	$$('.galerie_top dd a img').each(function(el) {
		if(el.getProperty('rel')!='old'){
			var fx = new Fx.Morph(el, {
				duration: 100,
				link: 'cancel'
			});
			el.addEvents({
				'mouseenter': function(e) {
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','none');
					e.stop();
					fx.start({
						'width':146,
						'height':146,
						'margin':'-10px 0 0 -10px'
					});
				},
				'mouseleave': function(e) {
					e.stop();
					fx.start({
						'width':124,
						'height':124,
						'margin':0
					});
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','');
				}
			});
		}
	});
	
	/*/woob (img zoom)
	$$('.galerie_top dd div img').each(function(el) {
		if(el.getProperty('rel')!='old'){
			var fx = new Fx.Morph(el, {
				duration: 100,
				link: 'cancel'
			});
			el.addEvents({
				'mouseenter': function(e) {
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','none');
					e.stop();
					fx.start({
						'width':166,
						'height':166,
						'margin':'-10px 0 0 -10px'
					});
				},
				'mouseleave': function(e) {
					e.stop();
					fx.start({
						'width':146,
						'height':146,
						'margin':0
					});
					if($(this.getProperty('rel'))) $(this.getProperty('rel')).setStyle('display','');
				}
			});
		}
	});
	//*/
	
	//Barak Slideshow
	if($('caualSlider')){
		//var blinker = blink.periodical(10000, null, $('caualSlider'));
	}

	//Maps Route planen
	$$('.route').each(function(el){
		el.addEvent('click',function(){
			
			adr = 'http://maps.google.de/maps?hl=de&q='+this.getProperty('rel')+'&um=1&ie=UTF-8&hq=&hnear='+this.getProperty('rel')+'&gl=de&ei=IMNGTMrrM42isQbnrb2VBg&sa=X&oi=geocode_result';
			//'http://maps.google.com/maps?ll='+this.getProperty('rel')+'&spn=0.031111,0.057678&z=13&key=ABQIAAAAF7svcqK6BCaNWBvSLd7bXRSVpKijHu3m2Bxmuse8icRcWEOSQxQt1dam3o7rGF1RC-uojP3J4bZotw&mapclient=jsapi&oi=map_misc&ct=api_logo'
			MeinFenster = window.open(adr, "Zweitfenster", "width=800,height=600,left=0,top=0,resizable=yes");
			MeinFenster.focus();
		});
	});
	
	//Marktplatznavi
	$$('#mpNavi li').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('on');
				}
			},
			'mouseleave':function(){
				this.removeClass('on');
			},
			'click':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					$$('#mpNavi li').each(function(el){
						el.removeClass('act');
						$(el.getProperty('rel')).addClass('dnone');
					});
					$(this.getProperty('rel')).removeClass('dnone');
					this.addClass('act');
				}
			}
		});
	});
	$$('#mpNavi_c li').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('on');
				}
			},
			'mouseleave':function(){
				this.removeClass('on');
			},
			'click':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					$$('#mpNavi_c li').each(function(el){
						el.removeClass('act');
						$(el.getProperty('rel')).addClass('dnone');
					});
					$(this.getProperty('rel')).removeClass('dnone');
					this.addClass('act');
				}
			}
		});
	});
	
	//Hover bei allen tbody .pene td's
	$$('.pane table.hover td table tbody tr').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.getFirst('td').hasClass('gray_9')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				this.removeClass('act');
			}
		});
	});
	
	//alte Bilder Hover Effekt
	$$('#imgList td').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==true && this.getProperty('rel')!='act'){
					this.removeClass('act');
				}
			}
		});
	});
	
	if($('content')){
		$('content').setStyle('height',$('anzText').getSize().y);
	}
	
	if($('lb_gallery_container')){
		new SlideItMoo({itemsVisible:8, // the number of thumbnails that are visible
			currentElement: 0, // the current element. starts from 0. If you want to start the display with a specific thumbnail, change this
			thumbsContainer: 'lb_thumbs',
			elementScrolled: 'lb_thumb_container',
			overallContainer: 'lb_gallery_container'
		});
	}
	
	$$('#lb_thumbs a img').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false){
					var myEffectsD = new Fx.Morph(this.getProperty('id'), {duration: 200, transition: Fx.Transitions.Sine.easeOut});
		 			myEffectsD.start({
		    		'opacity': ['0.5','1']
					});
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==false){
					var myEffectsD = new Fx.Morph(this.getProperty('id'), {duration: 200, transition: Fx.Transitions.Sine.easeOut});
		 			myEffectsD.start({
		    		'opacity': ['1','0.5']
					});
				}
			}
		});
	});
	
	//*
	if ($('show')) {
  	$$('.showAll').each(function(el){
  		//*
			var divID = el.getPrevious('div').getProperty('id');
			if (divID == 'show') {
				el.setStyles({
					'display': 'block'
				//'top':625
				});
			}else {
				el.setStyles({
					'display': 'block'
				//'top':1400
				});
			}
				
			el.addEvent('click', function(){
				if (this.getProperty('rel') == 'myShow') {
					myShow.pause(1);
					viewer.show(0);
				}
				else if (this.getProperty('rel') == 'myShow1') {
					myShow1.pause(1);
					viewer1.show(0)
				}
			});
		});
	}
	
	$$('#slideNavi li').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==true && this.getProperty('rel')!='act'){
					this.removeClass('act');
				}
			},
			'click':function(){
				if(el.hasClass('off')==false){
					$$('#slideNavi li').each(function(el){
						el.removeClass('act');
						el.removeProperty('rel');
					});
				
					this.setProperty('rel','act');
					this.addClass('act');
				}
			}
		});
	});

	$$('#buttonBar td').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==true && this.getProperty('rel')!='act'){
					this.removeClass('act');
				}
			},
			'click': function(){
	  	
			}
		});
	});
	
	if($('slideNavi')){
		myTabs = new SlidingTabs('slideNavi','content', 'anzText');
	}
	
	if($('map_canvas')){
		map = new GMap2(document.getElementById("map_canvas"));
		map.setUIToDefault();
		map.removeMapType(G_PHYSICAL_MAP);
	}


//Club Profil wenn Modell online
	if($('content1')){
		$('content1').setStyle('height',$('anzText1').getSize().y);
	}
	$$('#slideNavi1 li').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==true && this.getProperty('rel')!='act'){
					this.removeClass('act');
				}
			},
			'click':function(){
				if(el.hasClass('off')==false){
					$$('#slideNavi1 li').each(function(el){
						el.removeClass('act');
						el.removeProperty('rel');
					});
				
					this.setProperty('rel','act');
					this.addClass('act');
				}
			}
		});
	});

	$$('#buttonBar1 td').each(function(el){
		el.addEvents({
			'mouseenter':function(){
				if(this.hasClass('act')==false && this.hasClass('off')==false){
					this.addClass('act');
				}
			},
			'mouseleave':function(){
				if(this.hasClass('act')==true && this.getProperty('rel')!='act'){
					this.removeClass('act');
				}
			},
			'click': function(){
	  	
			}
		});
	});
	
	if($('slideNavi1')){
		myTabs = new SlidingTabs('slideNavi1','content1', 'anzText1');
	}
	
	if($('map_canvas1')){
		map = new GMap2(document.getElementById("map_canvas1"));
		map.setUIToDefault();
		map.removeMapType(G_PHYSICAL_MAP);
	}

});
