var popup = new Class({
	initialize: function(options) {
		if ($('main')) {
			this.options = Object.extend({
				contentWidth: 100,
				contentHeight: 100,
				content: '<img src="images/shim.gif" width="100" height="100"/>',
				type: 'img'
			}, options || {});	
			//define border width and color
			this.borderWidth = 2;
			this.borderColor = '#ffffff';
			//define offset for shadow
			this.shadowXOffset = 13;
			this.shadowYOffset = 5;
			//define banner dimensions (top and bottom)
			this.topBannerHeight = 22;
			this.bottomBannerHeight = 50;
			//define corner radius (dimensions of the image used for the corners)
			this.cornerWidth = 22;
			this.cornerHeight = 22;
			//don't edit below here
			this.coordinates = $('main').getCoordinates();
			this.maxWidth = this.coordinates.width;
			this.maxHeight = this.coordinates.height;
			this.buildBase();
			this.buildContainer(this.options.content);
			if (!/MSIE (5.5|6.)/.test(navigator.userAgent)) this.buildShadow();
			return this.pop;
		};
	},
	buildBase: function() {
		this.lrg_content_width = this.options.contentWidth + (2 * this.borderWidth);
		this.lrg_content_height = this.options.contentHeight + (4 * this.borderWidth) + this.topBannerHeight + this.bottomBannerHeight;
		this.xPos = ((this.maxWidth/2-(this.lrg_content_width-this.shadowXOffset)/2) > -1) ? this.maxWidth/2-(this.lrg_content_width-30)/2 : 0;
		this.yPos = ((this.maxHeight/2-(this.lrg_content_height-this.shadowYOffset)/2) > -1) ? this.maxHeight/2-(this.lrg_content_height-this.shadowYOffset)/2 : 0;
		this.pop = new Element ('div').setProperties({id: 'popup'}).setStyles({position: 'absolute',left: this.xPos + 'px',top: this.yPos + 'px',width: this.lrg_content_width + 'px',height: this.lrg_content_height + 'px'}).setStyle('z-index','10000');
	},
	buildContainer: function(obj) {
		this.container = new Element ('div').setProperties({
			width: this.options.contentWidth,
			height: this.options.contentHeight + this.topBannerHeight + this.bottomBannerHeight + (this.borderWidth * 4)
		}).setStyles({
			width: this.options.contentWidth+'px',
			height: this.options.contentHeight + this.topBannerHeight + this.bottomBannerHeight + (this.borderWidth * 4) + 'px'
		}).setStyle('z-index','20').setStyle('background-color',this.borderColor).injectInside(this.pop);
		this.top_banner = new Element ('div').setProperties({
			width: this.options.contentWidth,
			height: this.topBannerHeight
		}).setStyle('width',this.options.contentWidth+'px').addClass('top_banner').injectInside(this.container);
		this.top_banner_link = new Element ('a').setProperties({href: 'javascript:closePopup();',target: '_self'}).setHTML('close').injectInside(this.top_banner);
		
		if(this.options.type === 'img') {
			obj.injectInside(this.container);
		} else {
			obj.injectInside(this.pop);
		};
		
		this.bottom_banner = new Element ('div').setProperties({
			width: this.options.contentWidth,
			height: this.bottomBannerHeight
		}).setStyles({
			position: 'absolute',
			top: this.options.contentHeight + this.topBannerHeight + (5 * this.borderWidth) +'px',
			left: '2px',
			width: this.options.contentWidth+'px',
			height: this.bottomBannerHeight+'px'
		}).addClass('bottom_banner').setHTML('&nbsp;').injectInside(this.container);
	},
	buildShadow: function() {
		this.shadow = new Element ('div').setProperties({
			width: this.lrg_content_width,
			height: this.lrg_content_height
		}).setStyles({
			position: 'absolute',
			left: this.shadowXOffset + 'px',
			top: this.shadowYOffset + 'px',
			width: this.options.contentWidth + 'px',
			height: this.lrg_content_height + 'px'
		}).setStyle('z-index','10').injectInside(this.pop);
		this.main_shadow = new Element ('div').setProperties({
			width: this.lrg_content_width - this.cornerWidth,
			height: this.lrg_content_height - (0.5 * this.cornerHeight)
		}).setStyles({
			position: 'absolute',
			top: this.cornerHeight + 'px',
			left: this.cornerWidth + 'px',
			width: this.lrg_content_width - this.cornerWidth + 'px',
			height: this.lrg_content_height - (0.5 * this.cornerHeight) + 'px',
			overflow: 'hidden',
			background: 'transparent url("/images/shadow/shadow.png") no-repeat bottom right'
		}).injectInside(this.shadow);
		this.top_shadow = new Element ('div').setProperties({
			width: this.cornerWidth,
			height: this.cornerHeight
		}).setStyles({
			width: this.cornerWidth + 'px',
			height: this.cornerHeight + 'px',
			position: 'absolute',
			top: '0px',
			left: this.lrg_content_width - this.cornerWidth + 4 + 'px',
			background: 'transparent url("/images/shadow/corner_tr.png") no-repeat top left'
		}).injectInside(this.shadow);
		this.bottom_shadow = new Element ('div').setProperties({
			width: this.cornerWidth,
			height: this.cornerHeight
		}).setStyles({
			width: this.cornerWidth + 'px',
			height: this.cornerHeight + 'px',
			position: 'absolute',
			top: this.lrg_content_height - (0.5 * this.cornerHeight) + 'px',
			left: '0px',
			background: 'transparent url("/images/shadow/corner_bl.png") no-repeat bottom left'
		}).injectInside(this.shadow);
	}
});

