function framedTeaserLink(fObj, show) {
	if (fObj.parentNode) {
	
		var p = fObj.parentNode;
		if (p.className != "item" && p.className != "item last") {
			if (p.parentNode && (p.parentNode.className == "item" || p.parentNode.className == "item last")) {
				p = p.parentNode;
			}
			else return false;
		}
		
		//alert(p.innerHTML);
		
		if(	p.children[1] && 
			p.children[1].className == "teaserimg" && 
			p.children[1].children[0] &&
			p.children[1].children[0].className == "framer"
		) {
			if(show)			
				p.children[1].children[0].style.display = "block";
			else
				p.children[1].children[0].style.display = "none";
		}
		
		if (p.children[2].lastChild && p.children[2].lastChild.className == "double") {
			if(show)			
				p.children[2].lastChild.style.textDecoration = "underline";
			else
				p.children[2].lastChild.style.textDecoration = "none";
		}
		
		//alert(p.children[2].innerHTML);
		//alert(p.innerHTML);
		
	}
}

/* ######### jQuery Carousel GMap ######### */
function mycarousel_initCallback(carousel) {
	
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
    
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	jQuery('#mycarousel-next').unbind('click');
	if (idx == 1) {
		jQuery('#mycarousel-next').html("In GoogleMaps ansehen");
		jQuery('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });
	}
	else {
		jQuery('#mycarousel-next').html("Impressionen");
		jQuery('#mycarousel-next').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	}
};

/* ######### jQuery Carousel GMap ######### */

function initGMaps(mapContainer, mapCenterLat, mapCenterLng, mapZoom, mapType) {
	if (GBrowserIsCompatible()) {
	
		var body = document.getElementById(mapContainer);
		var center = new GLatLng(mapCenterLat, mapCenterLng);		

		var map = new GMap2(body);
		map.setMapType(mapType);		
		map.setCenter(center, mapZoom);
		
		//map.addControl(new GSmallMapControl());
		map.addControl(new GMenuMapTypeControl());	
		map.addControl(new AdveniatControls());	
		
		map.savePosition();		
		return map;
	
	} else {
		alert("Your browser is not compatible with Google Maps!");
	}
}

function cPurpleMarker(map, point, index, path, format) {
	
	var ClickKOs = new Array(0,0, 27,0, 27,24, 0,24);
	
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "img/gmap_marker_shadow.png";
	baseIcon.iconSize = new GSize(28, 25);
	baseIcon.imageMap = ClickKOs;
	baseIcon.shadowSize = new GSize(28, 25);
	baseIcon.iconAnchor = new GPoint(12, 18);
	baseIcon.infoWindowAnchor = new GPoint(14, 0);
	
	var Icon = new GIcon(baseIcon);
	Icon.image = "img/gmap_marker.png";
	
	// Set up our GMarkerOptions object
	markerOptions = { icon:Icon, draggable: false };
	var marker = new GMarker(point, markerOptions);
		
	GEvent.addListener(marker, "click", function() {
		
		/*
		alert(
		"Marker: " +	
		marker.getPoint().lat() + "," + marker.getPoint().lng() +
		"\nKarte: " +
		map.getCenter() +
		"\nZoomstufe: " +
		map.getZoom() +
		"\nTyp: " +
		map.getCurrentMapType().getName()
		);
		*/
		
    });
	
	GEvent.addListener(marker, "dragend", function() {
		/*
		alert(
		"Marker: " +	
		marker.getPoint().lat() + "," + marker.getPoint().lng() +
		"\nKarte: " +
		map.getCenter() +
		"\nZoomstufe: " +
		map.getZoom() +
		"\nTyp: " +
		map.getCurrentMapType().getName()
		);
		*/
    });
	  
	GEvent.addListener(marker, "dragstart", function() {
  		map.closeExtInfoWindow();
  	});
	
	var imgfile = '<img src="' + path + '" style="cursor: pointer;" onclick="openGallery(' + index +');" />';
	GEvent.addListener(marker, "mouseover", function(){
		if (format == "v") {
			marker.openExtInfoWindow(map, "gmapThumbV", imgfile, {
				beakOffset: 3
			});
		}
		else {
			marker.openExtInfoWindow(map, "gmapThumbH", imgfile, {
				beakOffset: 3
			});
		}
	});
	
	return marker;
	
}

function cPurpleMarkerOpen(map, point, index, path, format) {
	
	// v 58,111
	// h 84,87
	
	// Vertical image format
	if (format == "v") {
	
		var ClickKOs = new Array(0, 0, 57, 0, 57, 110, 0, 110);
		//[0,0, 7,0, 7,7, 0,7]
		
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow = "img/gmap_marker_shadow_big.png";
		baseIcon.iconSize = new GSize(58, 111);
		baseIcon.imageMap = ClickKOs;
		baseIcon.shadowSize = new GSize(58, 111);
		baseIcon.iconAnchor = new GPoint(27, 105);
		baseIcon.infoWindowAnchor = new GPoint(25, 0);
		
	}
	// Probably Horizontal
	else {
		
		var ClickKOs = new Array(0, 0, 83, 0, 83, 86, 0, 86);
		//[0,0, 7,0, 7,7, 0,7]
		
		// v 58,111
		// h 84,8z
		
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow = "img/gmap_marker_shadow_big.png";
		baseIcon.iconSize = new GSize(84, 87);
		baseIcon.imageMap = ClickKOs;
		baseIcon.shadowSize = new GSize(84, 87);
		baseIcon.iconAnchor = new GPoint(42, 82);
		baseIcon.infoWindowAnchor = new GPoint(40, 0);
		
	}
	
	var Icon = new GIcon(baseIcon);
	Icon.image = path;
	
	// Set up our GMarkerOptions object
	markerOptions = { icon:Icon, draggable: false };
	var marker = new GMarker(point, markerOptions);
		
	GEvent.addListener(marker, "click", function() {       
	   openGallery(index);				
    });
	  
	GEvent.addListener(marker, "dragstart", function() {
  	});
	
	GEvent.addListener(marker, "dragend", function() {
		/*
		alert(
		"Marker: " +	
		marker.getPoint().lat() + "," + marker.getPoint().lng() +
		"\nKarte: " +
		map.getCenter() +
		"\nZoomstufe: " +
		map.getZoom() +
		"\nTyp: " +
		map.getCurrentMapType().getName()
		);
		*/
    });
	
	GEvent.addListener(marker, "mouseover", function() {
	});

	return marker;
	
}

Array.prototype.foreach = function( callback ) {
  for( var k=0; k<this .length; k++ ) {
    callback( k, this[ k ] );
  }
}

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function updateCharsLeft(field, cntfieldid) {

	var cntfield = document.getElementById(cntfieldid);
	var charsleft;	
	var maxlimit = 300;
	
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	else {
		charsleft = (maxlimit - field.value.length);
		cntfield.innerHTML = charsleft;
	}

}


function openGallery(index) {
    Shadowbox.open(pics, index);
    //return false;
}

