/// Non-Javascript users see old style 'add to list' link
isbn_post_str = '';
function create_add_link(isbn,override)
{
	div_id = "add_"+isbn;

	mouseeffect = 'onmouseover="this.src=\'http://images.booksfree.com/images/new/add_button_on.jpg\';" onmouseout="this.src=\'http://images.booksfree.com/images/new/add_button.jpg\';"';

	if(override !== undefined)
	{
		// 1 is add button
		if(override == 1)
		{
			add_button = '<a style="cursor: pointer" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'\', \'float_div\');"><img src="http://images.booksfree.com/images/new/add_button.jpg" ' + mouseeffect + ' alt="Add" border="0" height="22" width="92" /></a>';
		}
		// 2 is in queue
		else if(override == 2)
		{
			add_button = '<img src="http://images.booksfree.com/images/new/in_queue.jpg" alt="In Queue" border="0" height="22" width="92" />';
		}

		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
	}
	// go to the server to decide which button to display
	else
	{
		isbn_post_str += isbn + "^";
		add_button = '<a style="cursor: pointer" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'\', \'float_div\');"><img ' + mouseeffect + ' src="http://images.booksfree.com/images/new/add_button.jpg" alt="Add" border="0" height="22" width="92" /></a>';
		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
		myRequest.queuePost('/php/mp3/check_book', 'is_in_queue='+isbn, div_id);
	}
}

function create_save_link(isbn,override)
{
	div_id = "add_"+isbn;

	if(override !== undefined)
	{
		// 1 is add button
		if(override == 1)
		{
			add_button = '<a style="cursor: pointer" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'\', \'float_div\');"><img src="http://images.booksfree.com/images/new/save_button.jpg" alt="Save" border="0" height="22" width="92" /></a>';
		}
		// 2 is in queue
		else if(override == 2)
		{
			add_button = '<img src="http://images.booksfree.com/images/new/in_queue.jpg" alt="In Queue" border="0" height="22" width="92" />';
		}

		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
	}
	// go to the server to decide which button to display
	else
	{
		isbn_post_str += isbn + "^";
		add_button = '<a style="cursor: pointer" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'\', \'float_div\');"><img src="http://images.booksfree.com/images/new/save_button.jpg" alt="Save" border="0" height="22" width="92" /></a>';
		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
		//myRequest.queuePost('/php/cds/check_book', 'is_in_queue='+isbn, div_id);
	}
}

function create_add_link_rec(isbn,override)
{
	div_id = "add_"+isbn;

	if(override !== undefined)
	{
		// 1 is add button
		if(override == 1)
		{
			add_button = '<a style="cursor: pointer;" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'&button=small\', \'float_div\');"><img style="padding-top:4px;" src="http://images.booksfree.com/images/new/add_button_small.jpg" alt="Add" border="0" height="18"  width="56" /></a>';
		}
		// 2 is in queue
		else if(override == 2)
		{
			add_button = '<img style="padding-top:4px;" src="http://images.booksfree.com/images/new/in_q.jpg" alt="In Queue" border="0" height="18" width="56" />';
		}

		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
	}
	// go to the server to decide which button to display
	else
	{
		add_button = '<a style="cursor: pointer;" onClick="myRequest.queuePost(\'/cgi-bin/mp3_pop_queue.cgi\', \'isbn='+isbn+'&button=small\', \'float_div\');"><img style="padding-top:4px;" src="http://images.booksfree.com/images/new/add_button_small.jpg" alt="Add" border="0" height="18"  width="56" /></a>';
		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = add_button;
		//myRequest.queuePost('/php/cds/check_book', 'small_button=1&is_in_queue='+isbn, div_id);
	}
}

