// Link to profiles page
var profileLink = "http://www.ubs.com/1/e/career_candidates/mba/video.html";

// Array of profile objects
var arrProfiles = []; 

// Video profile object
var videoProfile = function()
{
    this.get_html = function()
    { 
        var strImage = (this.img_id && this.img_id != '') ? 'http://www.ubs.com/1/ShowImage/index?contentId=' + this.img_id : 'mba/profile_missing.gif';
        var txt = '<table border="0" width="100%" cellpadding="0" cellspacing="0"><tr>' +
                  '<td valign="top" width="58"><a href="' + profileLink + '"><img src="' + strImage  +
                  '" width="68" height="60" alt="" border="0"/></a></td>' +
                  '<td valign="top" width="155" class="content"><h3><a href="' + profileLink + '">Meet our people</a></h3>' +
                  this.name + '<br/>' + this.city + '<br/>' + this.working_group + '<br/></td></tr></table>';
        return txt;
    }

}

// When DOM is ready..
$(document).ready(function() { 
  // Remove event trapping
  window.onresize = null;
  document.onmousemove = '';
  $("div#promoPanel div.right").empty(); 

  // Load profile
  $.ajax({
    type: "GET",
    url: "http://www.ubs.com/2/e/medlib/group/graduates/videos/profiles/profiles.xml",
    dataType: "xml",
    success: function(xml) {
      $(xml).find('profile').each(function(i)
      {
        // Only consider "MBA" titles
        if( $(this).attr('profile') == 'Interview' && $(this).attr('title') == 'MBA' )
        {
          // Populate profiles
          var tmpProfile = new videoProfile();
          tmpProfile.id = $(this).attr('id');
          tmpProfile.name = $(this).attr('name');
          tmpProfile.profile = $(this).attr('profile');
          tmpProfile.business_group = $(this).attr('business_group');
          tmpProfile.city = $(this).attr('city');
          tmpProfile.region = $(this).attr('region'); // unused
          tmpProfile.studied = $(this).attr('studied'); // unused
          tmpProfile.working_group = $(this).attr('working_group');
          tmpProfile.title = $(this).attr('title');
          tmpProfile.url = $(this).attr('url');
          tmpProfile.img_id = $(this).attr('img_id');
          arrProfiles.push(tmpProfile);
        }
      }); // close each

      // Get random profile and display on home page
      var profileID = get_rand( arrProfiles.length ); 
      $('div#promoPanel div.right').html( arrProfiles[profileID].get_html() );
    },
    error: function(obj, str, exc){
      alert("Error: " + str);
    } 
  }); //close $.ajax 


}); //close $(document).ready


// Return a random number between zero and 'limit'
function get_rand(limit)
{
    var num = Math.random() * limit;
    return Math.floor(num); 
}
