naviki.main.WayInfo = function(config,tabview) {
	
	this.tabview  = tabview;
	this.config   = config;
	this.wayId    = config['wayuid'];
	this.divid    = config['divid'];
	this.legendid = config['legendid'];
	this.obj      = "wayinfo"+config['cid'];
	
	this.leftborder   =  60;
	this.rightborder  =  15;
	this.topborder    =  20;
	this.bottomborder =  40;
	this.height       = 150;	

	this.pointCount;
	this.trackCount;	
	this.coords;
	this.wayprofile = null;
	this.start      = "";
	this.end        = "";
	this.legend     = null;

	this.initialize();
	if(this.wayId>0){
		this.styleFacebookButton();
		this.displayInfos(config['waydata']);
	}else{
		this.hideMe();
	}
	
	/* register me for a routing result event */
	eventMgr.updateWayInfo.subscribe(this.updateWayInfo, this);
};

naviki.main.WayInfo.prototype.styleFacebookButton = function() {
	var element = new YAHOO.util.Element(this.config['cid']+"-facebook");
	element.on('contentReady', function() {
	    var iframe = element.getElementsByTagName("iframe")[0];
	    YAHOO.util.Dom.setStyle(iframe,"width","80px");
	});	
};

naviki.main.WayInfo.prototype.displayLegend = function() {

	var element = document.getElementById(this.legendid);

	var html = "<table>";
	for(var i=0;i<this.legend.length;i++){
		html += "<tr>";
		html += "<td style='vertical-align: middle;'><div style='background-color:"+this.legend[i]['color']+";width:50px;height:5px;'>&nbsp;</div></td>";
		html += "<td>&nbsp;</td>";
		html += "<td>"+this.legend[i]['title']+"</td>";
		html += "</tr>";
	}
	html += "</table>";
	
	element.innerHTML = html;
};

naviki.main.WayInfo.prototype.displayInfos = function(data) {
	
	if (data['STATE'] != "OK") {
		/* error occured, so do nothing */
		return;
	}
	
	document.getElementById(this.config['infokmid']).innerHTML         = naviki.main.Util.formatNumber(naviki.main.Util.round(data['stats']['km'], 2))+" km";
    document.getElementById(this.config['infokmtimeid']).innerHTML     = naviki.main.Util.formatTime((data['stats']['km']/15.0)*3600) + " " + naviki.Lang.getLL('hours');
    document.getElementById(this.config['infoheightmaxid']).innerHTML  = naviki.main.Util.formatNumber(naviki.main.Util.round(data['stats']['heightmax'],0))+" m";
    document.getElementById(this.config['infoheightminid']).innerHTML  = naviki.main.Util.formatNumber(naviki.main.Util.round(data['stats']['heightmin'],0))+" m";
    document.getElementById(this.config['infoheightdiffid']).innerHTML = naviki.main.Util.formatNumber(naviki.main.Util.round(data['stats']['heightdiff'],0))+" m";
    document.getElementById(this.config['infoslopemaxid']).innerHTML   = naviki.main.Util.formatNumber(naviki.main.Util.round(data['stats']['slopemax'],2))+"%";
    
    this.wayId      = data['WAYUID'];
	this.pointCount = parseInt(data['stats']['pointCount']);
	this.trackCount = parseInt(data['tracks']);
	this.setGpsDialog(0);
	
	if (this.config['roadbooktargetsite']>0) {
		document.getElementById(this.config['roadbookid']).href = document.getElementById(this.config['roadbookid']).href 
		+ "?id="+this.config['roadbooktargetsite']
		+ "&type=98"
		+ "&tx_naviki_pi_roadbook[wayuid]="+data['WAYUID']
        + "&tx_naviki_pi_roadbook[start]=" +this.start
		+ "&tx_naviki_pi_roadbook[end]="   +this.end
		+ "&tx_naviki_pi_roadbook[title]=" +data['title'];
	}
	
	if(typeof(data['coords'])!="undefined" && typeof(data['stats']['km'])!="undefined"){
		
		this.profile   = true;
		this.coords    = data['coords'];
		
		if(this.coords.length>1){
			this.setPaginator(this.coords.length);
		}else{
			document.getElementById(this.config['heightdiagimageid']+"_paginator").style.display = "none";
		}
		
		this.drawProfile(0);
		this.setMouseOver();	
	}else{
		this.profile = false;
	}
	
	var legend = document.getElementById(this.legendid+"_tab");
	if(this.legend == null || this.config['showlegend']==0){
		legend.style.display = "none";
	}else{
		this.displayLegend();
		legend.style.display = "";
	}

	this.tabview.selectTab(0);
	this.showMe();
};

