var images_before = new Array();
var images_after = new Array();

$(document).ready(function(){
	var i;
	
	i = 0;
	
	$.each( $('#global-nav li img'), function(){
//		images_before[i] = new Image();
//		images_before[i].src = $(this).attr('src').replace(/_ro\./i, '' );
		var reg_exp = new RegExp($(this).parents().parents().attr('ID').replace(/gbn\-/, '').replace(/\-/, '_'));
		if( !location.href.match(reg_exp)){
			images_after[i] = new Image();
			images_after[i].src  = $(this).attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1;
			$(this).mouseover( function(evt) {
				$(this).attr('src', $(this).attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1 );
			});
			$(this).mouseout( function(evt) {
				$(this).attr('src', $(this).attr('src').replace(/_ro\./i, '.' ));
			});
			i++;
		} else {
			$(this).attr('src', $(this).attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1 );
		}
	});
	if( !location.href.match(/[^\/]+\/[^\/\.]+/)){
		$('#gbn-top img').attr('src', $('#gbn-top img').attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1 );
	}
	
	$.each( $('a'), function(){
		document.URL.match(/\/\/([^\/]+)/);
		RegExp.$1.match(/.*(\w+\.\w+\.\w+)$/);
		rex = new RegExp( RegExp.$1, 'i' );
		if( $(this).attr('href') != undefined && ( $(this).attr('href').match(/http:/) && !$(this).attr('href').match(rex) )){
			$(this).click( function(evt){
				window.open( this.href );
				return false;
			});
		}
	});
	
	$.each( $('a.newwindow'), function(){
		$(this).click( function(evt){
			window.open( this.href );
			return false;
		});
	});
	
	$.each( $('.flow li img'), function(){
		if( $(this).attr('rel').length > 0 ){
			$(this).mouseover( function(evt) {
				$(this).parents().parents().next().children().attr('src', '_images/' + $(this).attr('rel'));
			});
			$(this).mouseout( function(evt) {
				$(this).parents().parents().next().children().attr('src', '_images/1-3-3_edu_blank.gif');
			});
		}
	});
	
	$.each( $('.flow a'), function(){
		$(this).click( function(evt) {
			return false;
		});
	});
});
/*
function auto_mo( img_src ){
	if( img_src.match(/over/)){
		this.src = images_after[img_src.replace(/over,/, '')];
		alert(img_src);
	} else {
		this.src = images_before[img_src.replace(/out,/, '')];
	}
}*/