//favorite authors popup
function create_fa_link(author_id, override, atf_num)
{
	div_id = "fa_"+author_id;

	if(override !== undefined)
	{
		// 1 is add button
		if(override == 1)
		{
			fa_button = '<a style="margin-left:10px; text-decoration: none;cursor: pointer;" onClick="myRequest.queuePost(\'/cgi-bin/mp3_add_fa.cgi\', \'add='+author_id+'\', \'float_div\'); create_fa_link(\''+author_id+'\', \'2\');"><img src="http://images.booksfree.com/images/add_to_favorite_authors.jpg" alt="Add to Favorite Authors" width="154px" height="18px" border="0" align=\"absmiddle\" /></a>';
		}
		// 2 is in favorite authors already
		else if(override == 2)
		{
			fa_button = '<img src="http://images.booksfree.com/images/added_to_favorite_authors.jpg" alt="Added to Favorite Authors" border="0" width="169px" height="18px" align=\"absmiddle\" style="margin-left:10px;" />';
		}
		// 3 is auto_add
		else if(override == 3)
		{
			fa_button = '<img src="http://images.booksfree.com/images/set_to_auto_adding.jpg" alt="Set to Auto Adding" border="0" width=\"160px\" height=\"22px\">';
			div_id = "auto_"+author_id;
		}
		// 4 is for text only, no image
		if(override == 4)
		{
			fa_button = '<a style="font-size: 8pt; text-decoration: underline; color: #003399; cursor: pointer;" onClick="myRequest.queuePost(\'/cgi-bin/mp3_add_fa.cgi\', \'add='+author_id+'\', \'float_div\'); create_fa_link(\''+author_id+'\', \'5\', \''+atf_num+'\');">(add to favorites)</a>';
			div_id = "atf_"+atf_num;
		}
		// 5 is in favorite authors already for text only, no image
		else if(override == 5)
		{
			fa_button = '(added to favorites)';
			div_id = "atf_"+atf_num;
		}

		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = fa_button;
	}
	// go to the server to decide which button to display
	else
	{
		// default to add button
		isbn_post_str += author_id + "^";
		fa_button = '<a style="margin-left:10px; text-decoration: none;cursor: pointer;" onClick="myRequest.queuePost(\'/mp3_cgi-bin/add_fa.cgi\', \'add='+author_id+'\', \'float_div\'); create_fa_link(\''+author_id+'\', \'2\');"><img src="http://images.booksfree.com/images/add_to_favorite_authors.jpg" alt="Add to Favorite Authors" width="154px" height="18px" border="0" align=\"absmiddle\" /></a>';
		if(document.getElementById(div_id)) document.getElementById(div_id).innerHTML = fa_button;
		//myRequest.queuePost('/php/check_book', 'is_in_queue='+isbn, div_id);
	}
}

function create_ship_next_link(isbn,image_url)
{
	div_id = "ship_next_"+isbn;
	ship_next = "Ship Next";
	if (image_url == "shipping_next.gif") { ship_next = "Shipping Next"; }
	newLink = '<a style="cursor: pointer" onClick="myRequest.queuePost(\'/cgi-bin/ship_next.cgi\', \'section=mp3&isbn='+isbn+'\', \''+div_id+'\');"><img src="http://images.booksfree.com/images/new/'+image_url+'" alt="'+ship_next+'" width="75" height="20" border="0"/></a>';
	document.getElementById(div_id).innerHTML = newLink;
}

//image rollover
function swapimages(which1,what1,which2,what2,which3,what3,which4,what4,which5,what5,which6,what6){
if (document.getElementById(''+which1+'')){
	document.getElementById(''+which1+'').src=''+what1+'';
}
if (document.getElementById(''+which2+'')){
	document.getElementById(''+which2+'').src=''+what2+'';
}
if (document.getElementById(''+which3+'')){
	document.getElementById(''+which3+'').src=''+what3+'';
}
if (document.getElementById(''+which4+'')){
	document.getElementById(''+which4+'').src=''+what4+'';
}
if (document.getElementById(''+which5+'')){
	document.getElementById(''+which5+'').src=''+what5+'';
}
if (document.getElementById(''+which6+'')){
	document.getElementById(''+which6+'').src=''+what6+'';
}
}

// higlight a table row.
function HighlightRowIfChecked(checkBox){
    var bgColor = checkBox.checked ? "#D9DDEF" : "";
    var el = checkBox.parentNode;
    while(el.tagName.toLowerCase() != "tr"){
        el = el.parentNode;
    }
    el.style.backgroundColor = bgColor;
}

//table row toggle
function toggle(id) {
	if(document.getElementById(id).style.display=='block')
		{
		document.getElementById(id).style.display='none';
		document.getElementById(id).style.visibility='hidden';
		//alert('Its hidden now');
		}
	else
		{
		document.getElementById(id).style.display='block';
		document.getElementById(id).style.visibility='visible';
		//alert('Its displaying now');
		}
}

// search stuff

function textClear (input) { if ( input.value == input.defaultValue ) { input.value = ""; } }
function textRestore (input) { if ( input.value == "" ) { input.value = input.defaultValue;	} }


function JSFX_FloatTopDiv(div_name)
{
}

// Long-in stuff