naviki.main.WayInfo.prototype.updateGpsDialog = function(){

	var elements = document.getElementsByName(this.divid+"_optionNAME");
	for(var i=0;i<elements.length;i++){
		if(elements[i].checked){
			break;
		}
	}
	
	this.setGpsDialog(i);
};

naviki.main.WayInfo.prototype.setGpsDialog = function(option){
	
	// update the gps dialog.
	var dialog = document.getElementById("naviki-dialogs_"+this.divid+"_content");
		
	if (naviki.Util.TCXdownload == "1") {
		template = naviki.Template.getSubpart("###TEMPLATE_DOWNLOADING_GPS_FILES###");
	} else {
		template = naviki.Template.getSubpart("###TEMPLATE_DOWNLOADING_GPS_FILES_WITHOUT_TCX###");
	}
		  
	sa = [];
	sa['###HEADER_DOWNLOAD###'] = naviki.Lang.getLL("wayinfogpsdialogmessage");
	sa['###FILE_KML_TEXT###']   = naviki.Lang.getLL("wayinfogpsdialogkmlinfo");
	sa['###FILE_GPX_TEXT###']   = naviki.Lang.getLL("wayinfogpsdialoggpxinfo");
	sa['###FILE_OVL_TEXT###']   = naviki.Lang.getLL("wayinfogpsdialogovlinfo");
	sa['###FILE_TCX_TEXT###']   = naviki.Lang.getLL("wayinfogpsdialogtcxinfo");
	
	sa['###HEADER_OPTION###'] = naviki.Lang.getLL("wayinfogpsdialogoption");
	sa['###TEXT_OPTION_0###'] = naviki.Lang.getLL("wayinfogpsdialogoption.0");
	sa['###TEXT_OPTION_1###'] = naviki.Lang.getLL("wayinfogpsdialogoption.1");
	sa['###TEXT_OPTION_2###'] = naviki.Lang.getLL("wayinfogpsdialogoption.2");
	sa['###TEXT_OPTION_3###'] = naviki.Lang.getLL("wayinfogpsdialogoption.3");
	sa['###ID_OPTION###']     = this.divid+"_option";
	sa['###ID_OPTION_0###']   = this.divid+"_option0";
	sa['###ID_OPTION_1###']   = this.divid+"_option1";
	sa['###ID_OPTION_2###']   = this.divid+"_option2";
	sa['###ID_OPTION_3###']   = this.divid+"_option3";	
	sa['###NAME_OPTION###']   = this.divid+"_optionNAME";
	sa['###CLICK_EVENT###']   = "onClick='"+this.obj+".updateGpsDialog();'";

	switch(option){
		case 0:
			sa['###CHECKED_0###'] = "checked='checked'";
			sa['###CHECKED_1###'] = "";
			sa['###CHECKED_2###'] = "";
			sa['###CHECKED_3###'] = "";
			break;
		case 1:
			sa['###CHECKED_0###'] = "";
			sa['###CHECKED_1###'] = "checked='checked'";
			sa['###CHECKED_2###'] = "";
			sa['###CHECKED_3###'] = "";
			break;
		case 2:
			sa['###CHECKED_0###'] = "";
			sa['###CHECKED_1###'] = "";
			sa['###CHECKED_2###'] = "checked='checked'";
			sa['###CHECKED_3###'] = "";
			break;
		case 3:
			sa['###CHECKED_0###'] = "";
			sa['###CHECKED_1###'] = "";
			sa['###CHECKED_2###'] = "";
			sa['###CHECKED_3###'] = "checked='checked'";			
			break;			
	}
		
	var restapi = "index.php?eID=tx_naviki_pi_rest&actionId=newExportWay&format=";
	var kmlexport = restapi+'kml&way='+this.wayId+'&option='+option;
	var gpxexport = restapi+'gpx&way='+this.wayId+'&option='+option;
	var ovlexport = restapi+'ovl&way='+this.wayId+'&option='+option;
	var tcxexport = restapi+'tcx&way='+this.wayId+'&option='+option;

	sa['###FILE_KML###'] = kmlexport;
	sa['###FILE_GPX###'] = gpxexport;
	sa['###FILE_OVL###'] = ovlexport;
	sa['###FILE_TCX###'] = tcxexport;
	
	this.GPSDialog.setBody(naviki.Template.substituteMarkerArray(template, sa));
	this.GPSDialog.render();
	
	if(this.trackCount==1 && this.pointCount<=500){
		document.getElementById(this.divid+"_option").style.display = "none";
		return;
	}
	
	if(this.trackCount==1 && this.pointCount>500){
		document.getElementById(this.divid+"_option2").style.display = "none";
		document.getElementById(this.divid+"_option3").style.display = "none";
	}

	if(this.trackCount>1 && this.pointCount<=500){
		document.getElementById(this.divid+"_option1").style.display = "none";
		document.getElementById(this.divid+"_option3").style.display = "none";
	}
};

