// Ajax activity indicator bound 
// to ajax start/stop document events

/*jQuery(document).ready(function() { 
	// Setup the ajax indicator
	jQuery("body").append('<div id="ajaxBusy"><p><img src="my-my-global/images/ajax_progress.gif" /></p></div>');
	jQuery('#ajaxBusy').css({
		display:"none",
		margin:"0px",
		paddingLeft:"0px",
		paddingRight:"0px",
		paddingTop:"0px",
		paddingBottom:"0px",
		position:"absolute",
		right:"3px",
		top:"3px",
		width:"auto"
	});

	
jQuery(document).ajaxStart(function(){ 
	jQuery('#ajaxBusy').show(); 
}).ajaxStop(function(){ 
	jQuery('#ajaxBusy').hide();
});
*/
	
var picshown = false;
var commentsshown = false;
var activemarker;
var latlongnull = 0;
// limit = cntpage-1;
function mapClick(j) {
	var activeMarker;
	var k;
	var spot;
	var tpage;
	
	k = ((page * limit)+j)-1;
	//alert(k);		
//	tpage = parseInt(((k + j)-1)/limit);
	tpage = parseInt(k/limit);
	//alert(tpage);
	activeMarker=k-(tpage*limit)+1;
	//alert(activeMarker);
	if (tpage == 1) {activeMarker++;}
	if (j<1 || j > limit) {



		var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/page/"+tpage+"/am/"+activeMarker+"#pos";
		latlongpos(activeMarker);
		window.location = loc;
	}


}
function pagePagination(dir, j) {

	var zcnt = ((page-1)*limit)+j;
	//alert(limit + " " + cruiseId + " " + zcnt + " " + mcnt);
	var activeMarker = limit;
	if (mcnt > limit) {
		if (dir == "next") {
			
			//seite 1
			if (zcnt == mcnt) {
				//seite wechseln
				page = 1;
				var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"#pos";
				window.location = loc;
				return false;				
			}
			else if (j == limit) {
				
			//seite wechseln
				page = page+1;
				var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/page/"+page+"#pos";
				latlongpos(0);
				window.location = loc;
				return false;
			}
			activeMarker = limit-2;
		}
		if (dir == "previous" ) {
			//last poi
			
			if (page == 1 && j == 1) {
				page = parseInt(mcnt / limit)+2;
				page = parseInt(mcnt / (limit-1))+1;
				//alert(page);
				//alert(mcnt+", " + limit + ", " + page);
				activeMarker=mcnt-((limit-1)*(page-1));
				var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/page/"+page+"/am/"+activeMarker+"#pos";
				latlongpos(activeMarker);
				window.location = loc;
				return false;
			}
			if (j==1) {
				//seite wechseln
				//alert(mcnt);
				//
				activeMarker = limit;
				if (page == 2) {
					activeMarker = limit+1;
					var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/am/"+activeMarker+"#pos";
					latlongpos(activeMarker);
				} else if (lastpage == 1) {
					activeMarker = limit+1;
					page = page-1;
					var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/page/"+page+"/am/"+activeMarker+"#pos";
					latlongpos(activeMarker);
				}
				else {
					page = page-1;
					var loc = urlself+"/page/turn/cruiseId/"+cruiseId+"/page/"+page+"/am/"+activeMarker+"#pos";
					latlongpos(activeMarker);
				}
				//activemarker = limit;
				window.location = loc;
				//alert('test');

				
				return false;
			}
		}

	}

}

	function dynamicRefresh(j) {
		//j = j-((page-1)*limit);
		if (picshown) {
			loadpic(j);
		//	alert(j);
		}
		if (commentsshown) {
			var lthis = '.comment'+j;
			var id = jQuery(lthis).attr('rel');
			jQuery(".comments"+id).load("ajax/getcomments/poiId/" +id, function () {
				
				CommentScrollPane();
			});
			
		}
	}
	function loadpic(j) {
		//alert(j);
		//alert(jQuery('.nbigbildclick'+j).attr('id'));
		//alert(picshown);
		if (picshown) {
		var lthis = '.nbigbildclick'+j;
		var filename= jQuery(lthis).attr('id');
	//alert(filename);
		
		var rel= ".nbigbildcontent" + jQuery(lthis).attr('rel');
		//alert(rel);
		if (!filename) {
		filename = "http://test.mysailinglog.com/my-my-global/images/no_photo_big.jpg";
		var rel= ".nbigbildcontent" + jQuery('.poi_img'+j).attr('rel');	
		
		}
			
//alert(filename + " "+rel);
			var image = new Image();
			jQuery(rel).empty().imageloader(filename,'bigpicrand',function(){
					jQuery(".bigpicrand").aeImageResize({height: 400, width: 445});
			}); 
		}
			//my-my-global/images/nophoto.jpg
			//jQuery(".nbigbild").slideToggle("slow");			
	}