function formatting() {
	if ($('main_bkgnd')) {
		//set opacities
		if ($( 'bkgnd01' )) {
			$( 'main_bkgnd' ).setOpacity(0.55);
			$( 'bkgnd00' ).setOpacity(0.20);
			$( 'bkgnd01' ).setOpacity(0.7);
		} else {
			$( 'main_bkgnd' ).setOpacity(0.6);
			$( 'bkgnd' ).setOpacity(0.7);
		};
		$( 'b_bkgnd00' ).setOpacity(0.00);
		$( 'b_bkgnd01' ).setOpacity(0.75);
		$( 'b_bkgnd02' ).setOpacity(0.60);
	
		//formatting2 and formatting3 set the background image, depending on the type of page being viewed
		if ((!$E( '.c' ))&&(!$( 'featuredImg' ))) {
			formatting2();
		} else {
			formatting3();
		};
	
		$each($ES('._bkgnd'),function(el) {
			var overlayContainer = el.getParent();
			var overlayParts = overlayContainer.getChildren();
			$each (overlayParts,function(part){
				part.setStyles({
					position: 'absolute',
					top: '0px',
					left: '0px'
				});
				if ((part.hasClass( '_bkgnd'))&&(!overlayContainer.hasClass( 'projects' ))) part.setStyle('background-color','#fff');
				if ((part.hasClass( '_bkgnd'))&&(overlayContainer.hasClass( 'projects' ))) part.setStyle('background-color','#efefef');
				if (part.hasClass( 'holder')) {
					part.setStyles({
						padding: '10px 0px',
						margin: '0px'
					});
				};
				if ((!overlayContainer.hasClass( 'projects' ))&&(part.hasClass( '_bkgnd'))) el.setOpacity(0.80);
			});
			overlayContainer.setStyles({
				position: 'absolute',
				top: '0px',
				left: '0px',
				width: '489px',
				height: '358px'
			});
		});
	};
};

