$(function()
{
	$('.hr-lnews').html('<img src="' + cnf.vir_path + 'templates/media/ajax-loader.gif" width="220" height="19">');
	
	$('#login_email').focus(function()
	{
		if (this.value == 'Email Address') {
			this.value = '';
		}
	}).blur(function()
	{
		if (this.value == '') {
			this.value = 'Email Address';
		}
	});

	$('#home_tickern').focus(function()
	{
		if (this.value == 'Ticker or Name') {
			this.value = '';
		}
	}).blur(function()
	{
		if (this.value == '') {
			this.value = 'Ticker or Name';
		}
	});

	$('input[alt*="date_"]').focus(function()
	{
		if ((this.alt == 'date_month' && this.value == 'MM') || (this.alt == 'date_day' && this.value == 'DD') || (this.alt == 'date_year' && this.value == 'YYYY')) {
			this.value = '';
		}
	}).blur(function()
	{
		if (this.value == '')
		{
			if (this.alt == 'date_month') {
				this.value = 'MM';
			}
			else if (this.alt == 'date_day') {
				this.value = 'DD';
			}
			else if (this.alt == 'date_year') {
				this.value = 'YYYY';
			}
		}
	});


	/* check if exists market block */
	if($('.nav-info').length) {
		updateMarket(true);
	}
	
	//-------------------------------------------------------------------------
	// READ FEEDS
	//-------------------------------------------------------------------------
	$.ajax({
		url: cnf.vir_path + "libs/lib.get_news.php",
		//data: "m=get_news",
		cache: true,
		success: function(data, textStatus)
		{
			var arr = data.split('|$|');
			
			$('.hr-lnews').html(data);
		}
	});
	
	
});


function updateMarket(first) 
{
	var self, _colorc;
	$.get(cnf.vir_path + 'index.php?m=get_ajax&p=get_market', function (responseText)
	{
		data = eval("(" + responseText + ")");
		$('#item_dtime').html(data.time);
		$.each(data, function()
		{
			if (this.name)
			{
				self = $('#item_' + this.name);
				_colorc = first || this.last_bid == $(self).find('.ni-newrap').html() ? false : true;
				$(self).find('.ni-newrap').html(this.last_bid);
				$(self).find('.ni-leftdata').html(this.days_change).removeClass(this.days_procentage < 0 ? 'ni-up' : 'ni-down').addClass(this.days_procentage < 0 ? 'ni-down' : 'ni-up');
				$(self).find('.ni-rightdate').html(this.days_procentage + '%');

				if (_colorc)
				{
					$(self).find('.ni-newrap, .ni-leftdata, .ni-rightdate').animate({'color': 'red'}, 2000);
					setTimeout('deleteMarketColors()', 5000);
				}

				// show nav info block
				if (first) {
					$('.nav-info').slideDown();
				}
			}
		});
	});

	setTimeout("updateMarket()", 30000);
}


function deleteMarketColors()
{
	$('.ni-newrap').animate({'color': '#666666'}, 2000);			
	$('.ni-leftdata, .ni-rightdate').animate({'color': '#000000'}, 2000);
}

function popCentered(url, widthh, heightt, params)
{

    var tp = Math.ceil((screen.height - heightt) / 2);
    var lf = Math.ceil((screen.width - widthh) / 2);
    if (params.length > 0)
		params = "," + params;

    var newwindow=window.open(url,'',"width=" + widthh + ",height=" + heightt + ",top=" + tp + ",left=" + lf + params);
	if (window.focus)
		newwindow.focus();

    return newwindow;
}






