// Initializes User Scripts:

$(document).ready(function() {

    //    Language Selector
    var selector = $('#selectLanguage');
    if (selector.size() >0) {
        var lang = selector.val();
        selector.change(function() {
            lang = selector.val();
            goToPage(lang);
        });
        
        function goToPage(page) {
            if (page == '') {
                location.href = '/';
            } else {
                location.href = '/' + page + '/';
            }
            setLanguage(page);
        }
        
        function setLanguage(language) {
            createCookie('rdxLanguage', language, 365);
        }
    }
    

  // Selects text in Search Box when focused:
  $('input.txtSearch').focus(function() {
    this.select();
  });

  // Footer Links - pop up in new window / tab:
  $('a#smartzLink').click(function() {
    window.open($(this).attr("href"), 'window2', '');
    return false;
  });
  
  pixelsilk2.renderSkin({skin: '[' + '[Menu1]' + ']', path: ''}, function(html) {
    $('#subNavigation').html(html);
    var sections = $('#subNavigation div');
    var topElements = $('#Menu li');
    for (z = 0; z < sections.length; z++) {
      var li = topElements[z+1];
      var lihtml = li.innerHTML;
      li.innerHTML = lihtml + sections[z].innerHTML;
    }
    $('#Menu').navMenu({
      menuWidth: 200,
      containerElement: "#theme",
      menuElement: "ul",
      rightArrow: '&nbsp;»'
    });
  });

  $("#sponsorSlider").easySlider({
    prevId: 'sliderPrevBtn',
    nextId: 'sliderNextBtn',
    prevText: '<img src="/sponsor-button-left.gif" width="25" height="25" alt="&lt;" />',
    nextText: '<img src="/sponsor-button-right.gif" width="25" height="25" alt="&gt;" />',
    continuous: true,
    controlsShow: false,
    auto: true,
    pause: 8000
  });

  $(".staffImage").each(function(){
    if ($(this).find("img").attr("src") == '' || $(this).find("img").attr("src") == '?w=100') {
      $(this).hide();
    }
  });
  if ($("#staffDetailImage img").attr("src") == '' || $("#staffDetailImage img").attr("src") == '?w=240') {
    $("#staffDetailImage").hide();
  }

});
