var Pager =
{
	updateBackground: true,
	_pageSelector: '.content-body fieldset',
	_navSelector: 'ul.nav',
	_navWithinPage: true,
	_tabSelector: 'div',
	_hasNav: true,
	_hasTabs: true
	,
	getInstance: function() {
		function F() {};
		F.prototype = this;
		return new F();
	}
	,
	init: function()
	{
		// hide pages
		this.hideAllPages();
		
		/*
		if (this._hasNav == true) 
		{
			// init click event on nav
			var that = this; // scope hack
			alert($(this._buildNavSelector() + ' li a').length);
			$(this._buildNavSelector() + ' li a').click(function(e) {
				$(that._buildNavSelector() + ' li a').removeClass('active');
				$(this).addClass('active');
				that.activatePage($(this).attr("href"));
				that.activateTab($(this).attr("href"));
				e.preventDefault();
			});
			$(this._navSelector + ' li:first-child a').click();
		}
		*/
	}
	,
	getPageID: function(href) {
		// default is to assume that - delimits the page from the tab
		var end = href.indexOf('-');
		if (this._hasTabs == false) {
			end = href.length;
		}
		return href.substring(1, end);
	}
	,
	getTabID: function(href) {
		return href.substring(1);
	}
	,
	hideAllPages: function() {
		$(this._pageSelector).hide();
	}
	,
	hideAllTabs: function(pageID) {
		if (pageID) {
			$(this._pageSelector + '[@id='+pageID+'] ' + this._tabSelector).hide();
		}
	}
	,
	_buildNavSelector: function () {
		return (this._navWithinPage == true) 
			? this._pageSelector + ' ' + this._navSelector 
			: this._navSelector;
	}
	,
	/**
	 * Takes href in the format #pageID-tabID
	 * eg:	#irmll-info
	 *		pageID = irmll
	 */
	activatePage: function(href) {
		var pageID = this.getPageID(href);
		if (this._hasNav == true && this._navWithinPage == true) {
			this.initNavForPage(href);
		}
		this.hideAllPages();
		$(this._pageSelector + '[@id='+pageID+']').show();
		this.activateTab(href);
	}
	,
	initNavForPage: function(href)
	{
		var pageID = this.getPageID(href);
		var navLinks = $('#' + pageID + ' ' + this._navSelector + ' li a');
		//alert(navLinks.length + ' items in ' + '#' + pageID + ' ' + this._navSelector + ' li a');
		var that = this;
		navLinks.click(function(e) {
			navLinks.removeClass('active');
			$(this).addClass('active');
			if (this._navWithinPage == false) {
				that.activatePage($(this).attr("href"));
			}
			that.activateTab($(this).attr("href"));
			e.preventDefault();
		});
		$(pageID + ' ' + this._navSelector + ' li:first-child a').click();
	}
	,
	/**
	 * Takes href in the format #pageID-tabID
	 * eg:	#irmll-info
	 *		pageID = irmll
	 *		tabID = irmll-info
	 */
	activateTab: function(href) {
		if (this._hasTabs == false) return;
		var pageID = this.getPageID(href);
		var tabID = this.getTabID(href);
		this.hideAllTabs(pageID);
		$(this._pageSelector + '[@id='+pageID+'] ' + this._tabSelector + '[@id='+tabID+']').show();
		sIFR.replace({
            selector: 'h3'
            ,src: '/flash/myriad.swf'
	        ,wmode: 'transparent'
            ,css: [
                '.sIFR-root { color: #1C0F07;text-align: left;padding:0px;}'
			        ]
            ,filters: {
             DropShadow: {
		        knockout: false
		        ,distance: 1
		        ,color: '#FFFFFF'
		        ,strength: 1
	        }
            }
      });
	}
	,
	activateTabLink: function(href) {
		$(this._buildNavSelector() + ' li a').removeClass('active');
		$(this._buildNavSelector() + ' li a[@href="'+href+'"]').addClass('active');
		sIFR.replace({
            selector: 'h3'
            ,src: '/flash/myriad.swf'
	        ,wmode: 'transparent'
            ,css: [
                '.sIFR-root { color: #1C0F07;text-align: left;padding:0px;}'
			        ]
            ,filters: {
             DropShadow: {
		        knockout: false
		        ,distance: 1
		        ,color: '#FFFFFF'
		        ,strength: 1
	        }
            }
        });
	}
}