var stopScroll = 0
var x, repeatHeight, boxHeight;

function scrollMe() {
   //alert(repeatHeight+" AND "+boxHeight);
   clearTimeout(x)
   if(stopScroll==1) {
      return

   }
   $('#highlights').scrollTop($('#highlights').scrollTop()+1);
   if($('#highlights').scrollTop()<=repeatHeight) {
      // keep on scrolin' 
      x = setTimeout("scrollMe()",60)
   }
   else { //we have hit the wrap point
      $('#highlights').scrollTop(0);
		$('#spacer').css({height:0});
      x = setTimeout("scrollMe()",60)
   }
}

function homeChat() {
	var gotoURL = "http://mail.carats.com:9090/webchat/start.jsp?workgroup=carats.com@workgroup.mail.carats.com&location=https://www.carats.com";	
	window.open(gotoURL,"csChat","width=450,height=300");
}

function doSubmit(id) {
  var form = $("#"+id);
  form.submit();
}

function manInstruct() {
	$('#login-mail').bind('focus', function() {
		if($('#login-mail').val() == 'e-mail address') {	
			$('#login-mail').val('');	
		}
	});
	
	$('#login-mail').bind('blur', function() {
		if($('#login-mail').val() == '') {												  
			$('#login-mail').val('e-mail address');
		}
	});
	
	$('#login-pass').bind('focus', function() {
		if($('#login-pass').val() == 'password') {
			$('#login-pass').val('')
		}
	});
	
	$('#login-pass').bind('blur', function() {
		if($('#login-pass').val() == '') {
			$('#login-pass').val('password');			
		}
	});
}

function makeMenu(menuElement) {
  menuElement.children().each(function(i, node){
     // if there is a submenu
     var submenu = $(node).children("ul").eq(0);
     if(submenu != null){
        // make sub-menu invisible
        $(submenu).css({display: 'none'});
        // toggle the visibility of the submenu
        $(node).bind('mouseover', function(){
           var parentElem = $(submenu).offsetParent();
           var titleImg  = $(this).find("a>img");
           $(submenu).css({display: 'block'});
           titleImg.attr({'src': $(titleImg[0]).attr('src').replace('OFF', 'ON')});
        });
        
        $(node).bind('mouseout', function(){
           $(submenu).css({display: 'none'});
           var parentElem = $(submenu).offsetParent();
           var titleImg  = $(this).find("a>img");

           titleImg.attr({'src': $(titleImg[0]).attr('src').replace('ON', 'OFF')});
        });
        
      }
   });
}

function makeMoreHover() {
   $('[rel="hover"]').each(function(i, img) {
      $(img).bind('mouseover', function() {
         $(this).attr({'src': $(this).attr('src').replace('OFF', 'ON')});
         return true;
      });
      
      $(img).bind('mouseout', function() {
         $(this).attr({'src': $(this).attr('src').replace('ON', 'OFF')});
         return true;
      });
   });   
}

var preLoad = new Array;
$(function() {
	makeMenu($('#topNav'));												
   $('#topNav li a img').each(function(i, s) {
      if (document.images) {
         var nImg = $(s).attr('src').replace('OFF', 'ON');
         preLoad[nImg] = new Image;
         preLoad[nImg].src = nImg;
      }
      
      $(s).bind('mouseover', function() {
         var nImg = $(s).attr('src').replace('OFF', 'ON');
         $(this).attr('src', nImg);
         return true;
      });
         
      $(s).bind('mouseout', function() {
         $(this).attr({'src':$(this).attr('src').replace('ON', 'OFF')});
         return true;
      });
   });

   makeMoreHover();
   
   $("#otherCats").bind('change', function() {
      window.location = "/us/shop/products/"+$(this).val();
   });
   
	try {
   	manInstruct();
	} catch(err) {}
   
   
});