$(function(){
				
				if( $(document).getUrlParam("sec")){
						var baseUrl = "https://www.techbeat.com.au/services/memory_selector.php";
					
				}else{
					var baseUrl = "http://www.techbeat.com.au/services/memory_selector.php";
				}
				//var baseUrl = "http://www.techbeat.com.au/services/memory_selector.php";
				$('#ram_eqp option:first').attr('selected', 'selected');
				$("select#ram_mfr").attr('disabled',true);
				$("select#ram_ser").attr('disabled',true);
				$("select#ram_mdl").attr('disabled',true);
				$("label[for='ram_eqp']").addClass("currentStep");
				$("select#ram_eqp").change(function(){
					$unloadMemory();
					$clearSelectOptions("select#ram_mfr");
					$clearSelectOptions("select#ram_ser");
					$clearSelectOptions("select#ram_mdl");
					$('#memory_description').empty();
					$('#ram_mfr option:first').attr('selected', 'selected').text('Loading ...');
					
					$.getJSON(baseUrl,{ram_eqp: $(this).val()}, function(j){
						var options = '<option value="">Choose Manufacturer</option>';
						//$('body').log(j.ram_eqp_json.length);
						//alert(j.ram_eqp_json.length);
						for (var i = 0; i < j.$ram_eqp_json.length; i++) {
							options += '<option value="' + j.$ram_eqp_json[i].categoryid + '">' + j.$ram_eqp_json[i].category + '</option>';
						}
						$("#ram_mfr").html(options).attr('disabled',false);
						$('#ram_mfr option:first').attr('selected', 'selected').text('Select Manufacturer');
						$("label[for='ram_eqp']").removeClass("currentStep");
						$("label[for='ram_mfr']").removeClass("currentStep");
						$("label[for='ram_ser']").removeClass("currentStep");
						$("label[for='ram_mdl']").removeClass("currentStep");
						$("label[for='ram_mfr']").addClass("currentStep");
						
					})
				});


				$("select#ram_mfr").change(function(){
					$unloadMemory();
					$('#memory_description').empty();
					$clearSelectOptions("select#ram_ser");
					$clearSelectOptions("select#ram_mdl");
					$('#ram_ser option:first').attr('selected', 'selected').text('Loading ...');
					$.getJSON(baseUrl,{ram_mfr: $(this).val()}, function(j){
						var options = '<option value="">Choose Manufacturer series</option>';
						//$('body').log(j.ram_eqp_json.length);
						//alert(j.ram_eqp_json.length);
						for (var i = 0; i < j.$ram_mfr_json.length; i++) {
							options += '<option value="' + j.$ram_mfr_json[i].categoryid + '">' + j.$ram_mfr_json[i].category + '</option>';
						}
						$("#ram_ser").html(options).attr('disabled',false);
						$('#ram_ser option:first').attr('selected', 'selected').text('Select Manufacturer series');
						$("label[for='ram_mfr']").removeClass("currentStep");
						
						
						$("label[for='ram_ser']").removeClass("currentStep");
						$("label[for='ram_mdl']").removeClass("currentStep");
						$("label[for='ram_ser']").addClass("currentStep");
					})
				});	



				$("select#ram_ser").change(function(){
					$unloadMemory();
					$('#memory_description').empty();
					$clearSelectOptions("select#ram_mdl");
					$('#ram_mdl option:first').attr('selected', 'selected').text('Loading ...');
					$.getJSON(baseUrl,{ram_mfr: $(this).val()}, function(j){
						var options = '<option value="">Choose Model</option>';
						//$('body').log(j.ram_eqp_json.length);
						//alert(j.ram_eqp_json.length);
						for (var i = 0; i < j.$ram_mfr_json.length; i++) {
							options += '<option value="' + j.$ram_mfr_json[i].categoryid + '">' + j.$ram_mfr_json[i].category + '</option>';
						}
						$("#ram_mdl").html(options).attr('disabled',false);
						$('#ram_mdl option:first').attr('selected', 'selected').text('Select Model');
						$("label[for='ram_ser']").removeClass("currentStep");
						$("label[for='ram_mdl']").addClass("currentStep");	
					})
				});	
			//  ===================SHOW MEMORY RESULTS ================= 
				$("select#ram_mdl").change(function(){
					
					$loadMemory($(this).val());	
				});	
				
				//------------------------------------------------- FUN
				
				$unloadMemory = function(){
					$('#memory_wrapper').empty();
				};
				
				$clearSelectOptions = function($select_arg){
					$($select_arg + ' option:not(:first)').remove();
					$($select_arg).attr('disabled',true);

				};
				$loadMemory = function(cat_arg){	
					$unloadMemory();
					$('#memory_description').empty();
					$.getJSON(baseUrl,{ram_mdl: cat_arg}, function(data){					
						$.each(data.$ram_mdl_json, function(index, entry){				
							// ********************** Need some work here to make sure saving is a positive number;**********************
							var savingPrice = entry.list_price - entry.price;
							
							
							var $html ='<div class="cah_productGroup"><div class="cah_bigImage">';
							$html += '<a href="http://www.techbeat.com.au/product.php?productid=' + entry.productid + '" >';
							$html += '<img src="http://www.techbeat.com.au/skin1/images/ipod_loading_catid_1.gif"   name="http://www.techbeat.com.au/image.php?type=T&id=' + entry.productid + '" />';		
							$html += '</a>';
							$html += '</div>';
							$html += '<h2><a name="memId_' + entry.productid +'"  href="http://www.techbeat.com.au/product.php?productid=' + entry.productid + '&cat=' + entry.categoryid + '&page=1" >' + entry.product + '</a></h2>';
							$html += '<div class="cah_marketPriceCatalog">Market price:<span><span class="cah_currency">AU$' + entry.list_price + '</span></span></div>';
							$html += '<div class="cah_priceCatalog">Our price: <span><span class="cah_currency">AU$' + entry.price +'</span></span></div>';	
							//$html += '<div class="cah_savePriceCatalog">Save AU$<span>' +  savingPrice + '</span></div>';		
							$html += '</div>';
							//alert($html);
							$("#memory_wrapper").append($html);
							
							var $fullDescr = '<div class="cah_addClear memory_fullDescr" id="memId_' + entry.productid + '">' + entry.fulldescr + '</div>';
							$("#memory_description").append($fullDescr);
							$('#memId_' + entry.productid).hide();
							/*
							$("#memory_wrapper .cah_productGroup  h2 a").log("--").truncate(80,{ // Default
							        chars: /\s/,
							        leave: false,
							        trail: [true, "...", ""]
							});
							*/
						});		
						setTimeout(function(){
							$('#memory_wrapper img').attr('src',function() { return this.name });
						}, 10);	
					});
				};	
				//-------------------------------------------------FUN
				
				$('.cah_productGroup h2 a').livequery(function(){
					$(this).hover(function(){	
					
					$('#'+$(this).attr('name')).show('slow');
					},
					function(){
					
						$('#'+$(this).attr('name')).hide();
					});
				
				}, function(){});

			});	