if($("popup")){

function getPageScroll() {
var x,y;
if (self.pageYOffset) {// all except Explorer
x = self.pageXOffset;
y = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {// Explorer 6 Strict
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
} else if (document.body) {// all other Explorers
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
return {x: x, y: y};
}

function showImage(id,img,title) {
$('popup').style.display = 'none';
$('pp_image').src = '/images/no.gif';
$('pp_image').src = img;//style.backgroundImage = 'url(/images/galleries/images/'+ img+')';
$('pp_image').onload = function() {document.getElementById('popup').style.display = 'block';};
//document.getElementById('popuplink').href='/galleries/images/'+id+'?show=';
document.getElementById('popuptitle').innerHTML = (title) ? title : "";

var top = Cookie.get('imgWinTop');
var left = Cookie.get('imgWinLeft');
var sc = getPageScroll();

if (parseInt(top) > 0 && !isNaN(parseInt(top)) && parseInt(left) > 0 && !isNaN(parseInt(left))) {
document.getElementById('popup').style.top = parseInt(top) + parseInt(sc.y) + 'px';
document.getElementById('popup').style.left = left+'px';
} else {
document.getElementById('popup').style.top = parseInt(sc.y)-341+'px';
document.getElementById('popup').style.left = '50px';
}
return false;
}


new Draggable('popup',{
snap: function(x,y,draggable) {
function constrain(n, lower, upper) {
if (n > upper) return upper;
else if (n < lower) return lower;
else return n;
}

element_dimensions = Element.getDimensions(draggable.element);
parent_dimensions = Element.getDimensions($('main'));
return[
constrain(x, 0, parent_dimensions.width - element_dimensions.width),
constrain(y, -341, parent_dimensions.height - element_dimensions.height-341)];
},
onEnd:function(){
var sc = getPageScroll();
Cookie.set('imgWinTop',parseInt($('popup').style.top)-parseInt(sc.y),{path: '/'});
Cookie.set('imgWinLeft',parseInt($('popup').style.left),{path: '/'}) },
revert:false
});
}