// JavaScript Document


$(document).ready(function(e) {

	var blogBoxClass = 'blogbox';
	
	$.jGFeed(feedXmlPath,
	function(feeds){
	  // Check for errors
	  if(!feeds){
		// there was an error
		return false;
	  }
	  // do whatever you want with feeds here
	  for(var i=0; i<feeds.entries.length; i++){
		var entry = feeds.entries[i];
		$( '.' + blogBoxClass + ' ul').append( '<li><a class="lg" href="' + entry.link + '" target="_blank">' + entry.title + '</a></li>' )
	  }
	}, 5);
	
	
	// Scroll blogBox
	var bbScrollSpeed = 1;
	$('.' + blogBoxClass).find('*[class|="scroll"]').hover( 
		function () {
			if ( $(this).hasClass('scroll-down') ) {
				scrollDown ( $(this).parents('.' + blogBoxClass).eq(0).find('ul') );
			}
			if ( $(this).hasClass('scroll-up') ) {
				scrollUp ( $(this).parents('.' + blogBoxClass).eq(0).find('ul') );
			}
		},
		function () {
			clearInterval ( bbScrollTimer );
		}
	);
	
	function scrollDown ( element ) {
		bbScrollTimer = setInterval ( function () {
			var posTop;
			var posTopInt;
			if ( element.css('top') == 'auto' )  { posTopInt = 0; } else { posTopInt = parseInt( element.css('top') ); }
			posTop = ( posTopInt - bbScrollSpeed ) + 'px';
			if ( element.innerHeight() + posTopInt > element.parent().height() ) { element.css({ 'top' : posTop }); }
			else { clearInterval ( bbScrollTimer ); }
		}, 5 );
	}
	function scrollUp ( element ) {
		bbScrollTimer = setInterval ( function () {
			var posTop;
			var posTopInt;
			if ( element.css('top') == 'auto' )  { posTopInt = 0; } else { posTopInt = parseInt( element.css('top') ); }
			posTop = ( parseInt( element.css('top') ) + bbScrollSpeed ) + 'px'; 
			if ( posTopInt < 0 ) { element.css({ 'top' : posTop }); }
			else { clearInterval ( bbScrollTimer ); }
		}, 5 );
	}
	
	
});
