/*************************************************************************
*   
*   J A V A S C R I P T  G L O B A L
*
*   Copyright 2008, Trevor Saint
*   www.trevorsaint.com
* 
*************************************************************************/


/*--------------------------------------------------------------------------
Hover Anything
--------------------------------------------------------------------------*/

$(document).ready(function() {

 $("#frmClientLogin button, #frmSearchSite button, #frmDomainName button, #frmDomainName button, #frmMailinglist button").hover(function() {
    $(this).addClass('btnHover');
  }, function() {
    $(this).removeClass('btnHover');
 }); 

});

/*--------------------------------------------------------------------------
Annoucements [ AJAX News Ticker ]
--------------------------------------------------------------------------*/
 
(function($) {

$.fn.newsTicker = $.fn.newsticker = function(delay)
{
  delay = delay || 4000;
  initTicker = function(el)
  {
    stopTicker(el);
    el.items = $("li", el);
    // hide all items (except first one)
    el.items.not(":eq(0)").hide().end();
    // current item
    el.currentitem = 0;
    startTicker(el);
  };
  startTicker = function(el)
  {
    el.tickfn = setInterval(function() { doTick(el) }, delay)
  };
  stopTicker = function(el)
  {
    clearInterval(el.tickfn);
  };
  pauseTicker = function(el)
  {
    el.pause = true;
  };
  resumeTicker = function(el)
  {
    el.pause = false;
  };
  doTick = function(el)
  {
    // don't run if paused
    if(el.pause) return;
    // pause until animation has finished
    el.pause = true;
    // hide current item
    $(el.items[el.currentitem]).fadeOut("slow",
      function()
      {
        $(this).hide();
        // move to next item and show
        el.currentitem = ++el.currentitem % (el.items.size());
        $(el.items[el.currentitem]).fadeIn("slow",
          function()
          {
            el.pause = false;
          }
        );
      }
    );
  };
  this.each(
    function()
    {
      if(this.nodeName.toLowerCase()!= "ul") return;
      initTicker(this);
    }
  )
  .addClass("newsticker")
  .hover(
    function()
    {
      // pause if hovered over
      pauseTicker(this);
    },
    function()
    {
      // resume when not hovered over
      resumeTicker(this);
    }
  );
  return this;
};

})(jQuery);

/*execute the script*/
/*
$.get("/scripts/index.html", {}, function(data) {
  $("#ulAnnouncements").append(data).find("ul").newsTicker();
})
*/
/*------------------------------------------------------------------------
Tabbed Navigation [Tools]
------------------------------------------------------------------------*/

$(document).ready(function(){
  
  $("#ulTools li a").click(function () {
   
   $("#ulTools li a.active").removeClass("active");
   $(this).addClass("active");
   
   $(".divToolsContent").hide();
   
   var content_show = $(this).attr("rel");
   $("#"+content_show).show();
   
   return false;
        
  }); 

});

/*------------------------------------------------------------------------
Tabbed Navigation [Features]
------------------------------------------------------------------------*/

$(document).ready(function(){
  
  $("#ulFeatures li a").click(function () {
                         
   $("#ulFeatures li a.active").removeClass("active");
   $(this).addClass("active");
   
   $(".divFeaturedContent").hide();
   
   var content_show = $(this).attr("rel");
   $("#"+content_show).show();
   
   return false;
        
  }); 

});

/*--------------------------------------------------------------------------
Toggle Field Input
--------------------------------------------------------------------------*/

(function ($) {

$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';

    return this.each(function () {
        var $$ = $(this); 
        var title = $$.attr('title'); 

        if (title) { 

            $$.blur(function () {
                if ($$.val() == '') {
                    $$.val(title).addClass(blurClass);
                }
            })

            .focus(function () {
                if ($$.val() == title && $$.hasClass(blurClass)) {
                    $$.val('').removeClass(blurClass);
                }
            })

            .parents('form:first').submit(function () {
                if ($$.val() == title && $$.hasClass(blurClass)) {
                    $$.val('').removeClass(blurClass);
                }
            }).end()

            .blur();

            if ($.browser.mozilla && !$$.attr('autocomplete')) {
                setTimeout(function () {
                    if ($$.val() == title) $$.val('');
                    $$.blur();
                }, 10);
            }
        }
    });
};

})(jQuery);

$(function(){ 
 $('input[title!=""], select[title!=""], textarea[title!=""]').hint();
});

/*--------------------------------------------------------------------------
External Web Sites | Images [Open Blank Window]
--------------------------------------------------------------------------*/

$(function() {
  $('a.viewWebsite').click(function() {
    window.open(this.href);
    return false;
  });
});

/*--------------------------------------------------------------------------
Scroll to the top of the page
--------------------------------------------------------------------------*/

$(document).ready(function(){
  $('a[href*=#top]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 2000); //My animation speed
      return false;
      }
    }
  });
});

/*----------------------------------------------------------------------------
Sub-menu behavior
-----------------------------------------------------------------------------*/
$(document).ready(function(){
	$('#divSubNavigation li span').click(function() {
		$(this.parentNode).toggleClass('open');
	});
});