$(document).ready(function(){
// разбирает строку и ищет имя
	if (window.location.toString().charAt(window.location.toString().length-1) == '/'){
		var x = new Number(window.location.toString().length-1);
		var str = new String(window.location.toString().substring(0,x));
		var slash = "";
	}
	else {
		var x = new Number(window.location.toString().length)
		var str = new String(window.location.toString().substring(0,x));
		var slash = "/";
	}
	x = str.lastIndexOf("/")+1;
	var name =	str.substring(x,str.length);
	
	$.getJSON("/parser/photos.html?name=" + name, function(json){
		photos(json.runame, json.lat, json.lon);
	});
	
	function photos(runame, lat, lon){
		var apiKey = 'cca01e354527dfc56ce75b730f4e2421';
		$.getJSON("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=" + apiKey + "&lat=" + lat + "&lon=" + lon + "&radius=10&min_taken_date=2000-11-01&sort=interestingness-desc&per_page=5&page=1&format=json&jsoncallback=?",
		function(data){
			$.each(data.photos.photo, function(i,item){
				url = "http://farm" + item.farm + ".static.flickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_t.jpg";
				urlbig = "http://farm" + item.farm + ".static.flickr.com/" + item.server + "/" + item.id + "_" + item.secret + ".jpg";
								$("#photos").append("<a href=" + urlbig + " title='Фотография c курорта " + runame + " ' > <img src=" + url + " alt='Фотография c горнолыжного курорта " + runame + " ' title='Фотография c курорта " + runame + " '> </a>");
			});
								$("#photos a").lightbox();
    });
	}
});

