// function to post-process Infor24 content areas upon load via HTTP or Ajax
// place ay functions i here that might normally be loaded with the content 
// as AJAX calls strip out <script>
function process24Content()
{
  // set local links to ajax handler
  set24Links();
  
  // set custom lightbox treatment for Azure intro videos
  if($("a[rel*='azurevid']").length > 0)
  {
    $("a[rel*='azurevid']").fancybox({
      'type': 'iframe',
      'width': 720,
      'height': 480
    });
  }
  
  if($("a[rel*='vidbox']").length > 0)
  {
   $("a[rel*='vidbox']").fancybox(); // Select all links that contains vidbox in the rel attribute
  }
  
  // resources carousel
  if($("#resource_carousel").length > 0)
  {
    jQuery('#resource_carousel').jcarousel({
      scroll: 4,
      itemLoadCallback: setupResourceLinks
    });
    
    setupResourceLinks();
  }
  
  // solutions nav select
  if($("#subnav24_select").length > 0)
  {
    $("#subnav24_select").change(function(){
      if($("#subnav24_select option:selected").val() != '')
      {
        if(!($.browser.msie && $.browser.version < 8))
        {
          $.ajax({
          type: "GET",
          url: $("#subnav24_select option:selected").val(),
          dataType: "html",
          success: replace24Content
          });
        }
        else
        {
          window.location.href = $("#subnav24_select option:selected").val();
        }
      }
    });
  }
}

// function to initiate the transition effect
// will replace the topbar links and fade out the previous content
function replace24Content(data)
{
  $('#topbar').html($(data).find('#topbar').html());

  $('#content_24').fadeOut(750, function(){replace24InnerContent(data); data = null;});
  $('#footer_24').fadeOut(750);
}
// function to replace the main page content and fade in
// then attempt to reformat internal links that we re added to DOM in the process
function replace24InnerContent(data)
{
  $('#content_24').html($(data).find('#content_24').html()).fadeIn(750);
  $('#footer_24').fadeIn(750);
  process24Content();
}

// Infor24 Ajax Links 
// FOS: This set of code will add onclick handlers to any links that match a regex 
// FOS: that identifies the link as being "internal" to the Infor24 Sub site 
// FOS: The demo considers any relative link starting with '24' to be a match, but any 
// FOS: suitably unique CSS regex string can be used to identify internal links; 
// FOS: See the JQuery documentation for other options for identifying links:
// FOS: http://api.jquery.com/category/selectors/
// FOS: Note that IE 6 & 7 have isues so they are prevented from using the effect
function set24Links()
{
  // kill IE 6 & 7
  if(!($.browser.msie))// && $.browser.version < 8))
  {
    $("a[href^='/infor24/']").click(function(){
      $.ajax({
        type: "GET",
        url: $(this).attr('href'),
        dataType: "html",
        success: replace24Content
      });
      return false;
    }); // reformat all infor24 links to load dynamically
  }
}


// resource center carousel and related functions
// tis function sets u pthe resource center carousel browser
jQuery(document).ready(function() {
    
});

// this function sets up links within the carousel that will load content into the viewer
function setupResourceLinks()
{
    jQuery('#resource_carousel li').click(function(){
      jQuery('#resource_display').html(jQuery(this).html());
      return false;
    });
    
    jQuery('#resource_carousel li').mouseover(function(){
      jQuery('#resource_display').html(jQuery(this).html());
      return false;
    });
}

