

$(document).ready( function() {
							
	$('.name a').each( function() {
		var myurl = $(this).attr('href');
		if (!$(this).hasClass('jz')) {
			$(this).removeAttr('href');
			$(this).css('cursor', 'pointer');
			$(this).click( function() {
				popup_modal(myurl);
			});
		}
	});


	var zcounter = 120;
							
	$('#main_nav a').each( function() {
		var myId = $(this).attr('id');
		var myHref = $(this).attr('href');
		var myWidth = $(this).css('width') == 'auto' ? $(this).width() -120  : depx( $(this).css('width')) -120 
		var myHeight = $(this).css('height') == 'auto' ? $(this).height() + 12 : depx( $(this).css('height')) + 12 

		var isOn = $(this).hasClass('always_on') ? ' always_on' : '';
		
		var linker = '<a class="fixLink'+isOn+'" href="'+myHref+'" id="linker_'+myId+'" style=" z-index: '+zcounter+++';top:'+$(this).offset().top+'px; left: '+($(this).offset().left + 120)+'px; width: '+myWidth+'px; height: '+myHeight +'px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>';
		
		$('body').append(linker);
		
		$('#linker_'+myId).html($('#' + myId).html());
		$('#'+myId).addClass("off");
		
		$('#linker_'+myId).mouseover( function() {
			if (myId != curPage) {
				$('#' + myId ).addClass('on');
			}
		});
		$('#linker_'+myId).mouseout( function() {
			if (myId != curPage) {
				$('#' + myId ).removeClass('on');
			}
		});
	});
	
});

function remove_popup_modal_window () {
	$('#modal_outer').remove();
}

function popup_modal (content, myWidth) {

	var innerhtml = "";
	var mywidthstyle = '';
	docheight = $(window).height();
	docWidth = $(window).width();
	if (!myWidth) {
		myWidth = 600;
	} 
	myLeft = ((docWidth - myWidth) / 2 );
	innerhtml += '<div id="modal_outer" style="height:' + docheight + 'px;"><div id="modal_bg">&nbsp;</div>';
	innerhtml += '<div id="modal_inner" style="width: '+myWidth+'px;left:'+myLeft+'px; height:' + docheight + 'px">';
	innerhtml += '	</div></div>';
	
	$('body').append(innerhtml);
	$('#modal_inner').load(content, function() {
		
	});	
	document.documentElement.style.overflow = "hidden";
	$('#modal_bg').css('cursor','pointer');
	
	if( $('#modal_inner').height() > docheight - 100) {
		$('#modal_inner').css('height', (docheight - 100) + 'px');
		$('#modal_inner').css('overflow','auto');
	}
	
	$('#modal_bg').click( function() {
		$('#modal_outer').remove();
		document.documentElement.style.overflow = "scroll";
   });	
	
}


function depx(str) {
	if (str.indexOf('px') >= 0) {
		return parseInt(str.substr (0, str.indexOf('px')));
	} else {
		return parseInt(str);
	}
}
