var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function loadMap3() {
	
	

	var north = "48.194329";
	var east = "11.381943";
	
		
	directionsDisplay = new google.maps.DirectionsRenderer();
	var juhhome = new google.maps.LatLng(north, east);
	var myOptions = {
		zoom:17,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		center: juhhome
  }
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  directionsDisplay.setMap(map);
	
}

function calcRoute(dest) {
	
	  var start = "Wildmoosstr. 28 82194 Gröbenzell";
	  var end = dest;
	  var request = {
	      origin:start, 
	      destination:end,
	      travelMode: google.maps.DirectionsTravelMode.DRIVING
	  };
	  directionsService.route(request, function(response, status) {
	    if (status == google.maps.DirectionsStatus.OK) {
	      directionsDisplay.setDirections(response);
	      
	     

	      directionsDisplay.setDirections(response);
	      
	    }
	  });
	  
	}



var captchacounter = 0;


function einsatz(){
	
	$('.einsatzbilder').corner();
	$('.einsatzbilder').hide();
	$(".imagelink").each(function()
    {
        $(this).toggle(function()
    	{
            $('.imagelinkopend').trigger('click');
        
       	    $(this).addClass('imagelinkopend');

           	$('#p' + $(this).attr('imgid')).hide();
    		$(this).html('ausblenden');
    		$('#e' + $(this).attr('imgid')).show();
    		$('#' + $(this).attr('imgid')).hide();
    	},function()
    	{
            $(this).removeClass('imagelinkopend');

	
    		$(this).html('anzeigen');
    		$('#e' + $(this).attr('imgid')).hide();
    		$('#' + $(this).attr('imgid')).show();
    	});
    });
    
    
	$(".peoplelink").each(function()
    {
        $(this).toggle(function()
    	{
            $('.peoplelinkopend').trigger('click');
        
       	    $(this).addClass('peoplelinkopend');

            
    		$(this).html('ausblenden');
    		$(".einsatzbilder").hide();
		$('#p' + $(this).attr('peopid')).show();
		


   		
    	},function()
    	{
            $(this).removeClass('peoplelinkopend');
        
    		$(this).html('anzeigen');
    		$('#p' + $(this).attr('peopid')).hide();
    		
    	});
    });
	
	$(".detaillink").click(function(){
		id = $(this).attr("detail");
		$.get('edetail.json', { id: id }, function(data) {
			$("#p"+id).html(data);
			$("#p"+id).show();
			initialize();
			$("#map").show();
			
		});	       	
	});
    
	$('.einsatzbilder').each(function()
    {
        $(this).find('a').lightBox(
        {
	        imageBlank: '/lightbox/lightbox-blank.gif',
	        imageLoading: '/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/lightbox/lightbox-btn-next.gif',
	        keyToClose: '\x1b', 
	        txtImage: 'Bild',
			txtOf: 'von'			
        });
        
        
    });
    
	$('.imagethumb').click(function()
    {
       $($('#e' + $(this).attr('id')).find('a').get(0)).trigger('click');
    });
    
	$('.slideshow a').lightBox(
		{
			imageBlank: '/lightbox/lightbox-blank.gif',
	        imageLoading: '/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/lightbox/lightbox-btn-next.gif',
	        keyToClose: '\x1b', 
	        txtImage: 'Bild',
			txtOf: 'von'
		}
	);
	
	Date.firstDayOfWeek = 1;
	Date.format = 'dd.mm.yyyy';
	$('.date').datePicker({startDate:'01/01/1900'});
}	
$(function() {
	einsatz();
	$('#captchaloader').click(function()
	{
		if (captchacounter >= 5)
		{
			$(this).html("Jetzt langt's!");
			$(this).click(function()
			{
				return false;
			});
			return false;
		}
		var microtime = new Date();
		$('#captcha').attr('src', 'captcha.png?new=' + microtime.getTime());
		captchacounter = captchacounter + 1;
		
		return false;
	});
    


	application.pictureupload();
});

application =
{
 
    pictureupload: function()
    {
        $('#pictureupload').change(function()
        {
            var path;  
            var time = new Date();
            time = time.getTime()

            
            $(this).attr('id', '').hide();
            
            application.pictureupload();
            
            path = $(this).val();
            path = path.split("\\");
            
            if (path.length <= 0)
            {
                path = $(this).val();
                path = path.split("/");
            }
            
            $('ul#pics_to_up').append('<li id="image_' + time + '"><img src="/animations/indicator.white.gif" style="vertical-align: middle; margin: 0 5px 0 0" />' + path[path.length - 1] + '</li>')

            $(this).parent('form').after('<form method="post" action="/intern/einsatzeingabe" class="pictureupload"><input type="file" name="pictureupload" id = "pictureupload"></form>');
            
            application.pictureupload();
            
            $(this).parent('form').ajaxSubmit(
            {
                data: {upload: 'picture', formname: 'einsatzadd', id: time},
                dataType: 'json',
                success: function(data)
                {
                    if (data.error != '')
                    {
                        $('li#image_' + data.imageid + ' img').attr('src', '/icon/error.png');
                        $('li#image_' + data.imageid).append(' ' + data.error);
                        
                    } else
                    {
                        $('li#image_' + data.imageid + ' img').attr('src', '/icon/accept.png');
                    }
                }
            });
            setTimeout("$('ul#pics_to_up > li > img').attr('src', '/icon/accept.png');", 30000);
        });
    }
    
}
    
