/**
* jQuery SlideTo Plugin by Jesse Price
*
* @copyright Jesse Price <jesseprice.com>
* @description Animate slide scroll to effects to specific elements in the document
*/
// Create closure
(function($) {
	$.fn.slideto = function(options) {
	var opts = $.extend({}, $.fn.slideto.defaults, options);
	var elem = (this.length > 0) ? this : 'a';
	
	//console.log(elem);
	// Element instance specific actions
	$(elem).each(function() {
		var e = $(this);
		var o = $.meta ? $.extend({}, opts, e.data()) : opts;

		$(e).bind('click', function(){
		var url = $(e).attr("href");
		var anchor = '';
		if(url && url.indexOf("#") != -1 && url.indexOf("#") == 0){
			var pieces = url.split("#",2);
			anchor = $("a[name='"+pieces[1]+"']");
			//console.log('first');
		} else {
			anchor = $(o.target);
			//console.log('second');
		}
		//console.log(anchor);
		$('html, body').animate({
			scrollTop: anchor.offset().top - 50,
			scrollLeft: anchor.offset().left
		}, o.speed);
	});
 });

 // Allow jQuery chaining
 return this;
 };

 /**
 * Plugin Options
 * ---------------------------------------------------------------------
 * Overwrite the default options? Go for it!
 */
 $.fn.slideto.defaults = {
 target : false, // Where to scroll? If it's false, we use the "scroll attribute"
 speed : 1500 // slow, medium, fast, numeric microseconds
 }
})(jQuery); 
