
var abs_path;
var _lang;
var _area;
var _id;
var activeHeader = "Image";
var markerclicked = false;
var startvideo;
var fullheight = 334;

function swapHeaderTab(headertab) {
	if ($('xxlHeaderTabImage') != null) { $('xxlHeaderTabImage').setStyle({backgroundColor: 'transparent'}); }
	if ($('xxlHeaderTabVideo') != null) { $('xxlHeaderTabVideo').setStyle({backgroundColor: 'transparent'}); }
	if ($('xxlHeaderTabMap') != null) { $('xxlHeaderTabMap').setStyle({backgroundColor: 'transparent'}); }
	if (headertab == undefined || headertab == '') {
		$('xxlHeaderTab' + activeHeader).setStyle({backgroundColor: '#ffffff'});
	} else {
		$('xxlHeaderTab' + headertab).setStyle({backgroundColor: '#ffffff'});
		//$('xxlHeaderTab' + headertab).setStyle({borderRight: '1px solid #aaaaaa'});
	}
}

function toggleHeader(showheader) {	

	//alert(js_lib);
	//alert(showheader);
	
	activeHeader = showheader;
	if ($('xxlHeaderTab') != null) { 
		swapHeaderTab(activeHeader);
	}
	
	_gaq.push(['_trackEvent', 'multiheader', 'click', showheader]);
	
	if ($('xxlHeaderImage') != null) { $('xxlHeaderImage').hide(); }
	if ($('xxlHeaderVideo') != null) { $('xxlHeaderVideo').hide(); }
	if ($('xxlHeaderMap') != null) { $('xxlHeaderMap').hide(); }
	
	if ($('xxlCall2Action') != null) {
		$('xxlCall2Action').hide();
	}
	$('xxlHeader' + showheader).show();
	if (showheader == "Map" && TirolMap == undefined) {
		initialize();
		loadMapData();
	}
	if (showheader == "Image" && $('xxlCall2Action') != null) {
		$('xxlCall2Action').show();
	}
	if (showheader == "Video") {
		if ($('xxlHomeFeature1') != null) {
			$('xxlHomeFeature1').hide();
			$('xxlHomeFeature2').hide();
			$('xxlHomeVideobox').show();
		}
		showHeaderVideo(startvideo);
	} else {
		if ($('xxlHomeFeature1') != null) {
			$('xxlHomeFeature1').show();
			$('xxlHomeFeature2').show();
			$('xxlHomeVideobox').hide();
		}
		$('xxlHeaderVideo').update('');
	}
}

function showHeaderVideo(videodata) {    
    if (videodata.search(/youtube/) != -1) {
        iframeurl = videodata.replace(/\/v\//, "/embed/") + '?wmode=transparent&controls=0&showinfo=0&rel=0';
    } else if (videodata.search(/vimeo/) != -1) {
        vimeoid = videodata.split("=");
        iframeurl = "http://player.vimeo.com/video/" + vimeoid[1];
    }    
    $('xxlHeaderVideo').update('<iframe width="752" height="334" frameborder="0" src="' + iframeurl + '"></iframe>');
}

function showDownload() {
	if (activeHeader == "Image" && $('xxlCall2Action') != null)  {
		$('xxlCall2Action').show();
	}
}

function hideDownload() {
	$('xxlCall2Action').hide();
}

function loadMapData() {
	ajaxurl = abs_path + 'scms/detail.php?template=ta07_map_ajax&_lang=' + _lang + '&_area=' + _area + '&_id=' + _id;
	new Ajax.Request(ajaxurl, {
		method: 'post',
		onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			eval(response);
			showPolygones();
			showPolylines();
			showMarker();
		}
	});
}

var polyclicked = false;

function highlightPoly(polynumber, cmsid) {
	if (typeof(window['polynumber_' + polynumber]) != "undefined") {
		$('xxlMapTableRow' + cmsid).addClassName('xxlMapTableRowActive');
		polyclicked = false;
		polygmapid = eval('polynumber_' + polynumber);
		high_polygon = TirolMap_overlayGroups['polygones'][polygmapid];
		GEvent.trigger(high_polygon, "mouseover");
	}
}

