/* HEY! THIS SCRIPT ASSUME AJAX.js WAS ALREADY LOADED */

function get_radio_value(elid)
{
for (var i=0; i < document.getElementById(elid).length; i++)
   {
 	  if (document.getElementById(elid)[i].checked)
      {
      	return document.getElementById(elid)[i].value;
      }
   }
}


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 tab_out(el)
{
	document.getElementById(el.id+"_link").className = document.getElementById(el.id+"_link").className.replace(/highlight/, '');
}
function tab_over(el)
{
	document.getElementById(el.id+"_link").className = document.getElementById(el.id+"_link").className + " highlight";
}

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+"');}",0);
		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"))
	{
			leftPos = 0;
			topPos = 0;
				if(grp=="slide"){
					 document.getElementById(el+"_dropdown").style.left = leftPos;
					 document.getElementById(el+"_dropdown").style.top = leftPos;
				
		
		}

		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];
		popup_el_left = arr_popup_pos[0];

		//hide the call out if too close to the bottom of the screen
		if(scroll_top + win_height - popup_el_top < 75 || topPos-scroll_top < 35)
		{
			document.getElementById(el+"_call_out").style.display='none';
		}
		else
		{
			document.getElementById(el+"_call_out").style.display='block';
		}
		//this group sets the corresponding absolute positioned popup's position relative to position coordinates of the el for the slide sections
		if(grp=="slide"){
				//get coords of el
				arr_pos = findPos(document.getElementById(el));
				leftPos = arr_pos[0];
				//get width of jacket image for offset should work for pb and cds
				match = /^[0-9]{13}/i.exec(el)
				width = $('#jacket_'+match).outerWidth() + 4;
				//we need to subtract the distance between the parent container and the left side of the screen
				off_pos = findPos(document.getElementById('slide_container'));
				offPos = off_pos[0];							
				left = leftPos + width - offPos;
				//set the left style attribute
				dropdown_el.style.left = left+'px';
				dropdown_el.style.zIndex = '10';
		}	
		//popup_el.style.left = document.getElementById(el).offsetWidth+"px";

	}
	 



				if(navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.slice(22,25) == "7.0"){
				//FOR GOD SAKES DO NOTHING::IE7 HATES OUR POPUPS!
				}
				else{
				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 insertAfter(newElm,elm)
{
	var clone = elm.cloneNode(true);
	elm.parentNode.insertBefore(clone,elm);
	elm.parentNode.replaceChild(newElm,elm);
}

function changeOpac(opacity, id)
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function opacity(id, opacStart, opacEnd, millisec)
{
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}



function numbers_only(e,element)
{
	var keynum;
	var keychar;
	var numcheck;
	keynum = e.keyCode;
	if(keynum == 13)
	{
		onKeyPress(e,element);
	}
	if((keynum >= 48 && keynum <= 57) || (keynum >= 96 && keynum <= 105) || keynum == 8 || keynum==46 || keynum==9 || ( keynum >= 37 && keynum <= 40) || keynum==190)
	{
		return true;
	}
	return false;
}

function capWords(inputString)
{
	var outputString = ""; // The output text field
	var tmpStr, tmpChar, preString, postString, strlen;
	tmpStr = inputString.toLowerCase();
	stringLen = tmpStr.length;

	if (stringLen > 0)
	{
		for (i = 0; i < stringLen; i++)
		{
			if (i == 0)
			{
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,stringLen);
				tmpStr = tmpChar + postString;
			}
			else
			{
				tmpChar = tmpStr.substring(i,i+1);
				if (tmpChar == " " && i < (stringLen-1))
				{
				tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
				preString = tmpStr.substring(0,i+1);
				postString = tmpStr.substring(i+2,stringLen);
				tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
outputString = tmpStr;
return outputString;
}

function select_element(select_el,target_el)
{
	// find and display target
	if(document.getElementById(target_el))
	{
		target_parent_el = document.getElementById(target_el).parentNode;
		for(i=0;i<target_parent_el.childNodes.length;i++)
		{
			this_el = target_parent_el.childNodes[i];

			if(this_el.id == target_el)
			{
				this_el.style.display = "block";
			}
			else
			{
				this_el.style.display = "none";
			}
		}
	}

	// highlight this trigger, normalize others
	parent_el = document.getElementById(select_el).parentNode;
	for(x=0;x<parent_el.childNodes.length;x++)
	{
		this_el = parent_el.childNodes[x];
		if(this_el.id == select_el)
		{
			opacity(this_el.id,100,60,40);
		}
		else
		{
			opacity(this_el.id,60,100,40);
		}
	}
}

function select_pref(el)
{
	arr_id = el.id.split('_');
	new_id = "";
	for(i=0;i<arr_id.length-1;i++)
	{
		if(i == 0)
		{
			new_id += arr_id[i];
		}
		else
		{
			new_id += "_"+arr_id[i];
		}
	}

	//highlight chosen element
	document.getElementById(el.id+"_div").className = document.getElementById(el.id+"_div").className.replace("_on","");
	document.getElementById(el.id+"_div").className += "_on";
	el.checked = true;


	// unhighlight others
	new_el = document.getElementById(new_id+"_div");

	for(i=0;i<new_el.childNodes.length;i++)
	{
		this_el = new_el.childNodes[i];
		if(this_el.id !== el.id+"_div" && this_el.id) {

			this_el.className = this_el.className.replace("_on","");
		}
	}
}

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

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;
autosuggest_selected_index = 0;
num_autosuggest_results = 0;

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

function select_autosuggest(e,highlight_el)
{
	if(!e)
	{
		e = window.event;
	}
	var selected_changed = 0;

	selected_changed = 1;
	autosuggest_selected = highlight_el.id.split('_');
	autosuggest_selected_index = autosuggest_selected[2];

	if(selected_changed == 1)
	{
		autosuggest_el = document.getElementById('autosuggestresults');
		for(i=1;i<=autosuggest_el.childNodes.length;i++)
		{
			if(i == autosuggest_selected_index)
			{
				// highlight
				document.getElementById('autosuggest_result_'+i).className = "autosuggest_on";
			}
			else
			{
				// un-highlight
				document.getElementById('autosuggest_result_'+i).className = "";
			}
		}
	}
}

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.txt');
function getautosuggest(value,e)
{
	if(!e)
	{
		e = window.event;
	}
	if(e)
	{
		keynum = e.keyCode;
		if(keynum == 38 || keynum == 40)
		{
		return false;
		}
	}

	autosuggestobj = document.getElementById('autosuggestresults');

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

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


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

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

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

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

 	num_autosuggest_results = 0;
 	autosuggest_selected_index = 0;
 	for(x=0; x<arr_flat.length; x++)
 	{
 		results = arr_flat[x].match(myRE);
 		if(results)
 		{
 			num_autosuggest_results++;
 			newhtml = newhtml + "<div id=\"autosuggest_result_" + num_autosuggest_results + "\" onmouseover='select_autosuggest(event, this);' onmousedown='blockBlur=true;' onClick=\"window.location.href='/search&s=" + escape(arr_flat[x].replace(/\./g,"")) + "';\"><a id=\"autosuggest_link_" + num_autosuggest_results + "\" onmousedown='blockBlur=true;' class='bluelink' href='/search&s=" + escape(arr_flat[x].replace(/\./g,"")) + "'>" + arr_flat[x] +  "</a></div>";
 			//newhtml = newhtml + arr_flat[x] + "<br />";
 			if(num_autosuggest_results > 10)
 			{
 				break;
 			}
 		}
 	}

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

	autosuggestobj = document.getElementById('autosuggestresults');
	autosuggestobj.innerHTML = newhtml;
	autosuggestobj.style.backgroundColor = '#FFFFFF';
	autosuggestobj.style.width = '243px';
	autosuggestobj.style.padding = '0px';
	autosuggestobj.style.border = '1px solid #BBBBBB';
}

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;
}

//dropdown menu form style
function tamingselect()
{
	if(!document.getElementById && !document.createTextNode){return;}

// Classes for the link and the visible dropdown
	var ts_selectclass='turnintodropdown'; 	// class to identify selects
	var ts_listclass='turnintoselect';		// class to identify ULs
	var ts_boxclass='dropcontainer'; 		// parent element
	var ts_triggeron='activetrigger'; 		// class for the active trigger link
	var ts_triggeroff='trigger';			// class for the inactive trigger link
	var ts_dropdownclosed='dropdownhidden'; // closed dropdown
	var ts_dropdownopen='dropdownvisible';	// open dropdown
/*
	Turn all selects into DOM dropdowns
*/
	var count=0;
	var toreplace=new Array();
	var sels=document.getElementsByTagName('select');
	for(var i=0;i<sels.length;i++){
		if (ts_check(sels[i],ts_selectclass))
		{
			var hiddenfield=document.createElement('input');
			hiddenfield.name=sels[i].name;
			hiddenfield.type='hidden';
			hiddenfield.id=sels[i].id;
			hiddenfield.value=sels[i].options[0].value;
			sels[i].parentNode.insertBefore(hiddenfield,sels[i])
			var trigger=document.createElement('a');
			ts_addclass(trigger,ts_triggeroff);
			trigger.href='javascript:void(0);';
			trigger.style.color = "#777777";
			trigger.onclick=function(){
				ts_swapclass(this,ts_triggeroff,ts_triggeron)
				ts_swapclass(this.parentNode.getElementsByTagName('ul')[0],ts_dropdownclosed,ts_dropdownopen);
				return false;
			}
			trigger.appendChild(document.createTextNode(sels[i].options[0].text));
			sels[i].parentNode.insertBefore(trigger,sels[i]);
			var replaceUL=document.createElement('ul');
			for(var j=0;j<sels[i].getElementsByTagName('option').length;j++)
			{
				if(sels[i].getElementsByTagName('option')[j].value)
				{
					var newli=document.createElement('li');
					var newa=document.createElement('a');
					newli.v=sels[i].getElementsByTagName('option')[j].value;
					newli.elm=hiddenfield;
					newli.istrigger=trigger;
					newa.href='javascript.void(0);';
					newa.appendChild(document.createTextNode(
					sels[i].getElementsByTagName('option')[j].text));
					newli.onclick=function(){
						this.elm.value=this.v;
						ts_swapclass(this.istrigger,ts_triggeron,ts_triggeroff);
						ts_swapclass(this.parentNode,ts_dropdownopen,ts_dropdownclosed)
						this.istrigger.firstChild.nodeValue=this.firstChild.firstChild.nodeValue;
						return false;
					}
					newli.appendChild(newa);
					replaceUL.appendChild(newli);
				}
			}
			ts_addclass(replaceUL,ts_dropdownclosed);
			var div=document.createElement('div');
			div.appendChild(replaceUL);
			ts_addclass(div,ts_boxclass);
			sels[i].parentNode.insertBefore(div,sels[i])
			toreplace[count]=sels[i];
			count++;
		}
	}

/*
	Turn all ULs with the class defined above into dropdown navigations
*/

	var uls=document.getElementsByTagName('ul');
	for(var i=0;i<uls.length;i++)
	{
		if(ts_check(uls[i],ts_listclass))
		{
			var newform=document.createElement('form');
			var newselect=document.createElement('select');
			for(j=0;j<uls[i].getElementsByTagName('a').length;j++)
			{
				var newopt=document.createElement('option');
				newopt.value=uls[i].getElementsByTagName('a')[j].href;
				newopt.appendChild(document.createTextNode(uls[i].getElementsByTagName('a')[j].innerHTML));
				newselect.appendChild(newopt);
			}
			newselect.onchange=function()
			{
				window.location=this.options[this.selectedIndex].value;
			}
			newform.appendChild(newselect);
			uls[i].parentNode.insertBefore(newform,uls[i]);
			toreplace[count]=uls[i];
			count++;
		}
	}
	for(i=0;i<count;i++){
		toreplace[i].parentNode.removeChild(toreplace[i]);
	}
	function ts_check(o,c)
	{
	 	return new RegExp('\\b'+c+'\\b').test(o.className);
	}
	function ts_swapclass(o,c1,c2)
	{
		var cn=o.className
		o.className=!ts_check(o,c1)?cn.replace(c2,c1):cn.replace(c1,c2);
	}
	function ts_addclass(o,c)
	{
		if(!ts_check(o,c)){o.className+=o.className==''?c:' '+c;}
	}
}


window.onload=function()
{
	tamingselect();
	// add more functions if necessary
}

//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+'';
}
}

// Begin image swapping funcion for How it Works page
// define the images and image maps you need to use for the swappings here
arr_ads = [];
arr_ads[1] = [];
arr_ads[1]['ad_img'] = 'how_it_works_1.jpg';
arr_ads[1]['button_img'] = 'how_it_works_button_1_over.jpg';
arr_ads[1]['button_img_off'] = 'how_it_works_button_1.jpg';
arr_ads[1]['button_id'] = 'hiw1';
arr_ads[1]['selected'] = 1;
arr_ads[2] = [];
arr_ads[2]['ad_img'] = 'how_it_works_2.jpg';
arr_ads[2]['button_img'] = 'how_it_works_button_2_over.jpg';
arr_ads[2]['button_img_off'] = 'how_it_works_button_2.jpg';
arr_ads[2]['button_id'] = 'hiw2';
arr_ads[2]['selected'] = 0;
arr_ads[3] = [];
arr_ads[3]['ad_img'] = 'how_it_works_3.jpg';
arr_ads[3]['button_img'] = 'how_it_works_button_3_over.jpg';
arr_ads[3]['button_img_off'] = 'how_it_works_button_3.jpg';
arr_ads[3]['button_id'] = 'hiw3';
arr_ads[3]['selected'] = 0;
arr_ads[4] = [];
arr_ads[4]['ad_img'] = 'how_it_works_4.jpg';
arr_ads[4]['button_img'] = 'how_it_works_button_4_over.jpg';
arr_ads[4]['button_img_off'] = 'how_it_works_button_4.jpg';
arr_ads[4]['button_id'] = 'hiw4';
arr_ads[4]['selected'] = 0;
arr_ads[5] = [];
arr_ads[5]['ad_img'] = 'how_it_works_5.jpg';
arr_ads[5]['button_img'] = 'how_it_works_button_5_over.jpg';
arr_ads[5]['button_img_off'] = 'how_it_works_button_5.jpg';
arr_ads[5]['button_id'] = 'hiw5';
arr_ads[5]['selected'] = 0;

//ad_timer = setTimeout('var test;',60000);
current_ad = 1;
function swap_next_ad(swap_ad)
{
	if(swap_ad)
	{
		if(swap_ad == current_ad)
		{
			document.getElementById(arr_ads[swap_ad]['button_id']).src= '/images/' + arr_ads[swap_ad]['button_img'];
			return false;
		}

		current_ad = swap_ad;

		this_ad_key = swap_ad;
		this_ad = arr_ads[swap_ad];
	}
	else
	{
		current_ad++;
		if(current_ad > 5)
		{
			current_ad = 1;
		}

		this_ad_key = current_ad;
		this_ad = arr_ads[current_ad];
	}


	if(current_ad == 5 && document.getElementById('next_button'))
	{
		document.getElementById('next_button').src='/images/how_it_works_button_beginning.jpg';
	}
	else if(document.getElementById('next_button'))
	{
		document.getElementById('next_button').src='/images/how_it_works_button_next.jpg';
	}

	arr_ads[this_ad_key]['selected'] = 1;

	// change clickable button
	document.getElementById(this_ad['button_id']).src= '/images/' + this_ad['button_img'];
	new_ad=document.createElement('img');
	new_ad.src = '/images/' + this_ad['ad_img'];
	new_ad.setAttribute('id', 'ad');
	new_ad.style.position = 'absolute';
	new_ad.style.border = '0px';
	new_ad.setAttribute('alt', "How it Works");
	new_ad.style.width = '655px';
	new_ad.style.height = '263px';

	// transparent object
	var object = new_ad.style;
	object.opacity = (0);
	object.MozOpacity = (0);
	object.KhtmlOpacity = (0);
	object.filter = "alpha(opacity=" + 0+ ")";

	fade_time = 500;

	old_ad = document.createElement('img');
	old_ad.src = document.getElementById('ad').src;
	old_ad.style.position = 'absolute';
	old_ad.style.border = 0;
	old_ad.style.width = '655px';
	old_ad.style.height = '263px';

	document.getElementById('ad_div').insertBefore(old_ad,document.getElementById('ad'));
	document.getElementById('ad_div').replaceChild(new_ad,document.getElementById('ad'));
	opacity('ad',0,100,fade_time);

	// switch all other button images back to their original (non-selected) position
	for(i=1;i<6;i++)
	{
		if(i !== this_ad_key)
		{
			document.getElementById(arr_ads[i]['button_id']).src= '/images/' + arr_ads[i]['button_img_off'];
			arr_ads[i]['selected'] = 0;
		}
	}
}

function ad_button_mouseout(ad_id)
{
	if(arr_ads[ad_id]['selected'] == 1)
	{
			document.getElementById(arr_ads[ad_id]['button_id']).src= '/images/' + arr_ads[ad_id]['button_img'];
	}
	else
	{
			document.getElementById(arr_ads[ad_id]['button_id']).src= '/images/' + arr_ads[ad_id]['button_img_off'];
	}
}


var fade_inprogress;
function changeOpac(opacity, id,opacEnd)
{
	//window.alert(id);
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
   // fading complete, notify everyone
	if(opacEnd && opacity == opacEnd)
	{
		fade_inprogress = '';
	}
}
function opacity(id, opacStart, opacEnd, millisec)
{
	if(fade_inprogress !== 1)
	{
		fade_inprogress = 1;
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;

		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout("changeOpac(" + i + ",'" + id + "', "+opacEnd+")",(timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout("changeOpac(" + i + ",'" + id + "', "+opacEnd+")",(timer * speed));
				timer++;
			}
		}
	}
	else
	{
		// wait a half second for the other fade to complete
		setTimeout('opacity("'+id+'", '+opacStart+', '+opacEnd+', '+millisec+');', 500);
	}
}
// End image swapping funcion for How it Works page

function slidediv(divid,direction)
{
	max_records = 40;
	records_per_page = window['slidedivnumbooks'];
	max_pages = max_records/records_per_page;
	current_page = window[divid+"_page"]; // not a reference just a way to get to this faster
	old_current_page = window[divid+"_page"]; // not a reference just a way to get to this faster

	// do nothing if trying to go into the void
	if((direction == "left" && current_page == 1) || (direction == "right" && current_page == max_pages)) { return; }

	if(direction == "left")
	{
		window[divid+"_page"]--;
	}
	else if(direction == "right")
	{
		window[divid+"_page"]++;
	}
	current_page = window[divid+"_page"]; // update our quick accessor

	new_html = "";
	start_record = ((current_page-1)*records_per_page)+1;
	current_record = start_record;

	while(current_record < start_record + records_per_page)
	{
		if(window[divid][current_record])
		{
			new_html += window[divid][current_record];
		}
		// no more records to show, don't go further
		else
		{
			break;
		}
		current_record++;
	}
	if(new_html)
	{
		//window.alert(new_html);
		document.getElementById(divid).innerHTML = new_html;
	}
	else
	{
		window[divid+"_page"] = old_current_page;
	}

	// update the left and right buttons
	if(current_page == 1)
	{
		document.getElementById('scroll_left_'+divid).src="/images/scroll_left_arrow_no.jpg";
		document.getElementById('scroll_right_'+divid).src="/images/scroll_right_arrow.jpg";
	}
	else if(current_page == max_pages)
	{
		document.getElementById('scroll_left_'+divid).src="/images/scroll_left_arrow.jpg";
		document.getElementById('scroll_right_'+divid).src="/images/scroll_right_arrow_no.jpg";
	}
	else
	{
		document.getElementById('scroll_left_'+divid).src="/images/scroll_left_arrow.jpg";
		document.getElementById('scroll_right_'+divid).src="/images/scroll_right_arrow.jpg";
	}
}