naviki.main.WayInfo.prototype.displayEventOk = function(o) {
	var result = YAHOO.lang.JSON.parse(o.responseText);
	var me     = o.argument[0];
	me.displayInfos(result);
};

naviki.main.WayInfo.prototype.displayEventFail = function(o) {
	var me = o.argument[0];
	me.hideMe();	
};

naviki.main.WayInfo.prototype.processWayUID = function() {
	
	var address = "index.php?eID=tx_naviki_pi_way_info&actionId=getInfoFromUID&wayuid="+this.wayId;

	var getXML = YAHOO.util.Connect.asyncRequest("GET",address, {
		success : this.displayEventOk,
		failure : this.displayEventFail,
		argument: [this],
		cache : false
	});
};

naviki.main.WayInfo.prototype.showFilesDialog = function() {
	this.GPSDialog.show();
};

/* handle the Ok Button from the addDialog */
naviki.main.WayInfo.prototype.handleGPSDialogOk = function(o) {
	this.wayinfo.GPSDialog.hide();
};

naviki.main.WayInfo.prototype.hideMe = function() {
	document.getElementById("nui-ce-id-"+this.config['cid']).style.visibility = "hidden";
	document.getElementById("nui-ce-id-"+this.config['cid']).style.position   = "relative";
	document.getElementById("nui-ce-id-"+this.config['cid']).style.display    = "none";
};

naviki.main.WayInfo.prototype.showMe = function() {
	document.getElementById("nui-ce-id-"+this.config['cid']).style.visibility = "visible";
	document.getElementById("nui-ce-id-"+this.config['cid']).style.position   = "static";
	document.getElementById("nui-ce-id-"+this.config['cid']).style.display    = "";
};

/* init the container */
naviki.main.WayInfo.prototype.initialize = function() {

	this.hideMe();
	this.region  = YAHOO.util.Dom.getRegion(this.divid);
	this.div     = document.getElementById(this.divid);
	this.profile = false;
	
	// create the dialog for the gps files
	var dialog_container = document.getElementById("naviki-dialogs");
	var dialog = document.createElement("div");
	dialog.id  = ""+dialog_container.id+"_"+this.divid;

	dialog_container.appendChild(dialog);
	
	this.GPSDialog = new naviki.main.ModalDialog(
			""+dialog.id,   
			{ 	width      : "310px", 
				fixedcenter: true,  
				visible    : false,
				modal      : true,
				draggable  : true,
				fixedcenter:true,
	       		zindex     : 5,  
				close      : true,  
				constraintoviewport: true,
				buttons: [ 
				          { text:"Ok", handler: this.handleGPSDialogOk }  
				         ]	 
			}
	 );

	this.GPSDialog.setHeader(naviki.Lang.getLL("wayinfogpsdialogtitle"));
	this.GPSDialog.wayinfo = this;
	this.GPSDialog.render();
	
	/* listener for resize window */
	YAHOO.util.Event.on(window, 'resize', this.updatWayInfo);
		
	/* create way rating obj */
	if (parseInt( this.config['showrating']) == 1){
		if(typeof this.config['waydata']['stats']!="undefined"){
			var conf            = new Object();
			conf['wayID' ]      = this.config['wayuid'];
			conf['wayowner']    = this.config['waydata']['stats']['fe_userid'];
			conf['userID']      = this.config['useruid'];
			conf['userName']    = this.config['username'];
			conf['passwordMD5'] = this.config['passwordMD5'];
			conf['ratingID']    = this.config['ratingid'];
			conf['myratingID']  = this.config['myratingid'];
			conf['unsuitedID']  = this.config['unsuitedid'];
			var rating = new naviki.main.WayRating(conf);
		}
	}		
};

