$(document).ready(function() {
  displayFeaturedRecruiterAdvertisements();

 // alert(height);

});

function displayFeaturedRecruiterAdvertisements () {
    /* JSON requests for featured recruiter banners and display */

    /* grab 100.
     * Depending on paqe size, assign a number
     * run foreach and create number depending on variable number.
     * if count is less than number (e.g. number = 10, count = 9)
     * display it, else dont.*/

    var $url = '/advertisement/featured-recruiter/get/50/'; //pull 50, not 25, only displays correct amount anyway.

    var height = $('div.bodyleft').height();
    var pathname = window.location.pathname;

    /* hack for FF */
    jQuery.each(jQuery.browser, function(i, val) {
        if(i=="mozilla")
     height = height - 100;
     });

    if (height < 500) {
      //alert('below 500');
        var number = 14;
    }
    if (height > 500 && height < 1000) {
      //alert('above 500, below 1000');
        var number = 14;
    }
    if (height > 1000 && height < 2000) {
      //alert('above 1000, below 2000');
        var number = 20;
    }
    if (height > 2000) {
      //alert('above 2000');
        var number = 25;
    }

    /* hack for homepage below */
    //var homeBarsHeight = $('div.bar').height();
   if($('div#langlist').length) {
       if($('div#indlist').length) {
            var number = 12;
       }
    }

    //alert(height);
    $.getJSON(
        $url,
        function(data){
            var count = 0;
            $.each(data, function(key, value) {
                if(count < number) {
                  if (value.alternate_code == undefined) {
                    $('.ad-container').append('<div class="ad-unit"><div class="ad"><a href="' + value.href + '" title="' + value.title + '" ><img src="' + value.img + '" alt="' + value.alt + '" title="' + value.title + '" width="120" height="45"/></a></div></div>');
                  } else {
                    //$('.ad-container').append('<div class="ad-unit"><div class="ad">'+$("<span/>").html(value.alternate_code).text()+'</div></div>');
                    $('.ad-container').append('<div class="ad-unit"><div class="ad">'+value.alternate_code+'</div></div>');
                  }
                  count ++;
                }
            });
        }
    );
}

