String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
}

//SWF OBJECT
swfobject.registerObject("myFlashContent", "9.0.0", "{theme}expressInstall.swf");


//TOP, LEFT, RIGHT, BOTTOM
function initPanels()
{
	l_file_result = "";

	l_files = ["site.index.news","site.index.top.21","site.index.top.22","site.index.top.23","site.index.top.25","site.index.top.menu.1","site.index.top.menu.2","site.index.top.recomends","site.index.top.secr_krasoti","site.index.left.2"];
	for( var i=0; i<l_files.length; i++ )
	{
		l_file_value = l_files[i];
		if ( $("#"+l_file_value.replaceAll(".","_")).length==1 )
		{
			l_file_result += "&file[]="+l_file_value;
		}//end_ if
	}//end_ for

//alert( '/ajax.php?href='+document.location.href+l_file_result );

	var l_url = '/ajax.php?href='+escape(document.location.href)+l_file_result;
	$.ajax({
		url: l_url,
		success: function( l_json_arr )
		{
			eval( "var l_json_result = "+l_json_arr );

			for( var i=0; i<l_files.length; i++ )
			{
				var l_panel_name = l_files[i];
				var l_panel_object = $("#"+l_panel_name.replaceAll(".","_"));
                                if ( l_panel_object.length>0 ) 
				{
					var l_panel_html = l_json_result[l_panel_name];
					l_panel_object.html(l_panel_html);
					if ( $("#company_pay").text()=="2" ) 
					{
						$("#site_index_top_secr_krasoti").html("");
						$("#site_index_top_recomends").html("");
					}
				}//end_ if
			}//end_ for_ i
		}//end_ success
	});//end_ ajax

}//end_ func

function initSlovar()
{
	//Словарь.Скрыть разделитель
	$(".slovar_item").each( function()
	{
		$($(".hide_splitter",this)[0]).hide();
	} );
}

function initQuestion()
{
	if ( GetCookie("question_pop")!=1 )
	{
		$("#question_pop").load( "/site.php?module=question_pop/1.site.list", function()
		{
		});//end_ func_ load
	}//end_ if
}

//NEWS
var g_timer1 = "";
function obzor_next()
{
	var e_index = -1;
	$(".obzor_menu_item").each( function(i)
	{
		if (  $(".active",this).is(":visible")==true  )
		{
			e_index=i;
		}
	} );//end_ func_ each

	e_index++;
	if ( e_index>2 ) e_index = 0;

	obzor_over( e_index );

	clearTimeout(g_timer1);
	g_timer1 = setTimeout(obzor_next,5000);
}//end_ func_ highlight

function obzor_over(e_index)
{
	clearTimeout(g_timer1);

	$(".obzor_menu_item").each( function(i)
	{
		if (i==e_index)
		{
			$(".active",this).show();
			$(".passive",this).hide();
		}
		else
		{
			$(".passive",this).show();
			$(".active",this).hide();
		}
	});
	$("#bigimage").html(   $(".bigimage", ".obzor_menu_item:eq("+e_index+")").html()  );
}//end_ func_ highlight

function obzor_out(e_object)
{
	clearTimeout(g_timer1);
	g_timer1 = setTimeout(obzor_next,5000);
}//end_ func_ out

function initNews()
{
	$(".obzor_menu_item").each( function(i)
	{
		var l_item_object = this;
		$(".passive",this).hover( function()
		{
			obzor_over(i);
		}, function(){} );
		$(".active",this).hover( function(){
		},function()
		{
			obzor_out(i);
		} );
	});//end_ func_ each
	obzor_next();
}//end_ func

$( function()
{

	//SWF OBJECT
	$("a.group").fancybox( {'hideOnContentClick': false} );

	initNews();


	//LOAD_PANELS
	initPanels();

	initSlovar();

	initQuestion();

} );