naviki.main.WayInfo.prototype.updateWayInfo = function(type, e, me){
	
	me.wayId = e[0];
	
	if(typeof e[1]!='undefined' && typeof e[2]!='undefined'){
		me.start = e[1];
		me.end   = e[2];
	}else{
		me.start = "";
		me.end   = "";
	}
	
	if(typeof e[3]!='undefined'){
		me.legend = e[3];
	}else{
		me.legend = null;
	}
	
	if(me.wayId>0){
		me.processWayUID();
	}else{
		me.hideMe();
	}	
};

naviki.main.WayInfo.prototype.setPaginator = function(numberOfprofiles){
	
	var paginator =  new YAHOO.widget.Paginator({
					 	template: '<div style="width: 100%">'+
					 			  '<table style="width: 100%; text-align: center"><tr style="text-align: center">'+
					 			  '<td>{PreviousPageLink}</td>'+
					 			  '<td style="width:100px;text-align: center">{PageLinks}</td>'+
					 			  '<td>{NextPageLink}</td>'+
					 			  '</tr></table>'+
					 			  '</div>'+
					 			  '',
					 	rowsPerPage: 1,
					 	previousPageLinkLabel : "&#9668;",
					 	nextPageLinkLabel : "&#9658;",
					 	pageLinks: 5,
					 	containers : this.config['heightdiagimageid']+"_paginator",
					 	totalRecords : numberOfprofiles,
					 	alwaysVisible: false
    				});

	paginator.render();
	paginator.subscribe('changeRequest', this.handlePagination); 
	paginator.myObj = this;
};

naviki.main.WayInfo.prototype.handlePagination = function (state) { 
	this.myObj.drawProfile(state.page-1);
    this.setState(state);
}; 

