/*
 * 1d3a Theme by Luis Serrano
 * Initialization & config file
 * 
 */ 

var enableFacebookSharing = true;
var enableGoogleDocPlugin = true;
var enableNavigationEffect = true;
var enableNewsTicker = true;

var siteRSS =  "http://www.1d3a.es/feed/rss"; // "http://localhost/wordpress/feed/rss/";
var rssLinks = [];
 
/* var tagManager = new Array (); */
var maxNumTags = 10;
var tagCounter = 0;
 
function init () {
	var $objects = $('#theTags > ul > li');
	// Clear container and tags div
	$('#theTags').html('');		
	var x = 100;	
	$objects.each(function () {
		tagCounter ++;
		if (tagCounter <= maxNumTags)
		{
			// Create tag
			var aTag = new floatingTag ($(this).html(), 'orbital');
			aTag.metaData = $(this).attr('class');
			aTag.centerX = x;
			aTag.centerY = 462;
			aTag.init(); // Initialize
			// Start moving!	
			aTag.start(); 		
			// Add to manager
			/* tagManager.push (aTag); */
			// Add some space between tags
			x += 25;
		}
	});	
	
	$objects = null;
}

function ApplyEffects () {
	// PDF & PPT & Google Docs	
	if (enableGoogleDocPlugin) {
		googleDocPlugin.replaceTag ("articleDetail", true);
		googleDocPlugin.replaceTag ("noticia_left2", false);
	}
	
	// Facebook sharing link
	if (enableFacebookSharing) {
		$(".noticia_detall > .tagsContainer").prepend ('<a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Compartir</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>&nbsp;');
	}	
	
	// Header menu effect
	if (enableNavigationEffect) {	
			$("#navigation a:not(.selectedCat)").css({
				'text-align' : 'center',
				'border-bottom' : '0px solid #ff0000',
				'background-color' : ''
			});
			
			$("#navigation a:not(.selectedCat)").each (function () {
				var originalWidth = $(this).parent().width();
				$(this).mouseover (function () {
					$(this).parent().animate(
					{ 
						width: originalWidth + 20,
						backgroundColor : 'white',
						'border-bottom' : '10px solid #ff0000'						
					} , 
					{ duration: 350, easing: 'swing' })
				});
				$(this).mouseout (function () {
					$(this).parent().animate(
					{ 
						width: originalWidth,
						'border-bottom' : '0px'
					} , 
					{ duration: 350, easing: 'swing' })
				});				
			});
	}
	
	if (enableNewsTicker) {		
		$("#orbital").append ('<div id="newsTickerDiv"></div>');
		$("#newsTickerDiv").append('<div id="newsTickerContent"></div>').hide();

		var containerHeight = $("#orbital").height();
		var containerWidth = $("#orbital").width();
		var tickerHeight = 50 ;
		var tickerTop = containerHeight - tickerHeight;				
		
		$("#newsTickerDiv").css ({
			'z-index': 5001,
			"background-color" : '#fff',
			"opacity" : 0.7,	
			'border-top' : '6px solid #000',
			'text-align' : 'right', 
			width : containerWidth,
			overflow: 'hidden',
			position: 'relative',				
			left: '0px',
			top: tickerTop,
			height: tickerHeight
		});
		
		$("#newsTickerContent").css ({
			padding: '10px',
			opacity: 1,
			color: '#000',
			'font-size' : '18px'
		});
		
		$.getFeed({
			url: siteRSS,
			success: function(feed) {		
				$(feed.items).each(function(){
					var $item = $(this);
					theHtml = '<a href="' + $item.attr("link") + '" title="' + $item.attr("title").replace('"', '\"') + '">' + $item.attr("title").replace('"', '\"') + '</a>';
					rssLinks.push (theHtml);
				});	
				$("#newsTickerDiv").fadeIn("slow", function () { newsTicker(); });				
			}
		});	
	}	
}

function newsTicker ()
{
	$.each(rssLinks, function(i, val) {
		setTimeout(function() {
			$('#newsTickerContent').fadeOut("slow", function() {
				$(this).html(val).fadeIn("slow", function () {
					var newWidth = $(this).width();
					//$("#newsTickerDiv").animate ({ width: newWidth }, { duration: 350, easing: 'swing' });					
					if (i == (rssLinks.length -1)) 
						setTimeout(function() { $('#newsTickerContent').fadeOut("slow", newsTicker); }, 1500);
				});
			});
			
		}, i * 3000);
	});
}
