$(document).ready(function() {

  


$(window).load(function(){
$('#frontpagearchiveswrapper').masonry({ columnWidth: 253,   });

    // Set the user's selection for the which issue browsing format

        var whichIssueFormat = $.cookie('whichIssueFormat');
    if (whichIssueFormat === 'covers') {
$('#issuesnav a[href="#issuescovers"]').click();
  };
   
});


$('.read_more').html('<strong>+More</strong>');

//$('.issuelistingpost a[href="#"]').each( function(){ $(this).remove();   });

//$('#issues h2+a[href="#"]').each( function(){ $(this).replaceWith("<span>Available Soon</span>");   });

//$('#issues div:contains("Soon")+div:contains("Soon")').css('display','none');



$('.largercontent').live('click',function(){
$('.instapaper_body').css({'fontSize':'14px'});
$('abbr', this).text("-");

$(this).removeClass().addClass('smallercontent').css({'fontSize':'11px'});
return false;

});


$('.smallercontent').live('click', function(){
$('.instapaper_body').css({'fontSize':'11px'});
$('abbr', this).text("+");

$(this).removeClass().addClass('largercontent').css({'fontSize':'13px'});


return false;


});

///////

$('a:has(img)').css("border-bottom","none");


$("a#expander").retina({preload:true,  css:{ width: 300, height: 300 }}).css({display:'inline-block'});

$("a.expander").fancybox({
	'overlayOpacity' : .7,
	'overlayColor' : '#2f2b2c',
'centerOnScroll' : true,
	'hideOnContentClick' : true,
	'speedOut' :100,
	});
	
 $("a#expander").fancybox({
 	'overlayOpacity' : .7,
 	'overlayColor' : '#2f2b2c',
 'centerOnScroll' : true,
 	'hideOnContentClick' : true,
 	'speedOut' :100,
 	});
	
	$(".media a:has(img)").fancybox({
	'overlayOpacity' : .7,
	'overlayColor' : '#2f2b2c',
'centerOnScroll' : true,
	'hideOnContentClick' : true,
	'speedOut' :100,
	});


 $(document).bind('keydown', 'Alt+q',function (evt){slideFunction(); return false; });
 
 


// Set the user's selection for the Header State

 var showTop = $.cookie('showTop');
    if (showTop == 'collapsed') {

 $("#dashbar").hide();
     $(this).removeClass("active");

 
 };
 
 
 $("a#closedashbar").click(function(){
 
 slideFunction();
 });
 
 
 function slideFunction(){
if ($("#dashbar").is(":hidden")) {
    $("#dashbar").slideDown("fast");
    $(this).addClass("active");
    $.cookie('showTop', 'expanded', { expires: 777, path: '/', domain: 'enjoyminutiae.com', secure: false });
    return false;

} else {
    $("#dashbar").slideUp("fast");
    $(this).removeClass("active");
    $.cookie('showTop', 'collapsed', { expires: 777, path: '/', domain: 'enjoyminutiae.com', secure: false });
    return false;}
 };


	



$("#selectionsnav a[rel!=all]").click(function(){

$("#selectionsnav a").removeClass('active');
$(this).addClass('active');

var linkString = $(this).attr('rel');
$("#selections a").hide();
$("#selections a." + linkString ).show();
return false;
});

 $("#selectionsnav a#all").click(function(){
$("#selectionsnav a").removeClass('active');
$(this).addClass('active');
$("#selections a").show();
return false;
        });
        
        
        


// Set the user's selection for the Header State

        var whichIssueFormat = $.cookie('whichIssueFormat');
    if (whichIssueFormat == 'covers') {
$("#issuesnav a").removeClass('active');
$('#issuesnav a[href="#issuescovers"]').addClass('active');
$("#issuesfull").hide(); 
$("#issuescovers").show();


 
 };
 

$("#issuesnav a").click(function(){

$("#issuesnav a").removeClass('active');
$(this).addClass('active');

 (linkString = $(this).attr('href'));
$("#issuesfull").hide(); $("#issuescovers").hide();
$(linkString).show();
    $.cookie('whichIssueFormat', $(this).attr('rel'), { expires: 777, path: '/', domain: 'enjoyminutiae.com', secure: false });

return false;
});


// Contact Form

    
$('#contact_form').each(function(){
    $('#contact_form').validate({
            submitHandler: function(form) { 
                var message =       $('#contact_form_msg').val();
                var sendername =    $('#contact_form_name').val();
                var senderaddress = $('#contact_form_email').val();
                var root = location.protocol + '//' + location.host;
                var dataString = 'action=contact_send&message=' + message + '&name=' + sendername + '&email=' + senderaddress; 
                $('#contactform form').css({'opacity':.5, 'pointer-events':'none'});
                jQuery.ajax({
                    type: "POST",
                    url: root+ "/wp-admin/admin-ajax.php",
                    data: dataString,
                    success: function(data) {
                        if (data == "mailed") {
                            $('#form-message, #form-fields, form input[type="submit"], #contact_form p').fadeOut('fast', function() {
                            $('#contact_form').addClass('sent');
                            $('#contact_form').html('<p><strong>Thank you.<br/>Computers are at work.</strong></p>');  
                            $('#contact_form').css({'opacity':1, 'pointer-events':'all'});
    
                            });
                        } else if (data == "nope") {
                            $('#contact_form form').css({'opacity':1, 'pointer-events':'all'});
                            $('#contact_form').append('<p><strong>Sorry</strong>, there was an error. Please try again.</p>');  
                        }
                    }
                });
            }
    });
});

$('#contactform form').submit(function(){

return false;
});

        

        

  
 });
