function htmlencode(s, quotes){
	if ( !quotes ) {
		return $("<div/>").text(s).html();
	} else {
		return $("<div/>").text(s).html().replace(/"/g, '&quot;').replace(/'/, '&#039;');
	}
}
function htmldecode(s){
	return $("<div/>").html(s).text();
}

$(document).bind("mobileinit", function(){
	//$.mobile.page.prototype.options.backBtnText = "Zur&uuml;ck";
	$.mobile.page.prototype.options.addBackBtn = false;
	$.mobile.useFastClick = false;
});

$('#gallery,#restaurant,#news').live("pagecreate", function() {
	$('.scrollable').scrollable({mousewheel: false, touch: false, circular: false, 
		onBeforeSeek: function(ev) {
			var api = ev.target.getRoot();
			if (api) {
				api.parent('.scrollablewrapper').find('.title').html('');
			}
		},
		onSeek: function(ev) {
			var api = ev.target.getRoot();
			if (api) {
				var item = ev.target.getItems().eq(ev.target.getIndex());
				if ('item') { 
					api.parent('.scrollablewrapper').find('.title').html(item.find('.imgTitle').html());
				}
			}
		}
	}).live('swipeleft swiperight', function(ev) { 
		var api = $(this).data('scrollable');
		if (api) {
			switch (ev.type) {
				case 'swipeleft': if (api.getIndex() < api.getSize()-1) api.next(); break;
				case 'swiperight': if (api.getIndex() > 0) api.prev(); break;
			}
			ev.preventDefault();
		}
	});
});


/* $('#map_canvas').gmap('search', { 'location': latlng }, function(results, status) {
if ( status === 'OK' ) {
	$('#from').val(results[0].formatted_address);
}
}); */



$('#shops,#restaurantmap').live("pageshow", function(ev) {

	var type = $(ev.target).attr('id');
	
	$('#map_canvas').gmap('refresh').gmap('getCurrentPosition', function(position, status) {
		if ( status === 'OK') {
			var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
			$('#map_canvas').gmap('clear', 'markers').gmap('addMarker', { position: latlng, id: 'currPos', title: 'Du bist hier', icon: 'http://'+document.location.hostname+'/image/pin_location.png'});
		} else {
			var latlng = new google.maps.LatLng(52.524118,13.401378);
		}
		$('#map_canvas').gmap('get', 'map').panTo(latlng);
		$('#map_canvas').gmap('getShopMarkers', type, latlng);
	}); 
}).live("pageinit", function() {
	$('#map_canvas').gmap({zoom: 14, center: '52.524118,13.401378'});
});