var replaceText = {
	init: function( options ) {
		this.labels = [];
		$each($ES('.label'),function(el){
			this.labels.push(el);
		}, this);
		$each($ES('.label2'),function(el){
			this.labels.push(el);
		}, this);
		if(($('main_bkgnd'))&&(this.labels.length > 0)){
			$each(this.labels,function(item){
				this.replace(item);
			}, this);
		};
	},
	replace: function( el ){
		var elParent = el.getParent();
		var elChild = (el.getFirst()) ? el.getFirst() : null;
		var elText = (elChild != null) ? elChild.innerHTML : el.innerHTML;
		var elGrandChild = (elChild.getFirst()) ? elChild.getFirst() : null;
			elText = (elGrandChild != null) ? elGrandChild.innerHTML : elText;
		var origElement = (elGrandChild) ? elGrandChild : elChild;
		var use_link = (elGrandChild) ? true : false;
		
		elChild.setStyle('display','inline');
		var _s = elChild.getSize();
		var _w = _s.size.x;
		
		var fg_color = 'fff';
		var bg_color = ((el.hasClass('display'))&&(elParent.hasClass('r'))) ? '44697d' : '81a019';
			
		elChild.setStyle('display','block');
		
		if ((elParent.hasClass('c'))&&(!el.hasClass('display'))) {
			el.setStyle('background-color','#fff');
			elChild.setStyle('display','none');
			var label_text = elText.replace(/&amp;/g,'and');
				label_text = label_text.replace(/ /g,'_');
			var new_hdr = new Element('img');
				new_hdr.setProperty('src','/images/headers/'+label_text+'.gif');
				new_hdr.addClass(label_text+'_hdr');
				new_hdr.injectInside($('main'));
				new_hdr.setOpacity(1);
		} else {
			if (elParent.hasClass('r')) {
				elChild.setStyle('width',_w+'px');
			}
			if ((elParent.hasClass('c'))&&(el.hasClass('display'))) {
				elChild.setStyle('width',(_w+50)+'px');
				el.setStyles({
					width: 482+'px',
					height: '22px'
				});
			};
			if (elParent.hasClass('legend')) {
				var fg_color = '81a019';
				var bg_color = 'fff';
				
				elChild.setStyle('display','block');
				elChild.setStyle('width',(_w+50)+'px');
				elWidth = (!el.hasClass('display')) ? _w+50 : 238;
				el.setStyles({
					display: 'block',
					width: elWidth+'px',
					height: '22px',
					margin: '0px'
				}).setStyle('padding','0px 0px 0px 7px');
			};
			if (elGrandChild) {
				var anchor_styles = elChild.getStyles('display','width');
				var anchor = new Element('a');
					anchor.setProperties({
						href: 'javascript:returnMenu();',
						target: '_self'
					}).setProperty('id','portfolio_return').setStyles(anchor_styles).setStyle('height','22px');
				elChild.replaceWith(anchor);
				origElement.injectInside(anchor);
			};
			var label_text = Url.encode(elText);
				label_text = label_text.replace('/','%25');
			var alt = new Element('span');
				alt.addClass('replaced');
				alt.innerHTML = elText;
				alt.injectInside(el);
			var img_url = 'index.php/heading/bold/'+bg_color+'/'+fg_color+'/'+label_text+'.jpg';
				var label_image = new Element('img');
					label_image.setProperties({
						src: img_url
					});
			origElement.replaceWith(label_image);
			label_image.setOpacity(1);
		};
	}
};

