$(document).ready(function() {
$("h1#wwd a").attr("href", "/wwdcareers/");

// search box function
    $("#jobSearchForm").submit(function() {
      if ($("input:nth-child(5)").val() == "Search by City or Zip") {
          $("input:nth-child(5)").val("");
      }
      if ($("input:nth-child(7)").val() == "Search by Keyword") {
          $("input:nth-child(7)").val("");
      }
        return true;
    });

// this function gets the videos from brightcove
    $.getJSON("http://api.brightcove.com/services/library?command=find_playlist_by_id&&playlist_id=17971674001&token=Tmpg-v1ATUWOLBqqW7ZKsyO0-t7PWwRRYGW7gAvf9dI.&format=json&callback=?",
        function(data) { $.each(data.videos, function(i,item){
          var thumbnail = item.videoStillURL;
          var headline = item.name;
          var dek = item.longDescription;
          var id = item.id;
            $("#video-list").append("<li><div class=\'video-photo\'><img width=\'68\' height=\'50\' src=\'" + thumbnail + "\'></div><div class=\'video-description\'><span class=\'video-headline\'>" + headline + "</span></div><div class=\'video-play\'><a href=\'javascript:wwd.video.start(17952544001," + id + ")\'><img src='\/images/fashion-careers/play-video.gif\' border=\'0\'></a></div></li><div style=\'clear:both;\'></div>");
            // determine the amount of videos to display here
            if ( i == 7 ) return false;
          });
        });

// this function gets the rss feeds from wwd
         $.ajax({
                 type: "GET",
                 url: "/rss/2/news/recentstories",
                 dataType: "xml",
                 success: function(xml) {
                     $(xml).find('item').each(function(i){
                         var title = $(this).find('title').text()
                         var link = $(this).find('link').text()
                         var description = $(this).find('description').text()
                             $("#content-list").append("<li><div class=\'content-headline\'><a href=\'" + link + "\'>" + title + "</a></div><div class=\'content-dek\'>" + description + "</div></li>");
                     if ( i == 7 ) return false;
                     });
                 }
             });

});

// this is the featured companies widget
text=xmlPrefCo1;
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(text);
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(text,"text/xml");
    }
  catch(e) {alert(e.message)}
  }
try
  {
  //document.write("xmlDoc is loaded, ready for use");
  }
catch(e) {alert(e.message)}

  $(document).ready(function(){

               $(xmlDoc).find('Company').each(function(){
                         var name = $(this).find('Name').text()
                         var ProfileUrl = $(this).find('ProfileUrl').text()
                         var LogoUrl = $(this).find('LogoUrl').text()
                         var ViewJobsUrl = $(this).find('ViewJobsUrl').text()
                         //$("#featuredemployers-list").append(name + "<br>" + ProfileUrl + "<br>" + LogoUrl + "<br>" + ViewJobsUrl);
$("#featuredemployers-list").append("<li><a href=\'" + ProfileUrl + "\'><img src=\'" + LogoUrl  + "\'></a></li>");
                     }); //close each(

  });


// this is the intern entry level widget
text=xmlInternString;
try //Internet Explorer
  {
  xmlDoc2=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc2.async="false";
  xmlDoc2.loadXML(text);
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    parser=new DOMParser();
    xmlDoc2=parser.parseFromString(text,"text/xml");
    }
  catch(e) {alert(e.message)}
  }
try
  {
  //document.write("xmlDoc is loaded, ready for use");
  }
catch(e) {alert(e.message)}

  $(document).ready(function(){

               $(xmlDoc2).find('Job').each(function(i){
                         var title = $(this).find('Title').text()
                         var employer = $(this).find('Employer').text()
                         var location = $(this).find('Location').text()
                         var description = $(this).find('Description').text()
                         var url = $(this).find('Url').text()
                         $("#intern-list").append("<li><div class=\'intern-headline\'><a href=\'" + url + "\'>" + title  + "</a></div><div class=\'intern-dek\'>" + location + "</div></li>");
                     if (i == 2) {
                         return false;
                     }
                     }); //close each(

  });

// search initial text functions
function changeCitySearchText(currentText) {
if (currentText == "Search by City or Zip")
return "";
else return currentText } function blurCitySearchText(currentText) { if (currentText.replace(/^\s+/,"") == "")
 return "Search by City or Zip";
 else
 return currentText
 }

function changeKeywordSearchText(currentText) {
if (currentText == "Search by Keyword")
return "";
else return currentText } function blurKeywordSearchText(currentText) { if (currentText.replace(/^\s+/,"") == "")
 return "Search by Keyword";
 else
 return currentText
 }
