
//jQuery.noConflict();

function wfb_try(code)
{
	try
	{
		eval(code);
	}
	catch (e)
	{
//		setTimeout(code, 1000);
//		alert('loading page. please wait.');
	}
}

jQuery.noConflict();

jQuery(document).ready(function()
{
	// +$time() ???
	var wfb_rpc_url = '/dynamic/datencenter/rpc/';  // rpc-base uri
	var wfb_gfx_base = '/dynamic/datencenter/gfx/';  // img base path
	var tmp;

	wfb_rzCC = function(s)
	{
		for(var exp=/-([a-z])/;
			exp.test(s);
			s=s.replace(exp,RegExp.$1.toUpperCase()));
		return s;
	};

	wfb_setStyle = function(element, declaration)
	{
		if (declaration.charAt(declaration.length-1)==';')
		{
			declaration = declaration.slice(0, -1);
		}
		var k, v;
		var splitted = declaration.split(';');
		for (var i=0, len=splitted.length; i<len; i++)
		{
			k = wfb_rzCC(splitted[i].split(':')[0]);
			v = splitted[i].split(':')[1];
			eval("element.style."+k+"='"+v+"'");
		}
	};

	wfb_showLoader = function(parent_id, offset_x, offset_y, in_body)
	{
		var obj, x, y;
		x = 0;
		y = 0;

		var tag;
		tag = jQuery('#'+parent_id);
		var pos = 'relative';
		if (in_body == 1)
		{
			x = tag.offset().left;
			y = tag.offset().top;;
			tag = jQuery('body');
			pos = 'absoulte';
		}
		if (tag)
		{
			var new_id = "loader-pic-"+parent_id;
			var ex_pic = jQuery('#'+new_id);
			if (ex_pic)
			{
				ex_pic.remove();
			}
			x += offset_x;
			y += offset_y;
			if (in_body != 1)
			{
				tag.empty();
			}
			tag.append('<img src="'+wfb_gfx_base+'base/ajax_waiting.gif" class="loader-pic" alt="load" id="'+new_id+'" style="position: '+pos+'; left: '+x+'px; top: '+y+'px;" />');
		}
	};

	wfb_hideLoader = function(id)
	{
		jQuery("#loader-pic-"+id).remove();
	};

	var wfb_old_content = Array();

	wfb_setOldContent = function(id)
	{
		try
		{
			if (typeof wfb_old_content[id] == 'undefined')
			{
				wfb_old_content[id] = jQuery('#'+id).html();
			}
		}
		catch (e)
		{

		}
	};

	wfb_getOldContent = function(id)
	{
		try
		{
			jQuery('#'+id).html(wfb_old_content[id]);
			delete wfb_old_content[id];
			wfb_recall();
		}
		catch (e)
		{

		}
	};

	wfb_emptyOldContent = function(id)
	{
		try
		{
			delete wfb_old_content[id];
		}
		catch (e)
		{

		}
	};


	wfb_getTime = function()
	{
		var now = new Date();
		return Math.round(now.getTime()/1000);
	};


	wfb_track = function()
	{
		try
		{
		}
		catch (e)
		{
		}
	};

	wfb_pushAds = function()
	{
		try
		{
		}
		catch (e)
		{

		}
	};

	wfb_recall = function()
	{
		// overwrite document.write !!!
		try
		{
			document.write = function(html_code)
			{
				jQuery('#wfb-ad-code').append(html_code);
			};
			document.writeln = function(html_code)
			{
				jQuery('#wfb-ad-code').append(html_code+"\n");
			};
		}
		catch (e)
		{
		}

		wfb_pushAds();
		wfb_track();

	};

	wfb_close = function(tag_id, kind)
	{
		var tag;
		tag = jQuery('#'+tag_id);

		if (kind == 1)
		{
			jQuery(tag).fadeOut(600);
		}
		else if (kind == 2)
		{
			jQuery(tag).empty();
		}
		else
		{
			jQuery(tag).remove();
		}
		wfb_recall();
	};

	wfb_loadData = function(tag_id, action)
	{
		wfb_showLoader(tag_id, 0, 0);
		var url;
		url = wfb_rpc_url+action+'/';
		jQuery('#'+tag_id).load(url);

	};

	wfb_globalClose = function(tag_id, kind)
	{
		jQuery('#'+tag_id).hover(function () {}, function() { wfb_close(tag_id, kind); } );
	};

	wfb_loadLiveBox = function(parent_id)
	{
		jQuery('#ticker').load(wfb_rpc_url+'live_box/');
	};

	wfb_convertIframeLinks = function()
	{
		jQuery("a").attr("target", "_top");
	};

	// init
//	wfb_loadLiveBox('rechts');

});

