/*
 * File: apme.content.js
 * Author: Jo�o Fonseca (j.fonseca@netcabo.pt)
 */
var apme = apme || {};

apme.news = {
	loadVideo: function(id) {
		$("#player_frame").attr('src',"/player.php?id="+id);
	},
	resultsCache: [],
	scrollCache: [],
	goBack: function() {
		 $("#right_container").html(apme.news.resultsCache.pop());
		 $(window).scrollTop(apme.news.scrollCache.pop());
	},
	showNews: function(id) {
		apme.news.resultsCache.push($("#right_container").html());
		apme.news.scrollCache.push($(window).scrollTop());
		$("#right_container").load('/news.php?id='+id+'&language='+apme.content.language+(apme.content.section==8?'&events=1':'')+'&nocache='+new Date().getTime(), function() {
			apme.content.setTitle();
			if ($(window).scrollTop() > 100) {
				$(window).scrollTop(100);
			}
		});
	},
	loadVideo: function(id) {
		$("#player_frame").attr('src',"/player.php?id="+id);
	},
	init: function(){
		var that = this;
		$(".news_item, .news_item_large, .news_item_link").live('click', function(){
			that.showNews($(this).attr('data-id'));
		});
		$(".pl_item").live('click', function(){
			that.loadVideo($(this).attr('data-id'));
		});
		$("#contactForm").live('submit', function(){
			$("#sendContactButton").after('<span id="sendingSpan">A enviar...</span>').hide();
		});
		$("#player_frame").attr('src', "/player.php?start=0&id=" + $('.pl_item:first').attr('data-id'));

		$('.pl_item').live({
			mouseover: function(){
				var title = $(this).find('.pl_title');
				title.replaceWith('<marquee class="pl_title">' + title.html() + '</marquee>');
			},
			mouseout: function(){
				var title = $(this).find('.pl_title');
				title.replaceWith('<div class="pl_title">' + title.html() + '</div>');
			}
		});
	}
};

function sendContactComplete(message)
{
	$("#sendingSpan").remove();
	$("#sendContactButton").show();
	$('<div style="text-align:center;"><br/><br/><b>'+message+'</b></div>').dialog({
		modal: true,
		buttons: {
			OK: function() {
				$(this).dialog('close');
			}
		}
	});
}

