function get_rss_feed() {
	//clear the content in the div for the next feed.
	$("#feedContent").empty();
 
	//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	$.get('http://www.pimpmytrain.com/wp-content/themes/pmt2.0/rss.php?url=http://www.pimpmytrain.com/pimp/rss.php', function(d) {

		//find each 'item' in the file and parse it
		$(d).find('item').each(function() {
 
			//name the current found item this for this particular loop run
			var $item = $(this);
			// grab the post title
			var title = $item.find('title').text();
			// grab the post's URL
			var link = $item.find('link').text();
			// next, the description
			var description = $item.find('description').text();

			//don't forget the pubdate
			var pubDate = $item.find('pubDate').text();
 
			// now create a var 'html' to store the markup we're using to output the feed to the browser window
			var html = "<li class=\"entry\">";
			
			//console.log(description.lastIndexOf('<br>'),description.length);
			var inizio =description.indexOf('<br>');
			description = description.substr(0,inizio);
			//description = description.replace('src="','src="load.png" class="wp-post-image" data-original="');
			html += description;
			html += "<a title=\"guarda pimp my train graffiti galleria\" href=\"" + link + "\" target=\"_blank\"><span class=\"postTitle\">" + title + "<\/span> - vai alla galleria<\/a><\/li>";
 			html = html.replace('<br>','');
			//put that feed content on the screen!
			$('#feedContent').append($(html));
			
			
		});
	});
 
};



function scrollTo(id){
	var dove = $("#"+id).offset().top;
	$('html,body').animate({
		scrollTop: dove
	},'slow');
}

function getHash() {
  var hash = window.location.hash;
  return hash.substring(1); // remove #
}

$(document).ready(function(){
	get_rss_feed();
	
	/*$('.adv_here').each(function(){
		var testo = '<p>spazio disponibile <br/> formato:';
		testo += $(this).width() + 'x' + $(this).height() + '</p>';
		$(this).html(testo);
	});*/
	
	var hash = getHash();
	if (hash){
		if(hash=='commenta'){
			scrollTo('facebook-comments');
		}else{
			scrollTo(hash);
		}
	}
	
	$('li.loadthis a').lightBox({
		overlayBgColor: '#111',
		overlayOpacity: 0.6,
		imageLoading: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Immagini',
		txtOf: 'di'
	}); 
	
	$('a.lighThis').lightBox({overlayBgColor: '#111',
		overlayOpacity: 0.6,
		imageLoading: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/js/lightbox/images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Immagini',
		txtOf: 'di'
	});
	
	
	$('a#tornaSu').click(function(){
		scrollTo('header');
	});

	$("img.wp-post-image").lazyload({ 
    	effect : "fadeIn",
    	placeholder: 'http://www.pimpmytrain.com/wp-content/themes/pmt2.0/images/ajax-loader.gif', 
   	
	});
	
	
	

	
	
	 /*var aboveHeight = $('#menu').outerHeight();
 
	//when scroll
        $(window).scroll(function(){
 
	        //if scrolled down more than the headerÕs height
                if ($(window).scrollTop() > aboveHeight){
 
	        // if yes, add ÒfixedÓ class to the <nav>
	        // add padding top to the #content
                
                $('#menu').addClass('fixed').css('top','20').next()
                .css('padding-top','10px');
 
                } else {
 
	        // when scroll up or less than aboveHeight,
              
                $('#menu').removeClass('fixed').next()
                .css('padding-top','0');
                }
        });*/
});




(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) return;
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));



window.___gcfg = {lang: 'it'};
	(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
