3     $.widget('wl.pictureviewer', {
 
   6             steps: 6, // steps of zoom
 
   7             max: -1, // max zoom in percent
 
   8             plus_button: undefined,
 
   9             minus_button: undefined,
 
  10             height: 500, // height to scale to initially
 
  19             // the initial thumbnailed picture
 
  22             var img = self.element.find('img.initial').get(0);
 
  29             self.element.width(self.initial_size[0]);
 
  30             self.element.height(self.initial_size[1]);
 
  32             self.initial_position = self.element.offset();
 
  34             var original = self.element.find('img.original').get(0);
 
  35             self._original = false;
 
  37             if (self.options.max <= 0) {
 
  38                 self.options.max = original.naturalWidth
 
  39                     * 100 / self.initial_size[0];
 
  46             self.element.offset(self.initial_position);
 
  47             self.element.draggable({containment:"parent"});
 
  49             if (self.options.plus_button)
 
  50                 self.options.plus_button.click(
 
  51                     function(ev) { self.zoom(1); });
 
  52             if (self.options.minus_button)
 
  53                 self.options.minus_button.click(
 
  54                     function(ev) { self.zoom(-1); });
 
  56             self.options.areas_links.hover(function() {
 
  58                 var coords = $this.data("coords");
 
  59                 this._picture_mark = self.createMark({
 
  64                 $(this._picture_mark).remove();
 
  65                 this._picture_mark = undefined;
 
  70         natural_size: function() { 
 
  71             var img = this.element.find('img').get(0);
 
  72             return [ img.naturalWidth, img.naturalHeight ] 
 
  75         currentZoom: function() { return this._zoom; },
 
  77         initOriginal: function() {
 
  78             if (!this._original) {
 
  79                 this.element.find("img.initial").remove();
 
  80                 this.element.find("img.loading").removeClass("loading");
 
  81                 this._original = true;
 
  86         zoom: function(steps) {
 
  88             var t = this._zoom + steps;
 
  89             return this.zoomTo(t);
 
  92         zoomForStep: function(step) {
 
  94             // max_step-1 => max %
 
  95             return 100 + (this.options.max - 100) / this.options.steps * step
 
  98         zoomTo: function(level) {
 
  99             if (level < 0 || level > this.options.steps)
 
 101             var ratio = this.zoomForStep(level) / 100;
 
 102             var new_width  = ratio * this.initial_size[0];
 
 103             var new_height = ratio * this.initial_size[1];
 
 107                                  this.initial_position.left 
 
 108                                  - (new_width - this.initial_size[0])/2),
 
 110                                 this.initial_position.top 
 
 111                                 - (new_height - this.initial_size[1])/2),
 
 115             this.element.animate(target, 200); // default duration=400
 
 118         allowedPosition: function(off) {
 
 119             var x = undefined, fix_x = undefined;
 
 120             var y = undefined, fix_y = undefined;
 
 121             var w = this.element.width();
 
 122             var h = this.element.height();
 
 123             var cw = $(window).width();
 
 124             var ch = $(window).height();
 
 125             var off = off || this.element.offset();
 
 152             if (fix_x !== undefined || fix_y !== undefined)
 
 153                 return { top: fix_y, left: fix_x };
 
 161         //  coords: [x, y, w, h]
 
 163         createMark: function(mark) {
 
 164             var $mark = $('<div class="mark"><div class="label">' + 
 
 165                           mark.label + '</div></div>');
 
 166             var ratio = this.zoomForStep(this.currentZoom()) *
 
 167                 this.initial_size[0] / (100 * this.natural_size()[0]);
 
 168             var scale = function (v) { 
 
 171             if (mark.coords[1][0] < 0 || mark.coords[1][1] < 0) { // whole
 
 172                 var s = self.natural_size();
 
 173                 if (mark.coords[1][0] < 0) mark.coords[1][0] = s[0];
 
 174                 if (mark.coords[1][1] < 0) mark.coords[1][1] = s[1];
 
 177             var coords = [[scale(mark.coords[0][0]), scale(mark.coords[0][1])],
 
 178                           [scale(mark.coords[1][0]), scale(mark.coords[1][1])]];
 
 179             this.element.append($mark);
 
 180             $mark.width(coords[1][0] - coords[0][0]);
 
 181             $mark.height(coords[1][1] - coords[0][1]);
 
 182             $mark.css({left: coords[0][0], top: coords[0][1]});
 
 189 $(document).ready(function(){
 
 190     $(".picture-wrap").pictureviewer({
 
 191         plus_button: $(".toolbar .button.plus"),
 
 192         minus_button: $(".toolbar .button.minus"),
 
 193         areas_links: $("#picture-objects a, #picture-themes a"),
 
 196     $.highlightFade.defaults.speed = 3000;
 
 198     $('.toolbar a.dropdown').each(function() {
 
 200         $($t.attr('href')).hide().insertAfter(this);
 
 203     $('.toolbar a.dropdown').toggle(function() {
 
 204         $(this).addClass('selected');
 
 205         $($(this).attr('href')).slideDown('fast');
 
 207         $(this).removeClass('selected');
 
 208         $($(this).attr('href')).slideUp('fast');