$('html').addClass('hasjs');

Cufon.replace('.history h5, .company h1:not(.company .desc h1), .identity.home h1', {
	hover: true,
	fontFamily: "Light"
});

Cufon.replace('#snav h3', {
	hover: true,
	fontFamily: "Black"
});



var $j = jQuery.noConflict();
$j(document).ready(function() {
	
	$j('#snav ul li.selected ul').show().addClass('visible');
	
	//accordion
	$j('#snav h3').click(function(){
		if ( $j(this).siblings('ul').is(':visible') ) {
			$j(this).siblings('ul').slideUp(400).removeClass('visible');
		} else {
			// added to close open :visible elements
			$j('#snav h3').siblings('ul').slideUp(400).removeClass('visible');
			$j('#snav .visible').slideUp(400).removeClass('visible');
			$j(this).siblings('ul').slideDown(400).addClass('visible');
		}
	});
	//end accordion
	
	
	if(($j('#itemcarousel li').index($j('li.selected'))+1) > 9) {
		var setStart = (9 * parseInt((($j('#itemcarousel li').index($j('li.selected')))+1)/9));
		
	} else {
		var setStart = 1;
	}
	
/*
	console.log($j('#itemcarousel li').index($j('li.selected'))+1);
	console.log(parseInt(20/9));
	console.log(setStart);
*/
  	
	
	// set up carousel
	$j("#itemcarousel ul").jcarousel({
  		scroll: 1,
  		start: setStart
  	});
  	
  	
  	function setStart(carousel, state) {
  	  	if ($j('#itemcarousel li.selected').attr('jcarouselindex') > 9) {
	  		carousel({
	  		start: $j('#itemcarousel li.selected').attr('jcarouselindex')
			});
	  	} else {
	  		carousel({
	  		start: 1
			});		
	  	}
  	}

    	if (!$j('body').hasClass('company')) {
  			if ($j('#itemcarousel li').size() <= 9) {
  		  		$j('.jcarousel-prev, .jcarousel-next').hide();
  			}
    	}

  

  
  //add carousel hovers
  $j('#itemcarousel:not(.advantage #itemcarousel, .history #itemcarousel) li .img').each(function(){
  	var a = $j(this).children('a').attr('href');
  	//console.log(a);
  	$j(this).after('<div class="hoverborder hidden"><a href="' + a + '"></a></div>')
  });
  
  $j('#itemcarousel li:not(.advantage #itemcarousel, .history #itemcarousel)').hover(function(){
  	//console.log('hover');
  	$j(this).find('.hoverborder').removeClass('hidden');
  	$j(this).css('z-index','2');
  },function(){
  	$j(this).find('.hoverborder').addClass('hidden');
  	$j(this).css('z-index','1');
  });
  // end carousel
 
 	//item image rotator
 	$j('.itemimg li:gt(0)').fadeOut(0);
 	$j('.itemimg li:eq(0)').addClass('visible');
 	
 	
 	$j('#colorname').html($j('.colors li:first').find('img').attr('alt'));
 	
 	$j('.colors li').hover(function(){
		var ind = $j(this).prevAll().length;
		//console.log(ind);
		$j('.itemimg .visible').fadeOut(200).removeClass('visible');
		$j('.itemimg li:eq(' + ind + ')').fadeIn(200).addClass('visible');
		$j('.colors .selected').removeClass('selected');
		$j(this).addClass('selected');
		$j('#colorname').html($j(this).find('img').attr('alt'));
 	}, function(){
 	
 	});
 	//end item image rotator
 
 
  //setup form js
  $j('#retailerd input').each(function(){
  	var ogval = $j(this).val()
  	$j(this).data('ogval', ogval)
  });
  
 
  $j('#retailerd input').focus(function(){
  	if ($j(this).hasClass('live')) {
  	} else {
  		//$j(this).val('');
  		$j(this).val('');
  		//console.log(val);
  		$j(this).keyup(function(){
  				$j(this).addClass('live');
  			if( $j(this).hasClass('live') ){
  			} else {
  			}
  		});
  	}
  });

	$j('#retailerd input').blur(function(){
  	if($j(this).val() == '') {
  		var ogval = $j(this).data('ogval');
  		$j(this).val(ogval).removeClass('live');
  	}
  });
  //end setup form js
  
  // inventory pop up
  $j('#inventory a').click(function(){
  	var href = $j(this).attr('href');
  	window.open(href, 'Inventory', 'width=638,height=359,left=0,top=0,scrollbars=yes');
  	return false;
  });
  
  //$j('.inventorypop').css({'height': '329px', 'overflow': 'auto'});
  
  //ie6 class fix
  if (document.all && !window.opera && !window.XMLHttpRequest) {
  	//IE 6
  	$j('tr td:first-child').addClass('firsttd');
  	$j('.last td:last-child, .toprow th:last-child').addClass('lastchild');
  	$j('.totals td:first-child, .toprow td:first-child').addClass('firstchild');
  	$j('.actions button').hover(function(){
  		$j(this).addClass('hover');
  	}, function(){
  		$j(this).removeClass('hover');
  	}); 
  } else if (window.XMLHttpRequest && document.all) {
  	//IE 7
  	$j('.last td:last-child, .toprow th:last-child, .totals td:last-child').addClass('lastchild');
  }
  
  
  // inventory & add to cart scroll
  
  if ($j('#retailerd').size() > 0) {
	var offset = $j(".col3").offset();
	var topPadding = 15;
	$j(window).scroll(function() {
	if ($j(window).scrollTop() > offset.top) {
	     $j(".col3").stop().animate({
	     marginTop: $j(window).scrollTop() - offset.top + topPadding
	     });
	} else {
	    $j(".col3").stop().animate({
	    marginTop: 0
	    });
	};
	});
  }
  
  // detail arcTechnology hovers
  
/*
  $j('.flexhover').hover(function(){
  	$j(this).find('span').html('easy stretch that flatters every shape and fit.');
  }, function(){
  	$j(this).find('span').html('');
  });
  
   $j('.luxhover').hover(function(){
  	$j(this).find('span').html('super soft and luxuriously touchable');
  }, function(){
  	$j(this).find('span').html('');
  });
*/

   $j('.techlogo img').hover(function(){
   	$j(this).next().html($j(this).attr('alt'));
  }, function(){
   	$j(this).next().html('');
  });


  
});
