// JavaScript Document

var openMenu = null;
var next = 0;

function openSubmenu(id){
	var expand = dojo.animateProperty({
		node: id,
		duration: 700,
		properties: {
			width: {end:550, unit:"px"}
		}							  
	});
	expand.play();
	
	if(openMenu != null)closeSubmenu(openMenu);
	if(openMenu == id)openMenu=null;
	else openMenu = id;
}

function closeSubmenu(id){
	var contract = dojo.animateProperty({
		node: id,
		duration: 700,
		properties: {
			width: {end:0, unit:"px"}
		}							  
	});
	contract.play();
}


$(function() {
        $('.lightbox').lightBox();
});

function getNewsFeed(){
	$("#ticker h2").fadeOut();
	$("#ticker h3").fadeOut("slow",function(){
		$.ajax({url: '/calls/ajax_ticker.php', data : {id:next}, cache: false, success: function(e){showNewsFeed(e)} });
	});
}

function showNewsFeed(e){
	$("#ticker h2").css({"display":"none"});
	$("#ticker h3").css({"display":"block","width":"0px"});
	
	var stuff = e.split("||");
	
	$("#ticker h2").html("<a href='/news?id="+stuff[3]+"'>"+stuff[0]+"</a>");
	$("#ticker h3").html("<a href='/news?id="+stuff[3]+"'>"+stuff[1]+"</a>");
	
	$("#ticker h2").fadeIn("slow",function(){
		$("#ticker h3").animate({"width":"790px"},1400,"linear",function() { next = stuff[2]; refreshTicker(); });							   });
}

function refreshTicker(){
	setTimeout(getNewsFeed,10000);
}

window.onload = function(){
	getNewsFeed();
};
