// JavaScript Document
var tempArray=new Array() 

$(function(){	
	
	$('.btn.find').changeSubMenu('#find',true,true);
	$('.btn.tryBuy').changeSubMenu('#tryBuy',true,true);
	$('.btn.explore').changeSubMenu('#explore',true,true);
	$('.btn.support').changeMenu();
							   

	$('#search').find('#textField').searchWidget();
	
	$('.textFiled.partNo').focus(function (){
		$(this).val("R5F56")
	})
	
	$('.keyword').focus(function (){
		$(this).val("")
	})
	

	$('#textFiled').val("Enter Part No.")
    $('#textFiledKeyword').val("Enter a Keyword")
	
	
	if($("input:radio:checked").val()=="key"){
       $('#keyword').css('display','block')
	   $('#partNo').css('display','none')	 		
	}else{
       $('#keyword').css('display','none')
	   $('#partNo').css('display','block')		
	}
	
	$('#RadioGroup1_0').click(function(){
       $('#keyword').css('display','block')
	   $('#partNo').css('display','none')	   
	})
	
	$('#RadioGroup1_1').click(function(){
	  $('#keyword').css('display','none')
	   $('#partNo').css('display','block')	   
	})
	

	$('#reset').find('.btn').bind("mousedown",function(){
	  resetSelector();											   
	})
	
	$('.selector.1').find('.item').bind("mouseover",function(){
	  var tempT=$(this).find('.desciption')
	  var tempH=-tempT.height()-20
	  tempT.css('top',30+"px")	
	})	
	
	
	$('#search').find('#btn').click(function(){
	  window.location="searchResult.html?textField="+$('#search').find('#textField').val()
	})	



    $('#result').find('.veiwAll').click(function(){
		window.location="deviceFinder.html?parameter="+$(this).attr('parameter')
						 
	})
	
	$( "#StartRxCore" ).find(".accordion").accordion({
			autoHeight: false,
			navigation: true,
			header:'h3',
			event: "mouseover"
	});



});

function tableData(data){       
   var tempL=data.length;
   var temptable='';
   
   $('#result').find('.count').text("("+tempL+")")
   
   
   
   for (var i = 0; i < tempL; i++) {
	  var tempCon=""
	  var tempComArry=data[i][2].split(",")
	  var tempComL=tempComArry.length
	  if(tempComArry[0]==0){
		  tempCon="-"
	  }else{		
		for(var k=0; k<tempComL; ++k){
		   tempCon=tempCon+tempComArry[k]+'<br/>'
		}
	  }
	   
	   
   temptable=temptable+'<tr><td class="partNo btn">'+data[i][1]+'</td>'+
		  '<td class="style1">'+data[i][3]+'</td>'+
		  '<td class="style2">'+data[i][4]+'</td>'+
		  '<td class="style1">'+tempCon+'</td>'+
		  '<td class="style4">'+data[i][5]+'</td>'+
		  '<td class="style5">'+data[i][6]+'</td><tr>';
   } 	   

   $('#resultList').html(temptable);
   $('#resultList').productInfo('#detail')	   
}

function loadXML(){	
  
  $.ajax({
	url: "http://www.rxmcu.com/USA/php/code.php",/*http://fhdxjaaj.joyent.us/php/code.php*/
	type: "GET",
	dataType: 'text/xml',
	success: function(xml) {
  
	  if (jQuery.browser.msie) {  
		 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
		  xmlDoc.loadXML(xml);  
		  xml = xmlDoc;  
	  } 
	  
	  
	  
	  $(xml).find("product").each(function(){
	   tempArray.push([$(this).find("Series").text(),
					   $(this).find("PartNo").text(),
					   $(this).find("Connectivity").text(),
					   $(this).find("ProgramMemory").text(),					   
					   $(this).find("RAM").text(),
					   $(this).find("Pins").text(),
					   $(this).find("Price").text(),
					   $(this).find("OrderPartNo").text()
					   ]);
	                   
	  })	  
	  
	  
	  
	  getCondition(tempArray,false,false)	 	 
	  $('fieldset').selectResult('mouseup',tempArray)
	  $('.selector.1').find('.btn').selectResult('mouseup',tempArray)
	  $('#apps').find('.btn').selectResult('mouseup',tempArray)
	  $('#reset').find('.btn').selectResult('mouseup',tempArray)
	},	   
	Error: function() {
	  alert("ERROR!!!");
	}
  });
}

function resetSelector(){
	if(jQuery.browser.msie & jQuery.browser.version==6.0){

	$('#selector').find('.btn').each(function(){
	  $(this).css('background-position','left top')
	  $(this).css('color','white')
	})	
	}
	
	$('#selector').find('.btn').each(function(){
	  $(this).removeClass('active')
	})	
	
	$('#selector').find('select').trigger('reset')
    $('#selector').find('.ui-slider-label').css('font-weight','normal')
	$('#selector').find('.ui-slider-label').css('color','#666666')
	
	$('#family').find('.btn').addClass('active')
	$('#Conectivity').find('.btn').addClass('active')
	

	
	getCondition(tempArray)
}


