+support interfaces tactiles.
[Portfolio.git] / skins / photo_film_viewer.js
1 /*
2 copyright 2008-2014 Benoit Pin - Centre de recherche en informatique - MINES ParisTech
3 http://plinn.org
4 Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
5 */
6
7 var FilmSlider;
8
9 (function(){
10
11 var keyLeft = 37, keyRight = 39;
12 var isTextMime = /^text\/.+/i;
13 var isAddToSelection = /.*\/add_to_selection$/;
14 var imgRequestedSize = /size=(\d+)/;
15 var DEFAULT_IMAGE_SIZES = [500, 600, 800];
16
17 FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) {
18 var thisSlider = this;
19 this.filmBar = filmBar;
20 this.filmBarWidth = getObjectWidth(this.filmBar);
21 var film = filmBar.firstChild;
22 if (film.nodeType === 3) { film = film.nextSibling; }
23 this.film = film;
24 this.slider = slider;
25 this.rail = slider.parentNode;
26 this.sliderSpeedRatio = undefined;
27 this.sliderRatio = undefined;
28 this.selectedSlide = undefined;
29 this.selectedSlideInSelection = undefined;
30 this.cartSlide = document.getElementById('cart_slide');
31 this.image = image;
32 this.stretchable = image.parentNode;
33 this.viewMode = 'medium';
34
35 this.buttons = [];
36 this.toolbar = toolbar;
37 if (breadcrumbs) {
38 var bcElements = breadcrumbs.getElementsByTagName('a');
39 this.lastBCElement = bcElements[bcElements.length-1];
40 var imgSrcParts = image.src.split('/');
41 this.lastBCElement.innerHTML = imgSrcParts[imgSrcParts.length-2];
42 this.hasBreadcrumbs = true;
43 }
44 else {
45 this.hasBreadcrumbs = false;
46 }
47
48 var buttons = toolbar.getElementsByTagName('img');
49 var b, name, i;
50 for (i=0 ; i<buttons.length ; i++) {
51 b = buttons[i];
52 name = b.getAttribute('name');
53 if (name) { this.buttons[name] = b; }
54 }
55
56 this.pendingImage = new Image();
57 this.pendingImage.onload = function() {
58 thisSlider.refreshImage();
59 };
60 this.initialized = false;
61
62 this.film.style.left='0';
63 this.film.style.top='0';
64
65 this.filmLength = ctxInfos.filmLength;
66 this.center = ctxInfos.center;
67 this.slideSize = ctxInfos.slideSize;
68 this.ctxUrlTranslation = ctxInfos.ctxUrlTranslation;
69
70 this.ddHandlers = {'down' : function(evt){thisSlider.mouseDownHandler(evt);},
71 'move' : function(evt){thisSlider.mouseMoveHandler(evt);},
72 'up' : function(evt){thisSlider.mouseUpHandler(evt);},
73 'out' : function(evt){thisSlider.mouseOutHandler(evt);}
74 };
75
76 if (browser.isMobile) {
77 this.rail.className = 'hidden';
78 }
79 else {
80 this.resizeSlider();
81 }
82 this.addEventListeners();
83 };
84
85 if (!browser.isMobile) {
86 FilmSlider.prototype.resizeSlider = function(evt) {
87 var filmBarWidth = this.filmBarWidth;
88 if (!filmBarWidth) { return; }
89 var filmWidth = this.slideSize * this.filmLength;
90 var sliderRatio = this.sliderRatio = filmBarWidth / filmWidth;
91 var sliderWidth = filmBarWidth * sliderRatio;
92 this.rail.style.width = filmBarWidth + 'px';
93 this.rail.style.display = 'block';
94 this.rail.style.visibility = 'visible';
95 if (sliderRatio < 1) {
96 this.slider.style.width = Math.round(sliderWidth) + 'px';
97 this.slider.style.visibility = 'visible';
98 }
99 else {
100 this.slider.style.visibility = 'hidden';
101 }
102
103 this.winSize = {'width' : getWindowWidth(),
104 'height' : getWindowHeight()};
105 this.maxRightPosition = filmBarWidth - sliderWidth;
106 this.sliderSpeedRatio = - (filmBarWidth - sliderWidth) / (filmWidth - filmBarWidth);
107 if (!this.initialized) {
108 this.centerSlide(this.center);
109 this.selectedSlide = this.filmBar.getElementsByTagName('img')[this.center].parentNode;
110 this.initialized = true;
111 }
112 };
113 }
114
115 else {
116 FilmSlider.prototype.resizeSlider = function(evt) {};
117 }
118
119 FilmSlider.prototype._checkSizeAfterLoad = function(evt) {
120 this._barSizes = [];
121 this.filmBarWidth = this._barSizes[this._barSizes.length] = getObjectWidth(this.filmBar);
122 this.resizeSlider();
123 var self = this;
124 this._checkSizeIntervalId = setInterval(function(evt){self._checkSize(evt);}, 25);
125 setTimeout(function(evt){self._checkSizeStability();}, 250);
126 };
127
128 FilmSlider.prototype._checkSize = function(evt) {
129 this._barSizes[this._barSizes.length] = getObjectWidth(this.filmBar);
130 if (this._barSizes.length >= 2 &&
131 this._barSizes[this._barSizes.length-2] !== this._barSizes[this._barSizes.length-1]) {
132 this.filmBarWidth = this._barSizes[this._barSizes.length-1];
133 this.initialized = false;
134 this.resizeSlider();
135 }
136 };
137
138 FilmSlider.prototype._checkSizeStability = function(evt) {
139 var self = this;
140 var i;
141 for (i=0 ; i<this._barSizes.length - 1 ; i++) {
142 if (this._barSizes[i] !== this._barSizes[i+1]) {
143 this._barSizes = [];
144 setTimeout(function(evt){self._checkSizeStability();}, 250);
145 return;
146 }
147 }
148 clearInterval(this._checkSizeIntervalId);
149 delete this._barSizes;
150 delete this._checkSizeIntervalId;
151 };
152
153 FilmSlider.prototype.fitToScreen = function(evt) {
154 this._fitToScreen();
155 var thisSlider = this;
156 addListener(window, 'resize', function(evt){thisSlider._fitToScreen();});
157 };
158
159 FilmSlider.prototype._fitToScreen = function(evt) {
160 var wh = getWindowHeight();
161 var rb = getObjectTop(this.rail) + getObjectHeight(this.rail); // rail bottom
162 var delta = wh - rb;
163 var sh = getObjectHeight(this.stretchable);
164 var newSize = sh + delta;
165 this.stretchable.style.height = newSize + 'px';
166
167 var ratio = this.image.height / this.image.width;
168 var bestFitSize = this.getBestFitSize(ratio);
169 var currentSize = parseInt(imgRequestedSize.exec(this.image.src)[1], 10);
170 if (currentSize !== bestFitSize) {
171 var src = this.image.src.replace(imgRequestedSize, 'size=' + bestFitSize);
172 this.pendingImage.src = src;
173 }
174 };
175
176 FilmSlider.prototype.getBestFitSize = function(ratio) {
177 var fw = getObjectWidth(this.stretchable) - 1;
178 var fh = getObjectHeight(this.stretchable) - 1;
179
180 var i, irw, irh;
181 if (ratio < 1) {
182 for (i=DEFAULT_IMAGE_SIZES.length -1 ; i>0 ; i--) {
183 irw = DEFAULT_IMAGE_SIZES[i];
184 irh = irw * ratio;
185 if (irw <= fw && irh <= fh) { break; }
186 }
187 }
188 else {
189 for (i=DEFAULT_IMAGE_SIZES.length -1 ; i>0 ; i--) {
190 irh = DEFAULT_IMAGE_SIZES[i];
191 irw = irh / ratio;
192 if (irw <= fw && irh <= fh) { break; }
193 }
194 }
195 return DEFAULT_IMAGE_SIZES[i];
196 };
197
198 FilmSlider.prototype.centerSlide = function(slideIndex) {
199 if (this.sliderRatio > 1) { return; }
200 var filmBarWidth = getObjectWidth(this.filmBar);
201 var x = slideIndex * this.slideSize;
202 x = x - (filmBarWidth - this.slideSize) / 2.0;
203 x = x * this.sliderSpeedRatio;
204 var p = new Point( -x, 0 );
205 this.setSliderPosition(p);
206 };
207
208 FilmSlider.prototype.setSliderPosition = function(point) {
209 if(point.x < 0) { point.x = 0; }
210 if (point.x > this.maxRightPosition) { point.x = this.maxRightPosition; }
211 this.slider.style.left = point.x + 'px';
212 this.setFilmPosition(point);
213 };
214
215 FilmSlider.prototype.setFilmPosition = function(point) {
216 this.film.style.left = point.x / this.sliderSpeedRatio + 'px';
217 };
218
219 FilmSlider.prototype.getSliderPosition = function() {
220 var x = parseInt(this.slider.style.left, 10);
221 var y = parseInt(this.slider.style.top, 10);
222 var p = new Point(x, y);
223 return p;
224 };
225
226 FilmSlider.prototype.getFilmPosition = function() {
227 var x = parseInt(this.film.style.left, 10);
228 var y = parseInt(this.film.style.top, 10);
229 var p = new Point(x, y);
230 return p;
231 };
232
233 FilmSlider.prototype.loadSibling = function(previous) {
234 var slide = null;
235 if (previous) {
236 slide = this.selectedSlide.parentNode.previousSibling;
237 if (slide && slide.nodeType===3) { slide = slide.previousSibling; }
238 }
239 else {
240 slide = this.selectedSlide.parentNode.nextSibling;
241 if (slide && slide.nodeType===3) { slide = slide.nextSibling; }
242 }
243
244 if (!slide) { return; }
245 else {
246 var target = slide.getElementsByTagName('a')[0];
247 raiseMouseEvent(target, 'click');
248 var index = parseInt(target.getAttribute('portfolio:position'), 10);
249 this.centerSlide(index);
250 }
251 };
252
253 FilmSlider.prototype.addEventListeners = function() {
254 var thisSlider = this;
255 addListener(window, 'resize', function(evt){thisSlider.resizeSlider(evt);});
256 addListener(this.filmBar, 'click', function(evt){thisSlider.thumbnailClickHandler(evt);});
257 addListener(this.toolbar, 'click', function(evt){thisSlider.toolbarClickHandler(evt);});
258 addListener(window, 'load', function(evt){thisSlider.fitToScreen(evt);});
259 addListener(window, 'load', function(evt){thisSlider._checkSizeAfterLoad(evt);});
260
261 // dd listeners
262 addListener(this.slider, 'mousedown', this.ddHandlers.down);
263 if(browser.isDOM2Event){
264 if (browser.isAppleWebKit) {
265 this.filmBar.addEventListener('mousewheel', function(evt){thisSlider.mouseWheelHandler(evt);}, false);
266 }
267 else {
268 addListener(this.filmBar, 'DOMMouseScroll', function(evt){thisSlider.mouseWheelHandler(evt);});
269 }
270 }
271 else if (browser.isIE6up) {
272 addListener(this.filmBar, 'mousewheel', function(evt){thisSlider.mouseWheelHandler(evt);});
273 }
274 if (browser.isMobile) {
275 this.filmBar.addEventListener('touchstart', function(evt){thisSlider.touchStartHandler(evt);}, false);
276 this.filmBar.addEventListener('touchmove', function(evt){thisSlider.touchMoveHandler(evt);}, false);
277 this.filmBar.addEventListener('touchend', function(evt){thisSlider.touchEndHandler(evt);}, false);
278 }
279
280 addListener(document, 'keydown', function(evt){thisSlider.keyDownHandler(evt);});
281 addListener(document, 'keypress', function(evt){thisSlider.keyPressHandler(evt);});
282 };
283
284
285 FilmSlider.prototype.mouseDownHandler = function(evt) {
286 this.initialClickPoint = new Point(evt.clientX, evt.clientY);
287 this.initialPosition = this.getSliderPosition();
288 this.dragInProgress = true;
289 addListener(document, 'mousemove', this.ddHandlers.move);
290 addListener(document, 'mouseup', this.ddHandlers.up);
291 addListener(document.body, 'mouseout', this.ddHandlers.out);
292 };
293
294
295 FilmSlider.prototype.mouseMoveHandler = function(evt) {
296 if(!this.dragInProgress) { return; }
297
298 clearSelection();
299 evt = getEventObject(evt);
300 var currentPoint = new Point(evt.clientX, evt.clientY);
301 var displacement = currentPoint.diff(this.initialClickPoint);
302 this.setSliderPosition(this.initialPosition.add(displacement));
303 };
304
305 FilmSlider.prototype.mouseUpHandler = function(evt) {
306 this.dragInProgress = false;
307 evt = getEventObject(evt);
308 this.mouseMoveHandler(evt);
309 };
310
311
312 FilmSlider.prototype.mouseOutHandler = function(evt) {
313 evt = getEventObject(evt);
314 var x = evt.clientX;
315 var y = evt.clientY;
316 if (x < 0 ||
317 x > this.winSize.width ||
318 y < 0 ||
319 y > this.winSize.height
320 ) {
321 this.mouseUpHandler(evt);
322 }
323 };
324
325 FilmSlider.prototype.thumbnailClickHandler = function(evt) {
326 var target = getTargetedObject(evt);
327 while (target.tagName !== 'A' && target !== this.filmBar) { target = target.parentNode; }
328 if (target.tagName !== 'A') { return; }
329 else {
330 if (this.viewMode === 'full') {
331 this.mosaique.unload();
332 this.mosaique = null;
333 this.viewMode = 'medium';
334 }
335 disableDefault(evt);
336 disablePropagation(evt);
337 target.blur();
338 history.pushState(target.href, '', target.href);
339
340 var imgBaseUrl = target.href;
341 var canonicalImgUrl;
342 if (this.ctxUrlTranslation[0]) {
343 canonicalImgUrl = imgBaseUrl.replace(this.ctxUrlTranslation[0],
344 this.ctxUrlTranslation[1]);
345 }
346 else { canonicalImgUrl = imgBaseUrl; }
347
348 var ajaxUrl = imgBaseUrl + '/photo_view_ajax';
349 var thisFS = this;
350
351 //this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=600';
352 var thumbnail = target.getElementsByTagName('IMG')[0];
353 var bestFitSize = this.getBestFitSize(thumbnail.height/thumbnail.width);
354 this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=' + bestFitSize;
355
356 // update buttons
357 var fullScreenLink = this.buttons.full_screen.parentNode;
358 fullScreenLink.href = canonicalImgUrl + '/zoom_view';
359
360 var toggleSelectionBtn = this.buttons.toggle_selection;
361 var toggleSelectionLink = toggleSelectionBtn.parentNode;
362 this.selectedSlideInSelection = (target.className==='selected');
363 if (this.selectedSlideInSelection) {
364 toggleSelectionBtn.src = portal_url() + '/unselect_flag_btn.gif';
365 toggleSelectionBtn.alt = toggleSelectionLink.title = 'Retirer de la sélection';
366 toggleSelectionLink.href = canonicalImgUrl + '/remove_to_selection';
367 }
368 else {
369 toggleSelectionBtn.src = portal_url() + '/select_flag_btn.gif';
370 toggleSelectionBtn.alt = toggleSelectionLink.title = 'Ajouter à la sélection';
371 toggleSelectionLink.href = canonicalImgUrl + '/add_to_selection';
372 }
373
374 var showBuyableButtonLink = this.buttons.show_buyable.parentNode;
375 showBuyableButtonLink.href = canonicalImgUrl + '/get_slide_buyable_items';
376 this.cartSlide.innerHTML = '';
377 this.cartSlide.style.visibility='hidden';
378
379
380 var metadataButton = this.buttons.edit_metadata;
381 if (metadataButton) {
382 var metadataEditLink = metadataButton.parentNode;
383 metadataEditLink.href = canonicalImgUrl + '/photo_edit_form';
384 }
385
386
387 var req = new XMLHttpRequest();
388 req.onreadystatechange = function() {
389 switch (req.readyState) {
390 case 1 :
391 showProgressImage();
392 break;
393 case 2 :
394 try {
395 if (! isTextMime.exec(req.getResponseHeader('Content-Type'))) {
396 req.onreadystatechange = null;
397 req.abort();
398 hideProgressImage();
399 window.location.href = thisFS._fallBackUrl;
400 }
401 }
402 catch(e){}
403 break;
404 case 4 :
405 hideProgressImage();
406 if (req.status === 200) { thisFS.populateViewer(req); }
407 break;
408 }
409 };
410
411 req.open("GET", ajaxUrl, true);
412 req.send(null);
413
414 // update old displayed slide className
415 var className = this.selectedSlide.className;
416 var classes = className.split(' ');
417 var newClasses = [];
418 var name, i;
419
420 for (i=0 ; i<classes.length ; i++) {
421 name = classes[i];
422 if (name !== 'displayed') {
423 newClasses.push(name);
424 }
425 }
426
427 this.selectedSlide.className = newClasses.join(' ');
428
429 // hightlight new displayed slide
430 this.selectedSlide = target;
431 className = this.selectedSlide.className;
432 classes = className.split(' ');
433 classes.push('displayed');
434 this.selectedSlide.className = classes.join(' ');
435 }
436 };
437
438 FilmSlider.prototype.toolbarClickHandler = function(evt) {
439 var target = getTargetedObject(evt);
440 var button, link, url;
441 if(target.tagName === 'IMG' && target.getAttribute('name')) {
442 switch(target.getAttribute('name')) {
443 case 'previous' :
444 disableDefault(evt);
445 disablePropagation(evt);
446 button = target;
447 link = button.parentNode;
448 link.blur();
449 this.loadSibling(true);
450 break;
451 case 'next' :
452 disableDefault(evt);
453 disablePropagation(evt);
454 button = target;
455 link = button.parentNode;
456 link.blur();
457 this.loadSibling(false);
458 break;
459 case 'full_screen':
460 disableDefault(evt);
461 disablePropagation(evt);
462 target.parentNode.blur();
463 if (this.viewMode === 'full') {
464 this.mosaique.unload();
465 this.mosaique = null;
466 this.viewMode = 'medium';
467 return;
468 }
469 var main = document.getElementById('photo_viewer');
470 url = target.parentNode.href;
471 url = url.substring(0, url.length - '/zoom_view'.length);
472 var margins = {'top':0, 'right':-1, 'bottom':0, 'left':0};
473 this.mosaique = new Mosaique(main, url, margins);
474 this.viewMode = 'full';
475 break;
476
477 case 'toggle_selection':
478 disableDefault(evt);
479 disablePropagation(evt);
480 button = target;
481 link = button.parentNode;
482 link.blur();
483
484 var req = new XMLHttpRequest();
485 url = link.href;
486 req.open("POST", url, true);
487 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
488 req.send("ajax=1");
489
490 // toggle button
491 var parts = url.split('/');
492 var canonicalImgUrl = parts.slice(0, parts.length-1).join('/');
493
494 if (isAddToSelection.test(url)) {
495 button.src = portal_url() + '/unselect_flag_btn.gif';
496 button.alt = link.title = 'Retirer de la sélection';
497 link.href = canonicalImgUrl + '/remove_to_selection';
498 this.selectedSlide.className = 'selected displayed';
499 this.image.parentNode.className = 'selected';
500 this.selectedSlideInSelection = true;
501 }
502 else {
503 button.src = portal_url() + '/select_flag_btn.gif';
504 button.alt = link.title = 'Ajouter à la sélection';
505 link.href = canonicalImgUrl + '/add_to_selection';
506 this.selectedSlide.className = 'displayed';
507 this.image.parentNode.className = '';
508 this.selectedSlideInSelection = false;
509 }
510 break;
511
512 case 'show_buyable':
513 disableDefault(evt);
514 disablePropagation(evt);
515 button = target;
516 link = button.parentNode;
517 link.blur();
518 var slide = this.cartSlide;
519 slide.innerHTML = '';
520 slide.style.visibility = 'visible';
521 var cw = new CartWidget(slide, link.href);
522 cw.onCancel = function() {
523 CartWidget.prototype.onCancel.apply(this);
524 slide.style.visibility = 'hidden';
525 };
526 cw.onAfterConfirm = function() {
527 slide.style.visibility = 'hidden';
528 };
529 break;
530
531
532
533
534 /*
535 case 'edit_metadata' :
536 disableDefault(evt);
537 disablePropagation(evt);
538 target.blur();
539 if (this.viewMode === 'full') {
540 this.mosaique.unload();
541 this.mosaique = null;
542 this.viewMode = 'medium';
543 return;
544 }
545 var fi = new FragmentImporter(absolute_url());
546 fi.useMacro('metadata_edit_form_macros', 'iptc', 'image_metadata');
547 break;
548 */
549 }
550 }
551 };
552
553
554 if(browser.isDOM2Event) {
555 if (browser.isAppleWebKit) {
556 FilmSlider.prototype.mouseWheelHandler = function(evt) {
557 disableDefault(evt);
558 var pos = this.getSliderPosition();
559 pos.x -= evt.wheelDelta / 40;
560 this.setSliderPosition(pos);
561 };
562 }
563 else {
564 FilmSlider.prototype.mouseWheelHandler = function(evt) {
565 disableDefault(evt);
566 var pos = this.getSliderPosition();
567 pos.x += evt.detail * 3;
568 this.setSliderPosition(pos);
569 };
570 }
571 }
572 else if (browser.isIE6up) {
573 FilmSlider.prototype.mouseWheelHandler = function() {
574 var evt = window.event;
575 evt.returnValue = false;
576 var pos = this.getSliderPosition();
577 pos.x -= evt.wheelDelta / 40;
578 this.setSliderPosition(pos);
579 };
580 }
581
582 FilmSlider.prototype.touchStartHandler = function(evt) {
583 this.filmStartX = parseInt(this.film.style.left, 10);
584 this.touchStartX = evt.pageX;
585 };
586
587 FilmSlider.prototype.touchMoveHandler = function(evt) {
588 var delta = this.touchStartX - evt.pageX;
589 this.film.style.left = String(this.filmStartX - delta) + 'px';
590 };
591
592 FilmSlider.prototype.touchEndHandler = function(evt) {
593 this.touchStartX = undefined;
594 };
595
596
597 FilmSlider.prototype.keyDownHandler = function(evt) {
598 evt = getEventObject(evt);
599 switch (evt.keyCode) {
600 case keyLeft :
601 this.loadSibling(true);
602 break;
603 case keyRight :
604 this.loadSibling(false);
605 break;
606 default:
607 return;
608 }
609 };
610
611
612 FilmSlider.prototype.keyPressHandler = function(evt) {
613 var target = getTargetedObject(evt);
614 if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') { return; }
615 evt = getEventObject(evt);
616 var charPress = String.fromCharCode((evt.keyCode) ? evt.keyCode : evt.which);
617 switch(charPress) {
618 case 'f':
619 case 'F':
620 raiseMouseEvent(this.buttons.full_screen, 'click');
621 break;
622 }
623 };
624
625 FilmSlider.prototype.populateViewer = function(req) {
626 var elements = req.responseXML.documentElement.childNodes;
627 var i;
628 for(i=0 ; i < elements.length ; i++ ) {
629 element = elements[i];
630 switch (element.nodeName) {
631 case 'fragment' :
632 var dest = document.getElementById(element.getAttribute('id'));
633 if (dest) { dest.innerHTML = element.firstChild.nodeValue; }
634 break;
635 case 'imageattributes' :
636 var link = this.buttons.back_to_portfolio.parentNode;
637 link.href = element.getAttribute('back_to_context_url');
638 link = this.buttons.show_buyable.parentNode;
639 var buyable = element.getAttribute('buyable');
640 if(buyable === 'True') { link.className = null; }
641 else if(buyable === 'False') { link.className = 'hidden'; }
642 this.image.alt = element.getAttribute('alt');
643 this.updateBreadcrumbs(element.getAttribute('last_bc_url'),
644 element.getAttribute('img_id'));
645 break;
646 }
647 }
648 };
649
650 FilmSlider.prototype.refreshImage = function() {
651 this.image.style.visibility = 'hidden';
652 this.image.src = this.pendingImage.src;
653 this.image.width = this.pendingImage.width;
654 this.image.height = this.pendingImage.height;
655 this.image.style.visibility = 'visible';
656 if (this.selectedSlideInSelection) { this.image.parentNode.className = 'selected'; }
657 else { this.image.parentNode.className = ''; }
658 };
659
660 FilmSlider.prototype.updateBreadcrumbs = function(url, title) {
661 if (this.hasBreadcrumbs) {
662 this.lastBCElement.href = element.getAttribute('lastBcUrl');
663 this.lastBCElement.innerHTML = element.getAttribute('img_id');
664 }
665 };
666
667 FilmSlider.prototype.startSlideShow = function() {
668 this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide;
669 return this.slideShowSlide.href;
670 };
671
672 FilmSlider.prototype.slideShowNext = function() {
673 var nextSlide = this.slideShowSlide.parentNode.nextSibling;
674 if (nextSlide && nextSlide.nodeType===3) { nextSlide = nextSlide.nextSibling; }
675
676 if (nextSlide) {
677 nextSlide = nextSlide.getElementsByTagName('a')[0];
678 this.pendingSlideShowSlide = nextSlide;
679 return this.pendingSlideShowSlide.href;
680 }
681 else {
682 var row = this.slideShowSlide.parentNode.parentNode;
683 var first = row.firstChild;
684 if (first.nodeType===3) { first = first.nextSibling; }
685 this.pendingSlideShowSlide = first.getElementsByTagName('a')[0];
686 return this.pendingSlideShowSlide.href;
687 }
688 };
689
690 FilmSlider.prototype.slideShowPrevious = function() {
691 var previousSlide = this.slideShowSlide.parentNode.previousSibling;
692 if (previousSlide && previousSlide.nodeType===3) { previousSlide = previousSlide.previousSibling; }
693
694 if (previousSlide) {
695 previousSlide = previousSlide.getElementsByTagName('a')[0];
696 this.pendingSlideShowSlide = previousSlide;
697 return this.pendingSlideShowSlide.href;
698 }
699 else {
700 var row = this.slideShowSlide.parentNode.parentNode;
701 var last = row.lastChild;
702 if (last.nodeType===3) { last = last.previousSibling; }
703 this.pendingSlideShowSlide = last.getElementsByTagName('a')[0];
704 return this.pendingSlideShowSlide.href;
705 }
706 };
707
708 FilmSlider.prototype.slideShowImageLoaded = function() {
709 this.slideShowSlide = this.pendingSlideShowSlide;
710 };
711
712 FilmSlider.prototype.stopSlideShow = function() {
713 raiseMouseEvent(this.slideShowSlide, 'click');
714 var index = parseInt(this.selectedSlide.getAttribute('portfolio:position'), 10);
715 this.centerSlide(index);
716 };
717
718
719 /* UTILS */
720 function Point(x, y) {
721 this.x = Math.round(x);
722 this.y = Math.round(y);
723 }
724 Point.prototype.diff = function(point) { return new Point(this.x - point.x, this.y - point.y); };
725 Point.prototype.add = function(point) { return new Point(this.x + point.x, this.y + point.y); };
726 Point.prototype.mul = function(k) { return new Point(this.x * k, this.y *k); };
727 Point.prototype.toString = function() { return "(" + String(this.x) + ", " + String(this.y) + ")"; };
728
729 }());