function login_demo() {
    $("#username").val("demosite");
    $("#domain").val("example.com");
    $("#password").val("demosite");
    $("#esprit_form").submit();
    return false;
}


$(document).ready(function () {
    var news_cnt = $('div.number').length;
    var prev_idx = 4;
    var cycle_timer = null;
    var cycle_count = 0;
	
    $('.number').mouseover(function (val) {
        hover_idx = parseInt($(this).text()-1);
        if (hover_idx == news_cnt-prev_idx-1) {

            return;
        }
        load_news(hover_idx);
        clearTimeout(cycle_timer);
    }).click(function () {
        location.href=$('#news_title > a').attr('href');
    });
    var cycle_news = function () {
        if (news_cnt-prev_idx > news_cnt-1) {
            idx = 0;
            cycle_count++;
        } else
            idx = news_cnt-prev_idx;
        if (cycle_count < 2)
            cycle_timer = setTimeout(cycle_news,3500);
        load_news(idx);

    }
    setTimeout(function () { setTimeout(cycle_news,3500); }, 5000);
	
    var load_news = function (item_idx) {
        $('.number :eq(' + (prev_idx) + ')').parent().removeClass('active');
        prev_idx = news_cnt-item_idx-1;

        $('#news_bit').fadeOut(250,function () {
            $('#news_title > a').attr('href',news_items[item_idx].link).text(news_items[item_idx].title);
            $('#news_date').text(news_items[item_idx].date);
        	$('.number :eq(' + (news_cnt-item_idx-1) + ')').parent().addClass('active');
            $('#news_bit').css({display: 'block'});
        });
    }
	
	$('#apnscp_demo').click(function() {
		return login_demo();
	});
	
	$('#apollo-clients').click (function(){
		var $div = $('<div>Clients can be migrated by opening a ticket within the control panel via <strong>Help</strong> &gt; ' +
					'<strong>Trouble Tickets</strong>. Migrations take approximately 24 hours to prepare, but complete instantaneously.</div>').append($('<input style="display: block;" type="submit" class="main" value="Access CP"/>').click(function() {
					$.modal.close();
					display_cp_login();
					$('#login-container input:first').focus();
					return false;
				}));
		$.modal(
				$div,
				{full: false}
		);
	});
});
