﻿// -----------------------------------------------------------------------------------
//	PageTrans v 0.3custom - 2008-03-11
//	by Sindre Wimberger - wimberger@sindre.at
//
var PageTrans = {	
	RE: {
        gallery:        /^pagetrans\[(.*?)\]/i, // rel attribute format for gallery link
//		rel:            /^pagetrans/i, // rel attribute format
		param:          /\s*([a-z_]*?)\s*=\s*(.+)\s*/ // rel string parameter
	},
	clickstate: 0,
	init: function() {
/*		PageTrans.ContainerID = ContainerID;
		PageTrans.EffectContainerID = ContainerID;
		PageTrans.fx = effect;
		PageTrans.LStatus = loadStatus; 
		if (loadLocation == "" || loadLocation == null) {PageTrans.LLocation = "body";} else {PageTrans.LLocation = loadLocation;}
		PageTrans.LID = loadID;
		PageTrans.LContent = LoadContent; */
		PageTrans.getLinks();
	},
    getLinks: function() {
		if (PageTrans.LStatus == true) {PageTrans.LoaderInit();}
		$$('body a[rel^=pagetrans]').invoke('observe', 'click', 
		 function(event){
			Event.stop(event);
			if (PageTrans.clickstate==0) {
				var link = Event.element(event);
				var href = this.getAttribute('href')
				var o = PageTrans.getLinkOptions(link);
				if (!o['block'] || !o['container']) { 
					PageTrans.redirect(href); 
				} else {
					PageTrans.ContainerID = o['container'];
					PageTrans.EffectContainerID = o['container'];
					if(o['effect']) {
						PageTrans.fx = o['effect'];
					} else {
						PageTrans.fx = 5;
					}
					PageTrans.AjaxParams = "?block="+o['block'];
					PageTrans.clickstate = 1;
					PageTrans.disappearFX(href);	
					if(o['active']) {
						PageTrans.removeClass(this,o['active']);
					}
				}
			}
		});
	}, 	
	getLinkOptions: function(el) {
		var o = Array();
        var rel = el.getAttribute('rel');
        if(rel){
            // extract gallery name from shadowbox[name] format
            var match = rel.match(PageTrans.RE.gallery);
            if(match) {
				o["group"] = escape(match[2]);
			}
            // other parameters
            var params = rel.split('|');
            for(var i = 0, len = params.length; i < len; ++i){
                match = params[i].match(PageTrans.RE.param);
                if(match){
					o[match[1]] = match[2];
                }
            }
        }
		return o;
	}, 	
	removeClass: function(el,tag) {
		el.up(tag).siblings().invoke('removeClassName', 'active');
		el.up(tag).addClassName('active');
//		$$('#detailAJAX .active').invoke('removeClassName', 'active');
	}, 	
    request: function(url,params) {
		if (PageTrans.LStatus == true) {PageTrans.LoaderAppear();}		
		new Ajax.Request(url, {
		 	parameters : PageTrans.AjaxParams,
			method: 'get',
			onFailure : function(resp) {PageTrans.redirect(url,resp.statusText);},
			onException : function(resp,ex) {PageTrans.redirect(url,ex);},
			onComplete:function(req){	
				PageTrans.insert(req.responseText);
		}});
	},
    insert: function(txt) {
		$(PageTrans.ContainerID).innerHTML = txt;
		if (PageTrans.LStatus == true) {
			PageTrans.LoaderDISAppear();			
		} else {
        	PageTrans.appearFX();
		}
	},
    disappearFX: function(url) {
		if (PageTrans.fx==1) {new Effect.Fade(PageTrans.EffectContainerID,
									 { duration:'0.2',
 									   afterFinish: function(){PageTrans.request(url)},
									   queue: { scope: 'aktive', position: 'front'}
									 });
		}
		if (PageTrans.fx==2) {new Effect.BlindUp(PageTrans.EffectContainerID,
									 { duration:'0.8',
									   afterFinish: function(){PageTrans.request(url)},
									   queue: { scope: 'aktive', position: 'front'}
									 });
		}
		if (PageTrans.fx==3) {new Effect.SlideUp(PageTrans.EffectContainerID,
									 { duration:'1.2',
									   afterFinish: function(){PageTrans.request(url)},
									   queue: { scope: 'aktive', position: 'front'}
									 });
		}
		if (PageTrans.fx==4) {new Effect.Shrink(PageTrans.EffectContainerID,
									{ duration:'1.2',
									  afterFinish: function(){PageTrans.request(url)},
									  queue: { scope: 'aktive', position: 'front'}
									});
		}
		if (PageTrans.fx==5) {PageTrans.request(url);}
		
	},
    appearFX: function() {
		if (PageTrans.fx==1) {new Effect.Appear(PageTrans.EffectContainerID,
									 { duration:'0.2',
 									   afterFinish: function(){PageTrans.functionJS();},
									   queue: { scope: 'aktive', position: 'end'}
									 });
		}
		if (PageTrans.fx==2) {new Effect.BlindDown(PageTrans.EffectContainerID,
									 { duration:'0.8',
 									   afterFinish: function(){PageTrans.functionJS();},
									   queue: { scope: 'aktive', position: 'end'}
									 });
		}
		if (PageTrans.fx==3) {new Effect.SlideDown(PageTrans.EffectContainerID,
									 { duration:'1.2',
 									   afterFinish: function(){PageTrans.functionJS();},
									   queue: { scope: 'aktive', position: 'end'}
									 });
		}
		if (PageTrans.fx==4) {new Effect.Grow(PageTrans.EffectContainerID,
									 { duration:'1.2',
 									   afterFinish: function(){PageTrans.functionJS();},
									   queue: { scope: 'aktive', position: 'end'}
									 });
		}
		if (PageTrans.fx==5) {new Effect.Pulsate(PageTrans.EffectContainerID,
									 { duration:'1.2',
 									   afterFinish: function(){PageTrans.functionJS();},
									   queue: { scope: 'aktive', position: 'end'}
									 });
		}
	},
    LoaderInit: function() {
		if (!$(PageTrans.LID)){
			if (PageTrans.LLocation=="body") {var objBody = document.getElementsByTagName("body").item(0);}
			else {var objBody = $(PageTrans.LLocation);}
			objLoading = document.createElement("div");
			objLoading.setAttribute('id',PageTrans.LID);
			objLoading.style.display = "none";
			objLoading.innerHTML = PageTrans.LContent;
			objBody.appendChild(objLoading);
		} else {
			objLoading = $(PageTrans.LID);			
			objLoading.style.display = "none";
		}		
	},	
    LoaderAppear: function() {
		objLoading.style.display = "block";
	},
    LoaderDISAppear: function() {
		objLoading.style.display = "none";
		PageTrans.appearFX();
	},
    redirect: function(url,res) {
//		alert(res);
		window.location.href = url;
	},
	functionJS: function(){
		this.clickstate = 0;				
		myLightbox.initialize();
		PageTrans.getLinks();
	}
};

