$(document).ready(function(){

	//over tabs
	var lastDownTab = "";
	$("#menu ul:eq(0) li").mouseover(
    	function(){
    		if($(this).find("ul:hidden").html()){
				if(lastDownTab)
					lastDownTab.fadeOut('slow');
				lastDownTab = $(this).find("ul:hidden");
				o = $(this).find("ul:hidden");
				o.css('z-Index','100').fadeIn('slow');
				if($.browser.msie)
					o.css('margin-left',$(this).width() * -1);
    		}
    	}
	);

	//change all popups...
	var img = new Array();
	$(".article a").each(function(){
		s = "dow.open(this.href,";
		i = 0;
		if($(this).attr('onclick'))
			i = $(this).attr('onclick').toString().indexOf(s);
	   
		if(i){
			w = 640;
			h = 480;
		   
			u = $(this).attr('href');
			var id = 'popwinlink_' + uid();
			e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
		   
			$(this).attr('id',id);
			if(e == 'png' || e == 'gif' || e == 'jpg'){
				img[id] = new Image();
				img[id].onload = function(){
					img[id].onload = null;
					w = img[id].width;
					h = img[id].height;
				   
					$("a#" + id).attr('onclick',"").addClass('popWindowLink').attr('href',"javascript:popWindow('" + u + "'," + w + "," + h + ");");
				}
				img[id].src = u;
			}else{
				c = $("a#" + id).attr('onclick');
				c = $("a#popwinlink_0").attr('onclick');
			   
				h = c.substring(c.indexOf('height=') + 7);
				h = h.substring(0,h.indexOf(','));
			   
				w = c.substring(c.indexOf('width=') + 6);
				w = w.substring(0,w.indexOf(','));
			   
				$("a#" + id).attr('onclick',"").addClass('popWindowLink').attr('href',"javascript:popWindow('" + u + "'," + w + "," + h + ");");
			}
		}
	});


	//images
	$(".article .content img").each(function(){
		if($(this).attr('align') == 'left')
			$(this).css('margin-right','10px');
	});
});

//make uniqID
var uid = (
	function(){
		var id=0;
		return function(){
			return id++ ;
		};
	}
)();


//emulate popup function...
function popWindow(u,w,h){
	e = u.substring(u.lastIndexOf('.')+1).toLowerCase();
	if(e == 'png' || e == 'gif' || e == 'jpg')
		popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><img src=\""+ u +"\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\" /></div>");
	else
		popEl = $("<div class=\"popWindowDiv\" style=\"display:block;\"><iframe src=\""+ u +"\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\" frameborder=\"0\"></iframe></div>");
	popEl.modal({
		onOpen: function (dialog) {
					dialog.overlay.fadeIn('slow', function () {
						dialog.container.slideDown('slow', function () {
							dialog.data.fadeIn('slow'); // See Other Notes below regarding
													   // data display property and
													   // iframe details
						});
					});
				},
		onClose: function (dialog) {
					dialog.data.fadeOut('slow', function () {
					  dialog.container.slideUp('slow', function () {
						dialog.overlay.fadeOut('slow', function () {
						  $.modal.close(); // must call this to have SimpleModal
										   // re-insert the data correctly and
										   // clean up the dialog elements
						});
					  });
					});
				}
				
	});
	$("#modalContainer").css('height',h).css('width',w).css('margin-left',(w / 2) * -1);
}