$(document).ready(function() {
	
	$("div.subtabs > div").hover(function() {
             if($(this).is('.subtab_off')) {
				$(this).removeClass("subtab_off");
            	$(this).addClass("subtab_hover");
            }
    }, function() {
    	 	if(!$(this).is('.subtab_on')) {
    			$(this).removeClass("subtab_hover");
    			$(this).addClass("subtab_off");                                
			}
    });
    
	$("div.subtabs > div").click(function() {
    	 	if(!$(this).is('.subtab_on')) {    	 		
    			//handle the subtabs
    	 		$("div.subtabs > div").removeClass("subtab_hover");
    			$("div.subtabs > div").removeClass("subtab_on");
    			$(this).addClass("subtab_on");
    			$("div.subtabs > div:not(.subtab_on)").addClass("subtab_off");

				//hide all the divs	
    			$("div#content > div").hide();
    			    			    			
    			var divId = $(this).attr('id').replace('subtab','content');    		
    			
    			if ($("div#"+divId).is('.empty_theme')) {    				
    				$("div#loading_themes").show();    				
    				var themeVal = $("div#"+divId+" div.theme_name").html();    				
    				//do a post
					$.post("/events/ajax/"+$("#event_id").val()+"/category/", { theme: themeVal },
   						function(data){     						   		   																
	   							$("div#"+divId).html(data.content);   						   							   							
									   							
	   							$("div#loading_themes").hide();	   								   															
								$("div#"+divId).removeClass("empty_theme");
    							$("div#"+divId).show(); 						    							
   						}, "json"   					
					);	    								    			
    			} else {    			    			    				    			    			
    				//show the one div    				
    				$("div#"+divId).show();
				}
    			    			
			}			            
    });

	$("#mc_submit").click(function() {
		if ($("#mc_email").val().length) {			
			//make it loading
			$("#mc_error").html("");
			$("#mc_error,#mc_form").hide();
			$("#mc_loading").show();			
			$.post("/mailchimp/ajax_subscribe/", { mc_email: $("#mc_email").val() },
					function(data){   						   				   												
						$("#mc_loading").hide();
						if (data.success) {		   								   								
							$("#mc_signup").html("Thanks!  You'll now receive updates about new ITMemos content.");
						} else {							
							$("#mc_error").html(data.error);
							$("#mc_error,#mc_form").show();
						}
					}, "json"   					
			);
		}
	});

});

function validateExportForm(exportForm) {
	var chks = document.getElementsByName('authors[]');
	for (var i = 0; i < chks.length; i++) {
		if (chks[i].checked)
		{			
			return true;
		}
	}

	chks = document.getElementsByName('articles[]');
	for (var i = 0; i < chks.length; i++) {
		if (chks[i].checked)
		{			
			return true;
		}
	}		
	return false;
}
