Event.observe(window, 'load', initPage);

 function initPage() {
	// Lightbox stuff:
	// full-frame iframe
	var links = $$('.lightwindow_iframe_link');
	links.each(function(link) {
		link.writeAttribute( 'target', 'blank' );
		Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false);}, false);
		link.writeAttribute( 'rel', '' );
		link.onclick = function() {return false;};
	});			

	// launching edetails in new windows
	links = $$('.edetail_link');
	links.each(function(link) {
		if(!link.hasClassName('comments')){
			link.writeAttribute( 'target', 'blank' );
			if(link.hasClassName('comment')){
				//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,null,null,455,245);}, false);
				link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,false,null,null,455,245);
							return false;};
			}
			else if (link.hasClassName('demo'))
			{
				//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,true);}, false);
				link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,true);
							return false;};
			}
			else
			{
				 if (link.hasClassName('banner'))
				{
					if (link.hasClassName('library'))
					{
						//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,'top-container','/mx/library_top.html');}, false);
						link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,false,['top-container','inner-tab-body'],[contextRoot + 'mx/library_top.html',contextRoot  + 'mx/ll.html']);
							return false;};
					}
					else if (link.hasClassName('eAbstract'))
					{
						//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,'top-container','/mx/ilight_top.html');}, false);
						link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,false,['top-container'],[contextRoot + 'mx/ilight_top.html']);
							return false;};
					}
				}
				else  if (link.hasClassName('list'))
				{
					if (link.hasClassName('library'))
					{
						//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,'inner-tab-body','/mx/ll.html');}, false);
						link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,false,['inner-tab-body'],[contextRoot  + 'mx/ll.html']);
							return false;};
					}
					else if (link.hasClassName('eAbstract'))
					{
						//Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,'inner-tab-body','/mx/ilight_list.html');}, false);
						link.onclick = function() {
							parent.myBBlw.loadLightWindow(link,false,['inner-tab-body'],[contextRoot  + 'mx/ilight_list.html']);
							return false;};
					}
				}
			}
			link.writeAttribute( 'rel', '' );
			
		}
	});
	
	links = $$('.lightbox_login_link');
	links.each(function(link) {
		link.writeAttribute( 'target', 'blank' );
		Event.observe(link, 'click', function() {parent.myBBlw.loadLightWindow(link,false,null,null,700,270);}, false);
		link.writeAttribute( 'rel', '' );
		link.onclick = function() {return false;};
	});
	
	links = $$('.lightwindow_img_link');
	links.each(function(link) {
		link.writeAttribute( 'target', 'blank' );
		Event.observe(link, 'click', function() {parent.myLightWindow.activate(null, link);}, false); 
		link.writeAttribute( 'rel', '' );
		link.onclick = function() {return false;};
	});

	// external links in new windows
	$$('a[rel=external]').each(function(link){
		if(link.readAttribute('href') != '' && link.readAttribute('href') != '#') {
			link.writeAttribute( 'target', 'blank' );
		}
	});
	
	links = $$('.categoryList');
	links.each(function(link){
		link.writeAttribute( 'target', 'blank' );
		link.writeAttribute( 'rel', '' );
		link.onclick = function() {
				parent.myAjaxLoader.clearParams();
				parent.myAjaxLoader.getAndSetParamsFromURL(link.href);
				parent.myAjaxLoader.makeRequestAndSubGroup([contextRoot + 'mx/ilight_list.html','inner-tab-body',contextRoot + 'mx/ilight_top.html','top-container',contextRoot + 'mx/ilight_cat_menu.html','filter-menu']);
				//~ parent.myAjaxLoader.makeRequestAndSub('/mx/ilight_list.html','inner-tab-body');
				//~ parent.myAjaxLoader.makeRequestAndSub('/mx/ilight_top.html','top-container');
				//~ parent.myAjaxLoader.makeRequestAndSub('/mx/ilight_cat_menu.html','filter-menu');
				return false;
			};		
	});
	
	links = $$('.ajax');
	links.each(function(link){
		link.writeAttribute( 'target', 'blank' );
		link.writeAttribute( 'rel', '' );
		link.onclick = function() {
			parent.myAjaxLoader.getAndSetParamFromURL(link.href,'d-2481363-p');
			parent.myAjaxLoader.getAndSetParamFromURL(link.href,'id');
			if(document.getElementById('entry-list').hasClassName('eAbstract'))
			{
				parent.myAjaxLoader.makeRequestAndSub(contextRoot + 'mx/ilight_list.html','inner-tab-body');
			}
			else if(document.getElementById('entry-list').hasClassName('library'))
			{
				parent.myAjaxLoader.makeRequestAndSub(contextRoot + 'mx/ll.html','inner-tab-body');
			}
			else if(document.getElementById('entry-list').hasClassName('eAbstractCommentList'))
			{
				parent.myAjaxLoader.makeRequestAndSub(contextRoot + 'mx/ilight_comments.html','inner-tab-body');
			}
			else
			{
				return true;
			}
			return false;};		
	});
	
	var dropdowns = $$('.AjaxPagesize');
	dropdowns.each(function(dropdown)
	{
		dropdown.onchange = function() {
			parent.myAjaxLoader.addParam('pagesize',dropdown.value);
			if(dropdown.form.id == 'library' || dropdown.form.id == 'll')
			{
				parent.myAjaxLoader.makeRequestAndSub(contextRoot + 'mx/ll.html','inner-tab-body');
			}
			else if(dropdown.form.id == 'eAbstracts' || dropdown.form.id == 'ilight_list')
			{
				parent.myAjaxLoader.makeRequestAndSub(contextRoot + 'mx/ilight_list.html','inner-tab-body');
			}
			else
			{
				dropdown.form.submit();
			}
			return false;
		};			
	});
}


function launchLinkInLightbox(url)
{
	myLightWindow.activateWindow( { href: url } );
	return false;
}
