Nav = new function(){
	var xml=null;
	this.menuWrapper;
	this.less;
	this.interval = null;
	this.more;
	this.selectedMenuItem=null;
	this.selectedMenuIndex=-1;
	this.animating=false;
	this.initMenu = function(selectedMenuItem,menuWrapper,less,more){
		this.selectedMenuItem=selectedMenuItem;
		this.menuWrapper = $('#'+menuWrapper);
		$.ajax( {
			type :"GET",
			url :"nav.xml",
			dataType :"xml",
			success : function(retXml) {
				xml = $(retXml);
				var topNav = xml;
				Nav.makeMenu(topNav);
			}
		});
		this.less = $('#'+less);
		this.more = $('#'+more);
		this.less.click(function(){
			Nav.scrollRight();
		});
		this.more.click(function(){
			Nav.scrollLeft();
		});
		$(document).bind('nav:scrolled',function(event,data){
			showHideLeftRight();
		});
	};
	var drawNavItem = function(topNav, index, data){
		var defaultHeight = topNav.attr('height');
		var id = data.attr('id');
		var navItem = $('#'+id);
		navItem.focus(function(){this.blur();});
		var itemWidth = data.attr('width');
		navItem.css('width',itemWidth+'px');
		navItem.css('height',defaultHeight+'px');
		if($.browser.firefox){
			navItem.css('display','-moz-inline-box');
		}else{
			navItem.css('display','inline-block');
		}
		var sprite = topNav.attr('sprite');
		if(sprite){
			navItem.css('background',  "url('../"+sprite+"') no-repeat");
			var yOffset = index*defaultHeight;
			var xOffset = 0;
			navItem.hover(function(){
				navItem.css('background-position', '-'+(xOffset+itemWidth)+'px -'+yOffset+'px');
			},function(){
				navItem.css('background-position', '-'+xOffset+'px -'+yOffset+'px');
			});
			navItem.css('background-position', '-'+xOffset+'px -'+yOffset+'px');
		}else{
			var imageFolder = topNav.attr('imageFolder');
			if(id!=Nav.selectedMenuItem){
				navItem.css('background',  "url('../"+imageFolder+data.attr('id')+".gif') no-repeat");
			}else{
				navItem.css('background',  "url('../"+imageFolder+data.attr('id')+"_over.gif') no-repeat");
				Nav.selectedMenuIndex=index;
			}
			navItem.hover(function(){
				navItem.css('background', "url('../"+imageFolder+data.attr('id')+"_over.gif') no-repeat");
			},function(){
				if(navItem.attr('id')!=Nav.selectedMenuItem){
					navItem.css('background', "url('../"+imageFolder+data.attr('id')+".gif') no-repeat");
				}
			});
		}
	};
	this.makeMenu = function(item){
		if(item.find('> ul').length>0){
			var secondLevelTopNavData = item.find('> ul');
			var secondLevelItems = secondLevelTopNavData.find('> li');
			var navWidth = 0;
			secondLevelItems.each(function(index,data){
				var subItemData = $(data);
				drawNavItem(secondLevelTopNavData,index,subItemData);
				//add item's width and its margin
				navWidth += Number(subItemData.attr('width')) + 10;
				if(index<secondLevelItems.length-1){
					//add delimiter's width and its margin
					navWidth += Number(secondLevelTopNavData.attr('delimiterWidth'))+ 10;
				}
				Nav.makeMenu(subItemData);
			});
			$('#'+secondLevelTopNavData.attr('id')).css('width',navWidth+'px');
			if(item.attr('id')){
				$('#'+item.attr('id')).click(function(){
					if($('#'+secondLevelTopNavData.attr('id')).hasClass('currentNav')){
					}else{
						Nav.scrollNav(secondLevelTopNavData.attr('id'));
					}
					return false;
				});
			}else{
			}
		}
	};
	var markItemsHiddenRight = function(nav,start,viewPort){
		var viewableArea = start;
		var viewPortWidth = viewPort+start;
		var tmp = 0;
		nav.children().each(function(index,child){
			if(tmp<start){
				tmp+= $(child).width()+10;
			}else{
				viewableArea+= $(child).width()+10;
				if($(child).css('opacity')!=1 || $(child).css('filter')=='alpha(opacity: 30)'){
					$(child).css('opacity',1);
					$(child).css('filter', 'alpha(opacity: 100)');
				}
				if(viewableArea>viewPortWidth){
					if(index%2==0){
						var stopIndex=index-2;
						nav.children().each(function(index,child){
							if(index>stopIndex){
								$(child).css('opacity','.3');
								$(child).css('filter', 'alpha(opacity: 30)');
							}
						});
					}else{
						var stopIndex=index-1;
						nav.children().each(function(index,child){
							if(index>stopIndex){
								$(child).css('opacity','.3');
								$(child).css('filter', 'alpha(opacity: 30)');
							}
						});
					}
					return false;
				}
			}
		});
	};
	this.currentNavPage=0;
	this.pages=[];
	this.scrollNav = function(id){
		if(!this.animating){
			this.animating=true;
			this.currentNavPage=0;
			if($('.currentNav').length>0){
				$('.currentNav').animate({top:'-=22px',opacity:'-=1'},'slow',function(){
					$(this).removeClass('currentNav');
					$(this).css('left',Nav.menuWrapper.css('width'));
					$(this).css('top',18);
					$(this).css('opacity',1);
				});
			}
			var nav = $('#'+id);
			var navWidth = nav.width();
			var viewPortWidth = this.menuWrapper.width();
			nav.addClass('currentNav');
			
			
			if(navWidth>viewPortWidth){
				this.pages=[0];
				markItemsHiddenRight(nav,0,viewPortWidth);
				var viewableArea = 0;
				var viewPort = viewPortWidth;
				nav.children().each(function(index,child){
					viewableArea+= $(child).width()+10;
					if(viewableArea>viewPort){
						if(index%2==0){
							Nav.pages.push(index);
						}else{
							Nav.pages.push(index-1);
						}
						viewPort=viewPortWidth;
						viewableArea=$(child).width()+10;
					}
				});
				$(document).trigger('nav:scrolled');
			}else{
				this.more.hide();
				this.less.hide();
			}
			setTimeout(function(){
				nav.animate({left:'-='+viewPortWidth+'px'},'slow',function(){
					Nav.animating=false;
					$(document).trigger('mainNav:loaded',id);
				});
			},200);
		}
	};
	this.scrollToGallery = function(parentId){
		this.scrollNav(parentId);
		$(document).one('mainNav:loaded',function(){
			var nav = $('.currentNav');
			var viewPortWidth = Nav.menuWrapper.width();
			for(var i=0;i<Nav.pages.length;i++){
				if(Nav.pages[i]>(Nav.selectedMenuIndex+Nav.selectedMenuIndex)){
					var previous = $(nav.children().get(Nav.pages[--i])).position().left;
					Nav.currentNavPage=i;
					markItemsHiddenRight(nav,previous,viewPortWidth);
					var seek = Math.abs(nav.position().left)-previous;
					Nav.animating=true
					nav.animate({left:'+='+seek+'px'},'slow',function(){
						Nav.animating=false;
						$(document).trigger('nav:scrolled');
					});
					break;
				}
				if(i==Nav.pages.length-1){
					var previous = $(nav.children().get(Nav.pages[i])).position().left;
					Nav.currentNavPage=i;
					markItemsHiddenRight(nav,previous,viewPortWidth);
					var seek = Math.abs(nav.position().left)-previous;
					Nav.animating=true
					nav.animate({left:'+='+seek+'px'},'slow',function(){
						Nav.animating=false;
						$(document).trigger('nav:scrolled');
					});
					break;
				}
			}
		});
	};
	this.scrollLeft = function(){
		if(!this.animating){
			this.animating=true;
			var nav = $('.currentNav');
			var viewPortWidth = this.menuWrapper.width();
			var next = $(nav.children().get(this.pages[++this.currentNavPage])).position().left;
			markItemsHiddenRight(nav,next,viewPortWidth);
			nav.animate({left:'-='+(next-Math.abs(parseInt(nav.css('left'))))+'px'},'slow',function(){
				Nav.animating=false;
				$(document).trigger('nav:scrolled');
			});
		}
	};
	this.scrollRight = function(){
		if(!this.animating){
			this.animating=true;
			var nav = $('.currentNav');
			var viewPortWidth = this.menuWrapper.width();
			var previous = $(nav.children().get(this.pages[--this.currentNavPage])).position().left;
			markItemsHiddenRight(nav,previous,viewPortWidth);
			var seek = Math.abs(nav.position().left)-previous;
			nav.animate({left:'+='+seek+'px'},'slow',function(){
				Nav.animating=false;
				$(document).trigger('nav:scrolled');
			});
		}
	};
	var showHideLeftRight = function(){
		if(Nav.currentNavPage==(Nav.pages.length-1)){
			Nav.more.hide();
		}else if(Nav.currentNavPage<(Nav.pages.length-1)){
			Nav.more.show();
		}
		if(Nav.currentNavPage==0){
			Nav.less.hide();
		}else if(Nav.currentNavPage>0){
			Nav.less.show();
		}
	};
}
function convertToFileName(str){
	return str.replace(' ','_').toLowerCase();
}

var loadingQuoteImage = false;
function quoteRotator(quotes,interval){
	var quoteBlock = $('#contentText blockquote');
	setInterval(function(){
		if(!loadingQuoteImage){
			var quote = quotes[Math.floor(Math.random()*quotes.length)];
			loadingQuoteImage=true;
			Util.loadImageNCall(quote.image,function(){
				$('#mainImage').fadeOut('fast',function(){
					var img = $(this);
					img.attr({src : quote.image, alt: ""});
					var top = $('#imageArea').height()/2-img.height()/2-12;
					img.css('top',top);
					//$('#imageLargeCaption').css('top',top);
					img.fadeIn('fast',function(){
						loadingQuoteImage=false;
					});
				}); 
			});
		}
	},interval*1000);
}
/** 
// jQuery Right Mouse Plugin
//
// Version 1.00
//
// Cory S.N. LaViska
**/
if(jQuery) (function(){
	$.extend($.fn, {
		noContext: function() {
			$(this).each( function() {
				$(this)[0].oncontextmenu = function() {
					return false;
				}
			});
			return $(this);
		}
	});
})(jQuery);	
$(function(){
	if($('#imageLink').length==1){
		$("#imageLink").noContext();
	}
});