function blabla() {
	var filename= jQuery(".nbigbildclick").attr('id');
		var rel= ".nbigbildcontent" + jQuery(this).attr('rel');
		jQuery(rel).empty().imageloader(filename,'bigpicrand',function(){
				jQuery(".bigpicrand").aeImageResize({height: 400, width: 445});
		}); 
		
		jQuery(".nbigbild").slideToggle("slow");
}

function saveRating(cruiseId, userId, ip) {

    var dude = new Request.JSON({  
        url: sDir + "/ajax/saverating/cruiseId/" + cruiseId + "/userId/" + userId + "/ip/" + ip,     
        onSuccess: function(ret){  
 			//alert(ret);
			}  
     }).get($('signup'));  
}

function postComment2() {


    var dude = new Request.JSON({  
        url: sDir + "/ajax/postcomment",     
        onSuccess: function(ret){  
 			//alert(ret);
			}  
     }).get($('signup'));  
		//alert(ret);
}


function getComments(poiId) {

	   jQuery.getJSON( sDir + "/ajax/getcomments/poiId/" + poiId,  function(json){

	    	if (!json) {
	    		alert("An error occured");
	    	}
	    	else {

	    			if (json == "1") {
	    				jQuery("#"+object).fadeTo("fast", 1.33);
	    				jQuery("#secretlinkbox").slideToggle('slow', function() {
	    				    // Animation complete.
	    				  });
	   			}
	    			else {
	    				jQuery("#"+object).fadeTo("fast", 0.33);
	    				jQuery("#secretlinkbox").slideToggle('slow', function() {
	    				    // Animation complete.
	    				  });
	    			}
	    	}
	    });
	          
}

function postComment3(id, name, comment) {

 
	   jQuery.getJSON( sDir + "/ajax/postcomment/id/"+id+"/name/"+name+"/comment/"+comment,  function(json){

	    	if (!json) {
	    		alert("An error occured");
	    	}
	    	else {

	    			if (json == "1") {
	    				jQuery(".commentname").val("");
	    				jQuery(".commentarea").val("");
	    				//jQuery(".message"+id).fadeTo("fast", 1.33);
	    				jQuery(".comments"+id).load(sDir + "/ajax/getcomments/poiId/" + id, function () {
	    					boxMsg();
	    					CommentScrollPane();
	    				});
						
	    				//jQuery("#secretlinkbox").slideToggle('slow', function() {
	    				    // Animation complete.
	    				 // });
	   			}
	    			else {
	    				alert('an error occured');


	    			}
	    	}
	    });
	      return false;
}

function postComment(id) {

	
	/*   jQuery.getJSON(sDir + "/ajax/postcomment",  function(json){
		   alert(json);
	    	if (!json) {
	    		alert("An error occured");
	    	}

	    });   */   

	var dataString = 'id='+ id + '&name=' + 'bu' + '&comment=' + 'be';  
	    //alert (dataString);return false;  
	    jQuery.ajax({  
	      type: "GET",  
	      url: sDir + "/ajax/postcomment",  
	      data: dataString,  
	      success: function(req) {  
	    	//alert(req);
	        	
	     }  
	   });  
	   return false;  
}