function unHighlightPoly(polynumber, cmsid) {
	if (typeof(window['polynumber_' + polynumber]) != "undefined") {
		$('xxlMapTableRow' + cmsid).removeClassName('xxlMapTableRowActive');
		polygmapid = eval('polynumber_' + polynumber);
		high_polygon = TirolMap_overlayGroups['polygones'][polygmapid];
		GEvent.trigger(high_polygon, "mouseout");
	}
}

function mapPolygonClick(polygon) {
	if (!polyclicked) {
		polyclicked = polygon;
	} else {
		polyoff = polyclicked;
		polyclicked = false;
		GEvent.trigger(polyoff, "mouseout");
		GEvent.trigger(polygon, "mouseover");
	}
}

function mapPolygonClick(polygon) {
	polygon.color = polygon.bgcolor;
	polygon.redraw(true);
	checkPolyline();
	// getElementById und innerHTML wegen GoogleMaps -> jquery geht nicht
	/*regiondata = document.getElementById(polygon.id).innerHTML;
	regiondata = regiondata.split("|");*/
	tisrgn = polygon.id.substring(11);
	/*cms_id = regiondata[0];
	lang = regiondata[1];*/
	if (_lang == 'cz') {
		syslang = 'cs';
	} else if (_lang == 'ru' || _lang == 'dk' || _lang == 'fr' || _lang == 'ro') {
		syslang = 'en';
	} else {
		syslang = _lang;
	}
	regionlink = abs_path + "at/guide/184921sy," + syslang + ",SCH1/_lang," + _lang + ",_area," + _area + ",objectId," + tisrgn + "/home.html";
	document.location.href = regionlink;
}

function mapPolygonOver(polygon) {
	polygon.color = polygon.hovercolor;
	polygon.redraw(true);
	checkPolyline();
	if (!markerclicked) {
		rgnid = polygon.id.substring(11);
		preview_img = $('previewImg' + rgnid).innerHTML;
		if (preview_img != "") {
			preview_img = '<img width="50" height="50" src="' + preview_img + '" style="float:left;">&nbsp; ';
		} else {
			preview_img = '';
		}
		TirolMap.openExtInfoWindow(
			polygon.point,
			"xxlExtInfoWindow",
			preview_img + polygon.html,
			{beakOffset: 3}
		);
	}
}

function mapPolygonOut(polygon) {
	polygon.color = polygon.bgcolor;
	polygon.redraw(true);
	checkPolyline();	
	if (!markerclicked) {
		TirolMap.closeExtInfoWindow();
	}
}

var directions;

function getDirections() {
	
	if (typeof directions == "object") {
		directions.clear();
	}
		
	directions = new GDirections(TirolMap, document.getElementById("xxlRouteResult"));	
	GEvent.addListener(directions, "error", handleErrors);
	
	fromAddress = $('fromcity').value;
	toAddress = $('tocity').value;
	locale = _lang;
	
	highways = $('nohighway').checked ? true : false;
	
	wp = new Array();
	wp.push(fromAddress);
	$$('input[class="viacity"]').each(function(element) {
		wp.push(element.value);
	});
	wp.push(toAddress);
	
	$("xxlRouteResult").update('');	
	directions.loadFromWaypoints(wp, { "locale": locale, "avoidHighways": highways });
	
	return false;
}

function addWayPoint() {
	viadata = document.getElementById('xxlRouteVia').innerHTML;
	newwaypoint = '<div class="xxlFactsLabel">Via:</div><div class="xxlFactsValue"><input type="text" class="viacity" size="23" /></div><div class="xxlFactsSep"></div>';
	$('xxlRouteVia').update(viadata + newwaypoint);
}

function handleErrors(){
	$('xxlRouteResult').update('Error: ' + directions.getStatus().code);
	/*if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		$('xxlRouteResult').update(directions.getStatus().code);
	else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
		$('xxlRouteResult').update(directions.getStatus().code);
	else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
		$('xxlRouteResult').update(directions.getStatus().code);
	else if (directions.getStatus().code == G_GEO_BAD_KEY)
		$('xxlRouteResult').update(directions.getStatus().code);
	else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
		$('xxlRouteResult').update(directions.getStatus().code);
	else
		$('xxlRouteResult').update('unknown error');*/
}
