var currentURL=new String(window.location);
var isIE=false;
jQuery.each(jQuery.browser, function(i, val) {
  if(i=="msie" && val==true)
  {
    isIE=true;
  }
});

jQuery.fn.log = function (msg) {
  if(!isIE)
  {
   // console.log("%s: %o", msg, this);
  }
  return this;
};
 
jQuery().ready(function(){
    
  jQuery(".feature").each(function(){
    if(jQuery('a', this).attr("href").indexOf("/video/")>-1)
    {
      jQuery(this).addClass("video");
      jQuery('a', this).hide();
      if(jQuery('.featureContent img', this).width()!=jQuery('.featureContent', this).width())
      {
        jQuery('.featureHeading, .featureSubHead', this).hide();
        setTimeout(resetVideoTextDivWidths, 1000);
      }
      jQuery('.featureHeading, .featureSubHead', this).width(jQuery('.featureContent', this).width());
    }
    if (jQuery(this).hasClass("featureSpanTwoCols"))
    {
      jQuery('.featureContent', this).width(376);  //  (189 * 2) - 2 for borders
    }
    else
    {
      jQuery('.featureContent', this).width(187);  // 189 - 2 for borders
    }
  });

	var now=new Date();
	var currYear=now.getFullYear();
  jQuery("#footerYear").html(currYear);

  jQuery("#topFeaturesDiv .feature").each(function(i){
    if(i==0)
    {
      if(jQuery(this).parent().hasClass('1FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('1FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
    if(i==1)
    {
      if(jQuery(this).parent().hasClass('2FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('2FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
  });

  jQuery("#bottomFeaturesDiv .feature").each(function(i){
    if(i==0)
    {
      if(jQuery(this).parent().hasClass('1FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('1FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
    if(i==1)
    {
      if(jQuery(this).parent().hasClass('2FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('2FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
  });


  // features
  jQuery(".feature a").click(function(e){
    e.stopPropagation();
  });
  jQuery(".feature").click(function(e){
    if(!jQuery(this).hasClass("video"))
    {
      if(jQuery('a', this).attr("target")=="_blank")
      {
        window.open(jQuery('a', this).attr("href"));
      }
      else
      {
        window.location=jQuery('a', this).attr("href");
      }
      e.stopPropagation();
    }

  });

  // highlight the link when you mouseover any part of the feature
  jQuery(".feature").mouseover(function(){
    jQuery(".promoLink a, .businessLandingPageSubNavText a", this).css("color", "#0066cc");
    jQuery(".promoLink", this).css("background", "url('/images/blueArrow.gif') no-repeat right 1px");
  });

  jQuery(".feature").mouseout(function(){
    jQuery(".promoLink a, .businessLandingPageSubNavText a", this).css("color", "#333333");
    jQuery(".promoLink", this).css("background", "url('/images/blackArrow.gif') no-repeat right 1px");
  });

  // if you click a video link, inserts a veil and adds a boxy window to display the video in.
  jQuery(".video").click(function(event){
    var veilFadeInOutSpeedMillis=800;
    jQuery("body").append("<div class='veil'></div>");
    jQuery(".veil").css("opacity", "0.6");
    jQuery(".veil").css("filter", "alpha(opacity=60)");
    jQuery(".veil").css("position", "absolute");
    jQuery(".veil").css("width", "100%");
    jQuery(".veil").css("height", "100%");
    jQuery(".veil").css("left", "0px");
    jQuery(".veil").css("top", "0px");
    jQuery(".veil").fadeIn(veilFadeInOutSpeedMillis);
    var box=Boxy.load(jQuery('a', this).attr("href"), 
      {title: jQuery('.featureHeading', this).html(), draggable: false, afterShow: function(){positionVideo()}, afterHide: function(){
        jQuery(".veil").fadeOut(veilFadeInOutSpeedMillis, function(){jQuery(".boxy-wrapper").remove();jQuery(".veil").remove();});
      }
    });
  });

  jQuery(".featureRightVertLine").prepend("<div class='featureRightBorder'></div>");
  jQuery(".featureLeftVertLine").prepend("<div class='featureLeftBorder'></div>");

});

function resetVideoTextDivWidths()
{
  if(jQuery('.featureContent img', this).width()!=jQuery('.featureContent', this).width())
  {
    setTimeout(resetVideoTextDivWidths, 1000);
  }
  else
  {
    jQuery(".feature").each(function(){
      if(jQuery('a', this).attr("href").indexOf("/video/")>-1)
      {
        jQuery('.featureHeading, .featureSubHead', this).show();
        jQuery('.featureHeading, .featureSubHead', this).width(jQuery('.featureContent', this).width());
      }
    });
  }
}

function positionVideo() {
  jQuery(".boxy-wrapper").hide();
  var leftOffset = jQuery("#middle").offset().left+(jQuery("#middle").width()/2)-((jQuery(".boxy-wrapper").width())/2);
  var topOffset=jQuery("#middle").offset().top+20;
  jQuery(".boxy-wrapper").css("left", leftOffset+"px");
  jQuery(".boxy-wrapper").css("top", topOffset+"px");
  jQuery(".boxy-wrapper").fadeIn(500);
}


