//  Exiva-specific java functions and tools

$(document).ready(function(){

	//  Set up external links with just rel="external"
	$("a[@rel='external']").attr("title", "<?=getStaticString('new-window')?>");
	$("a[@rel='external']").bind("click", function() {
	    var modifiers = '';
		if (this.className == 'popuplink') { modifiers = 'height=600,width=550';}
		if (this.className == 'helplink') { modifiers = 'height=550,width=450';}
		window.open(this.href, 'popup', modifiers); return false;
	});
	
	//  Replace standard checkboxes with flashy images if JS is in use
	$("span.exivacheckbox input").hide();
	$("span.exivacheckbox").each(function() {
	    var chkid = $(this).find("input").attr('id');
	    var chkcheck = $(this).find("input").attr('checked');

		$(this).append('<img src="/web_images/structure/generic/forms/checkbox_' +
						(chkcheck ? '1' : '0') + '.gif" alt="" id="img4chk_' + chkid+ '" />');
		//  This has the action of setting the tickboxes
		$(this).find("img").bind('click', function() {
		    var ticked = $(this).attr('src').match(/checkbox_(\d+)/);
			$(this).parent().find("input").attr('checked', ticked[1]==1 ? false : true);
			$(this).attr('src', '/web_images/structure/generic/forms/checkbox_' +
						 (ticked[1]==1 ? '0' : '1') + '.gif');
			//  Make sure the change event for the checkbox is called
			$(this).parent().find("input").change();
		});
	});
	//  Hide any apply buttons that are there if JS isn't enabled
	$("input.optional").hide();
	//  Make sure the option images are on the correct setting
	$("span.exivacheckbox img").click();
	$("span.exivacheckbox img").click();
});


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function bodyunload()
{
	var oPlayer=document.getElementById('oxford_flvplayer');
	if (oPlayer)
	{
        oPlayer.SetVariable('player:jsStop', '');
    	oPlayer=null; 
	}
	
}
