// Check for variables and set defaults
mp_search_widget['id'] = typeof mp_search_widget['id'] == 'string'? mp_search_widget['id']: 'mp_search_widget';
mp_search_widget['container_width'] = typeof mp_search_widget['container_width'] == 'number'? mp_search_widget['container_width']: 280;
mp_search_widget['container_border'] = typeof mp_search_widget['container_border'] == 'string'? mp_search_widget['container_border']: '1px solid #ddd';
mp_search_widget['search_input_width'] = typeof mp_search_widget['search_input_width'] == 'number'? mp_search_widget['search_input_width']: 200;
mp_search_widget['override_css'] = typeof mp_search_widget['override_css'] == 'boolean'? mp_search_widget['override_css']: false;

if (!mp_search_widget['override_css']) {
  //document.write('<link rel="stylesheet" type="text/css" media="all" href="http://media.ljworld.com/static/marketplace_default/stylesheets/widgets.css" />');
  document.write('<div id="'+mp_search_widget['id']+'" class="mp_search_widget" style="width:'+mp_search_widget['container_width']+'px; border:'+mp_search_widget['container_border']+'">');
}
else {
  document.write('<div id="'+mp_search_widget['id']+'" class="mp_search_widget">');
}
if (mp_search_widget['header_url']) document.write('<a href="'+mp_search_widget['marketplace_url']+'"><img src="'+mp_search_widget['header_url']+'" alt=""></a>');
if (!mp_search_widget['override_css']) {
  document.write('<form action="'+mp_search_widget['marketplace_url']+'search/" method="get"><p><input type="text" name="q" value="Find A Business" style="width:'+mp_search_widget['search_input_width']+'px;"> <button type="submit">Search</button></p></form>');
}
else {
  document.write('<form action="'+mp_search_widget['marketplace_url']+'search/" method="get"><p><input type="text" name="q" value=""> <button type="submit">Search</button></p></form>');
}
document.write('</div>');

function randomBusiness(data) {
  div = document.getElementById(mp_search_widget['id']);
  place = data[0]['fields'];
  
  html = (place['thumbnail'])? '<br /><a href="'+mp_search_widget['marketplace_url']+'businesses/'+place['slug']+'/"><img src="'+place['thumbnail']+'" alt="" align="left"></a>': '';
  html += '<span class="name"><a href="'+mp_search_widget['marketplace_url']+'businesses/'+place['slug']+'/">'+place['pre_name']+' '+place['name']+'</a></span>';
  html += (place['address1'] && place['city'])? '<br /><span class="address">'+place['address1']+', '+place['city']+'</span>': '';
  //html += (place['hours_text'])? '<p>'+place['hours_text']+'</p>': '';
  html += (place['phone1'])? '<br /><span class="phone">'+place['phone1']+'</span>': '';
  
  business_div = document.createElement('div');
  business_div.innerHTML = html;
  business_div.className = 'marketplace-ad2';
  div.appendChild(business_div);
}

