jQuery(function ($){
	
	$('.blink').focus(function () {
		if ($(this).val() == $(this).attr('title')) {$(this).val('');}
	}).blur(function () {
		if ($(this).val() == '') {$(this).val($(this).attr('title'));}
	});

	$('.print').click(function() {
		window.print();
		return false;
	});
	

	$('.subscriber-login').click(function() {
		if ($(this).hasClass('expanded')) {
			// don't ever hide it
			// $(this).removeClass('expanded').parent().next('.body').animate({ height: 0}, 300);
		} else {
			$(this).addClass('expanded').parent().next('.body').animate({ height: '136px'}, 300);
		};
		return false;
	});

	$('#navigation li').hoverIntent(
		function() {
			$(this).find('> a').addClass('hover').end().find('> ul').show();
		},
		function() {
			$(this).find('> a').removeClass('hover').end().find('> ul').hide();
		}
	);

	$('.welcome').hoverIntent(
		function() {
			$('.wrapper').before('<div id="explainer-compat"><div class="explainer-prof">Only a small portion of <i>SSIR</i> articles are available to non-subscribers.<br/><br/><strong>Subscriber-only articles are marked with a gray key.</strong></div></div>');
			
		},
		function() {
			$('.explainer-prof').delay(800).fadeOut('slow', function() {
				$('.explainer-prof').remove();
				$('#explainer-compat').remove();
			});			
		}
	);

	

	/* DISABLED FOR NOW
	$('.ico-key').hover(
		function() {
			$(this).after('<span class="explainer">This key indicates subscriber-only content.</span>');
		},
		function() {
			$('.explainer').delay(800).fadeOut('slow', function() {$('.explainer').remove();});
		}
	);
	*/

	if ($('.featured-slider').length) {
		$(".featured-slider ul").jcarousel({
			auto: 6,
			animation: 1000,
			scroll: 1,
			wrap: 'both',
			initCallback: function(carousel) {
				$('.featured-slider .slider-controls a').click(function() {
					var slide_num = parseInt($(this).text());
					carousel.scroll(slide_num);
					return false;
				});
				$('.featured-slider li').hover(
					function() {carousel.stopAuto();},
					function() {carousel.startAuto();}
				);
			},
			itemVisibleInCallback: function(carousel, li, idx, state) {
				$('.featured-slider .slider-controls a').removeClass('active');
				$('.featured-slider .slider-controls a').eq(idx-1).addClass('active');
			},
			buttonNextHTML: null,
			buttonPrevHTML: null
	    });
	};

	$('.slider').each(function() {
		var $this = $(this);
		
		myscroll = 1;
		if ($this.hasClass('issues')) {	myscroll = 4;	}

		$this.find('> ul').jcarousel({
			animation: 400,
			scroll: myscroll
	    });
	});

	$('.subscribe-to-magazine .field-initial-email').focus(function() {
		$('.subscribe-to-magazine .row').show();
		$(this).parent('.row').hide().next('.row').find('.field-email').focus();
		$('.subscribe-to-magazine').animate({ height: '405px' }, 300);
	});

	$('.widget-most-read .head li a').click(function() {
		var active_class = $(this).parent('li').attr('class'),
			href = $(this).attr('href');

		$(this).parents('.head:eq(0)').removeClass('tab-1 tab-2').addClass(active_class);
		$(this).parents('.head:eq(0)').next('.body').find('.tab').hide();
		$(href).fadeIn();
		return false;
	});

	$('#reply textarea').focus(function() {
		$(this).animate({ height: '184px' }, 400);
		$('#reply form > *').show();
	});

	$(window).resize(function() {
		if ($(window).width() <= 1040) {
			$('.btn-subscribe-sub, .btn-subscribe-help').fadeOut();
		} else {
			$('.btn-subscribe-sub, .btn-subscribe-help').fadeIn();
		};
	}).resize();

});

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