var activeButton = {
	init: function() {
		var returnLink = ($('portfolio_return')) ? $('portfolio_return') : null;
		if (returnLink != null) {
			var elParent = returnLink.getParent();
			var elChild = returnLink.getFirst();
			var elSource = elChild.src;
			var elOver = 'images/back_to_main_menu.gif';
			returnLink.onmouseover = function() {
				elParent.toggleClass('over');
			}
			returnLink.onmouseout = function() {
				elParent.toggleClass('over');
			};
		};
		this.buttons = [];
		$each($$('a'),function(el) {
			if (el != $( 'portfolio_return' )) this.buttons.push(el);
		},this);
		$each(this.buttons,function(button) {
			if(!((button.getParent().hasClass('global'))&&(!button.hasClass('lst')))) {
				this.activate(button);
			};
		},this);
	},
	activate: function( el ) {
		var elParent = el.getParent();
		var elChild = (el.getFirst()) ? el.getFirst() : null;
		//highlight selected thumbnail
		if (elParent.hasClass( 'thumbnails' )&&(elChild.hasClass( 'selected' ))) {
			elChild.setOpacity(0.3);
			return false;
		};
		if ((elParent.hasClass( 'icon' ))||(elParent.hasClass( 'inset' ))||(el.hasClass( 'award-thumbnail' ))) {
			var el_src = el.href.toString();
			el.setProperty ('href','javascript:showImg("'+el_src+'");');
			el.setProperty ('target','_self');
			return false;
		};
		//touch all links on the page that contain images
		if ((elChild != null)&&(elChild.src)&&(!elParent.hasClass( 'thumbnails' ))) {
			var imgSource = elChild.src;
			if (imgSource.indexOf('.png') > -1) var imgType = '.png';
			if (imgSource.indexOf('.jpg') > -1) var imgType = '.jpg';
			if (imgSource.indexOf('.gif') > -1) return false;
			var filename = imgSource.substring(0,imgSource.lastIndexOf(imgType));
			var inactiveFN = (filename.indexOf( '_active' ) > -1) ? filename.substring(0,filename.lastIndexOf('_active')) + imgType: filename + imgType;
			var activeFN = (filename.indexOf( '_active' ) > -1) ? filename + imgType : filename + '_active' + imgType;
			
			//automatically set the active state for the selected button image
			if ((imgSource.indexOf( 'buttons' ) > -1)&&(el.hasClass( 'active' ))) {
				filename = (filename.indexOf( '_active' ) > -1) ? filename.substring(0,filename.lastIndexOf('_active')) : filename;
				elChild.src = activeFN;
			};
			//handle mouseover states on image-based links
			if (!el.hasClass( 'active' )) {
				el.onmouseover = function() {
					if((elChild.style.filter)&&(elChild.style.filter.indexOf( 'buttons' ) > -1)) {
						var newName = elChild.style.filter;
						 	newName = newName.substring(newName.indexOf( 'http:'),newName.indexOf(imgType)) + '_active' + imgType;
						elChild.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newName + "', sizingMethod='scale')";
					} else {
						elChild.src = activeFN;
					};
				};
				el.onmouseout = function() {
					if((elChild.style.filter)&&(elChild.style.filter.indexOf( 'buttons' ) > -1)) {
						var newName = elChild.style.filter;
						 	newName = newName.substring(newName.indexOf( 'http:'),newName.indexOf( '_active' )) + imgType;
						elChild.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + newName + "', sizingMethod='scale')";
					} else {
						elChild.src = inactiveFN;
					};
				};
			};
		};
	}
};

function show(sel) {
	if(($E('.c .head .links'))&&(($E('.c .head .links').hasClass('hide')))) $E('.c .head .links').removeClass('hide');
	if($('tmp_label')) $('tmp_label').remove();
	var overlays = $ES('._bkgnd').getParent();
		overlays.each(function(el) {
			if(el.hasClass('show')) el.removeClass('show').addClass('hide');
		});
	var selected = $E('.'+sel);
		if(selected.hasClass('hide')) selected.removeClass('hide');
		selected.addClass('show');
};

