var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;

function show_calendar_description(url , announce_id, image_path)
{

	var id= announce_id;
	if(jQuery('#description_'+id ).css('display') == 'block')
	{
		jQuery('#description_'+id ).slideUp('slow');
	}
	else
	{
		jQuery('#economic_calendar_table').find('div div.economic_description_slide').each(function(){
			if(jQuery(this).css('display') == 'block');
			jQuery(this).slideUp('slow');
		});
		
		url += '/id/'+ announce_id;
		jQuery.ajax({
			type: "GET",
			url: url,
			loading: jQuery('#description_'+id ).slideDown('slow'),
			success: function(msg){
				jQuery('#description_'+id ).html('');
				jQuery('#description_'+id ).html(msg);

			}
		});
	}

}

function showCalendarFilters(lang)
{
	if(lang == 'ar')
	{
		if(jQuery('#more_calendar_filters').css('display') == 'none')
		{
		jQuery('#more_filter_link').html('');
		jQuery('#more_filter_link').html('اخفاء البحث المتقدم');
		}
		else
	    {
		jQuery('#more_filter_link').html('');
		jQuery('#more_filter_link').html('اظهار البحث المتقدم');
	    }
	}
	else
	{
		if(jQuery('#more_calendar_filters').css('display') == 'none')
		{
		jQuery('#more_filter_link').html('');
		jQuery('#more_filter_link').html('Hide advanced filters');
		}
		else
	    {
		jQuery('#more_filter_link').html('');
		jQuery('#more_filter_link').html('Show advanced filters');
	    }
	}
	    
	jQuery('#more_calendar_filters').toggle('slow');

}

var page3=1;
function goPage3(url, id, image_path)
{
	var url=url;
	url+='/page/'+page3;
	//sethtml(id, '');
	sethtml(id,"<div id='indicator'><img src='"+ image_path +"'/></div>");
	jQuery.get(url,function(data){
		sethtml(id,data);
	});
}

function setPage3(no, url, id, image_path)
{
	page3=no;
	goPage3(url, id, image_path);
}

function showBody(id, loader)
{
	jQuery(id).html('');
	jQuery(loader).show();

}

function completeLoading(id)
{
	jQuery('#indicator').hide();
	jQuery(id).hide();
	jQuery(id).fadeIn('slow');
}

function adjust_my_time(my_url, is_local)
{
	var dt = new Date();
	var off= dt.getTimezoneOffset()/60; // offset from GMT
	var url = my_url;
	if(is_local == 0 || is_local == '')
	{
		is_local = 0;
		off = 0;
	}
	url += '/t_diff/'+off;
	url += '/local/'+is_local;

	jQuery.ajax({
		type: "GET",
		url: url,
		success: function(msg){
			jQuery('#set_your_time_div').html('');
			jQuery('#set_your_time_div').html(msg);
			window.location.replace( window.location.href );
		}
	});
}

function getCurrency(url,time){
	var url=url;
	//window.setTimeout('runMoreCode(\''+someString+'\','+someNumber+')',10);
	startSrteemCurrency(url);
}
var t;
function setTime(time)
{
	t=time;
}
function startSrteemCurrency(url){
	var url=url
	var d = new Date();
	//alert(t);
	jQuery.ajax({
		type: "POST",
		url: url,
		data: "t="+t,
		success: function(msg){
			jQuery('#currency_home_data').html('');
			jQuery('#currency_home_data').html(msg);
		}
	});
	setTimeout('startSrteemCurrency(\''+url+'\')',1000*60);
}
function setChanges(updated)
{
	for(var i=0;i<updated.length;i++)
	{
		jQuery('#'+updated[i][0]+'_currentPrice').html(updated[i][2]);
		//jQuery('#'+updated[i][0]+'_status').html(updated[i][1]);
	}
	updated=null;
}

