var timer;
var selected_sub_sub;

$(document).ready(function(){ 
	
	// hide our sub menu items if they exist as expandHeader will show them when it runs
	$('#header #menu ul > li > div > ul').hide();

    /* SUB MENU HOVERS */
	$('#header #menu ul > li > div > ul > li > a').mouseover(function() {
		// hide all our sub sub menu divs
		$(this).parents('ul:first').find('div').hide();
		// show the sub sub menu div we want
		$(this).next('div').show();
		// remove the selected classes from all our our sub menus
		$(this).parents('ul:first').find('li').removeClass('on');		
		// select only the one we want
		$(this).parent('li').addClass('on');
		clearTimeout(timer);

	});

	$('#header #menu ul li ul li ul li a').mouseout(function() {
		startTimer();
	});


	$('input.selectme').click(function() {
		this.select();
	});

	$('form.submit-with-ajax').submit(function() {
		$(this).load(this.action, $(this).serializeArray());
		return(false);
	});
   
    $('A[rel="external"]').click( function() {
      var w = 340;
      var h = 415;
      var props = '';
      var winl = (screen.width - w) / 2;
      var wint = (screen.height - h) / 2;
      var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+props;      
      window.open( $(this).attr('href'), '', winprops );
        return false;
    });

	$('a.new-window').click(function() {
		window.open(this.href);
		return(false);
	});

}); 


function expandHeader(do_animation) {
	//$('#flash-container').remove()
	$('#banner').height(50);
	// remove all the currently selected styles from top menu items
	var attributes = {"height": "185px"};
	if(do_animation) {
		$('#header').animate(attributes, "medium", function() {
			$('#header #menu ul > li > div > ul').show(); // show the sub and sub menu items
		});
	} else {
		$('#header').css(attributes);
		$('#header #menu ul > li > div > ul').show(); // show the sub and sub menu items
	}

	selected_sub_sub = $('.selected > div:visible');
}

function startTimer() {
	clearTimeout(timer);
	timer = setTimeout('fadeMenu()', 2000);
}

function fadeMenu() {
	$('#header #menu ul > li > div > ul > li').
		children('div').hide().
		end().
		removeClass('on');
	if(selected_sub_sub) selected_sub_sub.show();
}

function NewWindow(mypage, myname, w, h, props)
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  var winprops = 'scrollbars=1,height='+h+',width='+w+',top='+wint+',left='+winl+','+props
  var win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function showArticlePrintWindow(article_id)
{
	var curlocation = document.location.href;
	var params = '?page=21';
	//probably should be done with string.replace and a regexp..
	var qpos = curlocation.indexOf('?');
	if(qpos==-1) qpos = curlocation.indexOf('#');
	
	if(qpos>=0)
	{
	curlocation = curlocation.substr(0,qpos);
	}

	if(article_id!=undefined && article_id!='') params = params + '&amp;id=' + article_id;
	NewWindow(curlocation + params,'print','630','400','yes');
	return(false);
}
