$(document).ready(function(){
		$("#pullTab").click(function (e) {
      e.preventDefault();
      this.blur();
			if($(this).hasClass("open")){
				$("#pull").animate({
					left: "-=258px"
				}, 1000, function() {
					$("img", "#pullTab").attr("src", "/sitefiles/images/home/tab_pull_close.png");
				});
				$(this).removeClass('open');
			} else {
				$("#pull").animate({
					left: "+=258px"
				}, 1000, function() {
					$("img", "#pullTab").attr("src", "/sitefiles/images/home/tab_pull_open.png");
				});
				$(this).addClass('open');
			}
			return false;
		});

		var previouson = "$(#pull a.on)";

		$("#pull a:not('#pullTab')").mouseover(function(){
			$("#pull a").each(function(){
				if($(this).hasClass("on"))
					previouson = $(this);
				$(this).removeClass("on");
			});
		});

		$("#pull a:not('#pullTab')").each(function(i){
			$(this).click(function(e){
        e.preventDefault();
        this.blur();
        clearInterval(Rotating);
				$(this).addClass("on");
				$('.features').fadeOut(300);
				$($('.features')[i]).fadeIn(300);

				previouson = $(this);
				//return false;
			});
		});

		$("#pull").mouseleave(function(){
			if (previouson != "undefined")
				previouson.addClass('on');
		});
		
		
		$("#hmFeatureCntnr h2").prepend("<span class='icon'></span>");
		
		var Rotating = setInterval("RotateBanner()", 3000);
		
		$(".features a").each(function(){
        var href = $(this).attr("href");
        $(this).parent().parent().parent().parent().css("cursor", "pointer").click(function(e){
            e.preventDefault();
            window.location.href = href;
        });
    });
});

var Banners = $(".features");
var BannerCount = Banners.length;
var CurrentBannerIndex = 0;
function RotateBanner(){
  $(Banners[CurrentBannerIndex]).fadeOut(500);
  CurrentBannerIndex++;
  if(CurrentBannerIndex == BannerCount){
    CurrentBannerIndex = 0;
  }
  $(Banners[CurrentBannerIndex]).fadeIn(500);
  /*
  $(PullTabs[CurrentBannerIndex]).removeClass("on");
  CurrentBannerIndex++;
  if(CurrentBannerIndex == BannerCount){
    CurrentBannerIndex = 0;
  }
  
  $(PullTabs[CurrentBannerIndex]).trigger("click");
  */
}
