jQuery(document).ready(function(){
	jQuery("#nmp_st_brand").change(function(event){
		var brand = jQuery("#nmp_st_brand").val();
		var pic = jQuery("#brandselect_pic");
		
		switch(brand){
			case "AVG":
				pic.attr("class","bigico avg");
				pic.css("margin-top","39px");
				break;
			case "KASPERSKY":
				pic.attr("class","bigico kas");
				pic.css("margin-top","19px");
				break;
			case "MCAFEE":
				pic.attr("class","bigico mca");
				pic.css("margin-top","38px");
				break;
			case "NORTON":
				pic.attr("class","bigico nor");
				pic.css("margin-top","29px");
				break;
			case "TREND-MICRO":
				pic.attr("class","bigico tren");
				pic.css("margin-top","20px");
				break;
			case "SOFTWARE-AVAST":
				pic.attr("class","bigico avast");
				pic.css("margin-top","20px");
				break;
			case "CA-SOFTWARE":
				pic.attr("class","bigico ca");
				pic.css("margin-top","20px");
				break;
			case "BITDEFENDER":
				pic.attr("class","bigico bit");
				pic.css("margin-top","20px");
				break;
			default:
				pic.attr("class","bigico all");
				pic.css("margin-top","17px");
				break;			
		}
	});
	
	jQuery("#slider_price").slider({
		range: true,
		min: 0,
		max: 200,
		values: [0, 200],
		step: 10,
		slide: function(event, ui) {
			/** Wrong 
			jQuery("#price_start").html("jQuery"+addCommas(ui.values[0]));
			jQuery("#price_stop").html("jQuery"+addCommas(ui.values[1]));
			*/
			jQuery("#price_start").html("$"+addCommas(ui.values[0]));
			jQuery("#price_stop").html("$"+addCommas(ui.values[1]));
			if (ui.values[0]===0) {jQuery("#price_start").html("$0");}
			if (ui.values[1]==200) {jQuery("#price_stop").html("$200 or more");}
			jQuery("#price_0").val(ui.values[0]);
			jQuery("#price_1").val(ui.values[1]);
		}
	});

	jQuery("#slider_av-type").slider({
		value:0,
		min: 0,
		max: 5,
		step: 1,
		slide: function(event, ui) {
			switch (ui.value) {
				case 1:	jQuery('#av-type').html("Total Protection");break;
				case 2:	jQuery('#av-type').html("Antivirus Protection");break;
				case 3:	jQuery('#av-type').html("Internet Security");break;
				case 4:	jQuery('#av-type').html("Firewall");break;
				case 5:	jQuery('#av-type').html("Backup and Restore");break;
				default:jQuery('#av-type').html("All Products");
			}
			jQuery("#slider_av-type_val").val(ui.value);
		}
	});
	jQuery("#avselector-form").submit(function(){
		jQuery.post("products/software-selector.php",{ nmp_st_brand:jQuery('#nmp_st_brand').val(),av_type:jQuery('#slider_av-type_val').val(),price0:jQuery("#price_0").val(),price1:jQuery("#price_1").val() } ,function(data){
			jQuery("#product-list").html(data);
			jQuery('body').load(scrollView());
		});
		return false;
	});
});

// function Add Commas to numbers
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, 'jQuery1' + ',' + 'jQuery2');
	}
	return x1 + x2;
}
scrollView = function(){
	var el = document.getElementById('avselector-form');
	el.scrollIntoView(true);
} 

