

$(document).ready(function(){


	/* Dropdown menu nav */
	// Girls button
	$('.for-girls').hover(function(){
		$('.for-guys-active').removeClass('for-guys-active');
		$('.brands-active').removeClass('brands-active');
		$('.subnav-guys, .subnav-brands').hide();
		$(this).addClass('for-girls-active');
		$('.subnav-girls').show();
	});
		// Close girls subnav
		$('.subnav-girls').hover(function(){}, function(){
			$('.for-girls-active').removeClass('for-girls-active');
			$(this).hide();
		});
	// Guys button
	$('.for-guys').hover(function(){ 
		$('.for-girls-active').removeClass('for-girls-active');
		$('.brands-active').removeClass('brands-active');
		$('.subnav-girls, .subnav-brands').hide();
		$(this).addClass('for-guys-active');
		$('.subnav-guys').show();
	});
		// Close guys subnav
		$('.subnav-guys').hover(function(){}, function(){
			$('.for-guys-active').removeClass('for-guys-active');
			$(this).hide();
		});
	// Guys button
	$('.brands').hover(function(){ 
		$('.for-girls-active').removeClass('for-girls-active');
		$('.for-guys-active').removeClass('for-guys-active');
		$('.subnav-girls, .subnav-guys').hide();
		$(this).addClass('brands-active');
		$('.subnav-brands').show();
	});
		// Close guys subnav
		$('.subnav-brands').hover(function(){}, function(){
			$('.brands-active').removeClass('brands-active');
			$(this).hide();
		});
	// Hide on masthead, logo, or searchfield hover
	$('#masthead, .rue-logo, .searchfield').mouseover(function(){
		$('.for-girls-active').removeClass('for-girls-active');
		$('.for-guys-active').removeClass('for-guys-active');
		$('.brands-active').removeClass('brands-active');
		$('.subnav').hide();
	});



	$.fancybox.init();
	$('a.modal').fancybox({
		'centerOnScroll' : true,
		'callBackOnShow' : function() { $('#fancybox-wrap').hide(); $.fancybox.showActivity(); }
	});
	

	$('.subnav-columns > ul').easyListSplitter({ colNumber: 5 });

	
	$('.searchfield').focus(function() {
		$(this).val('');
	});


	/* The above column magic requires the subnav to exist in the DOM, so display: none; doesn't work -
	   but visibility: hidden; does. We're now changing it back to display: none; and visibility: visible;. */
	$('.subnav').hide().css('visibility','visible');

	/* Open rel=external in new window */
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

	/* Preload callout images as to avoid the fancybox from collapsing */
	$('.modal').each(function(){ 
		$(this).removeClass('modal');
		$.preloadImages = function(){for(var i = 0; i<arguments.length; i++){$("<img>").attr("src", arguments[i]);}}	
		$.preloadImages("/images/homepage-callouts/content/trends.jpg", "/images/homepage-callouts/content/deals.jpg");
		$(this).addClass('modal');
	});


	/* Add pipes between masthead LIs */
	$('#masthead').children('ul').children('li:nth-child(1)').append('|');
	$('#masthead').children('ul').children('li:nth-child(2)').append('|');

	/* Pop open Login bubble */
	$('.login-trigger').hover(function(){
		$('.login-bubble').show();
	});
	
	$('.signup-link, .fb-likebutton').hover(function(){
		$('.login-bubble').hide();
	});
	
	$('.login-bubble').hover(function(){}, function(){
		$(this).hide();
	});
	

	/* Opacity hovers for slideshow controls on homepage */
	$('.left, .right').hover(function(){ 
		$(this).animate({opacity: 0.8}, 100);
	}, function(){
		$(this).animate({opacity: 1}, 100);
	});

	/* Adding nth-child support in JS for IE on brands page... */
	$('.brandstile:nth-child(3n+1)').addClass('middle-tile');

	/* Classes for and last products in row for product listing */
	 $(".item:nth-child(5n+1)").addClass('first');
	
	$('.ie7').find('.item').removeClass('first');
	$('.ie7').find('.row').css('clear','both');
	$('.ie7').find('.row').find('.item:nth-child(5n+1)').addClass('first');
	 
	 

	/* Shrink post width to image width on trends page */
	$('.post').each(function() { 
		var imagewidth = ($(this).children('img').width());
		$(this).css('width', imagewidth);
	});

	

	/* Tabbed Facebook / Twitter boxes on rueCommunity page */
	$('.fb-link').click(function(){
		$(this).addClass('active');
		$('.tw-link').removeClass('active');
		$('.fb-mini-container').show();
		$('.tw-mini-container').hide();
	});

	$('.tw-link').click(function(){
		$(this).addClass('active');
		$('.fb-link').removeClass('active');
		$('.fb-mini-container').hide();
		$('.tw-mini-container').show();
	});
	
	/* Open / close job descriptions */
	$('.job > p').toggle();
	
	$('.job > h4').click(function(){
		$(this).siblings('p').toggle();
		$(this).toggleClass('active');
	});

	/* Homepage cycle */
	$("#slideshow").cycle({
		fx: 'scrollHorz',
		easing: 'easeInOutExpo',
		next: '.right',
		prev: '.left',
		timeout: 4000
	});	
	
	/* Pause homepage cycle on click left / right */
	$('.right, .left, .modal').click(function() { 
	    $('#slideshow').cycle('pause'); 
		$('.play').hide();
		$('.paused').show();
	});
	
	$('.play').click(function(){
		$('#slideshow').cycle('pause');
		$(this).hide();
		$('.paused').show();
	}); 
	
	$('.paused').click(function(){
		$('#slideshow').cycle('resume');
		$(this).hide();
		$('.play').show();
	});
	
	$('.form-left').find('.submit-button').click(function(){
		var labelspan = $('.formrow').children('label').find('span');
		labelspan.each(function(){
			$(this).parent('label').css('color','red');
			$(this).hide();
		});	
	});


	
});
