$(document).ready(function(){
	//$(".alternate tr:even").addClass('verse1');
	//$(".alternate tr:odd").addClass('verse2');
	/*$(".alternate tr").find("td:first").each(function(){
		$(this).addClass('numbers');
	});*/

	$("table#biblia tr, table.leituras tr").hover(function(){
		$(this).find("td:eq(1)").css('color','#F00').attr('title', '');
		$(this).find("td:eq(2)").html('<span title="Enviar este versículo para o Twitter" style="background: url(/img/ico-twitter.gif); width: 16px; height: 16px; display: block; position: absolute;"></span>').css("cursor","pointer");
	},function(){
		$(this).find("td:eq(1)").css('color','#000').attr('title', '');
		$(this).find("td:eq(2)").html('');
	});
	
	$("table#biblia tr, table.leituras tr").find("td:eq(2)").click(function(){
		$verse = $(this).prev().html();
		$verse = ($verse.length > 97) ? $verse.substring(0,97) + "..." : $verse;
		var w = 550;
		var h = 450;
		var left = (screen.availWidth/2)-(w/2);
		var top = (screen.availHeight/2)-(h/2);
		var url = (location.href == 'http://www.bibliacatolica.com.br/leituras-fanpage.php') ? 'http://www.bibliacatolica.com.br/leituras.php': location.href;
		settings = 'width='+ w +',height='+ h +',top='+ top +',left='+ left +',scrollbars=no,toolbar=no';
		window.open('http://twitter.com/share?url=' + url + '&text=' + encodeURI($verse) + '&via=bibliacatolica&related=bibliacatolica,catolicosbrasil,blogcatolico&lang=pt', 'Twitter', settings);
		_gaq.push(['_trackSocial', 'Twitter', 'tweet', url]);
	});

	$("a.feed").click(function(){
		FB.ui({
			method: 'feed',
			link: $(this).attr("href"),
			picture: 'http://www.bibliacatolica.com.br/img/bibliacatolica-100x100.jpg',
			name: $(this).attr("title") + ' - Bíblia Católica Online',
			caption: $(this).attr("title"),
			description: $(this).parent().find(".versiculo").text()
		},function(response) {
			if (response && response.post_id) {
			  _gaq.push(['_trackSocial', 'Facebook', 'Share', response]);
			}
		});
		return false;
    });

	/*$("table.leituras tr").find("td:eq(2)").click(function(){
		$verse = $(this).prev().html();
		window.open("/include/twitterVerse.php?longUrl=http://www.bibliacatolica.com.br/leituras.php&verse=" + encodeURI($verse), "twitter");
	});*/
	
	$(".postTwitter").click(function(){
		$verse = $(this).parents("td").find(".versiculo").html();
		$longUrl = $(this).next().attr("href");
		window.open("/include/twitterVerse.php?longUrl="+ $longUrl +"&verse=" + escape($verse), "twitter");
	});
	
	$("ul#navVersion li a").each(function(){
		$title = $(this).html();
		$(this).attr("title", $title);
	});
	
	$(".podcast").each(function(){
		$mp3 = $(this).attr("rel");
		$(this).flash({ src: '/lib/player.swf', width: 450, height: 24, flashvars: { soundFile: [$mp3].join(' ') }}, { version: 9 });
	});

    if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1 && !$.cookie('no_cp')) {
        $("body").prepend('<div class="ext_bibliacatolica_chrome_promo_delay"></div>');
        setTimeout(function() {
            $(".ext_bibliacatolica_chrome_promo_delay").html('<p>Instale a extens&atilde;o da <a href="http://bit.ly/g93mBm">B&iacute;blia Cat&oacute;lica para Chrome</a> - A melhor maneira de acessar a Palavra de Deus!</p><a class="close" href="#">x</a><a class="install rounded" href="http://bit.ly/g93mBm">Install</a>').slideDown();
            $(".ext_bibliacatolica_chrome_promo_delay a.close").bind("click", function(e) {
                e.preventDefault();
                $.cookie('no_cp', 'no_cp', { expires: 365, path: '/', domain: 'bibliacatolica.com.br' });
                $(".ext_bibliacatolica_chrome_promo_delay").slideUp(function() { $(this).remove(); });
            });
        }, 2000);
    }

	$(".ticker").vTicker({ showItems: 1 });

});

function sendform(field,value) {
	field.value = value;
	document.forms[0].submit();
}

function plusone_vote( obj ) {
	//_gaq.push(['_trackSocial', 'Plusone', obj.state]);
}

(function($){
    jQuery.cookie = function (key, value, options) {
        if (arguments.length > 1 && (value === null || typeof value !== "object")) {
            options = jQuery.extend({}, options);
            if (value === null) {
                options.expires = -1;
            }
            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }
            return (document.cookie = [
                encodeURIComponent(key), '=',
                options.raw ? String(value) : encodeURIComponent(String(value)),
                options.expires ? '; expires=' + options.expires.toUTCString() : '',
                options.path ? '; path=' + options.path : '',
                options.domain ? '; domain=' + options.domain : '',
                options.secure ? '; secure' : ''
            ].join(''));
        }
        options = value || {};
        var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
        return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    };
})(jQuery);

