var query = event.latLng.toUrlValue(15);
function monthDays(year, month) {
return (month == 2 ?
((year % 4 != 0 ||
(year % 100 == 0 && year % 400 != 0)) ? 28 : 29) :
(((month < 8 && (month & 1) == 0) ||
(month > 7 && (month & 1) == 1)) ? 31 : 30));
}
function dateDiff(date1, date2) {
var years, months, days, hours, minutes, seconds;
var y1, m1, d1, d2, dd;
years = date2.getUTCFullYear()-(y1 = date1.getUTCFullYear());
months = date2.getUTCMonth()-(m1 = date1.getUTCMonth());
days = (d2 = date2.getUTCDate())-(d1 = date1.getUTCDate());
hours = date2.getUTCHours()-date1.getUTCHours();
minutes = date2.getUTCMinutes()-date1.getUTCMinutes();
seconds = date2.getUTCSeconds()-date1.getUTCSeconds();
dd = 0;
if (seconds < 0) {
seconds += 60;
minutes--;
}
if (minutes < 0) {
minutes += 60;
hours--;
}
if (hours < 0) {
hours += 24;
days--;
dd = 1;
}
if (days < 0) {
days = monthDays(y1, m1)-d1+d2-dd;
months--;
}
if (months < 0) {
months += 12;
years--;
}
return {years: years, months: months, days: days,
hours: hours, minutes: minutes, seconds: seconds};
}
var d1 = new Date("10/7/1917");
var d2 = new Date('3/28/2014');
var diff = dateDiff(d1, d2);
console.log(diff.years+' лет, '+
diff.months+' месяцев, '+
diff.days+' дней, '+
diff.hours+' часов, '+
diff.minutes+' минут, '+
diff.seconds+' секунд');
var points = [{x: 0, y: 0}, {x: 0, y: 50}, {x: 10, y: 50}, {x: 10, y: 0}];
var segLen = [];
var totalLen = 0;
for (var i = 0; i < points.length-1; i++) {
var l = Math.sqrt((points[i+1].x-points[i].x)*(points[i+1].x-points[i].x)+
(points[i+1].y-points[i].y)*(points[i+1].y-points[i].y));
segLen.push(l);
totalLen += l;
}
var percent = 55;
var needLen = totalLen*percent/100;
for (var i = 0; i < points.length-1 && needLen > 0; i++)
if (needLen >= segLen[i]) {
// пройти путь points[i] - points[i+1]
needLen -= segLen[i];
} else {
x = points[i].x+(points[i+1].x-points[i].x)*needLen/segLen[i];
y = points[i].y+(points[i+1].y-points[i].y)*needLen/segLen[i];
// пройти путь points[i] - {x, y}
needLen = 0;
}
// для каждого элемента с классом object_prev
$('.object_prev', this).each(function() {
// найти высоту элемента
var height = $(this).height();
// присвоить эту высоту всем элементам с классом live_view.
$('.live_view').css('height', height);
});
$(this).children('.live_view').css('height', height);
$(this).find('.live_view').css('height', height);