/**
* Projekt: MYCITYSECRETS
* Typ:     Javascripte
*
* @author webkrebse.com
* @version 1.1
*/

/*
Wechselt das Introimage
*/

function switchBildToURL(bild,url,alt) {
	document.images[bild].src = url;
	document.images[bild].alt = alt;
}


/*
Wechselt das image auf Single-Seite (Geheimnisse)
*/

function change_image($url,$zaehler) {
	document.getElementById("firstpic").src = $url;
	document.getElementById("count").innerHTML= $zaehler;
}

/*
Wechselt das image auf Bilder-Seite (Traderverwaltung)
*/

function change_picture($url,$zaehler,$position,$id) {
	document.getElementById("firstpic").src = $url;
	document.getElementById("count").innerHTML= $zaehler;
	document.getElementById("TraderpicturePosition").value = $position;
	document.getElementById("TraderpictureId").value = $id;
	document.getElementById("PictureId").value = $id;
}



/*
Scrollen
*/

var scrollval = new Array();

// Scroll links
function scroll2Left(id) {
	scrollval[id]['isScrolling'] = true;
	doScroll2Left(id);
};
function doScroll2Left(id)	{
	var div = document.getElementById(id);
	if ( scrollval[id]['isScrolling']==true) {
		if ( div.scrollLeft > 0 ) {
			div.scrollLeft -= scrollval[id]['dx'];
			window.setTimeout( "doScroll2Left('"+id+"')", scrollval[id]['delay']);
		};
	};
};

// Scroll rechts
function scroll2Right(id) {
	scrollval[id]['isScrolling'] = true;
	doScroll2Right(id);
};
function doScroll2Right(id) {
	var div = document.getElementById(id);
	if ( scrollval[id]['isScrolling']==true) {
		div.scrollLeft += scrollval[id]['dx'];
		window.setTimeout( "doScroll2Right('"+id+"')", scrollval[id]['delay']);
	};
};

// Und am Ende das Scrollen wieder anhalten
function stopScrolling(id) {
	scrollval[id]['isScrolling'] = false;
}

// Stadtteil �ndern (Suchmaske)
//function changeStadtteil(select) {
//	var index = document.getElementById("SucheStadt").selectedIndex || 0;
//	var value = document.getElementById("SucheStadt").options[index].value;
//	var select_stadtteil = document.getElementById("SucheStadtteil");
//
//	//l�scht inhalt aus den elementen
//	var clear = function() {
//	var anzahl = select_stadtteil.options.length-1;
//	for(var i = 0; i <= anzahl; i++)
//		select_stadtteil.removeChild(select_stadtteil.options[0]);
//	};
//
//	switch(value) {
//		case '-1':
//			clear();
//			new_option = new Option("alle", "0", false, true);
//  			select_stadtteil.options[0] = new_option;
//			select_stadtteil.options[0].value = "-1";
//			select_stadtteil.selectedIndex = 0;
//			break;
//		case '1':
//			clear();
//			new_option = new Option("alle", "0", false, true);
//  			select_stadtteil.options[0] = new_option;
//			select_stadtteil.options[0].value = "-1";
//			new_option = new Option("Bockenheim", "1", false, true);
//  			select_stadtteil.options[1] = new_option;
//			select_stadtteil.options[1].value = "3";
//			new_option = new Option("Bornheim", "2", false, true);
//  			select_stadtteil.options[2] = new_option;
//			select_stadtteil.options[2].value = "4";
//			new_option = new Option("Innenstadt", "3", false, true);
//  			select_stadtteil.options[3] = new_option;
//			select_stadtteil.options[3].value = "5";
//			new_option = new Option("Nordend", "4", false, true);
//  			select_stadtteil.options[4] = new_option;
//			select_stadtteil.options[4].value = "6";
//			new_option = new Option("Ostend", "5", false, true);
//  			select_stadtteil.options[5] = new_option;
//			select_stadtteil.options[5].value = "7";
//			new_option = new Option("Sachsenhausen", "6", false, true);
//  			select_stadtteil.options[6] = new_option;
//			select_stadtteil.options[6].value = "8";
//			new_option = new Option("Westend", "7", false, true);
//  			select_stadtteil.options[7] = new_option;
//			select_stadtteil.options[7].value = "9";
//			select_stadtteil.selectedIndex = 0;
//			break;
//		case '2':
//			clear();
//			new_option = new Option("alle", "0", false, true);
//  			select_stadtteil.options[0] = new_option;
//			select_stadtteil.options[0].value = "-1";
//			select_stadtteil.selectedIndex = 0;
//			break;
//	}
//}



/*
Google-Maps-Funktionen
*/
function google_initialize() {
   if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById("googlemap"));
     geocoder = new GClientGeocoder();
     var mapControl = new GSmallMapControl();
     map.addControl(mapControl);
     //map.addControl(new GMapTypeControl());
   }
 }

function google_showAddress(address) {
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.mycitysecret.com/img/marker/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.mycitysecret.com/img/marker/marker.png";

   geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 15);
        markerOptions = { icon:letteredIcon };
	    var marker = new GMarker(point, markerOptions);


        map.addOverlay(marker);
      }
    }
  );
}

function google_initializeGeo() {
   if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById("googlemap"));
   }
 }

function google_showGeo(laenge,breite) {
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.mycitysecret.com/img/marker/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.mycitysecret.com/img/marker/marker.png";

	var point = new GLatLng(laenge,breite);
	map.setCenter(point, 15);
    markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point, markerOptions);
	map.addOverlay(marker);
    var mapControl = new GSmallMapControl();
    map.addControl(mapControl);
}


function google_initialize_stadtplan() {
   if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById("googlemap"));
     geocoder = new GClientGeocoder();
     var mapControl = new GSmallMapControl();
     map.addControl(mapControl);
   }
}

function google_showAddress_stadtplan(address,index, text) {
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.mycitysecret.com/img/marker/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.mycitysecret.com/img/marker/marker" + letter + ".png";
	geocoder.getLatLng(address,  function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
	        map.setCenter(point, 12);
	        markerOptions = { icon:letteredIcon };
	        var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(text);
          });

	        map.addOverlay(marker);
	      }
    }
  );
}
function google_showAddress_top5(address,index, text) {
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.mycitysecret.com/img/marker/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	var letter = index+1;
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.mycitysecret.com/img/marker/marker" + letter + ".png";
	geocoder.getLatLng(address,  function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
	        map.setCenter(point, 12);
	        markerOptions = { icon:letteredIcon };
	        var marker = new GMarker(point, markerOptions);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(text);
          });

	        map.addOverlay(marker);
	      }
    }
  );
}
