/**
 * @author Nikolai Dimitrov
 * @copyright mochanin.com
 */

function sterShowBig( parentID ) {
  var big;
  var par = document.getElementById( parentID );
  
  sterHideBig();
  
  big = sterCreateBig(par.src);
  sterPositionBig(par, big);
  
  document.body.appendChild(big);
}

function sterHideBig() {
	var big = document.getElementById('sterBig');
	
	if (big !== null)
		document.body.removeChild(big);
}

function sterCreateBig(img) {
	var big = document.createElement('DIV');
	
	big.id = 'sterBig';
	big.className = 'sterBig';
	
	if (big.addEventListener) {
    big.addEventListener('mouseout', sterHideBig, true);
	}
  else {
    big.onmouseout = sterHideBig;
  }
	
	// Put the image
	big.innerHTML = '<img src="'+ img +'" alt="Big image" border="0">';
	
	return big;
}

function sterPositionBig(bParent, big) {
	var left = sterFindLeft(bParent);
	var top = sterFindTop(bParent);
	
	big.style.left = left +"px";
	big.style.top = top +"px";
}

function sterFindLeft(bParent) {
	var out = 0;
	
	do {
		out += bParent.offsetLeft;
		bParent = bParent.offsetParent;
	} while(bParent !== null);
	
	return out;
}

function sterFindTop(bParent) {
	var out = 0;
	
	do {
		out += bParent.offsetTop;
		bParent = bParent.offsetParent;
	} while(bParent !== null);
	
	return out;
}