naviki.main.WayInfo.prototype.drawProfile = function(section){

	if(this.profile==true){

		var color = this.config['color'];
		var r     = parseInt(color.substr(1,2),16);
		var g     = parseInt(color.substr(3,2),16);
		var b     = parseInt(color.substr(5,2),16);

		//determine width
		this.canvas     = document.getElementById(this.config['heightdiagimageid']+"_canvas");
		var aboveObject = this.getAboveObject(this.canvas);
		this.width      = aboveObject.offsetWidth - 60;
		
		//set width and height of canvas
		this.canvas.width  = "" + this.width;
		this.canvas.height = "" + this.height;

		if(typeof(this.ctx)=="undefined"){
			this.ctx = this.canvas.getContext("2d");
		}
		
		//draw background
		this.ctx.fillStyle = 'rgb(255,255,255)';
		this.ctx.fillRect(0, 0, this.width, this.height);
	 	
		//draw frame
		this.ctx.lineWidth = 1;
		this.ctx.strokeStyle = 'rgb(0,0,0)';
		this.ctx.beginPath();
		this.ctx.moveTo(this.leftborder,this.topborder);
		this.ctx.lineTo(this.width-this.rightborder,this.topborder);
		this.ctx.lineTo(this.width-this.rightborder,this.height-this.bottomborder);
		this.ctx.lineTo(this.leftborder,this.height-this.bottomborder);
		this.ctx.lineTo(this.leftborder,this.topborder);
		this.ctx.stroke();
		this.ctx.closePath();
		
		//number of points to adjust
		this.myCoords  = new Array();
		var lastIndex;
		var deltaX;
		
		if(this.coords[section]['coords'].length==1){
			this.coords[section]['coords'].push(this.coords[section]['coords'][0]);
		}
		
		if(this.coords[section]['coords'].length>(this.width-this.leftborder-this.rightborder)){
			deltaX    = (this.width-this.leftborder-this.rightborder)/this.coords[section]['coords'].length;
			lastIndex = -1;
			for(var i=0;i<this.coords[section]['coords'].length;i++){
				if(parseInt(i*deltaX)!=lastIndex){
					this.myCoords.push(this.coords[section]['coords'][i]);
					lastIndex = parseInt(i*deltaX);
				}
			}
		}
		else if(this.coords[section]['coords'].length<(this.width-this.leftborder-this.rightborder)){
			deltaX = (this.width-this.leftborder-this.rightborder)/(this.coords[section]['coords'].length-1);
			for(var i=0;i<this.coords[section]['coords'].length;i++){
				if(this.myCoords.length==parseInt(i*deltaX+0.5)){
					this.myCoords.push(this.coords[section]['coords'][i]);
				}
				else{
					do{
						this.myCoords.push(this.coords[section]['coords'][i]);
					}
					while(this.myCoords.length<parseInt(i*deltaX+0.5));
				}
			}
		}
		else{
			for(var i=0;i<this.coords[section]['coords'].length;i++){
				this.myCoords.push(this.coords[section]['coords'][i]);
			}			
		}
		
		//determine min/max of ele
		var eleMax = this.myCoords[0]["ele"];
		var eleMin = this.myCoords[0]["ele"];
		var tmp;
		for(var i=1;i<this.myCoords.length;i++){
			tmp = this.myCoords[i]["ele"];
			if(parseInt(tmp)>parseInt(eleMax)){
				eleMax = tmp;
			}
			if(parseInt(tmp)<parseInt(eleMin)){
				eleMin = tmp;
			}			
		}		

		//determine display area of y-axis
		var ymax = eleMax;
		var ymin = eleMin;
		var diff = eleMax-eleMin;
		var tmp;
		
		if(diff<40){
			ymin = (parseInt(eleMin/2)-1)*2;
			do{
				ymax++;
				tmp = "" + (ymax-ymin)/4;
			}while(tmp.indexOf(".")>0);
		}
		else{
			var potenz = -1;
			var multi;
			do{
				potenz ++;
				multi  = Math.pow(10,potenz);
				tmp    = parseInt((eleMax-eleMin)/multi);
				
			}while(tmp>0);
			ymax = parseInt(eleMax/Math.pow(10,potenz-1)+1)*Math.pow(10,potenz-1);
			ymin = parseInt(eleMin/Math.pow(10,potenz-1))*Math.pow(10,potenz-1);
			tmp = "" + ((ymax-ymin)/4);
			if(tmp.indexOf(".")>0){
				ymax=ymax+Math.pow(10,potenz-1);
			}
		}
		var scalDiff  = (ymax-ymin)/4;
		var pixelDiff = parseInt(((this.height-this.topborder-this.bottomborder)/4)+0.5);			
		
		//draw height profile with polygon
		var x;
		var y;
		var pointsX = new Array();
		var pointsY = new Array();
		var deltaY  = (this.height-this.topborder-this.bottomborder)/(ymax-ymin);
		
		for(var i=0;i<this.myCoords.length;i++){
			if(this.myCoords[i]["ele"]==eleMin || this.myCoords[i]["ele"]==eleMax){
				x  = this.leftborder+1+i;
				y  = this.height-(this.bottomborder+1+parseInt((this.myCoords[i]["ele"]-ymin)*deltaY)+0.5);
			}
			else{
				if(i==0){
					x   = this.leftborder+1+i;
					tmp = (this.myCoords[i]["ele"]+this.myCoords[i+1]["ele"]+this.myCoords[i+2]["ele"])/3;
					y   = this.height-(this.bottomborder+1+parseInt((tmp-ymin)*deltaY)+0.5);
				}else if(i==1){
					x   = this.leftborder+1+i;
					tmp = (this.myCoords[i]["ele"]+this.myCoords[i-1]["ele"]+this.myCoords[i+1]["ele"])/3;
					y   = this.height-(this.bottomborder+1+parseInt((tmp-ymin)*deltaY)+0.5);					
				}else if(i>=this.myCoords.length-3){
					x   = this.leftborder+1+i;
					tmp = (this.myCoords[i]["ele"]+this.myCoords[i-1]["ele"]+this.myCoords[i-2]["ele"])/3;
					y   = this.height-(this.bottomborder+1+parseInt((tmp-ymin)*deltaY)+0.5);					
				}else{
					x   = this.leftborder+1+i;
					tmp = (this.myCoords[i]["ele"]+this.myCoords[i+1]["ele"]+this.myCoords[i+2]["ele"]+this.myCoords[i-1]["ele"]+this.myCoords[i-2]["ele"])/5;
					y   = this.height-(this.bottomborder+1+parseInt((tmp-ymin)*deltaY)+0.5);
				}
				
			}
			pointsX.push(x);
			pointsY.push(y);
		}
		
		pointsX.push(this.width-this.rightborder-1);
		pointsY.push(y);
		pointsX.push(this.width-this.rightborder-1);
		pointsY.push(this.height-this.bottomborder-1);
		pointsX.push(this.leftborder+1);
		pointsY.push(this.height-this.bottomborder-1);	

		this.ctx.lineWidth = 1;
		this.ctx.strokeStyle = "rgba("+r+","+g+","+b+",0.5)";
		this.ctx.fillStyle   = "rgba("+r+","+g+","+b+",0.5)";
		this.ctx.beginPath();
		this.ctx.moveTo(pointsX[0],pointsY[0]);
		for(var i=0;i<pointsX.length;i++){
			this.ctx.lineTo(pointsX[i],pointsY[i]);
		}
		this.ctx.fill(); 
		this.ctx.stroke();
		this.ctx.closePath();

		
		//draw grid lines for y-axis
		var linewidth;
		for(var i=1;i<4;i++){
			linewidth = this.leftborder;
			do{
				this.ctx.beginPath();
				this.ctx.strokeStyle = 'rgb(0,0,0)';
				this.ctx.moveTo(linewidth,this.topborder+(i*pixelDiff));
				linewidth = linewidth + 5;
				if(linewidth>(this.width-this.rightborder)){
					linewidth = this.width-this.rightborder;
				}
				this.ctx.lineTo(linewidth,this.topborder+(i*pixelDiff));
				this.ctx.stroke();
				this.ctx.closePath();
				linewidth = linewidth + 5;
			}while(linewidth<(this.width-this.rightborder));
		}
		
		//draw label of y-axis
		var tmp;
		var len;
		var offset;
		this.ctx.fillStyle = "rgb(0,0,0)";
		this.ctx.font = "10px Verdana, sans-serif";
		for(var i=0;i<=4;i++){
			tmp = "" + (ymax-(i*scalDiff));
			len = tmp.length;
			offset = len*7;
			this.ctx.fillText(tmp, this.leftborder-5-offset, this.topborder+3+(i*pixelDiff)); 
		}
		this.ctx.font = "10px Verdana, sans-serif";
		this.ctx.fillStyle = "rgb(0, 0, 0)";
		this.ctx.translate(15,this.height-this.bottomborder-this.topborder);
		this.ctx.rotate(-0.5 * Math.PI);
		this.ctx.fillText(this.config['diaglabely']+" m", 0, 0);
		this.ctx.rotate(0.5 * Math.PI);
		this.ctx.translate(-15,-(this.height-this.bottomborder-this.topborder));

		//determine scaling of x-axis
		this.waylength = this.coords[section]['length'];

		if(this.waylength==0){
			this.waylength = 0.001;
		}
		
		var km;
		if(this.waylength>2){
			km = true;
		}
		else{
			km = false;
			this.waylength = this.waylength*1000;
		}
		
		var delta  = 50;
		var potenz = 0;
		var tmp    = (this.width-this.leftborder-this.rightborder)/delta;
		var tmp2   = parseInt(this.waylength/tmp);
		
		if(tmp2==0){
			tmp2=1;
		}
		else if(tmp2>10){
			tmp2 = "" + tmp2;
			tmp2 = tmp2.substr(0,tmp2.length-1) + "0";
		}
		var scalDiff  = tmp2;
		var pixelDiff = parseInt(((this.width-this.leftborder-this.rightborder)/this.waylength)*tmp2);	
		
		//draw grid lines for x-axis
		var linewidth;
		var i=1;
		do{
			linewidth = this.topborder;
			do{
				this.ctx.beginPath();
				this.ctx.strokeStyle = 'rgb(0,0,0)';
				this.ctx.moveTo(this.leftborder+(i*pixelDiff),linewidth);
				linewidth = linewidth + 5;
				if(linewidth>(this.height-this.bottomborder)){
					linewidth = this.height-this.bottomborder;
				}
				this.ctx.lineTo(this.leftborder+(i*pixelDiff),linewidth);
				this.ctx.stroke();
				this.ctx.closePath();
				linewidth = linewidth + 5;
			}while(linewidth<(this.height-this.bottomborder));
			i++;
		}while(i*pixelDiff<(this.width-this.rightborder-this.leftborder));
		
		//draw label of x-axis
		var tmp;
		var len;
		var offset;
		var i=0;
		this.ctx.fillStyle = "rgb(0,0,0)";
		this.ctx.font = "10px Verdana, sans-serif";
		do{
			tmp = "" + (i*scalDiff);
			len = tmp.length;
			offset = parseInt((len*7)/2);
			this.ctx.fillText(tmp, this.leftborder+(i*pixelDiff)-offset, this.height-this.bottomborder+15);
			i++;
		}while(i*pixelDiff<(this.width-this.rightborder-this.leftborder));

		var text;
		if(km==true){
			text   = this.config['diaglabelx']+" km";
		}
		else{
			text   = this.config['diaglabelx']+" m";
		}
		var posx   = this.leftborder+((this.width-this.rightborder-this.leftborder)/2);
		var offset = (text.length*6)/2;
		this.ctx.font = "10px Verdana, sans-serif";
		this.ctx.fillStyle = "rgb(0, 0, 0)";
		this.ctx.fillText(text, posx-offset, this.height-10);	
	}
};

