function loadCreditCardSliders()
{
	slider_fee = new Control.Slider('handleMaxFee', 'card_annual_fee_slider', {
		range:$R(0,100),
		values:[0,10,20,30,40,50,60,70,80,90,100],
		onSlide: function(v) {
				$('card_fee_display').innerHTML = '$' + Math.round(v*6);
				$('search_maxfee').value = Math.round(v) * 6;
				$('maxFeeBarBg').style.width = Math.round(v*1.77) + 'px';
			},
		onChange: function(v) {
				$('card_fee_display').innerHTML = '$' + Math.round(v*6);
				$('search_maxfee').value = Math.round(v) * 6;
	    		$('maxFeeBarBg').style.width = Math.round(v*1.77) + 'px';
			}
		});
}

function loadSliders()
{
	max_months = new Control.Slider(['handleNumMonths','handleNumMonths2'], 'slider-product-num-months', {
	range:$R(0,60),
	restricted:true,
	onSlide: function(v) {
			$('product-num-months-display-min').innerHTML = Math.round(v[0]);
			$('product-num-months-display-max').innerHTML = Math.round(v[1]);
			$('search_minmn').value = Math.round(v[0]);
			$('search_maxmn').value = Math.round(v[1]);
			start_bound = (v[0] * 3);
			end_bound = (v[1] * 3);
			bar_length = end_bound - start_bound;
			$('monthsBarBg').style.width = Math.round(bar_length) + 'px';
			$('monthsBarBg').style.left = Math.round(start_bound) + 'px';
		},
	onChange: function(v) {
			$('product-num-months-display-min').innerHTML = Math.round(v[0]);
			$('product-num-months-display-max').innerHTML = Math.round(v[1]);
			$('search_minmn').value = Math.round(v[0]);
			$('search_maxmn').value = Math.round(v[1]);
			start_bound = (v[0] * 3);
		  	end_bound = (v[1] * 3);
		  	bar_length = end_bound - start_bound;
			$('monthsBarBg').style.width = Math.round(bar_length) + 'px';
			$('monthsBarBg').style.left = Math.round(start_bound) + 'px';
		  
		}
	});

invest_amt = new Control.Slider('handleInvestAmt', 'product-invest-amt', {
	range:$R(1,300),		values:[1,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300],
	onSlide: function(v) {
			$('product-invest-amt-display').innerHTML = '$' + Math.round(v*100);
			$('search_maxamt').value = Math.round(v*100);
			$('investBarBg').style.width = Math.round(v*.59) + 'px';
		},
	onChange: function(v) {
			$('product-invest-amt-display').innerHTML = '$' + Math.round(v*100);
			$('search_maxamt').value = Math.round(v*100);
    		$('investBarBg').style.width = Math.round(v*.59) + 'px';
		}
});

slider_apy = new Control.Slider('handle1', 'product-apy', {
	range:$R(0,80),
	values:[0,5,10,12.5,15,17.5,20,22.5,25,27.5,30,32.5,35,37.5,40,42.5,45,47.5,50,52.5,55,57.5,60,62.5,65,67.5,70,72.5,75,77.5,80],
	onSlide: function(v) {
			$('product-apy-display').innerHTML = '' + Math.round(v*10)/100 + '%';
			$('search_minapy').value = Math.round(v)/10;
			$('apyBarBg').style.width = Math.round(v/.5) + 'px';
		},
	onChange: function(v) {
			$('product-apy-display').innerHTML = '' + Math.round(v*10)/100+ '%';
			$('search_minapy').value = Math.round(v)/10;
			$('apyBarBg').style.width = Math.round(v/.5) + 'px';
		}
});
}

function validateZip(zip)
{
	var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
	if (zip == '' || !zipCodePattern.test(zip)) 
	{
		alert('Please a valid 5 digit zipcode. ');
		return false;
	}
	return true;
}


// Toggle "active" class on the given element
toggleActiveClass = function (element) {
	if(Element.hasClassName(element, "product-row-featured"))
	{
		if(Element.hasClassName(element, "activefeatured")) {
			Element.removeClassName(element, "activefeatured");
		}
		else {
			Element.addClassName(element, "activefeatured");
		}

	}
	else
	{
		if(Element.hasClassName(element, "active")) {
			Element.removeClassName(element, "active");
		}
		else {
			Element.addClassName(element, "active");
		}
	}
}

var Clicker = Class.create();
Clicker.prototype = {
	initialize: function(link,detail,index) {
		Element.addClassName($(detail), 'hover');
		Event.observe(link, 'click', this.onClick.bindAsEventListener(this, index));
		Event.observe(link, 'mouseover', this.onMouseOver.bindAsEventListener(this, index));
		Event.observe(link, 'mouseout', this.onMouseOut.bindAsEventListener(this, index));
	},

	onClick: function(event, thisIndex) {
		toggleActiveClass($("result"+thisIndex));
		Effect.toggle($("productDetail"+thisIndex),'blind');
		Event.stop(event);
	},

	onMouseOver: function(event, thisIndex) {
		if(Element.hasClassName($('result'+thisIndex),'product-row-featured'))
			$('result'+thisIndex).addClassName('hover-featured ');
		else
			$('result'+thisIndex).addClassName('hover');
		Event.stop(event);
	},

	onMouseOut: function(event, thisIndex) {
		if(Element.hasClassName($('result'+thisIndex),'hover-featured'))
			$('result'+thisIndex).removeClassName('hover-featured');
		else
			$('result'+thisIndex).removeClassName('hover');
		Event.stop(event);
	}
}

function setupProductResults()
{
	if($("product-results"))
	{
		numResults = Math.round(($('product-results').getElementsByTagName("tr").length-1)/2);
		for(i = 1; i <= numResults; i++) {
			if($("result"+(i)))
				new Clicker("result"+(i),"productDetail"+(i),i);
		}
	}
}

 
