/****************** 

Filname:		elle.js
Theme Name: ELLE Blog
Author:		  Dustan Franks
Date:		    2011/08/10
Email:		  dustanf@gmail.com
Version:	  1.0

*****************/

$(document).ready(function(){  // Call jQuery functions

/* Email Subscription Form */
// validate signup form on keyup and submit
	$("#subscribeForm").validate({
		rules: {
			emailAddress: {
				required: true,
				email: true
			}
		},
		messages: {
			emailAddress: {
				required: "Please enter your email address",
				email: "Please enter a valid email address"		
		 }
	 }
});
// Sidebar Subscription Form	
	$("#subscribeFormSidebar").validate({
		rules: {
			emailAddress: {
				required: true,
				email: true
			}
		},
		messages: {
			emailAddress: {
				required: "Please enter your email address",
				email: "Please enter a valid email address"		
		 }
	 }
});

/* Blog Post Comment Form */

$("#commentsForm").validate(
	{
		rules: { 
			author: { 
				required: true,
				minlength: 3
			},
			email: {
				required: true,
				email: true
			},
			comment: {
				required: true,
				minlength: 10
			}
		},
		messages: { 
			author: {
				required: "Please enter your name",
				minlength: "Please enter at least 3 characters"	
			},
			email: {
				required: "Please enter your email address",
				minlength: "Please enter a valid email address"
			},
			comment: {
				required: "Please enter your message"	,
				minlength: "Please enter at least 10 characters"
			}
		}
	}
);					
							
/**** UX Controls ****/

/* Email Subscription DropDown */
$("a.subscribeBtn").click (function(){
	  if( $(this).hasClass("open") ){ // Check if button has "open" class
			$(this).next(".subscribeForm").slideToggle();
			$("#nav").css('z-index','99999');
			$(".searchForm").css('z-index','99999');
			$(this).removeClass("open");
		} else {
	  	$(this).addClass("open");
			$(this).next(".subscribeForm").slideToggle();
			$("#nav").css('z-index','9');
			$(".searchForm").css('z-index','9');
		}
		return false;
});

/* The Close Button */
$("a.closeBtn").click(function(){
	$(".subscribeForm").slideUp();
	$(".subscribeBtn").removeClass("open");	
	$("#nav").css('z-index','99999');
	$(".searchForm").css('z-index','99999');
	return false;
});

/* Navigation Dropdown (The Super Evil Amazingly Awesome Mega Sexy Dropdown Menu )*/ 

// Match The Height of the dropdown menu items ( to make it look pretty ) - FIX THIS SHIT


// This is a monster menu, call me if you need me to explain why / how I did this 

$("#nav ul li").hover(function(){ 
	 if( $(this).hasClass("active") ){
		//$(this).find('a.label').removeClass('hover');
		$(this).find('ul:first').hide();
	 } else {
		$(this).find('a.label').addClass('hover');
		$(this).find('ul:first').show();  
	 }
},function(){ 
	$(this).find('a.label').removeClass('hover');
	$(this).find('ul:first').hide(); 
});

	
/*** Home Page ***/ 

/* Content Slider */
$('#button a').click(function(){
	var integer = $(this).attr('rel');
	$('#myslide .cover').animate({left:-440*(parseInt(integer)-1)})  /*----- Width of div mystuff (here 160) ------ */
	$('#button a').each(function(){
	$(this).removeClass('activeButton');
		if($(this).hasClass('button'+integer)){
			$(this).addClass('activeButton')}
	});
	return false;
});	

	
/* Tabbed Content */
//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li").addClass("small").show(); // Add the small class to all tabs
	
	$(".firsTabs ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".firsTabs ul.tabs li:first").removeClass("small").show();
	
	$(".fashionTabs ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".fashionTabs ul.tabs li:first").removeClass("small").show();
	
	$(".elleWorld ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".elleWorld ul.tabs li:first").removeClass("small").show();
	
	$(".elleConnect ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".elleConnect ul.tabs li:first").removeClass("small").show();
	
	$(".firsTabs .tab_content:first").show(); //Show first tab content
	$(".elleWorld .tab_content:first").show(); //Show first tab content
	$(".elleConnect .tab_content:first").show(); //Show first tab content
	$(".fashionTabs .tab_content:first").show(); //Show first tab content
	
	//Home Page Left Column Tabs
	$(".firsTabs ul.tabs li").click(function() {

		$(".firsTabs ul.tabs li").removeClass("active"); //Remove any "active" class
		$(".firsTabs ul.tabs li").addClass("small"); //Remove any "active" class
		$(this).removeClass("small");	
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".firsTabs .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//Fashion Page Left Column Tabs
	$(".fashionTabs ul.tabs li").click(function() {

		$(".fashionTabs ul.tabs li").removeClass("active"); //Remove any "active" class
		$(".fashionTabs ul.tabs li").addClass("small"); //Remove any "active" class
		$(this).removeClass("small");	
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".fashionTabs .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//Elle World Home Page
	$(".elleWorld ul.tabs li").click(function() {

		$(".elleWorld ul.tabs li").removeClass("active"); //Remove any "active" class
		$(".elleWorld ul.tabs li").addClass("small"); //Remove any "active" class
		$(this).removeClass("small");	
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".elleWorld .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	//Sidebar Tabs
	$(".elleConnect ul.tabs li").click(function() {

		$(".elleConnect ul.tabs li").removeClass("active"); //Remove any "active" class
		$(".elleConnect ul.tabs li").addClass("small"); //Remove any "active" class
		$(this).removeClass("small");	
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".elleConnect .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

/* Contact Page Accordion */
$('.contactSearch .contactBlock:first').show(); // Expand The First Contact Section by Default
$('.contactSearch h4:first').addClass('active');
$('.contactSearch h4').click(function(){
	$('.contactBlock').slideUp();
		$('.contactSearch h4').removeClass('active');
		$(this).addClass('active');
		$(this).next('.contactBlock').slideDown();
		/*
	if ((this).hasClass('active')){
		// do nothing
	} else {
		
	}
	*/
});

/* Past Polls Accordion */
$('.pollsAccordion .pollsList:first').show(); // Expand The First Accordion by Default
$('.pollsAccordion h4:first').addClass('active');
$('.pollsAccordion h4').click(function(){
	$('.pollsList').slideUp();
		$('.pollsAccordion h4').removeClass('active');
		$(this).addClass('active');
		$(this).next('.pollsList').slideDown();
	/*
	if ((this).hasClass('active')){
		// prevent the active accordion from sliding
	} else {
		
	}*/
});

/*** ELLE TV ***/
$(".mainImages .largeVideo:first").show(); // Show the first video

$("ul.scrollingBox li").click(function(){		
	$(".mainImages .largeVideo").fadeOut();	
	var currentVideo = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
	$(currentVideo).fadeIn();
});

/* The Scroller */
var leftPos = $(".scrollingBox").css("marginLeft");
if( leftPos = '0px'){
	$(".left").hide();
}

/* The Left Button */
$("a.left").click(function(){
	var leftPos = $(".scrollingBox").css("marginLeft");
	if (leftPos == '0px'){
	// We won't see this
	} else if (leftPos == '-385px'){
		$("ul.scrollingBox").animate({ marginLeft: '0px'});
		$(this).hide();
		$("a.right").show();
	} else if (leftPos == '-770px'){
		$("ul.scrollingBox").animate({ marginLeft: '-385px'});		
		$("a.right").show();
	} else {
	// don't know
	}
	return false;
});

/* The Right Button */
$("a.right").click(function(){
	var leftPos = $(".scrollingBox").css("marginLeft");
	if (leftPos == '0px'){
		$("ul.scrollingBox").animate({ marginLeft: '-385px'});
		$("a.left").show();
	} else if (leftPos == '-385px'){
		$("ul.scrollingBox").animate({ marginLeft: '-770px'});
		$(this).hide();
		$("a.left").show();
	} else if (leftPos == '-770px'){
	} else {
		// don't know
	}
	return false;
});

/*** ELLE Runway ***/

/* The Vertical Scroller */
$('.currentItems ul').jcarousel({
	vertical: true,
   scroll: 4
});

/* Activating The ALPHABETICAL MENU */
$(".runwayBox .currentItems ul.jcarousel:first").show();
$(".runwayBox .currentItems ul.jcarousel:first").parent().parent().parent().show();

$(".alphaMenu a").click(function(){	
	var theLetter = $(this).html();
	var theDesigner = $(this).attr("href");
	$(".alphaMenu a").removeClass("active");
	$(this).addClass("active");
	$(".currentLetter").text(theLetter);
	
	$(".runwayBox .currentItems ul.jcarousel").fadeOut();
	$(".runwayBox .currentItems ul.jcarousel").parent().parent().parent().hide();
	
	$(theDesigner).fadeIn();
	$(theDesigner).parent().parent().parent().show(); 
	return false;
});

	
/**>> UX Controls <<**/

/**** Plugins ****/

/* Form Styling */
	$('input').ezMark();
	
// Cufon Text Replacement

	/* header and navgation */
	Cufon.replace('li.edsWorld', { fontFamily: 'Garamond 3 LT Std', fontWeight: 'bold' });
	Cufon.replace('.dateDisplay .month', { fontFamily: 'ELLE Gabor Std', fontWeight: 'bold' });	
		
	/* page titles */
	Cufon.replace('#sideBar h3 span.action', { fontFamily: 'ELLE Gabor Std', fontWeight: 'normal' });
	Cufon.replace('.twoColumnLeft h2 span.category', { fontFamily: 'ELLE Gabor Std', fontWeight: 'bold' });
	Cufon.replace('.twoColumnLeft h2 span.news', { fontFamily: 'ELLE Gabor Std', fontWeight: 'normal' });
	Cufon.replace('.fourOhFour .copyBlock p.heading', { fontFamily: 'ELLE Gabor Std', fontWeight: 'bold' });
	
	/* Poll Questions */
	Cufon.replace('h5.pollQuestion', { fontFamily: 'Garamond 3 LT Std', fontWeight: 'bold' });
	
	/*Tab Headings */
	Cufon.replace('#leftColumn span.tabHeading', { fontFamily: 'Garamond 3 LT Std', fontWeight: 'bold' });
	Cufon.replace('.garamond', { fontFamily: 'Garamond 3 LT Std', fontWeight: 'bold' });
	Cufon.replace('.gabor', { fontFamily: 'ELLE Gabor Std', fontWeight: 'bold' });
		
	/* Sidebar Stuff */
	Cufon.replace('span.connectLabel', { fontFamily: 'Garamond 3 LT Std', fontWeight: 'bold' });
			


/**>> Plugins <<**/

}); // Close the jQuery functions

