// Superfish drop-down menus
$(function() {
    $("ul.sf-menu").supersubs({ 
		speed:      'fast',
		autoArrows:  false,	
        minWidth:    12,
        maxWidth:    27,
        extraWidth:  1
    }).superfish();
});

// Adding support placeholder text for forms fields
$(function() {
	$('[placeholder]').focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr('placeholder')) {
	    input.val('');
	    input.removeClass('placeholder');
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == '' || input.val() == input.attr('placeholder')) {
	    input.addClass('placeholder');
	    input.val(input.attr('placeholder'));
	  }
	}).blur().parents('form').submit(function() {
	  $(this).find('[placeholder]').each(function() {
	    var input = $(this);
	    if (input.val() == input.attr('placeholder')) {
	      input.val('');
	    }
	  })
	});
});

// Hide-show toggler for blog topics browser
$(function() {
	$('.topics').hide();
	$('li#topic_browser a').click( function() {
		$("li#topic_browser").addClass("selected");
		$(".topics").slideToggle("slow");
    	return false;
	});
});


// Fancybox dialog overlays
$(function() {
	$("a.fancybox").fancybox({
		'titlePosition' 	: 'inside',
		'titleFormat'		: formatTitle,		
		'transitionIn'		: 'fade',
		'transitionOut'		: 'none',
		'speedIn'			: 600, 
		'overlayShow'		: true,
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#666'
	});
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
    	return '' + (title && title.length ? '' + title + '' : '' ) + '<br />' + '<em>' + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</em>' + '';
	}
});

// Add target _blank to tweet a links
$(function() {
	$('.tweets').find('a').attr('target','_blank')
});
