var rootdir = '/';
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$.getScript(rootdir+'js/pngfix.js');
		DD_belatedPNG.fix('img, div, a');
		}
function Loader(id, file, action, boxid){
$.post(rootdir+file+'.php', { action:action, id:id }, function(data) { 
		$('#'+boxid).html(data);
		});
}

$(document).ready(function() {



$("#search").keyup(function(){
	var string = $("#search").val();
	if(string){
		$("#suggest").show();
		}
		else{
			$("#suggest").hide();
			$("#suggest").html('<div class="search_loading">Loading...</div>');
			}
	
	setTimeout("SendRequest('"+string+"')" , 1000); 
	});
	



});

function SendRequest(string){
	var current = $("#search").val();
	if(string==current && current!=''){
		$.post(rootdir+"search.php", {
			action:'search',
			string:string
			}, function(data) { $('#suggest').html(data); });
}
		
		
}

function HideSuggest(){
	$("#suggest").hide();
}


function IsFavorite(value, type, pinto){
		
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'is_favorite', type:type, value:value, pinto:pinto}),
		      dataType: "html",
		      success: ReturnPin(data)
		      }
		   
		);
		
		
	}


function PinSave(value, type, pinto, pinby, after){
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'save_pin', type:type, value:value, pinto:pinto, pinby:pinby}),
		      dataType: "html",
		      success: function(){
		      	//return true;
		      	if(after=='reload'){ location.reload(); }
		      	if(after=='route_photo'){
			      	ResetPin();
			      	LoadPinnedPhotos(type, pinto)
				}
			if(after=='event_photo'){
			      	ResetPin();
			      	LoadPinnedPhotos(type, pinto)
				}
			if(after=='event_route'){
			      	ResetPin();
			      	LoadPinnedRoutes(type, pinto)
				}
		      	}
		      }
		   
		);	
	}

function PinRemove(value, type, pinto, pinby, after){
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'remove_pin', type:type, value:value, pinto:pinto, pinby:pinby}),
		      dataType: "html",
		      success: function(data){
		      	//alert(data);
		      	if(after=='reload'){ location.reload(); }
		      	}
		      }
		   
		);	
	}

function PinPreview(additional, pinto, pin_type){
	$("#PinPreview").show();
	var type = $("#pin_type").val();
	var value = $("#pin_value").val();
	if(type && value){
	
	
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'preview_pin', type:type, value:value, pinto:pinto, additional:additional, pin_type:pin_type}),
		      dataType: "html",
		      success: function(data){
			$("#PinPreview").html(data);
		      }
		   }
		);
	
		}
	}

function ResetPin(){
	$("#PinPreview").html('');
	var type = $("#pin_type").val('');
	var value = $("#pin_value").val('');
	}

function LoadPinnedPhotos(type, pinto){
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'load_pinned_photos', type:type, pinto:pinto}),
		      dataType: "html",
		      success: function(data){
		      	$("#PinnedPhotos").html(data);
		      	}
		      }
		   
		);	
	}


function LoadPinnedRoutes(type, pinto){
		$.ajax({
		      url: rootdir+"pins.php",
		      global: false,
		      cache: false,
		      type: "POST",
		      data: ({action : 'load_pinned_routes', type:type, pinto:pinto}),
		      dataType: "html",
		      success: function(data){
		      	$("#PinnedRoutes").html(data);
		      	}
		      }
		   
		);	
	}
