var MoveFollow = (function(){
var global = this;
var theInterface = {
getPageX:function(){
return (((readScroll.scrollLeft|0) -
(readScroll.clientLeft|0)) + x);
},
getPageY:function(){
return (((readScroll.scrollTop|0) -
(readScroll.clientTop|0)) + y);
},
getPageXY:function(){
return {x:this.getPageX(),y:this.getPageY()};
},
getTarget:function(){
return lastTarget;
},
upDate:function(ev){
mm(ev);
}
};
var x = 0, y = 0;
var readScroll = {scrollTop:0,scrollLeft:0,
clientLeft:0,clientTop:0};
var lastTarget = null;
var posReadX = 'pageX';
var posReadY = 'pageY';
function mm(e){
e = e||global.event;
x = e[posReadX];
y = e[posReadY];
lastTarget = e.target||e.srcElement;
if (desc_div = document.getElementById('descDiv')){
	desc_div.style.top = (theInterface.getPageY()+20)+'px';
	desc_div.style.left = (theInterface.getPageX())+'px';
}
}
function initEvent(ev){
if(document.body){ //Not safe to configure until the
//BODY exists in the DOM.
ev = ev||global.event;
if(ev){
if(typeof ev.pageX != 'number'){ //Opera 7 has pageX
posReadX = 'clientX';
posReadY = 'clientY';
if((typeof document.compatMode == 'string')&&
(document.compatMode.indexOf('CSS') != -1)&&
(document.documentElement)){
readScroll = document.documentElement;
}else if((document.body)&&(!global.opera)){
//Not an Opera <= 6 browser (becaue its
//clientX/Y are page-relative already).
readScroll = document.body;
}
}
setUpOnMouse(mm);
mm(ev);
}
}
}
function setUpOnMouse(f){
if(document.onmousemove != f){
document.onmousemove = f;
if((document.captureEvents)&&(global.Event)&&
(document.layers)&&(typeof Layer == 'function')){
//Netscape 4 *only* (or probably harmless in context)
document.captureEvents(Event.MOUSEMOVE);
/* captureEvents on Netscape 6+/Mozila/Gecko would
cause all move events to be processed in the
capturing phase in addition to when they arrived
at the target. There is no reason to be
processing the same event twice (and good reasons
for avoiding doing so).
*/
}
}
}
setUpOnMouse(initEvent); // Attach initEvent as the initial
// mousemove handler.
return (function(){
return theInterface;
});
})();

document.onclick = function(){
	if (o = document.getElementById('search_keywords')){
		o.style.display = 'none';
	}	
	if (o = document.getElementById('search_where')){
		o.style.display = 'none';
	}
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function checkData(){
	if (!((document.getElementById('input_where').value.length == 0) && (document.getElementById('input_keywords').value.length == 0))){
		document.search_form.submit();
	}
}

function showPosition(elem){
	if (elem.checked){
		document.getElementById('homepage_pos').style.display = 'inline';
	}
	else{
		document.getElementById('homepage_pos').style.display = 'none';
	}
}

function setValue(what, val){
	if (o = document.getElementById('input_'+what)){
		o.value = val;
	}
}

function completeauto(o, what){
	var val = o.value;
	if (val.length > 0){
		if (o = document.getElementById('preload_img')){
			o.style.display = 'block';
		}
		xajax_autoComplete(val, what);
	}
	else{
		if (o = document.getElementById('search_'+what)){
			o.style.display = 'none';
		}
	}
}

function bgBlue(o){
	o.style.background='#6699CC';
}

function showDesc(id, cat){
	xajax_setInfo(id, cat);
	if (divas = document.getElementById('descDiv')){
		divas.style.display='block';
	}
}

function bgGrey(o){
	o.style.background='#ECECEC';
	if (divas = document.getElementById('descDiv')){
		divas.style.display='none';
		divas.innerHTML='<div style="width:100%; text-align:center;"><img src="http://www.catalog.ie/public/frontend/images/desc_loader.gif" border="0" /></div>';
	}
}

function bgRed(o){
	o.style.background='#FF9900';
}

function moveDiv(o, link, id){
	var pos = findPos(o);
	layer = $('countFlash');
	layer.setAttribute('style', 'top: ' + pos[1] + 'px; left: ' + (pos[0]+10) + 'px;');
	layer.setAttribute('href', link);
	layer.onmouseover = function() { bgBlue(o.parentNode); showDesc(id); };
	layer.onmouseout = function() { bgGrey(o.parentNode); };
	layer.onclick = function() { xajax_countClick(id); };
	//removeEvent(layer,"click", function() { xajax_countClick(id); });
	//addEvent(layer, "click", function() { xajax_countClick(id); });
}

function setContHeight(){
    var a = window.location.href.split("//");
    a = (a[1] ? a[1] : a[0]).split("/");
    var obj = $('table_content');
    if (a[2] == 'content' && obj){
	c_height = $('banners').getHeight();
	vp_height = document.viewport.getHeight() - 183;
	if (c_height < vp_height){
	    obj.setStyle({
		height: vp_height + 'px'
	    });
	}
    }
}

document.observe('dom:loaded', setContHeight);
Event.observe(window, 'resize', setContHeight);