jQuery.noConflict();




// configuration:
// ---------------------------


var ajaxTabNavigation=false;


// ===========================



var IE6=((navigator.userAgent).search(/MSIE 6\./) > -1 ? true : false);

document.observe("dom:loaded", function() {

	/*** cockpit ***/
	(function(){
		if (IE6) return;

		try {
			var cockpit=$('cockpit');
			var f=(cockpit.select('form'))[0];
			var expcoll=(f.select('.expcoll'))[0];
			var expcolls=expcoll.down('span');
			var more=(f.select('.more'))[0];
			var morecontainer=more.down('.container');
		} catch (e) { return; }

		var defaultheight=cockpit.offsetHeight-4;

		var colla=function(){
			Timeline.addTweenings([
				[f,{height:defaultheight+'px'}],
				[more,{height:'0px'}]
			]);
			cockpit.addClassName('collapsed');
			cockpit.removeClassName('expanded');
			expcolls.addClassName('expand');
			expcolls.removeClassName('collapse');
			expcolls.firstChild.nodeValue='Mehr';
		};

		var expan=function(){
			var h=defaultheight;
			var c;

			for(c=0; f.children[c]; c++){
				Element.extend(f.children[c]);
				if (!f.children[c].measure) continue;
				var h2=f.children[c].measure('margin-box-height');
				if (more.descendantOf(f.children[c])) h2+=morecontainer.offsetHeight;
				if (h2 > h) h=h2;
			}

			Timeline.addTweenings([
				[f, {height:h+'px'}],
				[more, {height:morecontainer.offsetHeight+'px'}]
			]);
			cockpit.addClassName('expanded');
			cockpit.removeClassName('collapsed');
			expcolls.addClassName('collapse');
			expcolls.removeClassName('expand');
			expcolls.firstChild.nodeValue='Weniger';
		};

		expcoll.onclick=function(){
			if (cockpit.hasClassName('collapsed'))
				expan();
			else
				colla();
			return false;
		};

		expcoll.setStyle({display:'block'});
		f.setStyle({height:defaultheight+'px'});
		more.setStyle({height:'0px'});
	})();

	/*** login form ***/
	(function(){
		var loginout=$('loginout');
		if (loginout){
			var login=loginout.down('.login');
			if (login){
				login.select('*').each(function(e){
					e.observe('focus', function(){ this.fire('login:focus'); });
					e.observe('blur', function(){ this.fire('login:blur'); });
				});

				login.observe('login:focus', function(){ this.addClassName('active'); });
				login.observe('login:blur', function(){ this.removeClassName('active'); });
			}
		}
	})();

	/*** default form field values ***/
	setDefaultValue('email', 'Email-Adresse');
	setDefaultValue('simplesearch', 'Suchbegriff eingeben');
	setDefaultValue('detailsearch', 'Suchbegriff eingeben');
	setDefaultValue('membername', 'Member-Name');
	setDefaultValue('passtxt', 'Password', 'pass');

	/*** open external links in new window ***/
	$$('.external').each(function(i) {
		if(i.getAttribute('href').indexOf("javascript:")==-1)
			i.target='_blank';
	});

	var base64tag_decrypter=function(obj){
		var reg=/\[([A-Za-z0-9+\/=]+)\]/g;
		var e;

		while(obj){
			if (obj.nodeName == 'A' && obj.getAttribute('href'))
			{
				var href=decode_str(obj.getAttribute('href'));
				if (Prototype.Browser.IE) href=href.replace(/^.+?(?=mailto\:)/, '');
				if (obj.getAttribute('href') != href) obj.setAttribute('href', href);
			}

			if (obj.nodeName == 'IMG' && obj.getAttribute('alt'))
				obj.setAttribute('alt', decode_str(obj.getAttribute('alt')));

			if (obj.getAttribute && obj.getAttribute('title'))
				obj.setAttribute('title', decode_str(obj.getAttribute('title')));

			if ((obj.nodeName == 'TEXTAREA' || obj.nodeName == 'INPUT') && obj.value)
				obj.value=decode_str(obj.value);

			if (obj.nodeName == '#text' && obj.nodeValue)
				obj.nodeValue=decode_str(obj.nodeValue);

			obj=nextSiblingX(obj);
		}

		function nextSiblingX(obj){
			if (obj.firstChild) return obj.firstChild;
			while (!obj.nextSibling && obj.parentNode) obj = obj.parentNode;
			if (obj.nextSibling && obj.nextSibling.nodeName != 'BODY') return obj.nextSibling;
			return false;
		}

		function decode_str(str){
			return str.replace(reg, function(a,b,c){
				if ((e=base64.decode(b)) && e.substr(0,7) == 'b64tag:')
					return e.substr(7);
				return a;
			});
		}
	};
	base64tag_decrypter(document.body);

	/*** ajax tab navigation ***/
	if (ajaxTabNavigation)
	(function(){
		var indextab=$('indextab');
		var tabcontent=$('tabcontent');
		if (!indextab || !tabcontent) return;

		var additionalUrl=(location.href).match(/browse[0-9]\/[0-9]\/$/);
		if (additionalUrl)
			additionalUrl=additionalUrl[0];

		var base;
		try {
			base=$$('base')[0].getAttribute('href');
		} catch (x) {
			base=(((location.href).replace(/\#.*/, '')).replace(/\?.*/, '')).replace(/\/[^\/]*$/, '/');
		}

		var absoluteUrl=function(url){
			if (url.search(/^\//) == 0){
				url=base.replace(/^([a-z]+\:\/\/[^\/]+).*/i, '$1')+url;
			}
			else if (url.search(/^[a-z]+\:.+/i) == -1){
				url=base+url;
			}
			return url;
		};

		var relativeUrl=function(url){
			if (url.search(/^\//) == 0){
				url=absoluteUrl(url);
			}
			var regex=new RegExp('^'+RegExp.escape(base));
			url=url.replace(regex, '');
			return url;
		};

		var subUrl=function(url){
			return (absoluteUrl(url)).replace(subbaseregex, '');
		};

		var url2hash=function(url){
			return (base64.encode(subUrl(url))).replace(/\=/g, '-');
		};

		var hash2url=function(hash){
			return base64.decode(hash.replace(/\-/g, '='));
		};

		var subbase='';
		var lastremovedchar='';
		var indextab_a=indextab.select('a');
		indextab_a.each(function(a){
			var h=absoluteUrl(a.getAttribute('href'));
			var b;
			if (!subbase) subbase=h;
			for (b=subbase.length-1; b > 0; b--){
				if (subbase.substr(b,1) == h.substr(b,1)) break;
				lastremovedchar=h.substr(b,1);
				subbase=subbase.slice(0, -1);
			}
		});
		if (lastremovedchar == '/'){
			subbase=subbase+'/';
		}
		var subbaseregex=new RegExp('^'+RegExp.escape(subbase));


		var goto=function(url){
			new Ajax.Request(url,{
				method:'get',
				onComplete:function(xhr){
					var t=xhr.responseText;
					t=t.replace(/\r/g, '&#x0d;');
					t=t.replace(/\n/g, '&#x0a;');
					t=t.replace(/^.*\<body[^\>]*\>(.*)\<\/body\>.*$/, '$1');
					t=t.replace(/\&\#x0d\;/g, '\r');
					t=t.replace(/\&\#x0a\;/g, '\n');

					var d=new Element('div').update(t);
					try {
						var tc=d.select('#tabcontent')[0];
						if (tc) d.update(tc.innerHTML);
					} catch(x) {}

					(d.select('a')).each(insertAjaxRequest);

					tabcontent.innerHTML='';
					var c=d.firstChild;
					var c2;
					while (c){
						c2=c.nextSibling;
						tabcontent.appendChild(c);
						c=c2;
					}
					(tabcontent.select('.gallery')).each(setgallery);
					base64tag_decrypter(tabcontent);
					(tabcontent.select('.flapformbutton')).each(flapform);
					var h=url2hash(url);

					var currentsuburl=subUrl(url);
					var activate=false;
					indextab_a.each(function(a){
						var tabsuburl=subUrl(a.href);

						if (tabsuburl == '') return;

						if (currentsuburl.substr(0, tabsuburl.length) == tabsuburl)
							activate=a;
					});
					if (!activate) activate=indextab_a[0];
					indextab_a.each(function(a){
						if (a == activate)
							(a.up('li')).addClassName('active');
						else
							(a.up('li')).removeClassName('active');
						a.blur();
					});
				}
			});
		};

		var hashchangeHandler=function(){
			var m=(location.href).match(/.*\#\/(.*)$/);
			if (m) goto(subbase+m[1]);
		};

		if (!hashchangeEvent)
			Timeline.addEvent((function(){
				var m,lasthash,r=new RegExp('.*\#(.*)$');
				return function(){
					m=(location.href).match(r);
					if (m && lasthash != m[1]){
						lasthash=m[1];
						hashchangeHandler();
					}
				};
			})(),{duration:1000*60*60*24*30});
		else
			Event.observe(window, 'hashchange', hashchangeHandler);


		var insertAjaxRequest=function(a){
			var h=url2hash(a.getAttribute('href'));
			a.store('hash', h);

			var h=absoluteUrl(a.getAttribute('href'));
			if (h.search(subbaseregex) > -1){
				a.onclick=function(){
					location.href=subbase+(additionalUrl ? additionalUrl : '')+'#/'+subUrl(this.href);
					return false;
				};
			}
		};

		indextab_a.each(insertAjaxRequest);
		$$('#tabcontent a').each(insertAjaxRequest);

		hashchangeHandler();

		if (location.href.search(/tab\/to\_(be|do|see)\/(places\.html|)$/) != -1)
		{
			indextab_a.each(function(a){
				if (a.href.search(/tab\/to\_(be|do|see)\/(places\.html|)$/) != -1)
				{
					a.href=a.href.replace(/tab\/to\_(be|do|see)\/(places\.html|)$/, 'tab/to_$1/places.html');
					(a.up('li')).addClassName('highlight');
				}
			});
		}
	})();

	/*** rotator ***/
	$$('.rotator').each(function(rotator_e){
		var rotator_li=rotator_e.select('li');

		if (!rotator_li.length) return;

		var intervali=5000;
		var duration=1500;

		var rotator_ul=rotator_e.select('ul')[0];
		var rotator=new swgallery(rotator_li,{duration2next:duration,duration2prev:duration});

		var button_update=function(){
			for (var a=0; a < rotator.elements.length; a++)
			{
				var b=rotator.elements[a].retrieve('controlbutton');
				if (a == rotator.current)
				{
					rotator.elements[a].setStyle({zIndex:1});
					b.addClassName('active');
				}
				else
				{
					rotator.elements[a].setStyle({zIndex:0});
					b.removeClassName('active');
				}
			}
		};

		var pause=false;
		var play=function(){
			if (!pause && !interval)
				interval=setInterval(intervalf, intervali);
		};

		var intervalf=function(){
			if (pause) { clearInterval(interval); interval=null; return; }
			rotator.next.bind(rotator)();
			button_update();
		};
		var interval=setInterval(intervalf, intervali);

		var change=function(nr){
			if (rotator.current == nr) return;
			clearInterval(interval);
			interval=null;
			var e=[
				rotator.elements[rotator.current],
				rotator.elements[nr]
			];
			rotator.current=nr;
			rotator.change(e,0,rotator.options.transition2prev,rotator.options.duration2prev);
				
			button_update();
			play();
		}.bind(this);

		var controlpanel=new Element('div');
		controlpanel.addClassName('controlpanel');
		for (var a=1; a <= rotator_li.length; a++)
		{
			var i=new Element('span').update(a);
			rotator_li[a-1].store('controlbutton', i);
			//i.store('item', rotator_li[a-1]);
			i.store('itemNr', a);
			i.observe('mousedown',function(e){ e.stop(); });
			i.observe('click',function(){ change(this.retrieve('itemNr')-1); });
			controlpanel.appendChild(i);
		}
		rotator_e.appendChild(controlpanel);

		rotator_ul.observe('mouseenter', function(){
			pause=true;
		});
		rotator_ul.observe('mouseleave', function(){
			pause=false;
			play();
		});
		controlpanel.observe('mouseenter', function(){
			pause=true;
		});
		controlpanel.observe('mouseleave', function(){
			pause=false;
			play();
		});

		button_update();
	});

	/*** recommendations ***/
	(function(){
		var recommendations_ul=$$('#recommendations .wrapper')[0];
		if (!recommendations_ul) return;

		var duration=1000;
		var recommendations_li=recommendations_ul.select('ul');
		var recommendations=new swgallery(recommendations_li,{
			duration2next:duration,
			duration2prev:duration,
			style:[
				{left:recommendations_ul.offsetWidth+'px'},
				{left:'0px'},
				{left:'-'+recommendations_ul.offsetWidth+'px'}
			]
		});

		var prev=new Element('div');
		prev.addClassName('prev');
		var next=new Element('div');
		next.addClassName('next');

		prev.observe('click', function(){recommendations.prev();}.bind(this));
		next.observe('click', function(){recommendations.next();}.bind(this));

		recommendations_ul.appendChild(prev);
		recommendations_ul.appendChild(next);
	})();

	/*** Top Offers list ***/
	(function(){
		var elements=$$('.jslist ul li .expcoll');
		var defaultstyle={height:'87px'};

		var change=function(current){
			var tweenings=[];
			elements.each(function(element){
				var
					container=element.retrieve('container'),
					subcontainer=element.retrieve('subcontainer'),
					content=element.retrieve('content'),
					style={};

				if (element == current && container.hasClassName('collapsed'))
				{
					style={height:content.measure('margin-box-height')+'px'};
					container.addClassName('expanded');
					container.removeClassName('collapsed');
				}
				else
				{
					style=defaultstyle;
					container.addClassName('collapsed');
					container.removeClassName('expanded');
				}
				tweenings.push([subcontainer,style]);
			});
			Timeline.addTweenings(tweenings);
		};

		elements.each(function(e){
			var container=e.up('li');
			e.store('container', container);
			var subcontainer=container.down('span');
			e.store('subcontainer', subcontainer);
			subcontainer.setStyle(defaultstyle);
			container.addClassName('collapsed');
			container.removeClassName('expanded');

			e.store('content', e.up('li').select('.text')[0]);
			e.onclick=function(){ change(this); return false; }.bind(e);
		});
	})();

	/*** all destinations ***/
	(function(){
		var elements=$$('#alldestinations ul li h3');
		var defaultstyle={height:'0px'};
		var opened='open';
		var closed='closed';

		var change=function(current){
			var tweenings=[];
			elements.each(function(element){
				var
					li=element.retrieve('li'),
					container=element.retrieve('container'),
					content=element.retrieve('content'),
					style={};

				if (element == current && li.hasClassName(closed))
				{
					style={height:content.measure('margin-box-height')+'px'};
					li.addClassName(opened);
					li.removeClassName(closed);
				}
				else
				{
					style=defaultstyle;
					li.addClassName(closed);
					li.removeClassName(opened);
				}
				tweenings.push([container,style]);
			});
			Timeline.addTweenings(tweenings);
		};

		var cur=false;
		var def=false;

		elements.each(function(e){
			var li=e.up('li');
			e.store('li', li);
			var container=e.next('.container');
			e.store('container', container);
			container.setStyle(defaultstyle);
			li.addClassName(closed);
			li.removeClassName(opened);

			e.store('content', container.down('ul'));
			e.observe('click', function(){ change(this); }.bind(e));

			if (container.down('li.sel')) cur=e;
			if (e.firstChild.nodeValue == 'Europa')
				def=e;
		});

		if (!cur) cur=def;
		if (cur) change(cur);
	})();

	/*** gallery ***/
	var setgallery=function(g){
		var c=g.select('.gallerypart');
		if (!c || !c.length) return;
		var imgs=g.select('img');

		if (!imgs || imgs.length < 2) return;
		var wh={
			w:imgs[0].parentNode.offsetWidth,
			h:imgs[0].parentNode.offsetHeight
		};

		var prev=(new Element('div')).update('<div class="arrow"></div><div class="clickbox"></div>');
		var next=(new Element('div')).update('<div class="arrow"></div><div class="clickbox"></div>');
		prev.addClassName('prev');
		next.addClassName('next');
		prev.setStyle({height:wh.h+'px',width:'50%',position:'absolute',left:0,top:0,zIndex:3});
		next.setStyle({height:wh.h+'px',width:'50%',position:'absolute',right:0,top:0,zIndex:3});

		var gallery=new swgallery(c);
		(prev.down('.clickbox')).setStyle({width:'100%',height:'100%',position:'absolute',left:0,top:0,padding:0,margin:0,border:0,background:'#f00',opacity:0.0001});
		(next.down('.clickbox')).setStyle({width:'100%',height:'100%',position:'absolute',left:0,top:0,padding:0,margin:0,border:0,background:'#f00',opacity:0.0001});

		var setZIndex=function(p){
			var follower=gallery.current+p;
			if (follower < 0) follower=(gallery.elements.length-1);
			if (follower >= gallery.elements.length) follower=0;
			gallery.elements.each(function(e){
				if (e == gallery.elements[follower]) e.setStyle({zIndex:2});
				else if (e == gallery.elements[gallery.current]) e.setStyle({zIndex:1});
				else e.setStyle({zIndex:0});
			});
		};

		(prev.down('.clickbox')).observe('click', function(){ setZIndex(-1); gallery.prev(); }.bind(this));
		(next.down('.clickbox')).observe('click', function(){ setZIndex(1); gallery.next(); }.bind(this));
		g.appendChild(prev);
		g.appendChild(next);

		var i=function(){
			var a,c=true;
			for (a=0; imgs[a]; a++){
				if (!imgs[a].complete)
					c=false;
				if (imgs[a].height > wh.h)
					wh.h=imgs[a].height;
				if (imgs[a].width > wh.w)
					wh.w=imgs[a].width;
				imgs[a].setStyle({
					marginTop:Math.round((wh.h-imgs[a].height)/2)+'px',
					marginLeft:Math.round((wh.w-imgs[a].width)/2)+'px'
				});
			}
			prev.setStyle({height:wh.h+'px'});
			next.setStyle({height:wh.h+'px'});
			if (c) clearInterval(ii);
		};
		var ii=setInterval(i.bind(this),30);
		i();
	};
	$$('.gallery').each(setgallery);

	/*** print ***/
	$$('a[href=#print]').each(function(p){
		p.onclick=function(){
			print();
			return false;
		};
	});

	/*** flapform ***/
	var flapform=function(a){
		var container=a.next('.flapform');
		if (!container) return;
		var formtag=container.down('form');

		if(self.location.href.indexOf('mail_sended=1')==-1 && self.location.href.indexOf('mail_error_')==-1)
			container.setStyle({overflow:'hidden',height:'0px'});

		a.onclick=function(){
			if (container.offsetHeight > 0)
				container.tween({height:'0px'});
			else{
				container.tween({height:formtag.measure('border-box-height')+'px'});
			}
			return false;
		};
	};
	$$('.flapformbutton').each(flapform);

});

//jQuery - move to mootools ??? Habe es in Mootools versucht und einfach zu lang gebraucht
jQuery(document).ready(function($) {

	/*** Alert ausblenden nach 3 Sekunden ***/
	setTimeout("jQuery('#alert').fadeOut('slow');",3000);

	/*** Cockpit ***/
	$("#cockpit").each(function() {
		var cockpit = this;

		/*** Store desinations for display:none equivalent ***/
		$(cockpit).append('<div id="destination_store"></div>');
		$(cockpit).find("#destination_store").hide();
		$(cockpit).find("option").each(function() {
			$("#destination_store").append('<span value="'+$(this).attr("value")+'" class="'+$(this).attr('class')+'">'+$(this).text()+'</span>');
		});

		$(cockpit).find("select").each(function() {
			this.selectedIndex=0;
		});
		$(cockpit).find("#region").attr("disabled","disabled");
		$(this).find("#land").change(function() {
			land = this;

			$(cockpit).find("#region").removeAttr("disabled").empty();
			$(cockpit).find("#region").append('<option value="">Bitte auswählen</option>');
			$("#destination_store").find("span.parent-"+$(land).val()).each(function() {
				$(cockpit).find("#region").append('<option value="'+$(this).attr("value")+'">'+$(this).text()+'</option>');
			});

			$(cockpit).find("#region")[0].selectedIndex=0;

			/*$(cockpit).find("#region").removeAttr("disabled").find("option").each(function() {
				$(this).show();
				if($(this).attr('class')!="parent-"+$(land).val())
					$(this).hide();
			});*/
		});
		$(cockpit).submit(function(e) {
			if($(this).find("input[name=detailsearch]").val()=='Suchbegriff eingeben') $(this).find("input[name=detailsearch]").val('');
			if($(this).find("input[name=simplesearch]").val()=='Suchbegriff eingeben') $(this).find("input[name=simplesearch]").val('');
		});
	});

	/*** Check Registration ***/
	$("#register form").each(function() {
		$(this).find(".bt").css("cursor","pointer").click(function() {
			$(this).parents("form:first").submit();
		});
	});

	/*** Top Link ***/
	$(".top").live("click",function(e) {
		e.preventDefault();
		$(document).scrollTop(0);
	});

	$("#rating .info").click(function(e) {
		e.preventDefault();
		window.open("http://"+window.location.hostname+"/"+$(this).attr("href"),"_blank","width=600,height=400, scrollbars=yes");
	});

	/*** Google Maps ***/
	var gmap_id_counter = 0;
	$(".gmap").each(function() {

		var gmap = this;
		var id = gmap_id_counter++;

		$(gmap).attr('id','gmap-'+id);

		if($(gmap).find(".m-elements").find("li").length == 1) {

			$(gmap).removeClass('hide');

			var lat = $(gmap).find(".m-lat").text();
			var lng = $(gmap).find(".m-lng").text();
			var zoom = parseInt($(gmap).find(".m-zoom").text());
			var icon = $(gmap).find(".m-icon").text();
			var map = new GMap2(document.getElementById('gmap-'+id));

			var baseIcon = new GIcon(G_DEFAULT_ICON);
			baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			baseIcon.iconSize = new GSize(10, 10);
			baseIcon.shadowSize = new GSize(0, 0);
			baseIcon.iconAnchor = new GPoint(0, 0);
			baseIcon.infoWindowAnchor = new GPoint(0, 0);
			var markerIcon = new GIcon(baseIcon);
			markerIcon.image = "/"+icon;


			map.checkResize();
			map.enableScrollWheelZoom();
			map.setCenter(new GLatLng(lat,lng),zoom);

			var marker = new GMarker(new GLatLng(lat,lng),{icon:markerIcon});
			map.addOverlay(marker);
		}
		else if($(gmap).find(".m-elements").find("li").length > 1) {

			$("body").append('<div id="gmap_data-'+id+'" class="hide">'+$(gmap).html()+'</div>');
			var gmap_data = $("#gmap_data-"+id)[0];

			$(gmap).removeClass('hide');

			var map = new GMap2(document.getElementById('gmap-'+id));
			map.checkResize();
			map.enableScrollWheelZoom();
			map.setCenter(new GLatLng('48.21124470069878', '16.369972229003906'),6); // BOUND

			var north = $(gmap_data).find(".m-elements").find("li:first").find(".m-lat").text();
			var south = $(gmap_data).find(".m-elements").find("li:first").find(".m-lat").text();
			var east = $(gmap_data).find(".m-elements").find("li:first").find(".m-lng").text();
			var west = $(gmap_data).find(".m-elements").find("li:first").find(".m-lng").text();
			var north_t = north;
			var south_t = south;
			var east_t = east;
			var west_t = west;

			$(gmap_data).find(".m-elements").find("li").each(function() {

				var element = this;
				var lat = $(element).find(".m-lat").text();
				var lng = $(element).find(".m-lng").text();
				var zoom = parseInt($(element).find(".m-zoom").text());
				var icon = $(element).find(".m-icon").text();
				var link = $(element).find(".m-link").text();

				if(lat>north) 	{ north_t=lat; north=lat; }
				if(lat<south) 	{ south_t=lat; south=lat; }
				if(lng<west) 	{ west_t=lng; west=lat; }
				if(lng>east) 	{ east_t=lng; east=lat; }

				var baseIcon = new GIcon(G_DEFAULT_ICON);
				baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
				baseIcon.iconSize = new GSize(10, 10);
				baseIcon.shadowSize = new GSize(0, 0);
				baseIcon.iconAnchor = new GPoint(0, 0);
				baseIcon.infoWindowAnchor = new GPoint(0, 0);
				var markerIcon = new GIcon(baseIcon);
				markerIcon.image = "/"+icon;

				var marker = new GMarker(new GLatLng(lat,lng),{icon:markerIcon});
				map.addOverlay(marker);

				if(link!="") {
					GEvent.addListener(marker, 'click', function() {
						self.location.href="http://www.ccircle.cc/"+link;
					});
				}

			});

			var bounds = new GLatLngBounds;
			bounds.extend(new GLatLng(south_t,west_t));
			bounds.extend(new GLatLng(north_t,east_t));
			map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
		}

	});

	/** lang russisch ru .. */
	if (navigator.appName == 'Netscape')
		var language = navigator.language;
	else
		var language = navigator.browserLanguage;
	if(language.indexOf("ru")!=-1) $(".lang-ru").show();

	if(self.location.href.indexOf('#test') != -1) {
		alert(navigator.userAgent);
	}

	/*** login move ***/
	$(".move-login").submit(function(e) {
		if(e.preventDefault) e.preventDefault();
		else e.returnValue = false;

		var member = 	$(this).find("input[name=user]").val();
		var pass = 		$(this).find("input[name=pass]").val();

		$("#loginout").find("#membername").val(member);
		$("#loginout").find("#pass").val(pass);
		$("#loginout").find("form").find("input[type=submit]").click();
	});
});




var setDefaultValue=function(input_element, value, password_field){
	input_element=$(input_element);
	if (!input_element) return;
	if (password_field){
		password_field=$(password_field);
		if (!password_field) return;
		password_field.setStyle({display:'none'});

		input_element.observe('focus',function(){
			this.setStyle({display:'none'});
			password_field.setStyle({display:''});
			password_field.focus();
		});

		password_field.observe('blur',function(){
			if (this.getValue() == ''){
				this.setStyle({display:'none'});
				input_element.setStyle({display:''});
			}
		});

		if (input_element.getValue() == '')
			input_element.value=value;
	}else{
		input_element.observe('focus',function(){
			if (this.getValue() == value)
				this.value='';
		});
		input_element.observe('blur',function(){
			if (this.getValue() == '')
				this.value=value;
		});
		if (input_element.getValue() == '')
			input_element.value=value;
	}
};



















/* GET hashchangeEvent value */
var hashchangeEvent;
(function(){
	ret = {};
	var _hasOwnProperty = ({}).hasOwnProperty, hasOwnProperty;
	if (typeof _hasOwnProperty !== 'undefined' && typeof _hasOwnProperty.call !== 'undefined') {
	hasOwnProperty = function (object, property) {
	return _hasOwnProperty.call(object, property);
	};
	}
	else {
	hasOwnProperty = function (object, property) { /* yes, this can give false positives/negatives, but most of the time we don't care about those */
	return ((property in object) && typeof object.constructor.prototype[property] === 'undefined');
	};
	}

	    isEventSupported = (function(){

		var TAGNAMES = {
		  'select':'input','change':'input',
		  'submit':'form','reset':'form',
		  'error':'img','load':'img','abort':'img'
		},
		cache = { };

		function isEventSupported(eventName, element) {
		    var canCache = (arguments.length == 1);

		    // only return cached result when no element is given
		    if (canCache && cache[eventName]) {
			return cache[eventName];
		    }

		    element = element || document.createElement(TAGNAMES[eventName] || 'div');
		    eventName = 'on' + eventName;

		    // When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize"
		    // `in` "catches" those
		    var isSupported = (eventName in element);

		    if (!isSupported && element.setAttribute) {
			element.setAttribute(eventName, 'return;');
			isSupported = typeof element[eventName] == 'function';
		    }

		    element = null;
		    return canCache ? (cache[eventName] = isSupported) : isSupported;
		}

		return isEventSupported;
	    })();

	var tests={};
	var classes=[];
	var hashchange='hashchange';
	tests[hashchange]=function(){
		return isEventSupported(hashchange, window) && ( document.documentMode === undefined || document.documentMode > 7 );
	};

	    for ( var feature in tests ) {
		if ( hasOwnProperty( tests, feature ) ) {
		    // run the test, throw the return value into the Modernizr,
		    //   then based on that boolean, define an appropriate className
		    //   and push it into an array of classes we'll join later.
		    classes.push( ( ( ret[ feature.toLowerCase() ] = tests[ feature ]() ) ?  '' : 'no-' ) + feature.toLowerCase() );
		}
	    }
	hashchangeEvent=ret[hashchange];
})();



if (typeof(window["GIcon"]) != "undefined") {
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 24);
baseIcon.shadowSize = new GSize(0, 0);
baseIcon.iconAnchor = new GPoint(10, 30);
baseIcon.infoWindowAnchor = new GPoint(0, 0);
var markerIcon = new GIcon(baseIcon);
markerIcon.image = "/css/img/icon_googlemap.png";
}


function G_SetDestination(hotels, north, east, south, west) {

	var map = new GMap2(document.getElementById('map'));
	GGeocoder = new GClientGeocoder();
	map.enableScrollWheelZoom();

	for(i=0;i<hotels.length;i++) {
		hotels[i]['marker'] = new GMarker(new GLatLng(hotels[i]['lat'],hotels[i]['lng']),{icon:markerIcon});
		hotels[i]['marker'].html = hotels[i]['html'];
		map.addOverlay(hotels[i]['marker']);
		GEvent.addListener(hotels[i]['marker'], 'click', function(marker) {
			map.openInfoWindowHtml(marker, this.html);
		});
	}

	var bounds = new GLatLngBounds;
	bounds.extend(new GLatLng(south,west));
	bounds.extend(new GLatLng(north,east));
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)-1);

}

function G_SetHotel(hotel) {

	var map = new GMap2(document.getElementById('map'));
	GGeocoder = new GClientGeocoder();
	map.enableScrollWheelZoom();

	map.setCenter(new GLatLng(hotel['lat'],hotel['lng']),parseInt(hotel['zoom']));

	hotel['marker'] = new GMarker(new GLatLng(hotel['lat'],hotel['lng']),{icon:markerIcon});
	hotel['marker'].html = hotel['html'];
	map.addOverlay(hotel['marker']);
	GEvent.addListener(hotel['marker'], 'click', function(marker) {
		map.openInfoWindowHtml(marker, this.html);
	});



}

function G_SetDestinationByAdress(address) {

	var map = new GMap2(document.getElementById('map'));
	GGeocoder = new GClientGeocoder();
	map.enableScrollWheelZoom();

	GGeocoder = new GClientGeocoder();
	GGeocoder.getLatLng(address, function(point){
		if (!point) {
			alert(address + ' not found');
		} else {
			map.setCenter(point,12);
		}
	});

	for(i=0;i<hotels.length;i++) {
		hotels[i]['marker'] = new GMarker(new GLatLng(hotels[i]['lat'],hotels[i]['lng']),{icon:markerIcon});
		hotels[i]['marker'].html = hotels[i]['html'];
		map.addOverlay(hotels[i]['marker']);
		GEvent.addListener(hotels[i]['marker'], 'click', function(marker) {
			map.openInfoWindowHtml(marker, this.html);
		});
	}
}

/* Functions for Advertorial Timer*/

var TimerAd_zielDatum=new Date();
TimerAd_zielDatum.setHours ( 0 );
TimerAd_zielDatum.setMinutes ( 0 );
TimerAd_zielDatum.setMilliseconds ( 0 );
TimerAd_zielDatum.setDate ( TimerAd_zielDatum.getDate()+1);

function TimerAd_pad(num, size)
{
    var s = "000000000" + num;
    return s.substr(s.length-size);
}

function TimerAd_countdown()
{
	startDatum=new Date();

	if ( startDatum<TimerAd_zielDatum )
	{

	  var stunden=0, minuten=0, sekunden=0;
	  var out = "<span class='timerh'>";

	  stunden=Math.floor((TimerAd_zielDatum-startDatum)/(60*60*1000));
	  startDatum.setTime(startDatum.getTime()+stunden*60*60*1000);
	  minuten=Math.floor((TimerAd_zielDatum-startDatum)/(60*1000));
	  startDatum.setTime(startDatum.getTime()+minuten*60*1000);
	  sekunden=Math.floor((TimerAd_zielDatum-startDatum)/1000);

	  out += TimerAd_pad ( stunden, 2 );
	  out += "</span><span class='timercolon1'>:</span><span class='timerm'>";
	  out += TimerAd_pad ( minuten, 2 );
	  out += "</span><span class='timercolon2'>:</span><span class='timers'>";
	  out += TimerAd_pad ( sekunden, 2 );
	  out += "</span>";
	  if ( document.getElementById ( 'timer' ) )
		  document.getElementById ( 'timer' ).innerHTML = "<span class='timertext'>" + out + "</span>";

	  setTimeout('TimerAd_countdown()',200);
	}
	else if ( document.getElementById ( 'timer' ) ) document.getElementById ( 'timer' ).innerHTML = "<span class='timertext'>00:00:00</span>";
}

function TimerAd_stopEvent(e) {
	if(!e) var e = window.event;

	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}
function TimerAd_init( linkid )  {
	document.getElementById(linkid).onclick=function(e) {
		e=e||window.event;
		TimerAd_stopEvent(e);
		location.href="countlink.php?redirect="+linkid;
		return false;
	}
}