// -----------------------------------------------------------------------------------
function loadGoogleMaps() { 
	/* ABQIAAAA1NPrAg5my5Yyo4v80SyAKBSD8PTmm-y9dLZg1xS6EihasfGUuhTLtoyB8HeX35ddPCrX4V1azwENGg // novelli.at 
	   ABQIAAAA1NPrAg5my5Yyo4v80SyAKBS_z5jlT5VPh1d1xlbQFw9zg5jASxTaLEWKbeAIlLSmRYtE8DmhF6gKHg // novelli.echonet.at */
	var script = document.createElement("script");
	script.setAttribute("src", "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA1NPrAg5my5Yyo4v80SyAKBSD8PTmm-y9dLZg1xS6EihasfGUuhTLtoyB8HeX35ddPCrX4V1azwENGg&c&async=2&callback=createGoogleMaps&locale=de_AT");
	script.setAttribute("type", "text/javascript");
	script.setAttribute("id", "googlemaploader");
//	document.documentElement.firstChild.appendChild(script);
	document.getElementsByTagName("body").item(0).appendChild(script);
}
function initGoogleMaps() { 
	if(!$('googlemap')) { return false; }
	if($('googlemaploader')) {
		  createGoogleMaps();
	} else {
		  loadGoogleMaps();
	}
}
    