function textClear (input)
{
	if ( input.value == input.defaultValue )
	{
		input.value = "";
	}
}
function textRestore (input)
{
	if ( input.value == "" )
	{
		input.value = input.defaultValue;
	}
}

 function changeBox()
 {
    document.getElementById('div1').style.display='none';
    document.getElementById('div2').style.display='';
    document.getElementById('password').focus();
 }
 function restoreBox()
 {
    if(document.getElementById('password').value=='')
    {
      document.getElementById('div1').style.display='';
      document.getElementById('div2').style.display='none';
    }
 }


 function getUrl(url) {
 var http = new XMLHttpRequest();
 http.open("GET",url,false);
 http.send("");
 return http.responseText;
 }

 dateobj = new Date();
 last_type = dateobj.getTime();
 flat_file = "";
 blockBlur = false;

 function filterText(sText) {
 	var reBadWords = /"|'/gi;
 	return sText.replace(reBadWords, function (sMatch) {
 		return sMatch.replace(/./g, "*");
 	});
 }

 function show_autosuggest()
 {
 	document.getElementById('autosuggestresults').style.display = 'block';
 }

 function hide_autosuggest_maybe()
 {
 	if(!blockBlur)
 	{
 		document.getElementById('autosuggestresults').style.display = 'none';
 	}
 	blockBlur = false;
 }

 function hide_autosuggest()
 {
 	autosuggestobj = document.getElementById('autosuggestresults');
 	autosuggestobj.innerHTML = '';
 	autosuggestobj.style.backgroundColor = '';
 	autosuggestobj.style.width = '';
 	autosuggestobj.style.padding = '';
 	autosuggestobj.style.lineHeight = '';
 	autosuggestobj.style.border = '';
 }
 		flat_file = getUrl('/autosuggest_mp3.txt');
 function getautosuggest(value)
 {
 	autosuggestobj = document.getElementById('autosuggestresults');

 	if(value == "")
 	{
 		hide_autosuggest();
 		return;
 	}

 	if(document.getElementById('searchInput').value !== value)
 	{
 		return;
 	}


 	if(!flat_file)
 	{
 		flat_file = getUrl('/autosuggest_mp3.txt');
 		setTimeout("getautosuggest('" + value + "');", 1000);
 		hide_autosuggest();
 		return false;
 	}

 	value = filterText(value);
 	var newhtml = "";

 	myRE = new RegExp(value, "ig");

 	arr_flat = flat_file.split('\n');

 	count = 0;
 	for(x=0; x<arr_flat.length; x++)
 	{
 		results = arr_flat[x].match(myRE);
 		if(results)
 		{
 			newhtml = newhtml + "<div style='margin-bottom:8px;'><a onmousedown='blockBlur=true;' class='bluelink' href='http://www.booksfree.com/cgi-bin/mp3_search.cgi?searchTypeId=keyword&searchInput=" + escape(arr_flat[x]) + "'>" + arr_flat[x] +  "</a></div>";
 			//newhtml = newhtml + arr_flat[x] + "<br />";
 			count++;
 			if(count > 10)
 			{
 				break;
 			}
 		}
 	}

 	if(newhtml == "")
 	{
 		//hide_autosuggest();
 		return;
 	}

	autosuggestobj = document.getElementById('autosuggestresults');
	autosuggestobj.innerHTML = newhtml;
	autosuggestobj.style.backgroundColor = '#FFFFFF';
	autosuggestobj.style.width = '249px';
	autosuggestobj.style.padding = '5px';
	autosuggestobj.style.marginLeft = '5px';
	autosuggestobj.style.border = '1px solid #999999';
 }

 // DH 2009-07-15 automatically display sign in or out link
