
// 'stacks' is the Stacks global object.
// All of the other Stacks related Javascript will 
// be attatched to it.
var stacks = {};


// this call to jQuery gives us access to the globaal
// jQuery object. 
// 'noConflict' removes the '$' variable.
// 'true' removes the 'jQuery' variable.
// removing these globals reduces conflicts with other 
// jQuery versions that might be running on this page.
stacks.jQuery = jQuery.noConflict(true);

// Javascript for stacks_in_13_page3
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_13_page3 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_13_page3 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
//-- Like It Stack v1.1.0 by Joe Workman --//

/*  Tallest jQuery Plugin
 *	@author	nickf
 *	@date	2009-08-19
 *	@version 1.0 $Id: jquery.tallest.js 100 2009-08-19 00:40:09Z spadgos $
 */
jQuery(function($) {
	$.fn.tallest = function()       { return this._extremities({ 'aspect' : 'height', 'max' : true  })[0] };
	$.fn.tallestSize = function()   { return this._extremities({ 'aspect' : 'height', 'max' : true  })[1] };
	$.fn.shortest = function()      { return this._extremities({ 'aspect' : 'height', 'max' : false })[0] };
	$.fn.shortestSize = function()  { return this._extremities({ 'aspect' : 'height', 'max' : false })[1] };
	$.fn.widest = function()        { return this._extremities({ 'aspect' : 'width',  'max' : true  })[0] };
	$.fn.widestSize = function()    { return this._extremities({ 'aspect' : 'width',  'max' : true  })[1] };
	$.fn.thinnest = function()      { return this._extremities({ 'aspect' : 'width',  'max' : false })[0] };
	$.fn.thinnestSize = function()  { return this._extremities({ 'aspect' : 'width',  'max' : false })[1] };
	$.fn._extremities = function(options) {
		var defaults = {
			aspect : 'height', // or 'width'
			max : true	// or false to find the min
		};
		options = $.extend(defaults, options);
		if (this.length < 2) {
			return [this, this[options.aspect]()];
		}
		var bestIndex = 0,
			bestSize = this.eq(0)[options.aspect](),
			thisSize
		;
		for (var i = 1; i < this.length; ++i) {
			thisSize = this.eq(i)[options.aspect]();
			if ((options.max && thisSize > bestSize) || (!options.max && thisSize < bestSize)) {
				bestSize = thisSize;
				bestIndex = i;
			}
		}
		return [ this.eq(bestIndex), bestSize ];
	};
});
(function($){ 
    $.getScript = function(url, callback, cache){
    	$.ajax({
    			type: "GET",
    			url: url,
    			success: callback,
    			dataType: "script",
    			cache: true
    	});
    };
})(jQuery)

