var magiczoom_ua = 'msie';
var w = navigator.useragent.tolowercase();
if (w.indexof("opera") != -1) {
magiczoom_ua = 'opera'
} else if (w.indexof("msie") != -1) {
magiczoom_ua = 'msie'
} else if (w.indexof("safari") != -1) {
magiczoom_ua = 'safari'
} else if (w.indexof("mozilla") != -1) {
magiczoom_ua = 'gecko'
}
var magiczoom_zooms = new array();
function _el(id) {
return document.getelementbyid(id)
};
function magiczoom_getbounds(e) {
if (e.getboundingclientrect) {
var r = e.getboundingclientrect();
var wx = 0;
var wy = 0;
if (document.body && (document.body.scrollleft || document.body.scrolltop)) {
wy = document.body.scrolltop;
wx = document.body.scrollleft
} else if (document.documentelement && (document.documentelement.scrollleft || document.documentelement.scrolltop)) {
wy = document.documentelement.scrolltop;
wx = document.documentelement.scrollleft
}
return {
'left': r.left + wx,
'top': r.top + wy,
'right': r.right + wx,
'bottom': r.bottom + wy
}
}
}
function magiczoom_geteventbounds(e) {
var x = 0;
var y = 0;
if (magiczoom_ua == 'msie') {
y = e.clienty;
x = e.clientx;
if (document.body && (document.body.scrollleft || document.body.scrolltop)) {
y = e.clienty + document.body.scrolltop;
x = e.clientx + document.body.scrollleft
} else if (document.documentelement && (document.documentelement.scrollleft || document.documentelement.scrolltop)) {
y = e.clienty + document.documentelement.scrolltop;
x = e.clientx + document.documentelement.scrollleft
}
} else {
y = e.clienty;
x = e.clientx;
y += window.pageyoffset;
x += window.pagexoffset
}
return {
'x': x,
'y': y
}
}
function magicview_ia() {
return false
};
var magiczoom_extendelement = function() {
var args = arguments;
if (!args[1]) args = [this, args[0]];
for (var property in args[1]) args[0][property] = args[1][property];
return args[0]
};
function magiczoom_addeventlistener(obj, event, listener) {
if (magiczoom_ua == 'gecko' || magiczoom_ua == 'opera' || magiczoom_ua == 'safari') {
try {
obj.addeventlistener(event, listener, false)
} catch(e) {
alert("magiczoom error: " + e + ", event=" + event)
}
} else if (magiczoom_ua == 'msie') {
obj.attachevent("on" + event, listener)
}
};
function magiczoom_removeeventlistener(obj, event, listener) {
if (magiczoom_ua == 'gecko' || magiczoom_ua == 'opera' || magiczoom_ua == 'safari') {
obj.removeeventlistener(event, listener, false)
} else if (magiczoom_ua == 'msie') {
obj.detachevent("on" + event, listener)
}
};
function magiczoom_concat() {
var result = [];
for (var i = 0; i < arguments.length; i++) for (var j = 0; j < arguments[i].length; j++) result.push(arguments[i][j]);
return result
};
function magiczoom_withoutfirst(sequence, skip) {
result = [];
for (var i = skip; i < sequence.length; i++) result.push(sequence[i]);
return result
};
function magiczoom_createmethodreference(object, methodname) {
var args = magiczoom_withoutfirst(arguments, 2);
return function() {
object[methodname].apply(object, magiczoom_concat(arguments, args))
}
};
function magiczoom_stopeventpropagation(e) {
if (magiczoom_ua == 'gecko' || magiczoom_ua == 'safari' || magiczoom_ua == 'opera') {
e.cancelbubble = true;
e.preventdefault();
e.stoppropagation()
} else if (magiczoom_ua == 'msie') {
window.event.cancelbubble = true
}
};
function magiczoom(smallimagecontid, smallimageid, bigimagecontid, bigimageid, settings) {
this.recalculating = false;
this.smallimagecont = _el(smallimagecontid);
this.smallimage = _el(smallimageid);
this.bigimagecont = _el(bigimagecontid);
this.bigimage = _el(bigimageid);
this.pup = 0;
this.settings = settings;
if (!this.settings["header"]) {
this.settings["header"] = ""
}
this.bigimagesizex = 0;
this.bigimagesizey = 0;
this.smallimagesizex = 0;
this.smallimagesizey = 0;
this.popupsizex = 20;
this.popupsizey = 20;
this.positionx = 0;
this.positiony = 0;
this.bigimagecontstyleleft = '';
this.loadingcont = null;
if (this.settings["loadingimg"] != '') {
this.loadingcont = document.createelement('div');
this.loadingcont.style.position = 'absolute';
this.loadingcont.style.visibility = 'hidden';
this.loadingcont.classname = 'magiczoomloading';
this.loadingcont.style.display = 'block';
this.loadingcont.style.textalign = 'center';
this.loadingcont.innerhtml = this.settings["loadingtext"] + '
';
this.smallimagecont.appendchild(this.loadingcont)
}
this.baseuri = '';
this.safarionloadstarted = false;
magiczoom_zooms.push(this);
this.checkcoords_ref = magiczoom_createmethodreference(this, "checkcoords")
};
magiczoom.prototype.stopzoom = function() {
magiczoom_removeeventlistener(window.document, "mousemove", this.checkcoords_ref);
if (this.settings["position"] == "custom") {
_el(this.smallimagecont.id + "-big").removechild(this.bigimagecont)
}
};
magiczoom.prototype.checkcoords = function(e) {
var y = 0;
var x = 0;
r = magiczoom_geteventbounds(e);
x = r['x'];
y = r['y'];
var smally = 0;
var smallx = 0;
var tag = this.smallimage;
while (tag && tag.tagname != "body" && tag.tagname != "html") {
smally += tag.offsettop;
smallx += tag.offsetleft;
tag = tag.offsetparent
}
if (magiczoom_ua == 'msie') {
r = magiczoom_getbounds(this.smallimage);
smallx = r['left'];
smally = r['top']
}
if (x > parseint(smallx + this.smallimagesizex)) {
this.hiderect();
return false
}
if (x < parseint(smallx)) {
this.hiderect();
return false
}
if (y > parseint(smally + this.smallimagesizey)) {
this.hiderect();
return false
}
if (y < parseint(smally)) {
this.hiderect();
return false
}
if (magiczoom_ua == 'msie') {
this.smallimagecont.style.zindex = 1
}
return true
};
magiczoom.prototype.mousedown = function(e) {
magiczoom_stopeventpropagation(e);
this.smallimagecont.style.cursor = 'move'
};
magiczoom.prototype.mouseup = function(e) {
magiczoom_stopeventpropagation(e);
this.smallimagecont.style.cursor = 'default'
};
magiczoom.prototype.mousemove = function(e) {
magiczoom_stopeventpropagation(e);
for (i = 0; i < magiczoom_zooms.length; i++) {
if (magiczoom_zooms[i] != this) {
magiczoom_zooms[i].checkcoords(e)
}
}
if (this.settings && this.settings["drag_mode"] == true) {
if (this.smallimagecont.style.cursor != 'move') {
return
}
}
if (this.recalculating) {
return
}
if (!this.checkcoords(e)) {
return
}
this.recalculating = true;
var smallimg = this.smallimage;
var smallx = 0;
var smally = 0;
if (magiczoom_ua == 'gecko' || magiczoom_ua == 'opera' || magiczoom_ua == 'safari') {
var tag = smallimg;
while (tag.tagname != "body" && tag.tagname != "html") {
smally += tag.offsettop;
smallx += tag.offsetleft;
tag = tag.offsetparent
}
} else {
r = magiczoom_getbounds(this.smallimage);
smallx = r['left'];
smally = r['top']
}
r = magiczoom_geteventbounds(e);
x = r['x'];
y = r['y'];
this.positionx = x - smallx;
this.positiony = y - smally;
if ((this.positionx + this.popupsizex / 2) >= this.smallimagesizex) {
this.positionx = this.smallimagesizex - this.popupsizex / 2
}
if ((this.positiony + this.popupsizey / 2) >= this.smallimagesizey) {
this.positiony = this.smallimagesizey - this.popupsizey / 2
}
if ((this.positionx - this.popupsizex / 2) <= 0) {
this.positionx = this.popupsizex / 2
}
if ((this.positiony - this.popupsizey / 2) <= 0) {
this.positiony = this.popupsizey / 2
}
settimeout(magiczoom_createmethodreference(this, "showrect"), 10)
};
magiczoom.prototype.showrect = function() {
this.pup.style.left = (this.positionx - this.popupsizex / 2) + 'px';
this.pup.style.top = (this.positiony - this.popupsizey / 2) + 'px';
this.pup.style.visibility = "visible";
perx = parseint(this.pup.style.left) * (this.bigimagesizex / this.smallimagesizex);
pery = parseint(this.pup.style.top) * (this.bigimagesizey / this.smallimagesizey);
this.bigimage.style.left = ( - perx) + 'px';
this.bigimage.style.top = ( - pery) + 'px';
this.bigimagecont.style.display = 'block';
this.bigimagecont.style.visibility = 'visible';
this.bigimage.style.display = 'block';
this.bigimage.style.visibility = 'visible';
this.recalculating = false;
this.bigimagecont.style.left = this.bigimagecontstyleleft
};
magiczoom.prototype.hiderect = function() {
if (this.settings && this.settings["bigimage_always_visible"] == true) return;
if (this.pup) {
this.pup.style.visibility = "hidden"
}
this.bigimagecont.style.left = '-10000px';
this.bigimagecont.style.visibility = 'hidden';
if (magiczoom_ua == 'msie') {
this.smallimagecont.style.zindex = 0
}
};
magiczoom.prototype.recalculatepopupdimensions = function() {
this.popupsizex = (parseint(this.bigimagecont.style.width) - 0) / (this.bigimagesizex / this.smallimagesizex);
if (this.settings && this.settings["header"] != "") {
this.popupsizey = (parseint(this.bigimagecont.style.height) - 0 - 0) / (this.bigimagesizey / this.smallimagesizey)
} else {
this.popupsizey = (parseint(this.bigimagecont.style.height) - 0) / (this.bigimagesizey / this.smallimagesizey)
}
if (this.popupsizex > this.smallimagesizex) {
this.popupsizex = this.smallimagesizex
}
if (this.popupsizey > this.smallimagesizey) {
this.popupsizey = this.smallimagesizey
}
this.pup.style.width = this.popupsizex + 'px';
this.pup.style.height = this.popupsizey + 'px'
};
magiczoom.prototype.initpopup = function() {
this.pup = document.createelement("div");
this.pup.classname = 'magiczoompup';
this.pup.style.zindex = 10;
this.pup.style.visibility = 'hidden';
this.pup.style.position = 'absolute';
this.pup.style["opacity"] = parsefloat(this.settings['opacity'] / 100.0);
this.pup.style["-moz-opacity"] = parsefloat(this.settings['opacity'] / 100.0);
this.pup.style["-html-opacity"] = parsefloat(this.settings['opacity'] / 100.0);
this.pup.style["filter"] = "alpha(opacity=" + this.settings['opacity'] + ")";
this.recalculatepopupdimensions();
this.smallimagecont.appendchild(this.pup);
this.smallimagecont.unselectable = "on";
this.smallimagecont.style.mozuserselect = "none";
this.smallimagecont.onselectstart = magicview_ia;
this.smallimagecont.oncontextmenu = magicview_ia
};
magiczoom.prototype.initbigcontainer = function() {
var bigimgsrc = this.bigimage.src;
while (this.bigimagecont.firstchild) {
this.bigimagecont.removechild(this.bigimagecont.firstchild)
}
if (magiczoom_ua == 'msie') {
var f = document.createelement("iframe");
f.style.left = '0px';
f.style.top = '0px';
f.style.position = 'absolute';
f.style.filter = 'progid:dximagetransform.microsoft.alpha(style=0,opacity=0)';
f.style.width = this.bigimagecont.style.width;
f.style.height = this.bigimagecont.style.height;
f.frameborder = 0;
this.bigimagecont.appendchild(f)
}
var ar1 = document.createelement("div");
ar1.style.overflow = "hidden";
this.bigimagecont.appendchild(ar1);
this.bigimage = document.createelement("img");
this.bigimage.src = bigimgsrc;
this.bigimage.style.position = 'relative';
ar1.appendchild(this.bigimage)
};
magiczoom.prototype.initzoom = function() {
if (this.loadingcont != null && !this.bigimage.complete && this.smallimage.width != 0 && this.smallimage.height != 0) {
this.loadingcont.style.left = (parseint(this.smallimage.width) / 2 - parseint(this.loadingcont.offsetwidth) / 2) + 'px';
this.loadingcont.style.top = (parseint(this.smallimage.height) / 2 - parseint(this.loadingcont.offsetheight) / 2) + 'px';
this.loadingcont.style.visibility = 'visible'
}
if (magiczoom_ua == 'safari') {
if (!this.safarionloadstarted) {
magiczoom_addeventlistener(this.bigimage, "load", magiczoom_createmethodreference(this, "initzoom"));
this.safarionloadstarted = true;
return
}
} else {
if (!this.bigimage.complete || !this.smallimage.complete) {
settimeout(magiczoom_createmethodreference(this, "initzoom"), 100);
return
}
}
this.bigimagesizex = this.bigimage.width;
this.bigimagesizey = this.bigimage.height;
this.smallimagesizex = this.smallimage.width;
this.smallimagesizey = this.smallimage.height;
if (this.bigimagesizex == 0 || this.bigimagesizey == 0 || this.smallimagesizex == 0 || this.smallimagesizey == 0) {
settimeout(magiczoom_createmethodreference(this, "initzoom"), 100);
return
}
if (this.loadingcont != null) this.loadingcont.style.visibility = 'hidden';
this.smallimagecont.style.width = this.smallimage.width + 'px';
this.bigimagecont.style.left = this.smallimage.width + 15 + 'px';
this.bigimagecont.style.top = '0px';
switch (this.settings['position']) {
case 'left':
this.bigimagecont.style.left = '-' + (15 + parseint(this.bigimagecont.style.width)) + 'px';
break;
case 'bottom':
this.bigimagecont.style.top = this.smallimage.height + 15 + 'px';
this.bigimagecont.style.left = '0px';
break;
case 'top':
this.bigimagecont.style.top = '-' + (15 + parseint(this.bigimagecont.style.height)) + 'px';
this.bigimagecont.style.left = '0px';
break;
case 'custom':
this.bigimagecont.style.left = '0px';
this.bigimagecont.style.top = '0px';
break;
case 'inner':
this.bigimagecont.style.left = '0px';
this.bigimagecont.style.top = '0px';
break
}
this.bigimagecontstyleleft = this.bigimagecont.style.left;
if (this.pup) {
this.recalculatepopupdimensions();
return
}
this.initbigcontainer();
this.initpopup();
magiczoom_addeventlistener(window.document, "mousemove", this.checkcoords_ref);
magiczoom_addeventlistener(this.smallimagecont, "mousemove", magiczoom_createmethodreference(this, "mousemove"));
if (this.settings && this.settings["drag_mode"] == true) {
magiczoom_addeventlistener(this.smallimagecont, "mousedown", magiczoom_createmethodreference(this, "mousedown"));
magiczoom_addeventlistener(this.smallimagecont, "mouseup", magiczoom_createmethodreference(this, "mouseup"));
this.positionx = this.smallimagesizex / 2;
this.positiony = this.smallimagesizey / 2;
this.showrect()
}
};
magiczoom.prototype.replacezoom = function(e, ael) {
if (ael.href == this.bigimage.src) return;
var newbigimage = document.createelement("img");
newbigimage.id = this.bigimage.id;
newbigimage.src = ael.getelementsbytagname("img")[0].getattribute("tsimgs");
var p = this.bigimage.parentnode;
p.replacechild(newbigimage, this.bigimage);
this.bigimage = newbigimage;
this.bigimage.style.position = 'relative';
this.smallimage.src = ael.getelementsbytagname("img")[0].src;
this.safarionloadstarted = false;
this.initzoom()
};
function magiczoom_findselectors(id, zoom) {
var aels = window.document.getelementsbytagname("li");
for (var i = 0; i < aels.length; i++) {
if (aels[i].getattribute("rel") == id) {
magiczoom_addeventlistener(aels[i], "click",
function(event) {
if (magiczoom_ua != 'msie') {
this.blur()
} else {
window.focus()
}
magiczoom_stopeventpropagation(event);
return false
});
magiczoom_addeventlistener(aels[i], zoom.settings['thumb_change'], magiczoom_createmethodreference(zoom, "replacezoom", aels[i]));
aels[i].style.outline = '0';
aels[i].mzextend = magiczoom_extendelement;
aels[i].mzextend({
zoom: zoom,
selectthiszoom: function() {
this.zoom.replacezoom(null, this)
}
})
}
}
};
function magiczoom_stopzooms() {};
function magiczoom_findzooms() {
var loadingtext = 'loading zoom';
var loadingimg = '';
var iels = window.document.getelementsbytagname("img");
for (var i = 0; i < iels.length; i++) {
if (/magiczoomloading/.test(iels[i].classname)) {
if (iels[i].alt != '') loadingtext = iels[i].alt;
loadingimg = iels[i].src;
break
}
}
var aels = window.document.getelementsbytagname("a");
for (var i = 0; i < aels.length; i++) {
if (/magiczoom/.test(aels[i].classname)) {
while (aels[i].firstchild) {
if (aels[i].firstchild.tagname != 'img') {
aels[i].removechild(aels[i].firstchild)
} else {
break
}
}
if (aels[i].firstchild.tagname != 'img') throw "invalid magiczoom invocation!";
var rand = math.round(math.random() * 1000000);
aels[i].style.position = "relative";
aels[i].style.display = 'block';
aels[i].style.outline = '0';
aels[i].style.textdecoration = 'none';
magiczoom_addeventlistener(aels[i], "click",
function(event) {
if (magiczoom_ua != 'msie') {
this.blur()
} else {
window.focus()
}
magiczoom_stopeventpropagation(event);
return false
});
if (aels[i].id == '') {
aels[i].id = "sc" + rand
}
if (magiczoom_ua == 'msie') {
aels[i].style.zindex = 0
}
var smallimg = aels[i].firstchild;
smallimg.id = "sim" + rand;
var bigcont = document.createelement("div");
bigcont.id = "bc" + rand;
re = new regexp(/opacity(\s+)?:(\s+)?(\d+)/i);
matches = re.exec(aels[i].rel);
var opacity = 50;
if (matches) {
opacity = parseint(matches[3])
}
re = new regexp(/thumb\-change(\s+)?:(\s+)?(click|mouseover)/i);
matches = re.exec(aels[i].rel);
var thumb_change = 'click';
if (matches) {
thumb_change = matches[3]
}
re = new regexp(/zoom\-width(\s+)?:(\s+)?(\w+)/i);
matches = re.exec(aels[i].rel);
bigcont.style.width = '400px';
if (matches) {
bigcont.style.width = matches[3]
}
re = new regexp(/zoom\-height(\s+)?:(\s+)?(\w+)/i);
matches = re.exec(aels[i].rel);
bigcont.style.height = '297px';
if (matches) {
bigcont.style.height = matches[3]
}
re = new regexp(/zoom\-position(\s+)?:(\s+)?(\w+)/i);
matches = re.exec(aels[i].rel);
bigcont.style.left = aels[i].firstchild.width + 15 + 'px';
bigcont.style.top = '0px';
var position = 'right';
if (matches) {
switch (matches[3]) {
case 'left':
position = 'left';
break;
case 'bottom':
position = 'bottom';
break;
case 'top':
position = 'top';
break;
case 'custom':
position = 'custom';
break;
case 'inner':
position = 'inner';
break
}
}
re = new regexp(/drag\-mode(\s+)?:(\s+)?(true|false)/i);
matches = re.exec(aels[i].rel);
var drag_mode = false;
if (matches) {
if (matches[3] == 'true') drag_mode = true
}
re = new regexp(/always\-show\-zoom(\s+)?:(\s+)?(true|false)/i);
matches = re.exec(aels[i].rel);
var bigimage_always_visible = false;
if (matches) {
if (matches[3] == 'true') bigimage_always_visible = true
}
bigcont.style.overflow = 'hidden';
bigcont.classname = "magiczoombigimagecont";
bigcont.style.zindex = 100;
bigcont.style.visibility = 'hidden';
if (position != 'custom') {
bigcont.style.position = 'absolute'
} else {
bigcont.style.position = 'relative'
}
var bigimg = document.createelement("img");
bigimg.id = "bim" + rand;
bigimg.src = aels[i].href;
bigcont.appendchild(bigimg);
if (position != 'custom') {
aels[i].appendchild(bigcont)
} else {
_el(aels[i].id + '-big').appendchild(bigcont)
}
var settings = {
bigimage_always_visible: bigimage_always_visible,
drag_mode: drag_mode,
header: aels[i].title,
opacity: opacity,
thumb_change: thumb_change,
position: position,
loadingtext: loadingtext,
loadingimg: loadingimg
};
var zoom = new magiczoom(aels[i].id, 'sim' + rand, bigcont.id, 'bim' + rand, settings);
aels[i].mzextend = magiczoom_extendelement;
aels[i].mzextend({
zoom: zoom
});
zoom.initzoom();
magiczoom_findselectors(aels[i].id, zoom)
}
}
};
if (magiczoom_ua == 'msie') try {
document.execcommand("backgroundimagecache", false, true)
} catch(e) {};
magiczoom_addeventlistener(window, "load", magiczoom_findzooms);