/******
*
*
*/


/**
* Create element
**/
function $E(data) {
    var el;
    if ('string'==typeof data) {
        el=document.createTextNode(data);
    } else {
        //create the element
        el = document.createElement(data.tag);
        delete(data.tag);
        //append the children
        if ('undefined' != typeof data.children) {
            if ('string' == typeof data.children || 'undefined'==typeof data.children.length) {
                //strings and single elements
                el.appendChild($E(data.children));
            } else {
                //arrays of elements
                for (var i=0, child=null; 'undefined' != typeof (child=data.children[i]); i++) {
                    el.appendChild($E(child));
                }
            }
            delete(data.children);
        }

        //any other data is attributes
        for (attr in data){ 
			el[attr] = data[attr];
        }
    }
		
    return el;
}


function mouseMove(ev){
	ev           = ev || window.event;
	return mousePos = mouseCoords(ev);
}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft),
		y:ev.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)
	};
}

function getWindowWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
 
function getWindowHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function imOn(el, photo){
	
	var ElPosition = Position.cumulativeOffset(el);
	var windowHeight = getWindowHeight();
	var ImContainer = {
			tag:'div',
			id: 'ROIMG',
			className:'ROIMG',
			children:[{
					 	tag:'img',
						src:photo
					 }]
		}
	if( !$('ROIMG')){
		document.body.appendChild($E( ImContainer ) );
	}
		
	Event.observe(el, 'mousemove', function(event) {
		var pos = mouseMove(event);
		if( $('ROIMG') ){	
			$('ROIMG').style.left = parseInt( pos.x - 200 )+'px'; 
			if( parseInt( ElPosition[1] + 285 ) < getWindowHeight() ){
				$('ROIMG').style.top = parseInt(pos.y + 35)+'px';
			}else{
				$('ROIMG').style.top = parseInt(pos.y - 200)+'px';
			}
			$('ROIMG').style.display = 'block';
		}
	});
	return true;
}

function imOff(){
	$('ROIMG').remove();
	}
	

