var mage;
var lookuparray =new Array();

var isIE = navigator.appName.toLowerCase().indexOf('internet explorer')+1;
var isMac = navigator.appVersion.toLowerCase().indexOf('mac')+1;
var topframe= false;
var images="http://images.jaggu.org/"


function update_rf()
{
	$j.get('rightframe.php', function(data){
			if (data.length > 10 )
			{
				$j('#infoframe').html(data);
			
			} else {
				//alert ("not so fast");
			}
		});
}
function load_json(cmd, win)
{
	var start = new Date();
	$j.get( "json.php", 'cmd='+cmd, function(data){pop_mage(data);}, 'script');
	var end = new Date();
	var difference = end.getTime() - start.getTime();
	//$j("#logger").html()+="<br/>updated " +cmd+" "+difference;
}


function get_html( cmd, return_id)
{
	var start = new Date();
	//new Ajax.Updater(, 'json.php?cmd='+cmd);
	
	return_id=$j.get( "json.php", 'cmd='+cmd, null, 'json' ).evalJSON();
	var end = new Date();
	var difference = (end.getTime() - start.getTime())/1000;
	//$j("#logger").html()+="<br/>updated " +cmd+" "+difference;
	
}

function setCSS(style)
{
	document.body.style.backgroundImage ='url(images/1/'+style+'.jpg)';
}
 
function idtoggle (id)
{
	$j('#'+id).toggle();
}

function clearDefault(el)
{
	el.value = '';
}


function winlookup (lookupurl,gettoit)
{
	// load the page specified in the trigger
	$j('#overlay_content').load(lookupurl, function(data) {
  alert('Load was performed.'+data);
});
	$j("#overlay").overlay().load(); 
}
function winlookup_facebox (lookupurl,gettoit)
{
    $j.get(lookupurl+'&ajax', function(data) {
    $j.facebox(data);
  })
}

function winlookup_old (lookupurl, gettoit) //, xMouse, yMouse
{
	if ($j('#lookup_content').length || topframe)
	{
		if (!lookuparray)
		{ 
			lookuparray=this.lookuparray;
		}
		if (lookuparray && lookuparray[lookupurl])
		{
			$j('#lookup_content').html(lookuparray[lookupurl]); 
		} else {
			
			$j('#lookup_content').load(lookupurl+"&ajax");
		}
		if ($j("#tabs").length)
		{
			$j("#tabs").tabs( 'select' , 1 );
		}
	}
	else
	{
		if (this.parent && this.parent.winlookup && !gettoit)
		{
			this.parent.winlookup(lookupurl, true);
		}
		else
		{
			window.open(lookupurl,'lookup','width=650,height=400,status=no,toolbar=no,scrollbars=yes,resizable=yes');
		}
	}
} 
function turn_info_content(txt)
{
	if ($j("#turn_info2"))
	{
		$j("#turn_info2").html($j("#turn_info2").html()+txt);
	}
}

function show_ad()
{ 
	if (tabs)
	{
		show_tab (tabs, 2);
	}
	if (tabs2 && ( Math.random ( ) * 100 + 1 )>80)
	{
		show_tab (tabs2, 4);
	}
}


function clr (element_name)
{
	$j(element_name).html('&nbsp;');
}

function load_html(cmd, win, force)
{
	if (!parent.lookuparray || !parent.lookuparray[cmd] || force)
	{
		$j(win).load(cmd);
	} else	{
		if (parent.lookuparray.lenght>50)
		{ 
			delete parent.lookuparray;
		}
		$j(win).html(parent.lookuparray[cmd]); 
	}
}

function toggle_menu()
{
	obj = $j('#menu');
	main = $j('#contentmenu');
	output = $j('#output');
	turn = $j('#turn_menu');
	warning= $j('#warning');
	if (obj && main)
	{
		if ( obj.style.display == "block"  )
		{
			obj.style.display = "none";
			document.cookie = 'menu_menu_= none ';

			main.style.marginLeft= '15px';
			output.style.marginLeft= '15px';
			if (turn) {
				turn.style.marginLeft= '15px';
			}
			if (warning) {
				warning.style.marginLeft='15px';
			}
		}
		else
		{
			obj.style.display = "block";
			document.cookie = 'menu_menu_= block';
				
			var dataString=navigator.appName;  // if firefox only
			if (dataString.indexOf('Netscape')!=-1)
			{
				main.style.marginLeft = '110px';
				output.style.marginLeft= '110px';
				if (turn) {
				turn.style.marginLeft='110px';
				}
				if (warning) {
				warning.style.marginLeft='110px';
				}
			}
		}
	} // if obj
}

function ctoggle (id, fromid)
{
   	var result=$j(id).toggle();
	//document.cookie = 'menu_'+ id + '='+result.style.display;
	if (fromid)
	{
		if (result.style.display=="block")
		{
			$j(fromid).html(" + ");
		} else
		{
			$j(fromid).html(" - ");
		}
	}
}

