$(document).ready(function() {
	
	$("#ActivePictureFrame").click(
	function() {
		var c = document.getElementById('ActivePictureFrame');
		c.style.left='-200px';
		c.style.top='-200px';
		
		$("#ActivePicture").html("Loading ...");
	});
	
	$(".GalleryPicture").click(
	function() {
		// load preloader
		$("#ActivePicture").html("Loading ...");
		
		var myPicture = $(this).attr("id");
		var lgPicture = $(this).attr("rel");
		
		//alert(myPicture);
		//alert(lgPicture);
		
		var c = document.getElementById('ActivePictureFrame');
		var x = findPosX(document.getElementById(myPicture))+0;
		var y = findPosY(document.getElementById(myPicture))+0;
		
		c.style.left=x+'px';
		c.style.top=y+'px';
		
		$("#ActivePicture").html("<img src='_images/gallery/"+lgPicture+"'>");
	});
});

// position of element on screen
function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    //alert('X: '+curleft);
	return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    //alert('Y: '+curtop);
	return curtop;
}
