// Popup windows and css window management javascrip
// Copyright 2007 Critical Pursuits, All Rights Reserved.

var htmlbase = "/";

function openPopup(url) {
    var w = window.open(htmlbase + 'popup.html?' + url,
			"Details","menubar=0,resizable=1,width=800,height=600,status=no,titlebar=no,toolbar=yes");
    w.focus();
}

function openNewsgroup(search) {
    openPopup("http://groups.google.com/groups?q=" + search)
}
	
var note;		// Note currently displayed
var hide;		// Hide note timeout

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 showNote(e, l) {
    var d=document.getElementById(l.id+"_def");
    clearHide();
    if (note != d) { hideNote() }
    note = d;
    var p = findPos(l);
    note.style.left=p[0]+"px";
    note.style.top=p[1]+30+"px";
    note.style.visibility='visible';
}

function keepNote(n) {
    if (note == n) { clearHide() }
}

function clearHide() {
    if (hide) {
	clearTimeout(hide);
	hide = null;
    }
}

function outNote(e) {
    hide = setTimeout("hideNote()", 750);
}

function hideNote() {
    if (note) {
	note.style.visibility='hidden';
	note = null;
    }
}

function showmarks() {
	var tagnum = 0;
	var mark;
	while (mark = document.getElementById('mark'+tagnum)) {
		var p = findPos(mark);
		var tag = document.getElementById('tag'+tagnum);
		tag.style.left=p[0]+"px";
		tag.style.top=p[1]+"px";
		tag.style.visibility='visible';
		tagnum++;
	}
}			   

function findMarkPos(mark, tag) {
	var p = findPos(mark);
	var h=tag.offsetHeight; var w=tag.offsetWidth;
	var x = p[0]; var y = p[1];
	var tagnum = 0;
	var t;	
	while (t = document.getElementById('tag'+tagnum++)) {
		if (t.style.visibility == 'visible') {
			var q = findPos(t);
			var x2 = q[0]; var y2 = q[1]; var h2=t.offsetHeight; var w2=t.offsetWidth;
//alert(x+','+y+','+h+','+w+'    '+x2+','+y2+','+h2+','+w2);
			if (y+h > y2 && y < y2+h2 && x+w > x2 && x < x2+w2) {
//alert('overlap');				
				y = y2-h;
				p[1] = y;
			}
		}
	}
	return p;
}			   

function showmark(mark, num) {
	tag = document.getElementById('tag'+num);
	var p = findMarkPos(mark, tag);
	tag.style.left=p[0]+"px";
	tag.style.top=p[1]+"px";
	tag.style.visibility='visible';
}	

function hidemark(num) {
	tag = document.getElementById('tag'+num);
	tag.style.visibility='hidden';
}

function ascDomain() {
    return 'assoc-' + aDomain();
}

function aDomain() {
    e = 'zon'+'.com';    
    return 'ama'+e;
}

function aFrame(project) {
    as = '<iframe src="http://rcm.'+aDomain()+'/e/cm?t='+project+'-20&o=1&p=20&l=qs1&f=ifr" width="120" height="90" frameborder="0" scrolling="no"></iframe>';    
    document.writeln(as);
}

function aTrack(project) {
    at = '<img src="http://www.'+ascDomain()+'/e/ir?t='+project+'&amp;l=ur2&amp;o=1" width="1" height="1" border="0" style="border:none !important; margin:0px !important;" />';
    document.writeln(at);
}

function aImg(url) {
    return 'http://ecx.images-amazon.com' + url;
}