function markTripAsPrivate2(cruiseId, userId) {

    var dude = new Request.JSON({  
        url: sDir + "/ajax/marktripasprivate/cruiseId/" + cruiseId + "/userId/" + userId,     
        onSuccess: function(ret){  
 			//alert(ret);
    		alert('bla');
    		
			}  
     }).get($('signup'));  
}
function markTripAsPrivate(object, cruiseId, userId, zustand) {
	
	jQuery(".pdflinkhide").slideToggle('slow');
/*
    jQuery.ajax({
    	  url: sDir + "/ajax/marktripasprivate/cruiseId/" + cruiseId + "/userId/" + userId, 
    	  success: function(data) {
    	    //jQuery('.result').html(data);
    	    alert('Load was performed.' + data);
    	  }
    	});
      */
	
    jQuery.getJSON( sDir + "/ajax/marktripasprivate/cruiseId/" + cruiseId + "/userId/" + userId, function(json){

    	if (!json) {
    		alert("An error occured");
    	}
    	else {
    			if (json == "1") {
    				if(zustand=="0") {
    					jQuery(".tripPrivate0").toggleClass('tripPrivate1a');
    				}
    				if(zustand=="1") {
    					jQuery(".tripPrivate1").toggleClass('tripPrivate0a');
    				}
    				jQuery("#secretlinkbox").slideToggle('slow', function() { });

    				
   			}
    			else {
    				jQuery("#secretlinkbox").slideToggle('slow', function() { });
    				if(zustand=="0") {
    					jQuery(".tripPrivate0").toggleClass('tripPrivate1a');
    				}
    				if(zustand=="1") {
    					jQuery(".tripPrivate1").toggleClass('tripPrivate0a');
    				}
    			}
    	}
    });
      
    
}

function markPoiAsPrivate(object, poiId, zustand, welcherwp) {

	
	    jQuery.getJSON( sDir + "/ajax/markpoiasprivate/poiId/" + poiId, function(json){
	    	if (!json) {
	    		alert("An error occured" + json);
	    	}
	    	else {
	    			if (json == "0") {
	    				//jQuery("#"+object+poiId).fadeTo("fast", 1.33);
						if(zustand=="0") {
    						jQuery(welcherwp+" .wpprivate0").toggleClass('wpprivate1a');
						}
						if(zustand=="1") {
							jQuery(welcherwp+" .wpprivate1").toggleClass('wpprivate0a');
						}
	    			}
	    			else {
	    				//jQuery("#"+object+poiId).fadeTo("fast", 0.33);
	    				if(zustand=="0") {
    						jQuery(welcherwp+" .wpprivate0").toggleClass('wpprivate1a');
						}
						if(zustand=="1") {
							jQuery(welcherwp+" .wpprivate1").toggleClass('wpprivate0a');
						}
	    			}
	    	}
	    });
	      
	    
	}


function saveModifiedPoi(poiId, data) {
	jQuery.post(sDir + "/ajax/savemodifiedpoi/", data, function(json) {
		if (!json) {
			alert("An error occured");
	    } else {
  			if (json == "-1") {
  				alert("An error occured");
  			} else {
  				//alert(json.poiName);
  				jQuery("#head" + json.poiId).text(json.poiName);
  				jQuery("#cText" + json.poiId).text(json.poiCommentText);
  				jQuery("#SpW" + json.poiId).text(json.poiSpW);
  				
  				jQuery(".editwindow" + json.poiId).slideToggle("slow",function() {});
  				jQuery("#waypointEdit" + json.poiId).show();
  			}
	    }
	}, 
	"json"
	);
	
	/*
	jQuery.getJSON( /id/"+poiId+"/lat/"+lat+"/lon/"+lon,  function(json){
		if (!json) {
			alert("An error occured");
	    } else {
  			if (json == "-1") {
  				alert("An error occured");
  			} else {
  				alert(json);
  			}
	    }
	});
	*/
	return false;
}