naviki.main.WayInfo.prototype.setMouseOver = function(){

	if(this.profile==true){

		var myObj    = this;
		
		YAHOO.util.Event.on(document, 'mousemove', function(e){
			
			var wayInfoDiv = document.getElementById("tab2");
			if(wayInfoDiv.className != "yui-hidden"){

				eventMgr.removeWayInfoMarker.fire();
	
				var posObj = myObj.getPosition(myObj.canvas);
				
				var posx = 0;
			    var posy = 0;
				if(document.all){
					posx = window.event.clientX + document.documentElement.scrollLeft;
					posy = window.event.clientY + document.documentElement.scrollTop;
				}else{
					posx = e.pageX;
					posy = e.pageY;
				}
		    
			    var area    = new Object();
			    area.startX = posObj.x + myObj.leftborder;
			    area.endX   = posObj.x + (myObj.width - myObj.rightborder);
			    area.startY = posObj.y + myObj.topborder;
			    area.endY   = posObj.y + (myObj.height - myObj.bottomborder);
	
			    var idx   = posx - area.startX;
			    var coord = myObj.myCoords[idx];
			    
				var line = document.getElementById(myObj.config['heightdiagimageid']+"_line");
				line.style.position = "absolute";
				line.style.zIndex   = "5";
				line.style.left   = (posObj.relativeX + myObj.leftborder + idx) + "px";
				line.style.top    = (posObj.relativeY + myObj.topborder ) + "px";
				line.style.height = (myObj.height - myObj.topborder - myObj.bottomborder) + "px";
			    
				if (posx > area.startX && posx < area.endX && posy > area.startY && posy < area.endY){
					eventMgr.addWayInfoMarker.fire(coord.lat, coord.lon);
					line.style.visibility = "visible";
				} else {
					line.style.visibility = "hidden";
					eventMgr.removeWayInfoMarker.fire();
				}
			}
		});
	}
};

naviki.main.WayInfo.prototype.getPosition = function(element){

	var aboveObject = document.getElementById(this.config["allinfosid"]);
	
	var regionA = YAHOO.util.Dom.getRegion(element); 
	var regionB = YAHOO.util.Dom.getRegion(aboveObject);    
    
    /* Objekt mit x und y zurueckgeben */
    var position=new Object();
    position.x = regionA.left;
    position.y = regionA.top;
    position.aboveX = regionB.left;
    position.aboveY = regionB.top;
    position.relativeX = regionA.left - regionB.left;
    position.relativeY = regionA.top  - regionB.top;
    
    return position;
};

naviki.main.WayInfo.prototype.getAboveObject = function(element){

	var loop = true;
	var CSSposition;
	do {
		if (element.parentNode != null) {
			element = element.parentNode;
		} else {
			loop = false;
		}
		if (element.style != null) {
			CSSposition = YAHOO.util.Dom.getStyle(element, "position");
			if (CSSposition == "absolute") {
				loop = false;
			}
		}
	} while (loop);
	
	return element;
};