function toggle (id)
{
   	$j('#id').toggle();
}
   
function fix_menu()
{
	// deprecated
}

function fix_bg ()
{
	if ((parent.status.location==undefined && parent.location.href!=document.location.href) || parent.document.getElementById('playscreen')) {
		document.body.style.backgroundColor='transparent';
	} else if (!parent.$j('#gametabs'))
	{
		document.body.style.backgroundColor='#000';
	}
}


function menuclick(tabcoll, tabno)
{
	$j("#tabs").tabs( 'select' , tabno );
}

function initOverLabels () {
	if (!document.getElementById) return;
	var labels, id, field;
	labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++) {
		if (labels[i].className == 'overlabel')
		{
			id = labels[i].htmlFor || labels[i].getAttribute ('for');
			if (!id || !(field = document.getElementById(id))) {
				continue;
			}
			if (field.value !== '') {
				hideLabel(field.getAttribute('id'), true);
			}
			field.onfocus = function () {
				hideLabel(this.getAttribute('id'), true);
			};
			field.onblur = function () {
				if (this.value === '') {
					hideLabel(this.getAttribute('id'), false);
				}
			};
			labels[i].onclick = function () {
				var id, field;
				id = this.getAttribute('for');
				if (id && (field = document.getElementById(id))) {
					field.focus();
				}
			};
		}
	}
}

function hideLabel (field_id, hide) {
	var field_for;
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++) {
		field_for = labels[i].htmlFor || labels[i]. getAttribute('for');
		if (field_for == field_id) {
			labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
			return true;
		}
	}
	return false;
}


/*
 * The facebook_onload statement is printed out in the PHP. If the user's logged in
 * status has changed since the last page load, then refresh the page to pick up
 * the change.
 *
 * This helps enforce the concept of "single sign on", so that if a user is signed into
 * Facebook when they visit your site, they will be automatically logged in -
 * without any need to click the login button.
 *
 * @param already_logged_into_facebook  reports whether the server thinks the user
 *                                      is logged in, based on their cookies
 *
 */
function facebook_onload(already_logged_into_facebook) {
  // user state is either: has a session, or does not.
  // if the state has changed, detect that and reload.
  FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
          var is_now_logged_into_facebook = session ? true : false;

          // if the new state is the same as the old (i.e., nothing changed)
          // then do nothing
          if (is_now_logged_into_facebook == already_logged_into_facebook) {
            return;
          }

          // otherwise, refresh to pick up the state change
          refresh_page();
        });
    });
}

/*
 * Our <fb:login-button> specifies this function in its onlogin attribute,
 * which is triggered after the user authenticates the app in the Connect
 * dialog and the Facebook session has been set in the cookies.
 */
function facebook_onlogin_ready(page) {
  // In this app, we redirect the user back to index.php. The server will read
  // the cookie and see that the user is logged in, and will deliver a new page
  // with content appropriate for a logged-in user.
  //
  // However, a more complex app could use this function to do AJAX calls
  // and/or in-place replacement of page contents to avoid a full page refresh.
  refresh_page(page);
}

/*
 * Do a page refresh after login state changes.
 * This is the easiest but not the only way to pick up changes.
 * If you have a small amount of Facebook-specific content on a large page,
 * then you could change it in Javascript without refresh.
 */
function refresh_page(page) {
  window.location = page;
}

/*
 * Prompts the user to grant a permission to the application.
 */
function facebook_prompt_permission(permission) {
  FB.ensureInit(function() {
    FB.Connect.showPermissionDialog(permission);
  });
}

/*
 * Show the feed form. This would be typically called in response to the
 * onclick handler of a "Publish" button, or in the onload event after
 * the user submits a form with info that should be published.
 *
 */
function facebook_publish_feed_story(form_bundle_id, template_data) {
  // Load the feed form
  FB.ensureInit(function() {
          FB.Connect.showFeedDialog(form_bundle_id, template_data);
          //FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);

      // hide the "Loading feed story ..." div
      ge('feed_loading').style.visibility = "hidden";
  });
}

/*
 * If a user is not connected, then the checkbox that says "Publish To Facebook"
 * is hidden in the "add run" form.
 *
 * This function detects whether the user is logged into facebook but just
 * not connected, and shows the checkbox if that's true.
 */
function facebook_show_feed_checkbox() {
  FB.ensureInit(function() {
      FB.Connect.get_status().waitUntilReady(function(status) {
          if (status != FB.ConnectState.userNotLoggedIn) {
            // If the user is currently logged into Facebook, but has not
            // authorized the app, then go ahead and show them the feed dialog + upsell
            checkbox = ge('publish_fb_checkbox');
            if (checkbox) {
              checkbox.style.visibility = "visible";
            }
          }
        });
    });
}


expandOrCollapse=idtoggle;