window.addEvent('domready',function(){Page.setup();});
window.addEvent('load',function(){Page.show();});

var Page = {
	firstpage:false,
	CurrentSubPage:0,
	setup: function()
	{
	
		if (Page.firstpage)
		{
		$('content').setOpacity(0);
		}
		
		Links.setup();
		Pictures.setup();
		TextPage.setup();
		ImageList.setup();
		Gallery.setup();
		Intro.setup();
		
		var dropdown = new DropDown('imgsel',{onItemSelected: function(e){ImageList.ShowList(e)}});
		
		if ($('pagetext')!=null)
		{
			$$('#pagetext img').setOpacity(0).removeClass('hidden').fade(1);
			$('fullcontent').setStyle('left','-325px').set('tween',{duration:'long'});
			$$('.overlay,.content').setOpacity(0).removeClass('hidden');
			
			
			if (!Page.firstpage)
			{
			Page.initPage();
			}
		}
		
		if ($$('.spage').length > 1)
		{
			var insPos = $$('#pagetext .content')[0];
			Page.prevbut = new Element('a',
				{
				'href':'#',
				'class':'prev',
				'html':'&lt; Previous',
				'events':{
					'click': function(e){
						Page.Show(-1);
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Page.prevbut.inject(insPos,'bottom');
			Page.nextbut = new Element('a',
				{
				'href':'#',
				'class':'next',
				'html':'Next &gt;',
				'events':{
					'click': function(e){
						Page.Show(1);
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Page.nextbut.inject(insPos,'bottom');
		}
		
	
		
	},
	Show: function(direction)
	{
		var s = $$('.spage');
		s[Page.CurrentSubPage].addClass('hidden');
		Page.CurrentSubPage += direction;
		if (Page.CurrentSubPage >= s.length)
			Page.CurrentSubPage=0;
		if (Page.CurrentSubPage < 0)
			Page.CurrentSubPage = s.length-1;
		s[Page.CurrentSubPage].removeClass('hidden');
	}
	,
	initPage: function()
	{
	if ($('pagetext')!=null)
		{
			var x = function(){
				$$('.overlay').fade(0.5);
				$$('.content').fade(1);
				$('fullcontent').tween('left','0');
				};
			x.delay(500);
			}
	}
	,
	show: function()
	{
		
		if (Page.firstpage)
		{
			
			var show = new Fx.Style('content','opacity',{duration:2500,transition: Fx.Transitions.Quart.easeInOut,onComplete:function(){TextPage.setScrollBar();}});
			show.start(1);
			Page.initPage.delay(1500);
			Links.showLinks();
			
		}
		else
		{
		
			
			
		
		}
		if ($('swf') != null)
		{
		
			intr.write('swf');
		}
		
	}
	}


var Gallery = {
	CurrentPic: 0,
	LargePic: 0,
	PageLeft: 0,
	Large: false,
	setup: function()
		{
		
		if ($('gallerythumb')!=null)
		{
			Gallery.Pics = $$('#gallerythumb img');
			Gallery.Scroll = new Fx.Scroll('gallerythumb',{duration:'long'});
			
			var x = 0;
			Gallery.Pics.each(function(e)
			{
				e.setStyle('position','absolute');
				e.setStyle('left',x);
				x += 475;
				e.addEvent('click',function(){
					var w = e.getSize().x;
					
					if (!Gallery.Anim)
					{
					/*if (w==950)
						Gallery.shrink(e)
					else
						Gallery.showLarge(e);*/
					}
				});
			});
			
			if (Gallery.Pics.length > 2)
			{
			Gallery.prevbut = new Element('a',
				{
				'href':'#',
				'class':'prev',
				'html':'&lt; Previous',
				'events':{
					'click': function(e){
						$clear(Gallery.cycle);
						if (!Gallery.Anim)
							Gallery.prev();	
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Gallery.prevbut.inject('gallery','bottom');
			Gallery.nextbut = new Element('a',
				{
				'href':'#',
				'class':'next',
				'html':'Next &gt;',
				'events':{
					'click': function(e){
						$clear(Gallery.cycle);
						if (!Gallery.Anim)
							Gallery.next();
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Gallery.nextbut.inject('gallery','bottom');
			}
			// force large
			Gallery.LargePic =Gallery.CurrentPic;
			var e = Gallery.Pics[0];
			e.setStyles({
				'z-index':'10',
				'top':0,
				'left':$('gallerythumb').getScroll().x,
				'width':950,
				'height':390
				});
		if (Gallery.prevbut != null)
		{
			Gallery.prevbut.setStyle('top','360px');
			Gallery.nextbut.setStyle('top','360px');
		}
		$('clicktozoom').setOpacity(0);
		if (Gallery.Pics[Gallery.LargePic].hasClass('inv'))
		{
			Gallery.prevbut.addClass('inv');
			Gallery.nextbut.addClass('inv');
		}
		else
		{
			Gallery.prevbut.removeClass('inv');
			Gallery.nextbut.removeClass('inv');
		}
		Gallery.Large = true;
		Gallery.cycle = Gallery.next.periodical(9000);
		}
		},
	showLarge: function(e)
		{
		
		if (Gallery.CurrentPic== Gallery.Pics.length-1 && Gallery.Pics.length % 2 == 1)
		{
			if (e.getPosition($('gallerythumb')).x > $('gallerythumb').getScroll().x)
				Gallery.LargePic=Gallery.CurrentPic;
			else
				Gallery.LargePic = Gallery.CurrentPic-1;
			
		}
		else
		{
		Gallery.LargePic = Gallery.CurrentPic;
		if (e.getPosition($('gallerythumb')).x > $('gallerythumb').getScroll().x)
			Gallery.LargePic++;
		}
		e.setStyle('z-index','10');
		var fx = new Fx.Morph(e,{duration:'long',
						'onStart':function()
							{
								Gallery.Anim = true;
								Gallery.Large = true;
							},
						'onComplete':function()
							{
								Gallery.Anim = false;
							}});
					fx.start({
						'top':0,
						'left':$('gallerythumb').getScroll().x,
						'width':950,
						'height':390
						});
		if (Gallery.prevbut != null)
		{
		Gallery.prevbut.morph({top:'360'});
		Gallery.nextbut.morph({top:'360'});
		}
		$('clicktozoom').fade(0);
		if (Gallery.Pics[Gallery.LargePic].hasClass('inv'))
		{
			Gallery.prevbut.addClass('inv');
			Gallery.nextbut.addClass('inv');
		}
		else
		{
			Gallery.prevbut.removeClass('inv');
			Gallery.nextbut.removeClass('inv');
		}
		},
	shrink: function(e)
		{
		var newX = Math.floor(Gallery.LargePic / 2);
		Gallery.CurrentPic = newX * 2;
		
		var scrollX = newX = newX * 950;
		
		
		if (Gallery.LargePic == Gallery.Pics.length-1 && Gallery.Pics.length % 2 == 1)
		{
			$('gallerythumb').scrollTo(scrollX,0);
			e.setStyle('left',scrollX);
			scrollX = scrollX - 475;
		}
		
		
		$('gallerythumb').scrollTo(scrollX,0);
		e.setStyle('left',scrollX);
		var fx = new Fx.Morph(e,{duration:'1000',
						'onStart':function()
							{
								Gallery.Anim = true;
							},
						'onComplete':function()
							{
								Gallery.Anim = false;
								Gallery.Large = false;
								e.setStyle('z-index','0');
							}});
					fx.start({
						'top':100,
						'left':Gallery.LargePic * 475,
						'width':475,
						'height':195
						});
		
		var fade = new Fx.Tween(e,'opacity',{'duration':'750','link':'chain'});
		fade.start(0.5).start(1);
		if (Gallery.prevbut != null)
		{
		Gallery.prevbut.morph({top:'310'});
		Gallery.nextbut.morph({top:'310'});	
		}
		Gallery.prevbut.removeClass('inv');
		Gallery.nextbut.removeClass('inv');
		$('clicktozoom').fade(1);
		
		},
	slidePic: function(direction)
	{
				
				Gallery.nextId = Gallery.LargePic+direction;
				if (direction==0)
				{
					Gallery.nextId = 0;
					direction=1;
				}
				if (direction==-2)
				{
					Gallery.nextId = Gallery.Pics.length-1;
					direction=-1;
				}
				
				var next = Gallery.Pics[Gallery.nextId];
				
				Gallery.pos = next.getPosition($('gallerythumb'));
				next.setStyles({
						'top':0,
						'left':$('gallerythumb').getScroll().x,
						'width':950,
						'height':390,
						'z-index':9
						});
						
				var e = Gallery.Pics[Gallery.LargePic];
				var fx = new Fx.Morph(e,{duration:'long',
						'onStart':function()
							{
								Gallery.Anim = true;
							},
						'onComplete':function()
							{
								Gallery.Anim = false;
								e.setStyles(
								{
								'top':100,
								'left':Gallery.LargePic * 475,
								'width':475,
								'height':195,
								'z-index':0
								}
								);
								Gallery.LargePic=Gallery.nextId;
								
								if (Gallery.Pics[Gallery.LargePic].hasClass('inv'))
								{
									Gallery.prevbut.addClass('inv');
									Gallery.nextbut.addClass('inv');
								}
								else
								{
									Gallery.prevbut.removeClass('inv');
									Gallery.nextbut.removeClass('inv');
								}
								
								Gallery.Pics[Gallery.LargePic].setStyle('z-index','10');
							}});
					fx.start({
						'left':$('gallerythumb').getScroll().x-(950*direction)
						});
	},
	next: function()
	{
		if (!Gallery.Large)
		{
		Gallery.CurrentPic += 2;
		if (Gallery.CurrentPic > Gallery.Pics.length-1)
		{
			Gallery.CurrentPic = (Math.floor((Gallery.Pics.length-1)/2)*2);
		}
		Gallery.PageLeft++;
		Gallery.Scroll.toElement(Gallery.Pics[Gallery.CurrentPic]);
		}
		else
		{
			
			
			if (Gallery.LargePic < Gallery.Pics.length-1)
			{	
				Gallery.slidePic(1);
			}
			else
			{
				Gallery.slidePic(0);
			}
		}
	},
	prev: function()
	{
		if (!Gallery.Large)
		{
		Gallery.CurrentPic -= 2;
		if (Gallery.CurrentPic < 0)
			Gallery.CurrentPic = 0;
		Gallery.PageLeft--;
		Gallery.Scroll.toElement(Gallery.Pics[Gallery.CurrentPic]);
		}
		else
		{
		
			if (Gallery.LargePic > 0)
			{	
				Gallery.slidePic(-1);
			}
			else
			{
				Gallery.slidePic(-2);
			}
		}
	}
	}

var Intro = {
	Current: 0,
	CurText: 0,
	setup: function()
	{
		Intro.Pics = $$('#intro img');
		Intro.Pics.setOpacity(0);
		if (Intro.Pics.length > 0)
			Intro.Pics[0].fade(1);
			
		if (Intro.Pics.length > 1)
		{
			Intro.next.periodical(8000);
		}
		
		Intro.Text = $$('#introheader h1,#introheader p');
		Intro.Text.setOpacity(0);
		Intro.showText.delay(1000);
	},
	showText: function()
	{
		if (Intro.Text.length > 0)
		{
		Intro.Text[Intro.CurText].fade(1);
		if (Intro.CurText < Intro.Text.length-1)
		{
			Intro.CurText++
			Intro.showText.delay(1500);
		}
		}
	},
	next: function()
	{
		var hide = new Fx.Style(Intro.Pics[Intro.Current],'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeIn});
		hide.start(0);
		
		Intro.Current++;
		if (Intro.Current >= Intro.Pics.length)
			Intro.Current=0;
			
		var show = new Fx.Style(Intro.Pics[Intro.Current],'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeIn});
		show.start(1);
	}
	}

var Pictures = {
	Current: 0,
	setup: function()
	{
		Pictures.All = $$('#pictures img');
		
		Pictures.All.setOpacity(0);
		Pictures.All.removeClass('hidden');
		if (Pictures.All.length > 0)
			Pictures.All[0].fade(1);
		
		if (Pictures.All.length > 1)
		{
			Pictures.prevbut = new Element('a',
				{
				'href':'#',
				'class':'prev',
				'html':'&lt; Previous',
				'events':{
					'click': function(e){
						$clear(Pictures.cycle);
						Pictures.prev();
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Pictures.prevbut.inject('pictures','bottom');
			Pictures.nextbut = new Element('a',
				{
				'href':'#',
				'class':'next',
				'html':'Next &gt;',
				'events':{
					'click': function(e){
						$clear(Pictures.cycle);
						Pictures.next();
						e = new Event(e);
						e.stop();
					}
				}
				}
				);
			Pictures.nextbut.inject('pictures','bottom');
			if (Pictures.All[0].hasClass('inv'))
			{
				Pictures.prevbut.addClass('inv');
				Pictures.nextbut.addClass('inv');
			}
			
			Pictures.cycle = Pictures.next.periodical(7000);
		}

				
	},
	next : function()
		{
		
		Pictures.All[Pictures.Current].fade(0);
		Pictures.Current++;
		if (Pictures.Current >= Pictures.All.length)
			Pictures.Current=0;
		Pictures.All[Pictures.Current].fade(1);
		if (Pictures.All[Pictures.Current].hasClass('inv'))
			{
				Pictures.prevbut.addClass('inv');
				Pictures.nextbut.addClass('inv');
			}
		else
		{
		Pictures.prevbut.removeClass('inv');
				Pictures.nextbut.removeClass('inv');	
		}
		},
	prev: function()
	{
		Pictures.All[Pictures.Current].fade(0);
		Pictures.Current--;
		if (Pictures.Current <0)
			Pictures.Current=Pictures.All.length-1;
		Pictures.All[Pictures.Current].fade(1);
		if (Pictures.All[Pictures.Current].hasClass('inv'))
			{
				Pictures.prevbut.addClass('inv');
				Pictures.nextbut.addClass('inv');
			}
		else
		{
				Pictures.prevbut.removeClass('inv');
				Pictures.nextbut.removeClass('inv');	
		}
	}
}


var ImageList = 
	{
	CurrentList: Class.empty,
	DropDownOffset: 45,
	SelectedImage: 0,
	setup: function()
	{
	ImageList.ListItems = $$('.imagelist');
	if (ImageList.ListItems.length >= 1)
		ImageList.CurrentList = ImageList.ListItems[0];
	
	if (ImageList.ListItems.length > 1)
		for(var i=1;i<ImageList.ListItems.length;i++)
			ImageList.ListItems[i].addClass('hidden');
	
	ImageList.RequestLinks = $$('.imagelist a.reqimg');
	for(var i=0;i<ImageList.RequestLinks.length;i++)
	{
		ImageList.RequestLinks[i].addEvent('click',function(e){ImageList.RequestImage(e);e = new Event(e); e.preventDefault()});
	}
	
	if ($('backbutton') != null)
	{
		$('backbutton').addEvent('click',function(e){ImageList.RestoreList();e = new Event(e);e.preventDefault();});
	}
	
	if ($('submitbutton') != null)
	{
		$('submitbutton').addEvent('click',function(e){ImageList.Submit();e = new Event(e);e.preventDefault();});
	}

	if ($('imageLibraryReturn') != null)
	{
		$('imageLibraryReturn').addEvent('click',function(e){ImageList.RestoreList();e = new Event(e);e.preventDefault();});
	}	
	
	var lblinks = $$('a.openlb');
	for(var k=0;k<lblinks.length;k++)
	{
		lblinks[k].addEvent('click',function(e){ e = new Event(e); Lightbox.show(e.target.href,e.target.alt); e.preventDefault();});
	}
	},
	Submit: function()
	{
		var er = false;
		if ($('name').value.trim().length == 0) { $('name').addClass('ferr');	er = true;	}	else 	{	$('name').removeClass('ferr');		}
		if ($('organisation').value.trim().length == 0) {	$('organisation').addClass('ferr');	er = true;	}	else	{	$('organisation').removeClass('ferr');	}
		if ($('telephone').value.trim().length == 0) {	$('telephone').addClass('ferr'); er = true;	}	else	{	$('telephone').removeClass('ferr');	}
		if (!$('email').value.test("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$","i")) { $('email').addClass('ferr');	er = true;	}	else	{	$('email').removeClass('ferr');	}
		if ($('usage').value.trim().length == 0) {	$('usage').addClass('ferr'); er = true;	}	else	{	$('usage').removeClass('ferr');	}
		if ($('publicationdate').value.trim().length == 0) 	{ $('publicationdate').addClass('ferr');	er = true;	}	else	{	$('publicationdate').removeClass('ferr');	}
		
		if (!er)
		{
		ImageList.doSubmit();
		}
		else
		{
		alert('One or more required fields haven\'t been entered correctly.\nPlease check those fields that have been highlighted and try again.');
		}
	},
	doSubmit: function()
	{
	var post=$('requestform').toQueryString();
	post += '&ajax=1';
	post += '&image_id=' + ImageList.SelectedImage;
	new Ajax('requestimage.aspx', {method:'post',onComplete: ImageList.handleResponse, data:post}).request();
	},
	handleResponse: function(e)
	{
	if (e.length > 2)
	{
	if (e.substr(0,2)=='OK')
		var i = e.split('|');
		var fName = i[1];
		var fSize = i[2];
		$('downloadLink').setProperty('href',fName);
		$('downloadLink').setHTML($('selectedImage').getProperty('alt') + ' (' + fSize + ')');
		var hideCur = new Fx.Style($('imageask'),'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeOut});
		hideCur.start(0);
		
		ImageList.showDownload.delay(1000);
	}
	
	}
	,
	showDownload: function()
	{
		$('downloadImage').setProperty('src',$('selectedImage').getProperty('src'));
		$('imagedownload').setOpacity(0);
		$('imagedownload').removeClass('hidden');
		var showCur = new Fx.Style($('imagedownload'),'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeIn});
		showCur.start(1);
		TextPage.RequestShown = 2;
	},
	RestoreList: function()
	{
		TextPage.hidePage(TextPage.Current);
	},
	RequestImage: function(e)
	{
		e = new Event(e);
		var l_id = e.target.id;
		var id = l_id.substr(6,l_id.length-6);
		ImageList.SelectedImage = id;
		
		$('imageask').setOpacity(0);
		$('imageask').removeClass('hidden');
		$('name').value = ''; $('organisation').value = ''; $('telephone').value =''; $('email').value=''; $('usage').value=''; $('publicationdate').value='';
		
		$('selectedImage').setProperty('src',$('img' + id).getProperty('src'));
		$('selectedImage').setProperty('alt',$('img' + id).getProperty('alt'));
		var hideCur = new Fx.Style(TextPage.List[TextPage.Current],'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeOut});
		hideCur.start(0);
		ImageList.ShowRequestImage.delay(1000);
		TextPage.RequestShown = 1;
	},
	ShowRequestImage: function()
	{
	var showCur = new Fx.Style('imageask','opacity',{duration:2000,transition: Fx.Transitions.Quart.easeIn});
	showCur.start(1);
	
	},

	ShowList: function(e)
	{
		if (e.indexOf('#')>0) e = e.substr(e.indexOf('#'),e.length-e.indexOf('#')); //for IE
		
		var sI = $$(e);
		
		if (sI.length > 0)
		{
			ImageList.CurrentList.toggleClass('hidden');
			sI[0].toggleClass('hidden');
			ImageList.CurrentList = sI[0];
			TextPage.setScrollBar();
		}
	},
	DropDownFix: function(scrollbar)
	{
	
		if (ImageList.ListItems != null)
		{
		var vs = $('imgsel');
		
		if (vs != null)
		{
			
			
			var nT = $('categorysel').getTop() - $('pagebody').getTop() - scrollbar.content.scrollTop;
			
			
			vs.setStyle('top',nT+ 'px');
			
			if (vs.getTop() < TextPage.List[TextPage.Current].getElements('.scrollpage')[0].getTop())
				vs.addClass('vishide');
			else
				vs.removeClass('vishide');
				
			
		}
		}
	}
	}
	
var Links = 
	{
		SelectedLink : 1,
		setup: function()
		{
			if (Page.firstpage)
			{
				$('navigation').setOpacity(0);
				$('subnavigation').setOpacity(0);
				$('extranavigation').setOpacity(0);
			}
			
			Links.SubNav = $$('#subnavigation ul');
			
			
			$$('#navigation a').addEvent('mouseover',function(e){
					
					Links.SubNav.each(function(l){			
						if (l.id=="nav"+e.target.rel)
						{
							l.setOpacity(0);
							l.removeClass('hidden');
							var sl = new Fx.Style(l,'opacity');
							sl.start(1);
							
						}
						else
						{
							l.addClass('hidden');	
						}
						});
					
					
					});
			
			
			
			
			
			
		},
		showLinks : function()
		{
			if (Page.firstpage)
			{
				$('navigation').fade(1);
				$('extranavigation').fade(1);
				$('subnavigation').fade(1);
			}
			
			
		},
		hideSWF: function()
		{
			/*$('worldmap').addClass('hidden');
			$('finmap').removeClass('hidden');
			$('swf').addClass('hidden');*/
		}
	}
	
var TextPage = 
	{
	Current: 0,
	Scroller: 0,
	ExtraShown: false,
	CurrentExtraId:0,
	RequestShown: 0,
	setup: function()
		{
		TextPage.List = $$('div#pagebody div.textpage');
		TextPage.Count = TextPage.List.length;
		
		var anchor = $get('#');
		
		
		if (anchor.length > 0)
		{
			pId = anchor.substr(7,anchor.length-6);
			TextPage.Current = (pId*1)-1;
		}
		
		if (TextPage.Count > 1)
		{
			$$('#subnavigation ul').each(function(e){
				if (!e.hasClass('hidden'))
				{
					var j=e.getElements('li a');
					j.addEvent('click',function(a){
								var anc = $get('#',a.target.href);
								if (anc.length > 0)
								{
									pId = anc.substr(7,anc.length-6);
									TextPage.hidePage((pId*1)-1);
									TextPage.Current = (pId*1)-1;
									for(var i=0;i<j.length;i++)
										if (i==TextPage.Current)
											j[i].addClass('selected');
										else
											j[i].removeClass('selected');
									
								}
							}
							);
				}
			});;
			
			for(var i=0;i<TextPage.Count;i++)
			{
				if (i != TextPage.Current)
					TextPage.List[i].setOpacity(0);
					
			
			}
		}
		
		TextPage.ExtraPage = $$('div#pagebody div.extrapage');
		TextPage.ExtraCount = TextPage.ExtraPage.length;
		
		for(var i=0;i<TextPage.ExtraCount;i++)
			TextPage.ExtraPage[i].setOpacity(0);
		
		
		TextPage.Scroller = new Array();
		for(var k=0;k<TextPage.List.length;k++)
		{
			var cur = TextPage.List[k];
			TextPage.Scroller[k] = new ScrollBar(cur, cur.getElementsByTagName('div')[0],{'hScroll':false, onScroll: function(s) { ImageList.DropDownFix(s); } });
		}

		TextPage.ExtraScroller = new Array();
		for(var k=0;k<TextPage.ExtraPage.length;k++)
		{
			var cur = TextPage.ExtraPage[k];
			TextPage.ExtraScroller[k] = new ScrollBar(cur, cur.getElementsByTagName('div')[0],{'hScroll':false });
		}

		
		TextPage.Links = $$('div#pagebody div#pagenav li a.tlink');
		for(var j=0;j<TextPage.Links.length;j++)
			TextPage.Links[j].addEvent('click',new Function('evt','TextPage.hidePage('+j+');evt = new Event(evt); evt.preventDefault();'));
		
		TextPage.ExtraLinks = $$('div#pagebody div.textpage td a');
		for(var j=0;j<TextPage.ExtraLinks.length;j++)
			if (TextPage.ExtraLinks[j].href.indexOf('#') > 0)
				{
				var hr = TextPage.ExtraLinks[j].href;
				var id = hr.substr(hr.indexOf('#')+1,hr.length-hr.indexOf('#'));
				var sel = 0;
				for(var k=0;k<TextPage.ExtraPage.length;k++)
				{
					if (TextPage.ExtraPage[k].id==id)
					{
						sel=k;
						break;
					}
				}
					TextPage.ExtraLinks[j].addEvent('click',new Function('evt','TextPage.extraPage('+sel+',\'' +id +'\'); evt = new Event(evt); evt.preventDefault();'));
				}
		
		},
		extraPage: function(id,show)
		{
			var hideCur = new Fx.Style(TextPage.List[TextPage.Current],'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeOut});
			hideCur.start(0);
			TextPage.CurrentExtra = show;
			TextPage.CurrentExtraId = id;
			TextPage.ExtraShown = true;
			TextPage.showExtra.delay(1000);
		},
		showExtra: function()
		{
			var startCur = new Fx.Style($(TextPage.CurrentExtra),'opacity',{duration:2000,transition: Fx.Transitions.Quart.easeIn});
			startCur.start(1);
			
			if (TextPage.ExtraScroller[TextPage.CurrentExtraId] != null)
				TextPage.ExtraScroller[TextPage.CurrentExtraId].update();
		},
		hidePage: function(j)
		{
			if ($('imageask') != null && TextPage.RequestShown > 0)
			{
				if (!$('imageask').hasClass('hidden') && TextPage.RequestShown == 1)
				{
					
						var hideCur = new Fx.Style($('imageask'),'opacity',{duration:1500,transition: Fx.Transitions.Quart.easeOut});
						hideCur.start(0);
						if (TextPage.Current == j)
						{
						TextPage.showPage.delay(500);
						}
						TextPage.RequestShown = 0;
					
				}
				
				if (!$('imagedownload').hasClass('hidden') && TextPage.RequestShown == 2)
				{
					
					
						var hideCur = new Fx.Style($('imagedownload'),'opacity',{duration:1500,transition: Fx.Transitions.Quart.easeOut});
						hideCur.start(0);
						if (TextPage.Current == j)
						{
						TextPage.showPage.delay(500);
						}
						TextPage.RequestShown = 0;
					
				}
			}
			if (TextPage.ExtraShown)
			{
				TextPage.ExtraShow = false;
				var hideCur = new Fx.Style($(TextPage.CurrentExtra),'opacity',{duration:1500,transition: Fx.Transitions.Quart.easeOut});
				hideCur.start(0);
				if (TextPage.Current == j)
				{
				TextPage.showPage.delay(500);
				}
			}
			if (TextPage.Current != j)
			{
				var hideCur = new Fx.Style(TextPage.List[TextPage.Current],'opacity',{duration:1500,transition: Fx.Transitions.Quart.easeOut});
				hideCur.start(0);
				TextPage.Links[TextPage.Current].removeClass('selected');
				TextPage.Current = j;
				TextPage.Links[TextPage.Current].addClass('selected');
				TextPage.showPage.delay(500);
			}
		},
		showPage: function()
		{
		
		var startCur = new Fx.Style(TextPage.List[TextPage.Current],'opacity',{duration:1500,transition: Fx.Transitions.Quart.easeIn});
		startCur.start(1);
		TextPage.setScrollBar();
		
		},
		setScrollBar: function()
		{
		if (TextPage.Scroller[TextPage.Current] != null)
			TextPage.Scroller[TextPage.Current].update();
		}
	}
	
/* code for sliding doors */
/*var Doors = {
		
		open : function()
		{
			if (!$defined(Doors.lMove))
				Doors.lMove= new Fx.Style('leftdoor','left',{duration:4500,transition: Fx.Transitions.Quart.easeInOut});
			if (!$defined(Doors.rMove))
				Doors.rMove= new Fx.Style('rightdoor','left',{duration:4500,transition: Fx.Transitions.Quart.easeInOut});
			
			Doors.lMove.start(-454);
			Doors.rMove.start(910);
			Links.showLinks.delay(3000);
			Links.showSWF.delay(4000);
			Pictures.next.delay(10000);
			
		
		},
		close: function()
		{
		}
		,
		fixOpen: function()
		{
			$('leftdoor').setStyle('left','-600px');
			$('rightdoor').setStyle('left','1200px');
			Links.showSWF.delay(1000);
		}
	}*/