//Start headline rotation
var t=setTimeout("headlineRotation('btn-next')",5000);
var TimerOn = true;

$(function(){  
	$("h3 a#lnk1").click(function(){
		href = $(this).attr('href');
		$(href).toggle();
		return false;
	})
  
  togglePanel = function(link)
  {
    if($(link).hasClass('hide-panel'))
    {
      $('#side-panel').hide();
      $('#content').addClass("full-screen");
      $(link).text('show panel').attr('class', 'show-panel');
    } else {
      $('#side-panel').show();
      $('#content').removeClass("full-screen");
      $(link).text('hide panel').attr('class', 'hide-panel');    
    }
  }
  toggleSection = function(link, parent, item, cls_a, cls_b)
  {
    item = $(link).parents(parent).children(item);
    visible = $(link).hasClass(cls_a);
    
    if(visible)
    {
      $(item).hide();
      $(link).attr('class',cls_b);
    } else {
      $(item).show();
      $(link).attr('class',cls_a);
    }
    return false;
  }
  
  $('.required').each(function(){
    $(this).parent().append('<span class="icn-required">*</span>');
  });
  
  $("body#help #col-2 #svPortal dt a").click(function(){
  	$(this).toggleClass('toggle-up');
	$(this).parent().parent().find('dd').toggle();
	return false;
  })
  
  $("body#homepage .hl-controls li a").click(function(){
		var action = $(this).attr('class');
		headlineRotation(action)		
		return false;
	})

	/* Sticky Table Headers
	   Craig McQueen 
	   http://cmcqueen1975.bitbucket.org/htmlFloatingTableHeader/tables.html
	   
	   Modified by Bayleaf Software
	*/
	$("table.tableWithFloatingHeader").each(function() {
		$(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
		var originalHeaderRow = $("tr:first", this)
		originalHeaderRow.addClass("tableFloatingHeaderOriginal");
	});
            
	UpdateTableHeaders();
	$(window).scroll(UpdateTableHeaders);
	$(window).resize(UpdateTableHeaders);

});

function headlineRotation(action){
	var total = new Number;
	total = $("body#homepage .hl-controls span.total").html();
	var current = new Number;
	current = $("body#homepage .hl-controls span.current").html();
		
	if(action == "btn-prev"){
		current--;
		if(current == 0){
			current = total;
		}
		$("body#homepage .hl-controls span.current").html(current);
	}else if(action == "btn-next"){
		current++;
		if(current > total){
			current = 1;
		}
		$("body#homepage .hl-controls span.current").html(current);
	}else if(action == "btn-stop"){
		$(".btn-stop").css('display','none');
		$(".btn-play").css('display','block');
		TimerOn = false;
	}else if(action == "btn-play"){
		$(".btn-stop").css('display','block');
		$(".btn-play").css('display','none');	
		TimerOn = true;
	}
	
	$(".hl-text").hide();
	$(".hl-img").hide();
	$(".headline-rotator .image"+current).show();
	$(".headline-rotator .content"+current).show();
	
	if(TimerOn == true){
		clearTimeout(t)
		t=setTimeout("headlineRotation('btn-next')",5000);
	}else{
		clearTimeout(t)
	}
}

/* Sticky Table Headers
   Craig McQueen 
   http://cmcqueen1975.bitbucket.org/htmlFloatingTableHeader/tables.html
   
   Modified by Bayleaf Software
*/

function UpdateTableHeaders() {
	$("div.divTableWithFloatingHeader:visible").each(function() {
		var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
		var offset = $(this).offset();
		var scrollTop = $(window).scrollTop();
		if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
			originalHeaderRow.css("position", "relative");
			originalHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height() - originalHeaderRow.height()) + "px");
		}
		else {
			originalHeaderRow.css("visibility", "visible");
			//floatingHeaderRow.css("position", "absolute");
			originalHeaderRow.css("top", "0px");
		}
	});
}