function sign_in_out()
{
	if(typeof(document.getElementById('sign_in_out')) != "undefined" && document.getElementById('sign_in_out'))
	{
		sign_in_out = document.getElementById('sign_in_out');
		signed_in = 0;

		var ck_name=new Array(12)
		ck_name[0]="BFmem";
		ck_name[1]="BFcdmem";
		ck_name[2]="BFmp3mem";
		ck_name[3]="BFcombo";
		ck_name[4]="BFkids";
		ck_name[5]="BFmemsession";
		ck_name[6]="BFcdmemsession";
		ck_name[7]="BFmp3memsession";
		ck_name[8]="BFcombosession";
		ck_name[9]="BFkidssession";
		ck_name[10]="BFalacarte";
		ck_name[11]="BFalacartesession";

		var x=0;
		for(x=0; x<12; x++)
		{
			if(signed_in != 1) {
				var ck_data = readCookie(ck_name[x]);
				if(ck_data != '000' && ck_data){signed_in = 1;} // they are signed in, or at least are pretending to be
			}
		}

		if(signed_in)
		{
		sign_in_out.href= "http://www.booksfree.com/cgi-bin/logout.cgi";
		sign_in_out.innerHTML = "Sign Out";
		}
		else
		{
		sign_in_out.href= "https://www.booksfree.com/cgi-ssl/login.cgi";
		sign_in_out.innerHTML = '<span style="padding-left:5px;">Sign In</span>';
		}
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload=function()
{
	sign_in_out();
	// add more functions if necessary
}
dropdowns = [];
function delay(el,grp)
{
	// the delay has already occured, do not do it again
	if(window['delay_setting_'+el] == 1)
	{
		return true;
	}
	// not occured yet, start the delay
	else
	{
		window['delay_setting_'+el] = 1;
		if(grp=="fb"){
		window['dropdown_timeout_'+el] = setTimeout("if(delay('"+el+"','"+grp+"')){show_dropdown('"+el+"','"+grp+"');}",100);
		}
		else{
		window['dropdown_timeout_'+el] = setTimeout("if(delay('"+el+"','"+grp+"')){show_dropdown('"+el+"','"+grp+"');}",600);
		}
		return false;
	}
}

function show_dropdown(el,grp)
{
alert('This is what an alert message looks like.');


	//one dropdown at a time !
	for(dropdown in dropdowns)
	{
		if(document.getElementById(dropdown+"_popup")){	document.getElementById(dropdown+"_popup").style.display = 'none';}
	}
	dropdowns[el] = el;
	window['delay_setting_'+el] = 1;
	window['block_dropdown_hide_'+el] = 1;
	dropdown_el = document.getElementById(el+"_dropdown");
	dropdown_el.style.visibility = 'hidden';
	dropdown_el.style.display="block";

	if(document.getElementById(el+"_image"))
	{
		image_el = document.getElementById(el+"_image");
		image_el.src=image_el.src.replace('_over','');
		image_el.src=image_el.src.replace('.jpg','_over.jpg');
	}
	if(document.getElementById(el+"_popup_content"))
	{

				if(grp=="fb"){
				alert(grp);
				arr_pos = findPos(document.getElementById(el));
				leftPos = arr_pos[0];
				document.getElementById(el+"_popup").style.left = leftPos - 283;
		}
		leftPos = 0;
		topPos = 0;
		popup_el = document.getElementById(el+"_popup_content");
		popup_el.style.display='block';
		document.getElementById(el+"_popup").style.display='block';

		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];
		arr_scroll = getScrollXY();
		arr_size = getSize();
		scroll_top = arr_scroll[1];
		win_height = arr_size[1];
		new_top = Math.round((popup_el.scrollHeight/2))-10;
		new_top = -(new_top);
		popup_el.style.top = new_top+"px";
		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];



		// move up if too close to the bottom of the screen
		if(topPos+(popup_el.scrollHeight)-scroll_top > win_height)
		{
			//document.getElementById(el+"_call_out").style.top="-10px";
			do
			{
				arr_pos = findPos(popup_el);
				topPos = arr_pos[1];
				new_top -=10;
				popup_el.style.top = new_top+"px";
			}
			while(topPos+(popup_el.scrollHeight)-scroll_top > win_height);
		}

		// move the popup down if too close to top of screen
		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];
		if(topPos+new_top < scroll_top+(document.getElementById(el).scrollHeight/2.5))
		{
			do
			{
				arr_pos = findPos(popup_el);
				topPos = arr_pos[1];
				new_top +=10;
				popup_el.style.top = (new_top)+"px";
			}
			while(topPos+new_top < scroll_top+(document.getElementById(el).scrollHeight/2.5));
		}

		arr_popup_pos = findPos(document.getElementById(el));
		popup_el_top = arr_popup_pos[1];

		//hide the call out if too close to the bottom of the screen
		if(scroll_top + win_height - popup_el_top < 100 || topPos-scroll_top < 35)
		{
			document.getElementById(el+"_call_out").style.visibility='hidden';
		}
		else
		{
			document.getElementById(el+"_call_out").style.visibility='visible';
		}

		//popup_el.style.left = document.getElementById(el).offsetWidth+"px";

	}
	dropdown_el.style.visibility = 'visible';

}
function delay_hide_dropdown(el)
{
	window['block_dropdown_hide_'+el]=0;
	setTimeout("hide_dropdown('"+el+"')",300);
}
function hide_dropdown(el)
{
	if(window['block_dropdown_hide_'+el]) return false;
	clearTimeout(window['dropdown_timeout_'+el]);
	window['block_dropdown_hide_'+el] = 0;
	window['delay_setting_'+el] = 0;
	dropdown_el = document.getElementById(el+"_dropdown");

	if(document.getElementById(el+"_image"))
	{
		image_el = document.getElementById(el+"_image");
		image_el.src=image_el.src.replace('_over','');
	}
	dropdown_el.style.display='none';
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
return [myWidth,myHeight];
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
return [myWidth,myHeight];
}