function showProjects() {
	var panel0 = ($('projects_panel_0')) ? $('projects_panel_0') : null;
	if (panel0 != null) {
		var overlays = $ES('._bkgnd').getParent();
			overlays.each(function(el) {
				if(el.hasClass('show')) el.removeClass('show').addClass('hide');
			});
		if ($('projects_panel_0').hasClass('hide')) $('projects_panel_0').removeClass('hide');
		
		var display_string = document.title;
			display_string = display_string.replace('/','%');
			display_string = Url.encode('all ' + display_string.substring(7).toLowerCase() + ' projects');
		var new_label = new Element('div');
		var new_img = new Element('img').setProperty('src','index.php/heading/bold/81a019/fff/' + display_string);
			new_label.setProperties({
				id:'tmp_label',
				width: '482',
				height: '22'
			}).addClass('label');
		if($E('.c .head .links')) {
			$E('.c .head .links').addClass('hide');
		};
		
		var mContent = $E('.c .content');
			new_label.injectInside(mContent);
			new_img.injectInside(new_label);
			new_img.setOpacity(1);
			
		var panels = $ES('.projects');
			if (panels.length > 1) {
				var links = new Element ('span');
				var i = 1;
				panels.each(function(el){
					var link = new Element ('a').setProperties({
						target: '_self',
						href: 'javascript:showProject('+i+')'
					}).addClass('page_link');
					if (i==1) link.addClass('active');
					link.innerHTML = i;
					i++;
					link.injectInside(links);
				});
				links.injectInside(new_label);
			};
			
		if($E('.links')) $E('.links').addClass('hide');
		if($E('.mImage')) $E('.mImage').addClass('hide');
		if($E('.legend')) $E('.legend').addClass('hide');
	};
};
function showProject(num) {
	var panels = $ES('.projects');
		panels.each(function(el){
			if (!el.hasClass('hide')) el.addClass('hide');
		});
	var panel = $('projects_panel_'+(num-1));
	if (panel.hasClass('hide')) panel.removeClass('hide');
	var links = $ES('.label .page_link');
		links.each(function(el){
			if ((el.innerHTML != num) && (el.hasClass('active'))) el.removeClass('active');
			if ((el.innerHTML == num) && (!el.hasClass('active'))) el.addClass('active');
		})
};
function hideProjects() {
	if(($E('.mImage'))&&($E('.mImage').hasClass('hide'))) $E('.mImage').removeClass('hide');
	if(($E('.legend'))&&($E('.legend').hasClass('hide'))) $E('.legend').removeClass('hide');
	if(($E('.c .head .links'))&&(($E('.c .head .links').hasClass('hide')))) $E('.c .head .links').removeClass('hide');
	if($('tmp_label')) $('tmp_label').remove();
	var projects = $ES('.projects');
		projects.each(function(el) {
			if(!el.hasClass('hide')) {
				el.addClass('hide');
			};
		});
}

function hide() {
	if(($E('.mImage'))&&($E('.mImage').hasClass('hide'))) $E('.mImage').removeClass('hide');
	if(($E('.legend'))&&($E('.legend').hasClass('hide'))) $E('.legend').removeClass('hide');
	if(($E('.c .head .links'))&&(($E('.c .head .links').hasClass('hide')))) $E('.c .head .links').removeClass('hide');
	if($('tmp_label')) $('tmp_label').remove();
	var overlays = $ES('._bkgnd').getParent();
		overlays.each(function(el) {
			if(el.hasClass('show')) {
				el.removeClass('show');
				el.addClass('hide');
			};
		});
};

function showImg (img_src) {
	if($('popup')) $('popup').remove();
	var img_dim = img_src.substr(img_src.indexOf('?dim=')+5);
	var img_w = parseInt(img_dim.substr(0,img_dim.indexOf('x')));
	var img_h = img_dim.substr(img_dim.indexOf('x')+1);
		img_h = parseInt(img_h);
	var image_hldr = new Element ('div').setProperties({
			width: img_w,
			height: img_h
		}).setStyles({
			width: img_w+'px',
			height: img_h+'px',
			background: 'transparent url('+img_src+') no-repeat 0px 0px'
		}).addClass('popup_img');
	var enlargement = new popup({contentWidth:img_w,contentHeight:img_h-4,content:image_hldr,type:'img'});
		enlargement.injectInside($('main'));
};

function showMsg (msg) {
	if($('popup')) $('popup').remove();
	var image_hldr = new Element ('div').setProperties({
			width: 400,
			height: 200
		}).setStyles({
			width: 400+'px',
			height: 200+'px',
			background: '#FFFFFF url(images/shim.gif) no-repeat 0px 0px'
		}).addClass('popup_img');
	var text_hldr = new Element('p').setStyles({
		margin: 10+'px'});
	text_hldr.innerHTML = msg;
	text_hldr.inject(image_hldr);
	var enlargement = new popup({contentWidth:400,contentHeight:200-4,content:image_hldr,type:'img'});
		enlargement.injectInside($('main'));
};

function closePopup() {
	if($('popup')) $('popup').remove();
};