function swapImage(id,imagepath){
	var id =id;
	//$("img").attr("src","test.jpg");
	jQuery("#"+id).attr({src: imagepath });
}
function swapImgRestore(id,imagepath){
	var id =id;
	//alert(id);
	//$("img").attr({ src: "test.jpg", alt: "Test Image" });
	jQuery("#"+id).attr({src:imagepath });
}
function getCurrencyData(show,hide,arrayDiv){
	
	var id = show.charAt(show.length -1);
	var num = 1;
	jQuery('#'+show).css({'display':'block'});
	jQuery('#'+hide).css({'display':'none'});
	jQuery('#medTabedArea div').each(function(){
		jQuery(this).removeClass('selected_upper_tab'+num);
		num += 1;
	});
	jQuery('.'+show).addClass('selected_upper_tab'+id);
	//jQuery('.'+hide+' a').removeClass('selected_upper_tab');
	var arrayDiv = arrayDiv;
	
	if(typeof(arrayDiv)!=undefined && arrayDiv != null){
		for(var i=0;i<arrayDiv.length;i++){
			jQuery('#'+arrayDiv[i]).css({'display':'none'});
		//	console.log(arrayDiv[i]);
		}
	}
}
function speedDown() {
	var speed;
	speed = document.getElementById('marquee-content').scrollDelay;
	if(speed <30) {
		speed += 5;
		document.getElementById('marquee-content').scrollDelay = speed;
	}
}

function speedUp() {
	var speed;
	speed = document.getElementById('marquee-content').scrollDelay;
	if(speed > 5) {
		speed -= 5;
		document.getElementById('marquee-content').scrollDelay = speed;
	}
}

function chDir() {
	var dir = document.getElementById('marquee-content').direction;
	if(dir == 'left') {
		document.getElementById('marquee-content').direction = 'right';
	}else {
		document.getElementById('marquee-content').direction = 'left';
	}
}

function show_analyzer_content(id, url)
{
	var news_id = id;
   if(news_id != '' && typeof(new_id) != undefined)
   {   	
   	url += '/id/' + news_id;
   	jQuery.ajax({
   		type: "GET",
		url: url,
		success: function(msg){
		   jQuery('#technical_body').html('');
		   jQuery('#technical_body').html(msg);
		}
   	});
  }
}
function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
  jQuery("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
    $(this).css('top','210px');
    });
  jQuery("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
  old_headline = current_headline;
}

function startSrteemPindingOrders(url, image_path){
	var url=url;
/*	//alert(t);
	jQuery.ajax({
		type: "POST",
		url: url,
		data: 'page='+page3,
		success: function(msg){
			jQuery('#religion_data2').html('');
			jQuery('#religion_data2').html(msg);
		}
	});
	*/

	sethtml('religion_data2',"<div id='indicator'><img src='"+ image_path +"'/></div>");
	jQuery.get(url,function(data){
		sethtml('religion_data2',data);
	});
	//setTimeout('startSrteemPindingOrders(\''+url+'\',\''+image_path+'\')',5000);
}

function updateOpenTrading(url){
	var url=url;
	//alert(t);
	jQuery.ajax({
		type: "POST",
		url: url,
		success: function(msg){
			jQuery('#religion_data').html('');
			jQuery('#religion_data').html(msg);
		}
	});
}


function getPendingChanges(url)
{
 var url=url;
	jQuery.ajax({
		type: "POST",
		url: url,
		success: function(msg){
			jQuery('#curr_pending_change').html('');
			jQuery('#curr_pending_change').html(msg);
		}
	});
	
	setTimeout('getPendingChanges(\''+url+'\')', 5000);
}

function setPendingChanges(updated)
{

	for(var i=0;i<updated.length;i++)
	{
		jQuery('#'+updated[i][0]).html(updated[i][1]);
	}
	updated=null;
}
function getAjaxTabs(obj){
	jQuery('#medTabedArea div.home_tabs').each(function(i){
		jQuery(this).removeClass('medTabedArea_active');
		jQuery(this).children('a').removeClass('activeTabLink');
	});
	jQuery(obj).parent().addClass('medTabedArea_active');
	jQuery(obj).addClass('activeTabLink');
	var href = obj.attr('href');
	jQuery.ajax({
   type: "POST",
   url: href,
   success: function(msg){
     jQuery('#medTabsDetail_text').html(msg);
   }
 });
}


function goToUrl(url, id)
{
    var url=url;
    jQuery('#'+id).html("<div class=\'result_loader\'> &nbsp; </div>");
    jQuery.get(url,function(data){
        jQuery('#'+id).html(data);
    });
}

var newwindow = ''
function popitup(url) {
if (newwindow.location && !newwindow.closed) {
    newwindow.location.href = url;
    newwindow.focus(); }
else {
    newwindow=window.open(url,'htmlname','width=500,height=350,resizable=0');}
}

function tidy() {
if (newwindow.location && !newwindow.closed) {
   newwindow.close(); }
}