jQuery(document).ready(function(){
	
		jQuery("img.poiIsPublic1").fadeTo("fast", 0.33);
	
	//falls nicht homepage
	//jQuery('ul.pagination a[rel="5"]').click();
	//jQuery('ul.pagination a[rel="5"]').click();
	jQuery(".closepic").click(function () {
		picshown=false;
		return false;
	});			
	jQuery(".openpic").click(function () {
		picshown=true;
		return false;
	});			
	jQuery(".commentclick").click(function () {
		if(commentsshown==true) {
			commentsshown = false;
		}
		else {
			commentsshown = true;
		}
		return false;
	});			

	jQuery("body").append('<div id="ajaxBusy"><p><img src="my-my-global/images/ajax-loader.gif" /></p></div>');
	jQuery('#ajaxBusy').css({
		display:"none",
		margin:"0px",
		paddingLeft:"0px",
		paddingRight:"0px",
		paddingTop:"0px",
		paddingBottom:"0px",
		position:"absolute",
		right:"3px",
		top:"3px",
		width:"auto"
	});

	
	jQuery(document).ajaxStart(function(){ 
		jQuery('#ajaxBusy').show(); 
	}).ajaxStop(function(){ 
		jQuery('#ajaxBusy').hide();
	});

	
	jQuery("#loading").bind("ajaxSend", function(){
		jQuery(this).show();
		 }).bind("ajaxComplete", function(){
			 jQuery(this).hide();
		 }).bind("ajaxError", function(){
			 alert('error');
		 });

	
	jQuery('.log').ajaxSuccess(function() {
		  alert('Triggered ajaxSuccess handler.');
		});
	/*
	jQuery("a").simpletip({ 
		// Configuration properties  
		content: 'My Simpletip', fixed: false });
*/
	jQuery("img.rate").fadeTo("fast", 0.33);
	jQuery("img.rate").mouseout(function(event){
	   jQuery(this).stop();
	   jQuery(this).fadeTo("fast", 0.33);
	}).mouseover(function(event){
		   jQuery(this).stop();
		   jQuery(this).fadeTo("fast", 1.33);
	}).click(function(event){
		jQuery("span.ratecnt").fadeOut("fast");
		jQuery("#thx").fadeIn("slow");
		//jQuery("#iconbar2 span").text("thx!");
		jQuery(this).unbind();

	});
	


	
	jQuery("#more_worldwidetrips").click(function(event){
		jQuery("#accordion_worldwidetrips .bottom").slideToggle('slow', function() {
		    // Animation complete.
		  });
	});
	
	jQuery("#more_district").click(function(event){
		jQuery("#accordion_district .bottom").slideToggle('slow', function() {
		    // Animation complete.
		  });
	});
	
	jQuery(".commentname, .commentarea").focus(function(){
		jQuery(document).unbind('keyup');
	});
	jQuery(".commentname, .commentarea").blur(function(){
		jQuery(document).keyup(function(event) {
			  //zurueck
			  if (event.keyCode == 37) {
					jQuery('.previous').click();
			  }
			  //vor
			  else if (event.keyCode == 39) {
		    		//gmap.setCenter ( new GLatLng(0,0), 0 );
					jQuery('.next').click();
					var position = jQuery("#lastPageSummary").position();
					/*
					if (position.left==1036) {
						hidePagination();
					};
					*/
			  }

		});
	});
	
	
	
	
	jQuery(document).keyup(function(event) {
		  //zurueck
		  if (event.keyCode == 37) {
				jQuery('.previous').click();
		  }
		  //vor
		  else if (event.keyCode == 39) {
	    		//gmap.setCenter ( new GLatLng(0,0), 0 );
				jQuery('.next').click();
				var position = jQuery("#lastPageSummary").position();
				/*
				if (position.left==1036) {
					hidePagination();
				};
				*/
		  }

	});
	
	//alert('gut');
	jQuery("#pos").click(function () {
		//timer = setTimeout("zoomStuff()",1500);
		jQuery('ul.pagination a[rel="'+activeMarker+'"]').click();
		
		return false;
	});		
	//alert('2');
	
 });