function setDirections(fromAddress) {
  gdir.load("from: " + fromAddress + " to: Bräunerstrasse 11a, 1010 Wien",
			{ "locale": "de_AT" });
}

function GDirectionshandleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("Die angegebene Adresse konnte nicht gefunden werden. Entweder sie ist relativ neu, oder fehlerhaft.\nFehler Code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("Der Anfahrtsplan konnte nicht erstellt werden.\n Fehler Code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Fehler Code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("Der Schlüssel passt nicht zur angegeben Domain.\n Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("Der Anfahrtsplan konnte nicht erstellt werden.\n Fehler Code: " + gdir.getStatus().code);
	
   else alert("Fehler. Bitte überprüfen Sie Ihre Angaben.");
   
}

function onGDirectionsLoad(){ 
  // Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...
}

function createGoogleMaps() { 
	if (!GBrowserIsCompatible()) { return false; }
//	window.onunload=GMap2.Unload; 
	if(!$('planbar')) {
		new Insertion.Top('textpad', '<div id="planbar"><p>Geben Sie Ihren momentanen Standort ein und erstellen Sie Ihren persönlichen Anfahrtsplan zu Vista3.</p><form class="bg" onsubmit="setDirections(this.standpunkt.value); return false"><input id="standpunkt" name="standpunkt" /><button type="submit">Anfahrtsplan erstellen</button></form><div id="fahrtbeschreibung"></div></div>');
	}
	showmap(48.20712925493621, 16.368298530578613);
//    setDirections("Schottenfeldgasse 24, 1070 Wien", "Bräunerstrasse 11a, 1010 Wien");
	function showmap(x,y) {
		mapelement = $('googlemap');
/*		mapelement.setStyle({
			height: "371px",
			width: "660px"
		});*/
		map = new GMap2(mapelement);
		gdir = new GDirections(map, document.getElementById("fahrtbeschreibung"));
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", GDirectionshandleErrors);
		map.addControl(new GLargeMapControl());
		map.addControl(new GOverviewMapControl());
		map.addControl(new GScaleControl());
		map.setCenter(new GLatLng(x,y), 15);
		map.addOverlay(createMarker(new GLatLng(x,y)));
	}
	
	function createMarker(point) {
		var icon = new GIcon();
		icon.image = "/assets/content/icon-googlemaps.png";
		icon.printImage = "/assets/content/icon-googlemaps-print.gif";
		icon.mozPrintImage = "/assets/content/icon-googlemaps-print.gif";
	//	icon.shadow = "/grafik/content/icon-googlemaps-shadow.png";
		icon.iconSize = new GSize(71, 73);
	//	icon.shadowSize = new GSize(36, 36);
		icon.iconAnchor = new GPoint(35, 36);
		icon.infoWindowAnchor = new GPoint(35, 36);		
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml('<div style="height:110px;"><strong>Vista 3 bistro • conference • event </strong><br />Schlachthausgasse 28 / Ecke Alfred-Dallinger-Platz 1 | 1034 Wien<br />Tel.: +43/1/402 08 08 | Fax: +43/1/402 08 08 80 | www.vista3.at<br />E-Mail: <a href="mailto:office@vista3.at">office@vista3.at</a></div>');
		});
		return marker;
	}  
}

// -----------------------------------------------------------------------------------
document.observe("dom:loaded", function() {										
		
	// Ajax Übergänge
	PageTrans.init();	

	// Lighthover Effext
 	initLightbox();
	
	// Google Maps 
  	initGoogleMaps();

});