$(document).ready(function() {	
    
// Twitter Buttons
switch ( 3 ) {
case 1:
	$('#like_twitter1 a').attr('data-count', 'vertical');
    $.getScript('http://platform.twitter.com/widgets.js');
    break;
case 2:
    $('#like_twitter2 a').attr('data-count', 'horizontal');
    $.getScript('http://platform.twitter.com/widgets.js');
    break;
case 3:
    $('#like_twitter3 a').attr('data-count', 'none');
    $.getScript('http://platform.twitter.com/widgets.js');
    break;
default:
    // Do Nothing
}
// Google Buttons
switch ( 3 ) {
case 1:
	$('#like_google1 .like_google').html('<g:plusone size="small" count="false"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 2:
	$('#like_google2 .like_google').html('<g:plusone size="small" count="true"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 3:
	$('#like_google3 .like_google').html('<g:plusone size="medium" count="false"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 4:
	$('#like_google4 .like_google').html('<g:plusone size="medium" count="true"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 5:
	$('#like_google5 .like_google').html('<g:plusone size="standard" count="false"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 6:
	$('#like_google6 .like_google').html('<g:plusone size="standard" count="true"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
case 7:
	$('#like_google7 .like_google').html('<g:plusone size="tall" count="true"></g:plusone>');
    $.getScript('https://apis.google.com/js/plusone.js');
    break;
default:
    // Do Nothing
}

// Facebook Buttons
switch ( 2 ) {
case 1:
    $('#like_facebook1 .like_facebook').html('<fb:like show_faces="false" width="280"></fb:like>');
    break;
case 2:
    $('#like_facebook2 .like_facebook').html('<fb:like layout="button_count" show_faces="false" width="50"></fb:like>');
    break;
case 3:
    $('#like_facebook3 .like_facebook').html('<fb:like layout="box_count" show_faces="false" width="50"></fb:like>');
    break;
case 4:
    $('#like_facebook4 .like_facebook').html('<fb:like show_faces="false" width="450" action="recommend"></fb:like>');
    break;
case 5:
    $('#like_facebook5 .like_facebook').html('<fb:like layout="button_count" show_faces="false" width="50" action="recommend"></fb:like>');
    break;
case 6:
    $('#like_facebook6 .like_facebook').html('<fb:like layout="box_count" show_faces="false" width="50" action="recommend"></fb:like>');
    break;
default:
    // Do Nothing
}
// Digg Buttons
switch ( 0 ) {
case 1:
    $('#like_digg1 a').addClass('DiggWide');
    $.getScript('http://widgets.digg.com/buttons.js');
    break;
case 2:
    $('#like_digg2 a').addClass('DiggMedium');
    $.getScript('http://widgets.digg.com/buttons.js');
    break;
case 3:
    $('#like_digg3 a').addClass('DiggCompact');
    $.getScript('http://widgets.digg.com/buttons.js');
    break;
case 4:
    $('#like_digg4 a').addClass('DiggIcon');
    $.getScript('http://widgets.digg.com/buttons.js');
    break;
default:
    // Do Nothing
}
// LinkedIn Buttons
switch ( 0 ) {
case 1:
    $('#like_linkedin1').html('<script type="in/share" data-counter="top"></script>');
    $.getScript('http://platform.linkedin.com/in.js');
    break;
case 2:
	$('#like_linkedin2').html('<script type="in/share" data-counter="right"></script>');
	$.getScript('http://platform.linkedin.com/in.js');
	break;
case 3:
	$('#like_linkedin3').html('<script type="in/share"></script>');
	$.getScript('http://platform.linkedin.com/in.js');
	break;
default:
    // Do Nothing
}
// Evernote Button
if (0 != 0) {
    $.getScript('http://static.evernote.com/noteit.js');
}
//Email Button
$('.like_email a').attr('href','mailto:?subject=Check out this webpage&body='+location.href);
// Make all buttons have the same height and display it
// $('.like_button_wrapper').height( $('.like_button').tallest().height() );
});

//-- End Like It Stack --//
	return stack;
})(stacks.stacks_in_13_page3);


// Javascript for stacks_in_16_page3
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_16_page3 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_16_page3 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	
//-- Totem Stack v1.1.0 by Joe Workman --//

/*  Totem Ticker Plugin
 *	Copyright (c) 2011 Zach Dunn / www.buildinternet.com
 *	Released under MIT License */
(function(a){if(!a.omr){a.omr=new Object()}a.omr.totemticker=function(c,b){var d=this;d.el=c;d.$el=a(c);d.$el.data("omr.totemticker",d);d.init=function(){d.options=a.extend({},a.omr.totemticker.defaultOptions,b);d.ticker;d.format_ticker();d.setup_nav();d.start_interval()};d.start_interval=function(){clearInterval(d.ticker);if(d.options.direction=="up"){d.ticker=setInterval(function(){d.$el.find("li:last").detach().prependTo(d.$el).css("marginTop","-"+d.options.row_height);d.$el.find("li:first").animate({marginTop:"0px",},d.options.speed,function(){})},d.options.interval)}else{d.ticker=setInterval(function(){d.$el.find("li:first").animate({marginTop:"-"+d.options.row_height,},d.options.speed,function(){a(this).detach().css("marginTop","0").appendTo(d.$el)})},d.options.interval)}};d.reset_interval=function(){clearInterval(d.ticker);d.start_interval()};d.stop_interval=function(){clearInterval(d.ticker)};d.format_ticker=function(){if(typeof(d.options.max_items)!="undefined"&&d.options.max_items!=null){var f=d.options.row_height.replace(/px/i,"");var e=f*d.options.max_items;d.$el.css({height:e+"px",overflow:"hidden",})}else{d.$el.css({overflow:"hidden",})}};d.setup_nav=function(){if(typeof(d.options.stop)!="undefined"&&d.options.stop!=null){a(d.options.stop).click(function(){d.stop_interval();return false})}if(typeof(d.options.start)!="undefined"&&d.options.start!=null){a(d.options.start).click(function(){d.start_interval();return false})}if(typeof(d.options.previous)!="undefined"&&d.options.previous!=null){a(d.options.previous).click(function(){d.$el.find("li:last").detach().prependTo(d.$el).css("marginTop","-"+d.options.row_height);d.$el.find("li:first").animate({marginTop:"0px",},d.options.speed,function(){d.reset_interval()});return false})}if(typeof(d.options.next)!="undefined"&&d.options.next!=null){a(d.options.next).click(function(){d.$el.find("li:first").animate({marginTop:"-"+d.options.row_height,},d.options.speed,function(){a(this).detach().css("marginTop","0px").appendTo(d.$el);d.reset_interval()});return false})}if(typeof(d.options.mousestop)!="undefined"&&d.options.mousestop===true){d.$el.mouseenter(function(){d.stop_interval()}).mouseleave(function(){d.start_interval()})}};d.debug_info=function(){console.log(d.options)};d.init()};a.omr.totemticker.defaultOptions={message:"Ticker Loaded",next:null,previous:null,stop:null,start:null,row_height:"100px",speed:800,interval:4000,max_items:null,mousestop:false,direction:"down",};a.fn.totemticker=function(b){return this.each(function(){(new a.omr.totemticker(this,b))})}})(jQuery);

jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(document).ready(function() {	
	var bg_color = $('#stacks_in_16_page3').css('background-color');
	if (bg_color) { 
		$('#stacks_in_16_page3').css({'background-color': 'transparent'});	
		$('#totem_stacks_in_16_page3').css({'background-color': bg_color });	
	}
	var bg_border_style = $('#stacks_in_16_page3').css('border-bottom-style');
	if (bg_border_style) { 
		var bg_border_color  = $('#stacks_in_16_page3').css('border-bottom-color');
		var bg_border_top 	 = $('#stacks_in_16_page3').css('border-top-width');
		var bg_border_right  = $('#stacks_in_16_page3').css('border-right-width');
		var bg_border_bottom = $('#stacks_in_16_page3').css('border-bottom-width');
		var bg_border_left 	 = $('#stacks_in_16_page3').css('border-left-width');
		$('#stacks_in_16_page3').css({'border-width':0});	
		$('#stacks_in_16_page3 .totem_wrapper').css({	'border-style':bg_border_style,
							 			'border-color':bg_border_color,
										'border-top-width':bg_border_top,
										'border-right-width':bg_border_right,
										'border-bottom-width':bg_border_bottom,	
										'border-left-width':bg_border_left
		});	
	}
	// Remove the Nav containers if images were not used.
	if (! $('#totem_next_stacks_in_16_page3 img').exists()) {
	    $('#totem_next_stacks_in_16_page3').remove();
	}
	if (! $('#totem_prev_stacks_in_16_page3 img').exists()) {
	    $('#totem_prev_stacks_in_16_page3').remove();
	}
	
	$('#totem_stacks_in_16_page3').totemticker({
		row_height	:	'240px',
		next		:	'#totem_next_stacks_in_16_page3',
		previous	:	'#totem_prev_stacks_in_16_page3',
		stop		:	'#totem_stop',
		start		:	'#totem_start',
		mousestop	:	true,
        speed       :   400,
        interval    :   4000,
        max_items   :   1
	});	
	// Take the bottom borders into effect when calculating the height
	$('#totem_stacks_in_16_page3').height( (1 * 240) + (1 - 1));
});


//-- End Totem Stack --//
	return stack;
})(stacks.stacks_in_16_page3);


// Javascript for stacks_in_44_page3
// ---------------------------------------------------------------------

// Each stack has its own object with its own namespace.  The name of
// that object is the same as the stack's id.
stacks.stacks_in_44_page3 = {};

// A closure is defined and assined to the stack's object.  The object
// is also passed in as 'stack' which gives you a shorthand for refering
// to this object from elsewhere.
stacks.stacks_in_44_page3 = (function(stack) {

	// When jQuery is used it will be available as $ and jQuery but only
	// inside the closure.
	var jQuery = stacks.jQuery;
	var $ = jQuery;
	

//-- RSS JS Stack v1.3.0 by Joe Workman --//

//---------------------------
// Start Common RSS Code
//---------------------------
formatString = function(str) {
	str = str.replace(/<[^>]+>/ig,'');
	str=' '+str;
	return $.trim(str);
}

enrichString = function(str) {
	str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
	str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');
	str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');
	return $.trim(str);
}

parse_date = function(str) {
    if (str.match(/^\d+\-\d+\-\d+T/)) {
        str = str.replace(/T.+$/,'');
    }
	var d = new Date(str);
	var m = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
	if (d.getUTCDate()) {
		return d.getUTCDate() + ' ' + m[d.getUTCMonth()] + ' ' + d.getFullYear();
    }
    return str;
};

find_link = function(obj) {
    var default_string = '#';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.origLink == 'string') {
        return obj.origLink;
    }
    else if ($.isArray(obj.link)) {
        var mylink = obj.link[0].href;
        $.each(obj.link,function(index, value){
            if (value.rel === 'alternate') {
                mylink = value.href;
            }
		})
        return mylink;
    }
    else if (typeof obj.link == 'object') {
        return obj.link.href;
    }
    else if (typeof obj.link == 'string') {
        return obj.link;
    }
    else if (typeof obj.enclosure == 'object' && typeof obj.enclosure.url == 'string') {
        return obj.enclosure.url;
    }
    return default_string;
};

find_title = function(obj) {
    var default_string = 'No Items in RSS Feed';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.title.content == 'string') {
        return formatString(obj.title.content);
    }
    else if (typeof obj.title == 'string') {
        return formatString(obj.title);
    }
    else if (typeof obj.title == 'object') {
        return formatString(obj.title[0]);
    }
    return default_string;
};

find_date = function(obj) {
    var default_string = 'Date Unknown';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.pubDate == 'string') {
		return parse_date(obj.pubDate);
    }
    else if (typeof obj.date == 'string') {
		return parse_date(obj.date);
    }
    else if (typeof obj.published == 'string') {
		return parse_date(obj.published);
    }
    else if (typeof obj.updated == 'string') {
		return parse_date(obj.updated);
    }
    return default_string;
};

find_descr = function(obj) {
    var default_string = 'RSS Feed Invalid. No Description Found.';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.description == 'string') {
		return formatString(obj.description);
    }
    else if (typeof obj.encoded == 'string') {
		return formatString(obj.encoded);
    }
    else if (typeof obj.content == 'object' && typeof obj.content.content == 'string') {
		return formatString(obj.content.content);
    }
    return default_string;
};