function returnMenu() {
	var currMenu = $E('.r .content .fgnd');
	var returnMenu = $E('.r .content .bgnd');
	
	var fg_color = 'fff';
	var bg_color = '81a019';
	
	var old_label = $E('.r .label');
	var new_label = new Element('div').addClass('label');
	var new_label_text = 'index.php/heading/bold/'+bg_color+'/'+fg_color+'/portfolio.jpg';
	var new_text = new Element('img').setProperty('src',new_label_text).setOpacity(1).injectInside(new_label);
		new_text.setOpacity(1);
		old_label.replaceWith(new_label);
		
	if (!currMenu.hasClass('hide')) currMenu.addClass('hide');
	if (returnMenu.hasClass('hide')) returnMenu.removeClass('hide');
}

var introAnim = {
	init: function(options){
		if ($('loader')) {
			this.options = Object.extend({
				transDuration: 800
			}, options || {});
			this.step = 1;
			
			this.main_loader = $('loader');
			this.main_logo = new Image();
			this.main_logo.onload = this.nextStep.bind(this);
			this.main_logo.src = 'images/RTA_RGB_horz.gif';
			
			this.main_image = new Image();
			this.main_image.onload = this.nextStep.bind(this);
			this.main_image.src = 'images/backgrounds/home_01.jpg';
			
			var nextStep = this.nextStep.bind(this);
			
			this.fx = {
				logoIn: new Fx.Style(this.main_logo,'opacity',{duration: 800, onComplete: nextStep}),
				imageIn: new Fx.Style(this.main_image,'opacity',{duration: this.options.transDuration, onComplete: nextStep}),
				logoOut: new Fx.Style(this.main_logo,'opacity',{duration: this.options.transDuration, onComplete: nextStep}),
				imageOut: new Fx.Style(this.main_loader,'opacity',{duration: this.options.transDuration, onComplete: nextStep})
			};
		};
	},
	nextStep: function(){
		switch(this.step++){
			case 1:
				this.main_image.setOpacity(0).injectInside(this.main_loader).addClass('bkgnd');
				break;
			case 2:
				this.main_logo.setOpacity(0).injectInside(this.main_loader).addClass('logo');
				this.fx.logoIn.start(0,1);
				break;
			case 3:
				this.fx.imageIn.start(0,0.4);
				break;
			case 4:
				this.fx.logoOut.start(1,0);
				break;
			case 5:
				this.fx.imageOut.start(1,0);
				break;
			case 6:
				this.main_loader.remove();
				break;
		}
	}
};

var setupSlideshow = {
	init: function() {
		this.auto = true;
		this.count = 1;
		if (location.href.indexOf('slide_show') < 0) {
			return true;
			//this.auto = false;
			//this.count = 0;
		};
		this.anchors = [];
		$each($$('a'),function(el){
			if(el.href.indexOf('slide_show') > -1) {
				if (location.href.indexOf('slide_show') > -1) el.addClass('active');
				el.onclick = this.click.pass(el,this);
				this.anchors.push(el);
				if(this.count==0) {
					this.setup(el);
					this.count++;
				};
			};
		},this);
		if (location.href.indexOf('slide_show') > -1) this.setup();
	},
	setup: function(link) {
		if(!$('slideshow')) {
			this.slideBox = new Element ('div').setProperties({
				id:'slideshow',
				width: '739px',
				height: '327px'
			}).injectInside($('main'));
			this.firstImage = new Asset.image('images/slides/slide_001.jpg', {
				id: 'slide_1', 
				title:'slide_1', 
				onload: this.assemble.bind(this)
			});
		};
	},
	assemble: function() {
		if(this.count == 1) {
			this.count++;
			this.firstImage.setOpacity(0).injectInside(this.slideBox);
			if (this.auto == true) {
				this.startIt();
			};
		};
	},
	click: function(link) {
		$each(this.anchors, function(l) {
			l.addClass('active');
		},this);
		return this.startIt();
	},
	startIt: function() {
		if(!this.show){
			this.show = new Slideshow('slideshow', {
				hu: 'images/slides/', 
				images: ['slide_001.jpg','slide_002.jpg','slide_002b.jpg','slide_003.jpg','slide_003b.jpg','slide_004.jpg','slide_005.jpg','slide_006.jpg','slide_007.jpg','slide_008.jpg','slide_009.jpg','slide_010.jpg','slide_011.jpg','slide_012.jpg','slide_013.jpg','slide_014.jpg','slide_015.jpg','slide_016.jpg','slide_017.jpg','slide_018.jpg','slide_021.jpg','slide_022.jpg'], 
				height: 327, 
				width: 739,
				type:'fade'
			});
		};
		return false;
	}
};

