/// <reference name="MicrosoftAjax.js"/>
/// <reference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />   
/// <reference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />   
/// <reference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
/// <reference path="../Services/Support.asmx" />

jQuery(function($) {
    $('#nav li').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    $('h2.title').wrap('<span class="title-wrap" />');
    $('span.title-wrap').wrap('<span class="title-wrap-out" />');
    $('li.widget h3 span').wrap('<span class="title-wrap" />');
    $('#container img').wrap('<div class="img-wrap" />');
    $('#container div.wrap').wrapAll('<div class="cont-wrap" />');
    $('#container div.cont-wrap').wrapAll('<div class="cont-wrap-out" />');
    if(jQuery().example) {
	    $('#search input').example('Search');
    };

  var show_popup = true;
  if (show_popup) {
      $('#brochures a, #onlinevideos a, #whitepapers a, #testimonials a, #case-studies a')
          .each(function() {
            //hide the original url
            this.rel = this.href;
            this.href = "javascript:void(0)";
          })
          .click(function(e) {
              e.preventDefault();

              var originalUrl = this.href;

              if (typeof(registered) !== "undefined" && !registered) {
                  e.stopPropagation();

                  var oWnd = $find(downloadAppWindow);
                  oWnd.set_navigateUrl(popupUrl + "?item=" + this.innerHTML);
                  oWnd.show();

                  //handle the close
                  oWnd.add_close(function(sender, eventArgs) {
                      if (eventArgs.get_argument() != null) {
                          registered = true;
                          window.location = originalUrl;
                      }
                  });
              } else {
                  window.location = originalUrl;
              }
          });
  }
  else {
      $('#brochures a, #onlinevideos a, #whitepapers a, #testimonials a, #case-studies a').attr('target', '_blank');
  }


    //hook up the popup timer
    if (typeof(poppedReceived) != "undefined" && !poppedReceived) {
        window.setTimeout(function() {
            $("#scnXOW a").triggerHandler("click");
            HandsOn.Services.Support.PopUp(function(result, context) {
                poppedReceived = result;
            });
        }, 60000);        
    }
});