find_author = function(obj) {
    var default_string = 'Unknown Author';
    if (obj == null || obj == undefined) {
        return default_string;
    }	
    else if (typeof obj.creator == 'string') {
		return obj.creator;
    }
    else if ($.isArray(obj.author)) {
        return obj.author[0];
    }
    else if (typeof obj.author == 'object' && typeof obj.author.email == 'string') {
		return obj.author.email;
    }
    else if (typeof obj.author == 'string') {
		return obj.author;
    }
    return default_string;
};

$(document).ready(function() {
	/* Forming the query: */
	var feed = "http://neurospinenews.blogspot.com/feeds/posts/default?alt=rss";
	feed = feed.replace(/feed:\/\//,'http://'); // Replace feed:// with http://
	var query = 'select * from feed where url="' + feed + '" LIMIT 4';

	/* Forming the URL to YQL: */
	var url = "http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent(query)+"&format=json&callback=?";

	$.getJSON(url,function(data){
		if (data.query == null || data.query == undefined || data.query.results == null || data.query.results == undefined) {
			// Invalid or Empty RSS Feed - Add Blank/Default Entries
			add_feed_item();
	 	}
	 	else if ($.isArray(data.query.results.item || data.query.results.entry) ) {  //item exists in RSS and entry in ATOM feeds
			$.each(data.query.results.item || data.query.results.entry,function(){
	       		//Normal RSS Feed
	       		add_feed_item(this);
			})
		}
		else {
		    // RSS Feed with only one item in it
			add_feed_item(data.query.results.item || data.query.results.entry || null);
		}
		post_process_feed(this);
	});
});
//---------------------------
// End Common RSS Code
//---------------------------

function add_feed_item(obj) {
    var maxLength = 200;
	$('#rss-js-list-stacks_in_44_page3').append('<li><a  href="'+ find_link(obj) +
	  '" target="_blank"><p class="rss-js-title">'+ find_title(obj) +
	  '</p><p class="rss-js-date">'+ find_date(obj) + 
	  '</p><p class="rss-js-desc">'+ find_descr(obj).substring(0, maxLength) +
	  '</p></a></li>'
	);
	return;    	        
};
function post_process_feed(obj) {
	if ($().tipTip) { $(".tiptip").tipTip(); }
	return;    	        
};
//-- End RSS JS Stack --//

	return stack;
})(stacks.stacks_in_44_page3);



