$(document).ready(function() {	

   var mouse_is_inside = false;

   // These functions rely on DOM that needs to get build by other JS, once it is built it triggers the event JSDOMReady
   $('body').bind('JSDOMReady',function(){
      $("#dimebar_searchbox").focus(function(){
         if($(this).hasClass("empty")){
            $(this).attr({
               value:""
            });
         }
      })
      $("#dimebar_searchbox").blur(function(){
         if($(this).val()){
            $(this).removeClass("empty");
         }else{
            $(this).addClass('empty')
            $(this).val( "Search this Site");
         }
      })

      $('.has-dropDown').hover(function(){
         mouse_is_inside=true;
      }, function(){
         mouse_is_inside=false;
      });

      $('div.has-dropDown').find('.reg-link').click(function() {
         //      alert("dimebar click:" + $(this).next().attr("class") ); //this is the URL of the clicked link
         var $this = $(this).next();
         $('.db-dropDown').not($this).hide(220).siblings().removeClass('has-icon-hover');

         $(this).next('.db-dropDown').animate({
            height: "toggle"
         }, 400);
         //	alert("after");
         $(this).next().find('a.default-game').addClass('default-game-hover');
         $(this).toggleClass('has-icon-hover');
      //console.log('one')
      });

      $('li.db-franchise').hover(function() {
         $('li.db-franchise').find('a.default-game').removeClass('default-game-hover');
         var franchise = $(this).children().attr('id');
         $(this).children().addClass(franchise + '-hover');
      },function() {
         var franchise = $(this).children().attr('id');
         $(this).children().removeClass(franchise + '-hover');
         $('li.db-franchise').find('a.default-game').addClass('default-game-hover');
      });

      $('body > *:not(div#db-container)').click(function() {
         $('.has-icon-hover').removeClass('has-icon-hover');
         $('.db-dropDown').hide();
      });

      $('div.has-dropDown').find('a.reg-link').addClass('has-icon');

      $('#db-search label').fadeIn(1000);
      $('#db-search input').focus(function() {
         $(this).addClass('db-input-focused');
         if($(this).val() === '') {
            $('#db-search  label').fadeOut('fast');
         }
      });
      $('#db-search  input').blur(function() {
         $(this).removeClass('db-input-focused');
         if($(this).val() === '') {
            $('#db-search  label').fadeIn('slow');
         }
      });

   });

   
   $("body").mouseup(function(){
      //    	alert("mouse_is_inside:" + mouse_is_inside);
      if(! mouse_is_inside) {
         $('.has-icon-hover').removeClass('has-icon-hover');
         $('.db-dropDown').hide();
      }
   }); 


   ///-- Temp ---
   if(! $.browser.msie ) {
      $("#db-corporate-link").delay(1200).animate({
         backgroundPosition: '-210px 1px'
      }, 3200);
   }
		
				
   var Cookies = {
      init: function () {
         var allCookies = document.cookie.split('; ');
         for (var i=0;i<allCookies.length;i++) {
            var cookiePair = allCookies[i].split('=');
            this[cookiePair[0]] = cookiePair[1];
         }
      },
      create: function (name,value,days) {
         if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
         }
         else var expires = "";
         document.cookie = name+"="+value+expires+"; path=/";
         this[name] = value;
      },
      erase: function (name) {
         this.create(name,'',-1);
         this[name] = null;
      }
   };
   Cookies.init();
   var ncAionCookies=["NCLC","NCJSID","GPSESSIONID","JSESSIONID"];
	
   if(typeof(Cookies[(ncAionCookies[0])]) != "undefined"){
      $("#db-myAccount-link").html(ncDbLogoutString);
      $("#db-myAccount-link").addClass('mode-logout');
   }

});


