var timer, href, postid;
jQuery(document).ready(function($){

   /* bind download button to fancybox */
   $("a.download-buttons").click(function(e) {
		href = $(e.target).attr('href');
		postid = href.substring(9);
	}).fancybox({
		width          : '100%',
		height         : '100%',
		titlePosition  : 'inside',
		transitionIn   : 'none',
		transitionOut  : 'none',
		onStart        : function(){
			timer = true;
			countdown(15, postid);
		},
		onClosed       : function(){
			timer = false;
		}
   });

	/* timeout script */
	$.setCookie('fmw_interstitial', 1, { duration: 0, path: '/' });
	window.countdown = function(secs, postid) {
		if (secs == 0)
			  window.location = $('a#countdown-'+postid).attr('href');

		var plural = 's';
		if (secs == 1)
			plural = '';

		$('#countdown-'+postid).html('Your page will automatically load in ' +  secs + ' second' + plural + '.');
	
		secs--;

		if (secs > -1 && timer)
			setTimeout("countdown(" + eval(secs) + ", " + postid + ")", 1000);
	}
});