dropdowns = [];
function delay(el,grp)
{
	// the delay has already occured, do not do it again
	if(window['delay_setting_'+el] == 1)
	{
		return true;
	}
	// not occured yet, start the delay
	else
	{
		window['delay_setting_'+el] = 1;
		window['dropdown_timeout_'+el] = setTimeout("if(delay('"+el+"','"+grp+"')){show_dropdown('"+el+"','"+grp+"');}",1000);
		return false;
	}
}

function show_dropdown(el, grp)
{
	//one dropdown at a time !
	for(dropdown in dropdowns)
	{
		if(document.getElementById(dropdown+"_popup")){	document.getElementById(dropdown+"_popup").style.display = 'none';}
	}
	dropdowns[el] = el;
	window['delay_setting_'+el] = 1;
	window['block_dropdown_hide_'+el] = 1;
	dropdown_el = document.getElementById(el+"_dropdown");
	dropdown_el.style.visibility = 'hidden';
	dropdown_el.style.display="block";

	if(document.getElementById(el+"_image"))
	{
		image_el = document.getElementById(el+"_image");
		image_el.src=image_el.src.replace('_over','');
		image_el.src=image_el.src.replace('.jpg','_over.jpg');
	}
	if(document.getElementById(el+"_popup_content"))
	{

				if(grp=="fb"){
				arr_pos = findPos(document.getElementById(el));
				leftPos = arr_pos[0];
				document.getElementById(el+"_popup").style.left = leftPos - 283;
		}
		leftPos = 0;
		topPos = 0;
		popup_el = document.getElementById(el+"_popup_content");
		popup_el.style.display='block';
		document.getElementById(el+"_popup").style.display='block';

		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];
		arr_scroll = getScrollXY();
		arr_size = getSize();
		scroll_top = arr_scroll[1];
		win_height = arr_size[1];
		new_top = Math.round((popup_el.scrollHeight/2))-10;
		new_top = -(new_top);
		popup_el.style.top = new_top+"px";
		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];



		// move up if too close to the bottom of the screen
		if(topPos+(popup_el.scrollHeight)-scroll_top > win_height)
		{
			//document.getElementById(el+"_call_out").style.top="-10px";
			do
			{
				arr_pos = findPos(popup_el);
				topPos = arr_pos[1];
				new_top -=10;
				popup_el.style.top = new_top+"px";
			}
			while(topPos+(popup_el.scrollHeight)-scroll_top > win_height);
		}

		// move the popup down if too close to top of screen
		arr_pos = findPos(popup_el);
		topPos = arr_pos[1];
		if(topPos+new_top < scroll_top+(document.getElementById(el).scrollHeight/2.5))
		{
			do
			{
				arr_pos = findPos(popup_el);
				topPos = arr_pos[1];
				new_top +=10;
				popup_el.style.top = (new_top)+"px";
			}
			while(topPos+new_top < scroll_top+(document.getElementById(el).scrollHeight/2.5));
		}

		arr_popup_pos = findPos(document.getElementById(el));
		popup_el_top = arr_popup_pos[1];

		//hide the call out if too close to the bottom of the screen
		if(scroll_top + win_height - popup_el_top < 100 || topPos-scroll_top < 35)
		{
			document.getElementById(el+"_call_out").style.visibility='hidden';
		}
		else
		{
			document.getElementById(el+"_call_out").style.visibility='visible';
		}

		//popup_el.style.left = document.getElementById(el).offsetWidth+"px";

	}
	dropdown_el.style.visibility = 'visible';

}
function delay_hide_dropdown(el)
{
	window['block_dropdown_hide_'+el]=0;
	setTimeout("hide_dropdown('"+el+"')",300);
}
function hide_dropdown(el)
{
	if(window['block_dropdown_hide_'+el]) return false;
	clearTimeout(window['dropdown_timeout_'+el]);
	window['block_dropdown_hide_'+el] = 0;
	window['delay_setting_'+el] = 0;
	dropdown_el = document.getElementById(el+"_dropdown");

	if(document.getElementById(el+"_image"))
	{
		image_el = document.getElementById(el+"_image");
		image_el.src=image_el.src.replace('_over','');
	}
	dropdown_el.style.display='none';
}