var sitemap = {
	init: function() {
		this.baseURL = location.href.substring(0,location.href.indexOf('/index.php'));
		this.anchors = [];
		this.categories = ['about RTA','services','portfolio'];
		this.fg_color = 'fff';
		this.bg_color = '81a019';
		this.img_w = 853;
		this.img_h = 358;
		this.top_banner_h = 22;
		$each($ES( '.b_nav' ),function(el) {
			if(el.hasClass('global')) {
				$each(el.getChildren(),function(item) {
					if(item.href.test('sitemap')) item.onclick = this.click.pass(item,this);
				},this);
			};
		},this);
		this.setup();
	},
	setup:function() {
		this.map_container = new Element ('div').addClass('popup_content').setStyle('z-index','20000');
		this.c = 2;
		$each(this.categories, function(cat) {
			var m = (this.c > 0) ? 2 : 0;
			var _text = Url.encode(cat);
				_text = _text.replace('/','%25');
			this.colWidth = Math.ceil(this.img_w/3 - 6);
			this.labelWidth = (m > 0) ? this.colWidth : Math.ceil((this.img_w/3 - 6) / 2);
			var col = new Element ('div').setProperties({
				width: this.colWidth,
				height: this.img_h
			}).setStyles({
				margin: '0px '+m+'px 0px 0px',
				width: this.colWidth+'px',
				height: this.img_h+'px'
			}).setStyle('float','left').setStyle('clear','none').addClass('lrg').addClass('content').injectInside(this.map_container);
			//section labels
			var colLabel = new Element ('div').setProperties({
				width: this.labelWidth,
				height: '22'
			}).setStyles({
				position: 'absolute',
				top: '-26px',
				left: '0px',
				width: this.labelWidth+'px',
				height: this.top_banner_h+'px',
				background: 'transparent url("index.php/heading/bold/'+this.bg_color+'/'+this.fg_color+'/'+_text+'.jpg") no-repeat 11px 8px'
			}).setStyle('border-right',m+'px solid #fff').addClass('label').injectInside(col);
			var colReplaced = new Element('span').addClass('replaced').injectInside(colLabel).innerHTML = cat;
			//section content
			var colContent = new Element ('div').addClass('fgnd').injectInside(col);
			var myAjax = new Ajax(this.baseURL+'/index.php/sitemap/'+_text, {method: 'get', update: colContent }).request();
			//var myAjax = new Ajax('http://www.rosstarrant.com/index.php/sitemap/'+_text, {method: 'get', update: colContent }).request();
			this.c--;
		}, this);
		this.sitemap = new popup({contentWidth:this.img_w,contentHeight:this.img_h,content:this.map_container,type:'obj'});
	},
	click: function(link) {
		if($('popup')) $('popup').remove();
		this.sitemap.injectInside($('main'));
		return false;
	}
};
window.addEvent ( 'domready', formatting );
window.addEvent ( 'domready', introAnim.init.bind( introAnim ) );
window.addEvent ( 'domready', setupSlideshow.init.bind( setupSlideshow ) );
window.addEvent ( 'domready', replaceText.init.bind( replaceText ) );
window.addEvent ( 'domready', activeButton.init.bind( activeButton ) );
window.addEvent ( 'domready', sitemap.init.bind( sitemap ) );

var Url = {
	encode : function (string) {
		string = string.replace(/&amp;/g,'and');
		return escape(this._utf8_encode(string));
	},
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
};