$(document).ready(function(){

	$('#businessinfo').addClass('ajax_loading');
	
	var id = {'id': businessid};
  //ajax call to get the id
     $.ajax({
	   	 type: "POST",
	   	 url: "/city/findbusiness", 
	   	 cache: false,
	     dataType: "json", 
	     data: id,
	     success: function(data){
	       if (data.success == true){
	     	 $('#businessinfo').removeClass('ajax_loading');
	     	  var content = "";
	          
	          content += '<div class="sch_rlt_list_t_r" ><div class="sch_rlt_list_t_l">';
	          content += '<h1>' + data['company_name']+ '</h1>';
	          content += '</div></div>';
	          
	          //output the star function 
	          //according to the rate, calculate the width for star
              var width = outputStar(data['rate']);
              
             content += '<div class="rate"><div class="rate_star"  id = "rate" ><span style="width:' + width + 'px "></span></div>' + data['rate'] + '/5 (' + data['num_of_rate'] + ' reviews) </div>';
	          
	          if (data['image'] != null)
                 content += '<div class="rlt_list_blc"><img src="' + imagepath +  data['image'] +  '" alt="no image" class="no_img enlarge" /><img src="" style="display:none"/>';
	          else 
	             content += '<div class="rlt_list_blc"><img src="/img/no_img_defalt.gif" alt="no image" class="no_img" />';
	             
	          content += '<div class="biz_info"><ol><li><span class="dark_grey">location: </span>';
	          content += data['address']+ ' ' + data['city'] + ' ' + data['state'] + ' ' + data['postal_code'] + '</li>';
	          
	          if (data['phone_number'] != null)
	     	       content += '<li><span class="dark_grey">Telephone: </span>' + data['phone_number'] + '</li>';

	     	    
	     	    if (data['fax_number'] != null)
	     	       content += '<li><span class="dark_grey">Fax number: </span>' + data['fax_number'] + '</li>';
	     	       
	     	    if (data['url'] != null)
	     	       content += '<li><span class="dark_grey">Website: </span><a href="' + data['url'] + '" target="_blank" >'  + outputurl(data['url']) + '</a></li>';
	          var cat_description = replaceDash(data['description']);
	          content += '<li><span = "dark_grey">category: </span>';
              content += '<a href="/' + currentCity + '/category-'+cat_description + '-' + data['cid'] + '-4' + '">' + data['description'] + '</a> </li></ol>';
	          content += '</div><div class="biz_small_link"><a id= "addclipboard" href="/business/addclipboard?businessid=' + data['ID'] +  '" class="add_clipboard">add to clipboard</a></div>';

	        //load content 
	         $('#businessinfo').html(content);
            
	        //ajax call to add favourite business
	        $('a.add_clipboard').click(function(){
	            $.getJSON($(this).attr('href'), function(data){
	                loadClipBoard();
	            });
	          
	            return false;
	         });

            //enlarge the image on hover
	        $('img.enlarge').hover(
	           function(){

	           	  var src = $(this).attr('src');
	           	  var newsrc = src.replace(imagepath, imagepath_large);

	           	  $(this).next().attr('src', newsrc);
	           	  var offset = $(this).offset();

	           	  $(this).next().css('position', 'absolute').css('top', offset.top - 220)
	           	                         .css('left', offset.left + 100)
	           	                         .css('display', 'block')
	           	                         .css('width', '400px').css('height', '300px')
	           	                         .css('z-index', 500)
	           	                         .css('border', '1px solid black');
	           },
	           
	           function(){
	           	  $(this).next().removeClass('hover_show').css('display', 'none').css('z-index', -1);

	           }
	        );
             
	        //load the map
	        loadMap("map",  data);
	        
	        //setup category
	        setupCategory(4, data, currentCity);

	        
	       }
	       else
	         $('businessinfo').html('No business info has been found');
	        
	     },
	     error: function() {
            alert("Failed to connect server");
      }
     });
     
     loadClipBoard();
});


function setupCategory(category_level, data, currentCity){
  //set the forum category   
  var level = parseInt(category_level);
  if (level == 4) level--;
           
  var categorylink = "";
  /*
  for (var j = 0; j <= level; j++){
  	 var categoryName = "";
  	 if (data['level' + j +  '_des'].length > 15)
  	    categoryName = data['level' + j +  '_des'].substring(0, 14) + "...";
  	 else 
  	    categoryName = data['level' + j +  '_des'];
  	 
     categorylink += '<li class="nave_g"><a title="' + data['level' + j +  '_des'] 
                   + '" href="/' + currentCity + '/category-' + replaceDash(categoryName) 
                   + '-' + data['level'+j] + '-'  + j + '">' + categoryName + '</a>';
              
    if (j != level)
     categorylink += '></li>';
   
  }*/
   
	for (var j = 0; j <= 3; j++){
	  
		var cname = data['d'+j];
		if( cname.length > 15) cname = cname.substring(0, 14) + "...";
		
		if(cname.length > 0) {
			categorylink += '<li class="nave_g"><a title="' + cname
				+ '" href="/' + currentCity + '/category-' + replaceDash(data['d'+j]) 
				+ '-' + data['cid'] + '-'  + j + '"' + cname + ' >'+cname+'</a>>';
		}
	  
 	}

	categorylink += '</li>';
	   
	   
	$('div.nav_buz ul').append(categorylink);
 
}








