var menuPoller = 0;
var centerFrameOffset=0; 
var arrAuthorValues=[];
var arrAuthNames=[];
var viewOptions = ['matrixViewRadio', 'listViewRadio', 'miniViewRadio'];
var hoverTimers = {};
var defaultCookieSettings = false; 
var portfolioLink = null; 
/* dom ready handlers */
if(this.window === parent.frames[0]){
	$(function(){
		oPm = new panosMenu();
		$('#nav li').click(function(){menuHandler('menu_'+this.childNodes[0].id.split('_')[1])})
		$('#men_'+infradoxApp.mid).addClass('selected');
		$('.clickableLive').live('click',function(){panosClickHandler(this)});
	})
}else if(this.window === parent.frames[1] || top === self){
	$(function(){
		if (hC.enForceFrames()) return; 
		hC.domReady();
		$('.clickableLive').live('click',function(){panosClickHandler(this)});
		if (top !== self){
			$(window).scroll(function(){
				parent.frames[0].centerFrameOffset = $(window).scrollTop();
			})
			// wait for topframe to load,  then initiate the menu in it from centerframe
			if (typeof(parent.frames[0])=='undefined' || typeof(parent.frames[0].oPm)=='undefined'){
				menuPoller = setInterval(function(){
					if(typeof(parent.frames[0])!='undefined' && typeof(parent.frames[0].oPm)!='undefined'){
						clearInterval(menuPoller);
						parent.frames[0].centerFrameOffset=0;
						parent.frames[0].oPm.initMenuHandler();
					}
				},500);
			}else{
				parent.frames[0].centerFrameOffset=0;
				parent.frames[0].oPm.initMenuHandler();
			}
		}
		/* pPage object is created instance of panosPage in template to make available server globals */
		$('.clickable').click(function(){panosClickHandler(this)});
		
		if (document.body.id !== 'galleryItems') defaultCookieValues();
		
		switch(document.body.id){
			case 'galleryIndex':
				pPage.galleryIndexPageInit();			
			break; 
			case 'galleryItems':
				pPage.galleryItemsPageInit();
			break; 
			case 'lightboxPage':
				pPage.lightboxItemsPageInit();
			break; 
		}
		var gaTrackCode = "UA-10711454-1";  
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");  
	   	jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
   		try{
   			var pageTracker = _gat._getTracker(gaTrackCode);  
				pageTracker._initData();  
				pageTracker._trackPageview();    
			}catch(err){}
		});  
	})
}

/* global functions  */
function setcustomCheckbox(elInput){
	if (elInput.checked){
		$(elInput).parent().addClass('checked');
	}else{
		$(elInput).parent().removeClass('checked');
	}
}

panosClickHandler = function(el){ //alert(el.id)
	
	var spec = el.id.split('_');

	if (!el.id){
		switch(el.className.split(' ')[0]){//should only be triggered when logged in as guest
			case 'indexImageBox':
				var $el =$(el); 
				var u = top.location = $el.find('.storyLink').get(0).href; 
				
			break; 
		}
		return false;
	}
	switch (spec[0]){
		case 'closeThisKeywordContainer':
			if ((parent.frames[1]||window).$(".closeMe").length){
				(parent.frames[1]||window).$(".closeMe").get(0).onmousedown();
			}
		break; 
		case 'photographerPortfolio':
			pPage.loadPortfolio(spec[1],1);
		break;
		case 'tpp0':
		case 'tpp1':
		case 'tpp2':
			var m = $(el).parent().parent().find('input:first').get(0); 
			$('.viewRadio').each(function(){
				if (this === m){
					this.checked=true;
				}else{
					this.checked = false;
				}
			})
		break; 
		case 'showHoverThumb':
			$('.viewRadio').attr('checked','false');
			$('#miniViewRadio').get(0).checked = true; 
		break; 
		
		case 'bottomLink':
			if (pPage.toplevel == 1){//photographerssection
				$('#bigPicture').css('display','none');
				$('#'+el.id.replace('bottomLink_','')).click();
				
			}else{
				pPage.panosGalleryItems('front');
				pPage.findRefForBigImage(spec[3]);
				
				pPage.singleCallback =function(){
					pPage.pageData = infradoxState.props;
					pPage.setCurrentPhoto(0);
				}
				loadGalleryItems(spec[2], spec[3],spec[4]);
			}
			
		break;
		case 'startContainer':
		case 'startGallery':
			pPage.panosGalleryItems('viewImages');
		break; 
		case 'lightboxTools':
			lightboxToolsHandler('linkToggleToolbox');
			$(el).toggleClass('opened');
		break; 
		case 'cancelLightboxNotes':
		case 'saveLightboxNotes':
		 $(el).parent().parent().parent()
		 .find('.thumbnail').toggleClass('faded');
		 
		 $(el).parent().parent().parent().find('.clickableLive').removeClass('selected');
		break; 
		case 'lightboxNotes':
			$(el)
			.toggleClass('selected')
			.parent().parent().parent().find('.thumbnail').toggleClass('faded');
						
		break; 
		case 'lightboxCheck':
		 var chk = $(el).find('input');
		 chk.attr('checked',!chk.attr('checked'));
		 setcustomCheckbox(chk.get(0));
		break; 
		case 'photographerMap':
		parent.location='/bin/panos2.dll/go?a=disp&t=tp-loader.html&tpl=site\\photographersmap.html&topic=1003&_yp1=0&_yp2=0&_yp8=0&_men=menu_7&_m=7&_s=0&_ml=Photographers&_sl=&si='+pPage.si
		break
		case 'biographyTab':
			if (pPage.pfolio){
				pPage.loadPortfolio(false,1)
			}else{
				pPage.panosGalleryItems('front');
			}
		break; 
		case 'portfolioTab':
			if (pPage.pfolio){
				pPage.loadPortfolio(false,3)
			}else{	
				pPage.panosGalleryItems('viewImages');
			}
		break;
		case 'storiesTab':
			if (pPage.pfolio){
				pPage.loadPortfolio(false,4)				
			}else{	
				pPage.panosGalleryItems('photographerPfStories');
			}
		break; 
		case 'fauxLayout':
			removeModalLayer('layoutToolBox');
		break;
		case 'fauxAdvancedSearch':
			removeModalLayer('divToolBox_1');
		break;
		case 'layout':
			// set layout style in layout modal				
			$('#'+viewOptions[infradoxState.props.data.layout.style]).attr('checked',true);
			//set thumbs per page
			for (var j = 0; j<3; j++)	$('#tpp'+j+'_'+infradoxState.props.data.layout.option).attr('checked',true);

			$('#showHoverThumb').attr('checked',infradoxState.getSettingByName('_hints').value);
			$('#layoutToolBox').addClass('viewable');
			showModalLayer('layoutToolBox');
			break;
		case 'powerSearch':
			if (!$('#yearInput').change()) return false;
			$('#divToolBox_1').addClass('viewable');
			showModalLayer('divToolBox_1');
			break; 
		case 'searchWithinGo':
			infradoxSearchTools.searchTerm($('#searchWithinText').val(),true);
			break; 
		case 'powersearchButton':
		break;
		case 'powersearchCancelButton': 
			removeModalLayer('divToolBox_1');
			break;
		case 'cancelFormat':
			removeModalLayer('layoutToolBox');
			break;
		case 'applyFormat':
			$('.viewRadio').each(function(){
				if (this.checked){
					//set viewStyle:
					for (var i=0; i<viewOptions.length; i++){
							if (viewOptions[i] == this.id)infradoxState.props.data.layout.style=i;	
					}
					/* set hovers for thumbnails */
					infradoxState.getSettingByName('_hints').value = $('#showHoverThumb').attr('checked')?1:0;

					/* set thumbs per page : */
				 var selectedTppOption = 0;
				 $('#tppContainer_'+this.id+' input').each(function(){
				 		if (this.checked){
				 			var tpp = selectedTppOption;
				 			infradoxState.changeViewStyleOption(selectedTppOption);
				 			removeModalLayer('layoutToolBox');
				 			return;	
				 		}
				 		selectedTppOption++;
				 })
				}
			})
		break;
		default :
		alert(el.id+' - unhandled');
	}
	return false;
}

function selectTabs(elId){
	$('.pTabs').removeClass('selected');
	$('#'+elId).addClass('selected');
}

function getImage(el) {
	
	$('div, img').css('visibility','hidden');
	
	$("<img style='position:absolute; top:"+($(window).height()/3)+"px; left:50%; margin-left:-10px' src='/images/24-1.gif'/>").appendTo("body");
	
	URL='/artwork/blowup/'+el.name+'.jpg'; 
	var tester=new Image();
	tester.onload=function(){openFullScreenImage(URL,tester,el)};
	tester.onerror=function(){errorHandler(el)};
	tester.src=URL;
}

function errorHandler(el){
	if ($(el).hasClass('hasPortfolio')){
		var s = el.id.split('_');
		loadGallery(s[1],s[2],s[3],el.name);
	}else{
		infradoxApp.searchWord(el.innerHTML);
	}
}

function openFullScreenImage(URL,oImg,el){
	if (top !== self){	
		parent.document.getElementById("frSet").rows="0,*,0";
	}
	$(document.body).removeClass('menuPage');
	var img_width = oImg.width;
	var img_height =oImg.height;
	var visible = false;
	$body = $('body');
	$('body *').css('display','none');
	
	$body.append('<img id="blowupImage" style="display:none" src="'+URL+'" />');
	$body.fadeIn('fast')
	var img = $('#blowupImage');
	img.fadeIn('slow')
	
	resizeImage = function (){
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  
		newWidth = (myHeight/img.height() * img.width()) 
		if (newWidth <= myWidth ){
			img.width('auto').height(myHeight);
		}else{
				img.height('auto').width(myWidth);
		}
		if (!visible){
			img.fadeIn('slow');		
			visible = true;
		}
	}
	resizeImage();	
	$(window).resize(resizeImage);
	$body.append('<img onload="$(this).fadeIn(\'slow\').fadeTo(\'slow\',0.85)" style="position:absolute; display:none; top:0px; left:0px;" id="photographernamebanner" style="display:none" src="'+URL.replace(/\.jpg/i,'.gif')+'" />');
 
	var s = el.id.split('_');

	 $('img')
	  	.click(function(){$(this).fadeOut('slow',function(){
	  		if ($(el).hasClass('hasPortfolio')){
	  			if (hC.guest && portfolioLink){
	  				top.location = portfolioLink;
	  			}else{  			
		  			loadGallery(s[1],s[2],s[3],el.name);
		  		}
		  	}else{
	  			infradoxApp.searchWord(el.innerHTML);
	  		}
	  	})})
			.css({cursor:'pointer'});
}

curVisibleshowHideIndex = null; 
function moveIndexImage(ev,el){
	if (curVisibleshowHideIndex){
		curVisibleshowHideIndex.css('top',ev.pageY-37); 
	}else{
		showHideIndexImage('show',el,0);
	}
}
function showHideIndexImage(showHide,el,iMove){
	var newId; 
	var indexBox; 
	
	if (!showHideIndexLookup) {
		return; 
	}
	var indexBox; 
	var sName =	el.firstChild.firstChild.nodeValue;
	
	if (!showHideIndexLookup[sName]){ 
		 return
	}else {
		indexBox = showHideIndexLookup[sName];
	}
		
 	if (showHide=='show' && indexBox.style.display!='block'){
 		if (showHideIndexLookupCustom[sName]){// the custom thumbnails are in the artwork folder 
 			indexBox.firstChild.style.backgroundImage ='url('+showHideIndexLookupCustom[sName].src+')';
 		}
 		
		var iTop =	$(el).offset();
		$(indexBox).css({left:iTop.left+'px',top:(iTop.top-30)+'px',display:'block'});
		curVisibleshowHideIndex = $(indexBox); 
	}else	if(!iMove){
		$(indexBox).fadeOut('fast');
		curVisibleshowHideIndex = null; 
	}
}


function keydownHandler(e,el,pageCount,currentPage){
var keynum,n;
	if(window.event) // IE
	{
	  keynum = e.keyCode;
	}
	else if(e.which) // Firefox/Opera
  {
  keynum = e.which;
  }
	if (keynum ==13){
		switch (el.className){
			case 'currentPageText':
				n = parseInt(el.value); 
				if (isNaN(n) ||!n || n > pageCount || currentPage==n) return false;
				if (document.body.id!=='galleryIndex'){
					infradoxState.page(n);
				}else{
					loadGalleryPage(n)
				}
			break; 
			case 'searchWithinText':		
				infradoxSearchTools.searchTerm($('#searchWithinText').val(),true);
			break
		}
	}
}

/* custom pagination */

function loadGalleryPage(pgNr,sType){
	
	/*
	if (location.href.indexOf('&pgnr=')!=-1){
		var ptrn = /&pgnr=[1-9]+/g; 
		location.href = location.href.replace(ptrn,'')+'&pgnr='+pgNr;
	}else{
		location.href=location+'&pgnr='+pgNr;	
	}
	//ajax alternative:
	*/
	
	if (sType === 'entertainmentPage'){
		infradoxGallery.page = pgNr;
		$('.selectedGroup').removeClass('selectedGroup');
		drawEntertainment(pgNr);
	}else{
		infradoxGallery.page = pgNr;
		$('.selectedGroup').removeClass('selectedGroup');
		loadgroup = 13; 
		infradoxGallery.TOC_changeGroup(loadgroup, false, 'bodyContainer', 'indexImageBox', 'indexImageBoxThumbnail', 'indexImageBoxCaption');
	}
}

function paginateGalleries(dt,sType){
	if (!sType) sType= '';
 	eval('var pagData = '+dt.replace(';',''));
	var pgCnt = Math.ceil(pagData.totalrows/pagData.rpp);
	
	if (pgCnt == 1){
		$('#topNav').remove();	
		 return false;
	}

	$('#topNav').html('<span id="topNavLeft"></span><div>page:<input onkeydown="keydownHandler(event,this,'+pgCnt+','+pagData.pagenr+')" class="currentPageText" type="text" value="'+pagData.pagenr	+'" />&nbsp;of '+pgCnt+'</div><span id="topNavRight"></span>');
	
	//prev next links
	if(pagData.pagenr != 1){
		$('#topNavLeft').html('<a href="#" class="previous prevLink"/>');
	}
	
	if (pagData.pagenr < pgCnt){
		$('#topNavRight').html('<a href="#" class="next nextLink"/>');
	}
	
	$('.prevLink').click(function(){
		loadGalleryPage((pagData.pagenr-1),sType);
		return false;
	})
	$('.nextLink').click(function(){
		loadGalleryPage((pagData.pagenr+1),sType);
		return false;
	})
}

function GetPagination(settings) {
    var linksStartAt, linksOffset, linksEndAt, NextSetStartsAt, NextSetEndsAt, s;
    var data = infradoxState.props.data;
    linksStartAt = data.linkblocks.prev - data.linkblocks.maxlen;
    linksOffset = ((data.linkblocks.no - 1) * data.linkblocks.maxlen) + 1;
    linksEndAt = linksOffset + data.linkblocks.maxlen;
    if (linksEndAt > data.page.count) {
        linksEndAt = data.page.count + 1;
    }
    if (linksStartAt < 1) {
        linksStartAt = 1;
    }
    NextSetStartsAt = data.linkblocks.next;
    NextSetEndsAt = NextSetStartsAt + (data.linkblocks.maxlen - 1);
    if (NextSetEndsAt > data.page.count) {
        NextSetEndsAt = data.page.count;
    }
    s='';
    if (data.page.no > 1) {
        s += "<a class=\"previous\"  href=\"javascript:infradoxState.previous();\"></a>";
    }
    
    s += "<div class='navInfo'><span class=\"pageslabel\">page</span>";
    if (!data.spanning.thumbnails) {
    	s ='';
        return s;
    }
		s+='<input onkeydown="return keydownHandler(event,this,'+data.page.count+','+data.page.no+')" type="text" size="1" class="currentPageText" value="'+data.page.no+'" />';
    /*
    if (data.spanning.pages && (data.linkblocks.no > 1)) {
        s += "<a href=\"javascript:infradoxState.first();\"><img src=\"/images/all/pagenav-first.gif\" width=\"11\" height=\"13\" /></a>";
    }
    for (var i = linksOffset; i < linksEndAt; i++) {
        s += (data.page.no == i ? "<a class=\"currentPage\">" + i + "</a>" : "<a href=\"javascript:infradoxState.page(" + i + ");\">" + i + "</a>");
        if (i < linksEndAt - 1) {
            s += "|";
        }
    }
    */    
    s += "<span class=\"pagecount\"> of  " + data.page.count + "</span></div>";
    
    if (data.page.no < data.page.count) {
        s += "<a class=\"next\"  href=\"javascript:infradoxState.next();\"></a>";
    }
    /*
    if (data.spanning.pages && (data.page.no < data.page.count)) {
        s += "<a href=\"javascript:infradoxState.page(" + data.page.count + ");\"><img src=\"/images/all/pagenav-last.gif\" width=\"11\" height=\"13\" /></a>";
    }
    */
    if (document.body.id == 'searchResults' )$('#topNav').css('display','block');
    return s;
    
}

/*
infradoxGallery.loadCollectionResponse= function() {
	var e, s;

	gA.loadingcontent(false);

	e=gA.getElement(infradoxGallery._divGalleryItemsContainer); 
	if(!e) return;

	s = gX.xmlHttp.responseText.split('__________');
	if(s.length!=3) {
		alert('The retrieved data appears to be invalid. Please start a new session');
		return;
	}

	infradoxState.putPageData(eval('('+s[0]+')')); // 1st string is json page info

	infradoxPagination.showpagination();
	
	eval(s[1]); // 2nd string is json media data "content"
	
	e.innerHTML = s[2]; // parsed html containing thumbnails
	// call after putting s[2]
	infradoxMedia.initialize(content);
	// get the title and text for this gallery
	infradoxGallery.loadGalleryText(infradoxGallery._id);
	scroll(0,0);
}
*/
/* custom objects */
panosMenu = function(){
	this.assignApp=function(){
		curApp = this;
	}
	
	this.getSubContainer=function(el){
		try{return $(parent.frames[1].document.body).find('#subMenuContainer_'+el.id);}catch(err){}
	}
	this.drawSubContainer=function(el){
		try {
			this.assignApp();
			if(!parent.frames[1].document) { 
				return false; 
			}
			oSubList=[];
			var oSubMenu = $(el).data('oSubMenu');
			if (oSubMenu){
				for (var x in oSubMenu){
					if (typeof(oSubMenu[x].hide)=='undefined' || !oSubMenu[x].hide){
						oSubList.push('<li id = "submenu_'+el.childNodes[0].id.split('_')[1]+'_'+oSubMenu[x].id+'">'+oSubMenu[x].item+'</li>'); 
					}
				}
			}
			$(parent.frames[1].document.body).append('<div style="left:'+$(el).offset().left+'px" class="subMenuContainer" id="subMenuContainer_'+el.id+'"><ul>'+oSubList.join("\n")+'</ul></div>');
			var listItems = $(parent.frames[1].document.body).find('#subMenuContainer_'+el.id+' li');
			listItems.click(function(){try{parent.frames[0].menuHandler(this.id)}catch(err){}});
			
			listItems.mouseover(function(){try{
					var container = $(this).parent().parent();
					container.stop();
					container.css({top:centerFrameOffset+'px'});
					if (curApp.timer[el.id]){clearTimeout(curApp.timer[el.id]); this.className='hover'}
				}catch(err){}
			});
			listItems.mouseout(function(){try{this.className=''; $(el).mouseout()}catch(err){}});
			$(el).data('wasLoaded',true);
		}catch(err){}
	} 
};

panosMenu.prototype.timer={}; 

panosMenu.prototype.initMenuHandler= function(){
	
	this.currentSelected = 'men_'+infradoxApp.mid;
	this.assignApp();
	//tie submenu items to mainmenuItems.inc objects
	for (var x in menu.main){
		var c = menu.main[x];
		$('#nav a').each(function(){
			if (c.submenu && c.submenu.length && this.id.split('_')[1]==c.id){
				$(this).parent().data('oSubMenu',c.submenu);
				$(this).parent().data('wasLoaded',false);
				return;
			}
		});
	}
	$('#nav li').mouseover(function(){
		try{
			$(this.childNodes[0]).addClass('selected');
			if(!$(this).data('oSubMenu')) return;
			var el = this;
			if (!$(this).data('wasLoaded'))	curApp.drawSubContainer(this);
			var oSubContainer = curApp.getSubContainer(el);
			$(oSubContainer).stop()
			if ($.browser.msie || $.browser.mozilla){			
				if (curApp.timer[this.id]) clearTimeout(curApp.timer[this.id]);
				curApp.timer[this.id] = setTimeout(function(){
					oSubContainer.animate({top:centerFrameOffset+'px'},200, "", function(){});
				},10);
			}else{
				oSubContainer.css({top:centerFrameOffset+'px'});
			}
		}catch(err){}
	});

	$('#nav li').mouseout(function(){
		try{	
			var el = this;
			if ($(el).data('oSubMenu')){
				var oSubContainer = curApp.getSubContainer(el);
				$(oSubContainer).stop();
				if (curApp.timer[this.id]) clearTimeout(curApp.timer[this.id]);
				curApp.timer[this.id] = setTimeout(function(){
					if ($.browser.msie || $.browser.mozilla){
						oSubContainer.animate({top:'-170px'},200, "linear", function(){});
					}else{			
						oSubContainer.css({top:'-170px'});
					}
					if(curApp.currentSelected != el.childNodes[0].id)	$(el.childNodes[0]).removeClass('selected');
				},200);
			}else{
				if(curApp.currentSelected != el.childNodes[0].id) $(el.childNodes[0]).removeClass('selected');
			}
		}catch(err){}
	});
}

/*
*	panospage constructor
*/
var panosPage = function(){
	//this.pfolio = false; 
	this.refImage = false;
	
	if(arguments.length){
		this.lastKnowStyleOption = arguments[0].lastKnowStyleOption?arguments[0].lastKnowStyleOption:0; 
		if (arguments[0].pageData) this.pageData = arguments[0].pageData; 
		if (arguments[0].storyState) this.storyState=arguments[0].storyState; //<#CUSTOMPERSISTENT TAG=IDCCUSTOM_STORYSTATE DEFAULT=1>
		if (arguments[0].galleryId) this.galleryId=arguments[0].galleryId; //<#SERVER TAG=GALLERYID DEFAULT=null>
		if (arguments[0].si) this.si=arguments[0].si; //sessionid
		if (arguments[0].thumbPath) this.thumbPath = arguments[0].thumbPath;
		
		if (arguments[0].previewPath){
			this.previewPath=arguments[0].previewPath;
			this.previewPath2=this.previewPath.substr(this.previewPath,this.previewPath.length-1)+'2/';
		}
		this.advancedSearch = parseInt(arguments[0].advancedSearch) ? arguments[0].advancedSearch : 0;
		this.jGroups = arguments[0].oGroups ? arguments[0].oGroups : []; /* contains all photographer portfolios but is only loaded when neccesary */
		this.toplevel = arguments[0].toplevel ? arguments[0].toplevel : 0;
		
		this.pfolio = (getCookie('pfolio')==1) ?  getCookie('pfolio') : 0; // arguments[0].pfolio ? arguments[0].pfolio : 0;
		//alert(getCookie('pfolio'));
		
		if (arguments[0].oStories) this.jStories=arguments[0].oStories;
		if (arguments[0].currentPhotographer) this.currentPhotographer=arguments[0].currentPhotographer;
		if (arguments[0].crossLink){
				this.crossLink=arguments[0].crossLink;
		}
		
		this.currentPhoto = arguments[0].currentPhoto ? arguments[0].currentPhoto : 0;
		
		this.loadgroup = arguments[0].loadgroup ? arguments[0].loadgroup : 0;
		this.lightboxOptionsOpen = arguments[0].lightboxOptionsOpen !='' ? parseInt(arguments[0].lightboxOptionsOpen) : 0; 
	}
	
	this.homeCatImages = {shop:'shop.gif',stories:'stories.gif',news:'news.gif',photographers:'photographers.gif',exhibitions:'exhibitions.gif',multimedia:'multimedia.gif'};
	this.assignApp=function(){
		curApp = this;
	}
};

panosPage.prototype.loadPortfolio = function(sMatchcode,storyState){
	var x,arrPortfolios,pname,glbId= false, galleryId= false; 
	
	if (this.jGroups.length){
			arrPortfolios = this.jGroups.data;
	}else{
		arrPortfolios = this.jStories;
	}
	if (!sMatchcode){
		 sMatchcode = this.currentPhotographer;
	}else{
		this.currentPhotographer = sMatchcode
	}
	
	pname =authOptions[sMatchcode]; 
	
	for (x in arrPortfolios){
		if (arrPortfolios[x].title == pname){
			glbId = arrPortfolios[x].glbid;
			galleryId = arrPortfolios[x].id;
			break; 
		}
	}
	if (pname && (!glbId || !galleryId)){
		 infradoxApp.searchWord(pname);
		 return;
	}
	pPage.setPfolio(0,function(){
		pPage.loadStory({toplevelId:1,groupId:5,galleryId:galleryId,glbId:glbId,storyState:storyState,pname:pPage.currentPhotographer});
	});
}

panosPage.prototype.loadStory = function (args){
	if (!args.galleryId || !args.glbId){
		 alert('no gallery specified');
		 return;
	}
	
	var toplevelId  = args.toplevelId ? args.toplevelId : 2;
	var groupId = args.groupId ? args.groupId : 13; 
	
	if (typeof(args.storyState) != 'undefined'){
		$.post('/bin/panos2.dll/go?',{a:"disp", t:'site\\dummy.html',_storystate:args.storyState,si:this.si},function(){
			var url = 'go?a=disp&t=gl-loader.html&_tlid='+toplevelId+'&groupid='+groupId+'&galleryid='+args.galleryId+'&glbid='+args.glbId+(args.pname?'&_currentPhoto=0&_pname='+args.pname:'');					
			infradoxApp.loadParent(url,true);
		});
	}else{
		var url = 'go?a=disp&t=gl-loader.html&_tlid='+toplevelId+'&groupid='+groupId+'&galleryid='+args.galleryId+'&glbid='+args.glbId+(args.pname?'&_currentPhoto=0&_pname='+args.pname:'');					
		infradoxApp.loadParent(url,true);
	}
}

panosPage.prototype.crosslinkPageInit = function(parentId,customDataHolder,c,el){
	var arrChildren  = eval('['+customDataHolder[parentId].xChildren+']');
	$('#topNavContainer').css('display','none');
	$('.indexContent').css('margin-left','240px');
	$('#gtext').append(customDataHolder[parentId].desc);
	$('#gtitle').append('<div class="galleryTitle">'+customDataHolder[parentId].title+'</div>'); 
	$('#divGalleryText, #galleryTextContainer').css('display','block');
	
	$.get('/bin/panos2.dll/go?',{
		a:"disp", 
		t:'site\\xchildrendata.html',
		parentid:parentId,
		si:this.si},function(d){
			eval('var oData ='+ d);
			for (var x in arrChildren){/* draw indexBoxes */
				if (oData[arrChildren[x]]){
					var oC = oData[arrChildren[x]];
					if ( oC.id == parentId ) continue;
					var thumb = infradoxGallery.createThumbnail(c, oC, 2, el._boxClass, el._thumbnailClass, el._captionClass);
					if(thumb){
						_id = 'xgid_' + parentId + '_' + oC.id + '_' + oC.glbid;
						thumb[0].id = _id; // thumb
						thumb[1].id = '_strip_'+_id; // capt; textbox with eg title etc
						infradoxLinkHandler.listen(thumb[0].id);
					};
				}
				pPage.drawGalleryIndexOverlay(thumb[0],customDataHolder,oC.id,oData);
			}
			$('.indexImageBox').fadeIn('fast');
		});
}

panosPage.prototype.makeCrosslinkBox = function (el,customDataHolder,dataId){
	eval('var aChildren = [' + customDataHolder[dataId].xChildren +']'); 
	el.id='crossLinkContainer_'+el.id;
	$(el).data('xChildren',aChildren);	
}


/* draws overlay on one box  so must be looped: */
panosPage.prototype.drawGalleryIndexOverlay=function(el,customDataHolder,dataId,crossLinkPageData){
		
	var subtitle = false,title, desc;		
	if (typeof(crossLinkPageData)=='undefined') {
			
		if ($.trim(customDataHolder[dataId].auth)!='' && typeof(authOptions[customDataHolder[dataId].auth])!='undefined'){
			subtitle = $.trim(authOptions[customDataHolder[dataId].auth]);
		}
		title =  customDataHolder[dataId].title; 
		desc = customDataHolder[dataId].desc;
	}else{
		
		/* crossLink page  overlays */		
			if ($.trim(crossLinkPageData[dataId].auth)!='' && typeof(authOptions[crossLinkPageData[dataId].auth])!='undefined'){
				subtitle = $.trim(authOptions[crossLinkPageData[dataId].auth]);
			}
			title = crossLinkPageData[dataId].title;
			desc = crossLinkPageData[dataId].desc
	}
	/* hack  - in the hovertext only show the text enclosed in the <big> element  - this is invisible everywhere else*/
	var m  = desc.match(/<big>.*<\/big>/);
	desc = m ? m[0].replace(/<big>/g,'<p>').replace(/<\/big>/g,'</p>'):'';

	$(el)
	.before('<div class="caption"><span class="title">'+title+
					(subtitle?'<br /><a class="subtitle" >'+subtitle+'</a>':'')+
					'</span></div>')
	.after('<div class="indexImageBoxOverLay"><div>'+desc+'</div></div>')
	.parent().find('.indexImageBoxOverLay')
	.mouseout(function(){$('.indexImageBoxOverLay').fadeOut('fast')})
	.parent().find('.indexImageBoxOverLay,.indexImageBoxThumbnail')
	.click(function(){

			if(this.className == 'indexImageBoxThumbnail' && pPage.toplevel != 1) return; 

			var sId  = $(this.parentNode).find('.indexImageBoxThumbnail').attr('id');
			var s = sId.split('_');
			if (document.body.id =='galleryIndex'){
				if (!hC.guest) linkHandler(sId);

			}else if(s[0]=='xgid'){
				pPage.setPfolio(1);		
				$('#bigPicture').css('backgroundImage', $(this.parentNode).find('.indexImageBoxThumbnail').css('background-image').replace('Tcache','Pcache2')); 
				pPage.setCurrentPhoto(0);
				pPage.singleCallback =function(){
					this.pageData = infradoxState.props;
					pPage.panosGalleryItems('front');
				}
				loadGalleryItems(2, s[2], s[3]);
			}else if(s[0]=='crossLinkContainer'){
				alert('crosslink')	/* not supported in photographers section*/
			}
	})
	
	$(el).mouseover(function(){
		if (hoverTimers[el.id]) clearTimeout(hoverTimers[el.id]);
		hoverTimers[el.id] = setTimeout(function(){
			if ($.browser.msie) $('.indexImageBoxOverLay').css({filter:'alpha(opacity=85)', opacity: '0.85'});
			$(el).parent().find('.indexImageBoxOverLay').fadeIn('fast');
		},400)
	});

	$(el).mouseout(function(){
		if (hoverTimers[el.id]) clearTimeout(hoverTimers[el.id]);
	})
}

panosPage.prototype.findRefForBigImage=function (galleryId){
	
	for (var x in this.jStories){
		if (x == galleryId){
			var newP = this.thumbPath.replace('Tcache','Pcache2')+this.jStories[x].ref+'.jpg';
			$('#bigPicture').css('backgroundImage','url('+newP+')'); 
		}
	}
}

panosPage.prototype.execSingleCallback=function (){
	if (this.singleCallback && typeof(this.singleCallback == 'function')){
		this.singleCallback();
		this.singleCallback  = false;
	}
}

panosPage.prototype.setStoryState =function (n){
		if (this.storyState != n){
			this.storyState = n;
			$.post('/bin/panos2.dll/go?',{a:"disp", t:'site\\dummy.html',_storyState:n,si:this.si});
		}
}


panosPage.prototype.panosGalleryItems=function(section){
	//alert(section);
	var x,xgid,d,refcode;
	$('.sectionBound').css('display','none');
	if (this.pfolio) selectTabs('storiesTab');
	
	switch(section){
		case 'front':
			if (pPage.toplevel == 1 && !this.pfolio) selectTabs('biographyTab');	
			this.setCurrentPhoto(0);
			this.setStoryState(1);
			if (!pPage.pfolio || $('#bigPicture').css('background-image')=='none'){ 		
				if (this.refImage){
				 	refcode =this.refImage; 
				}else if(typeof(jStories[this.galleryId])!='undefined'){
					refcode = this.previewPath2+jStories[this.galleryId].ref; 
				}else{ /* pfolio */
					for (x in jPhotographerGroups.data){
						if (jPhotographerGroups.data[x].id == this.galleryId) refcode = this.previewPath2+jPhotographerGroups.data[x].ref
					}					
				}
				$('#bigPicture').css('background-image','url('+refcode+'.jpg)');
		 	}
			$('#bigPicture, #galleryTextContainer, #sectionButtonsContainer, #photographerStoriesList').fadeIn('fast');
			
		break;
			
		case 'viewThumbs':

			if (pPage.toplevel == 1 && !this.pfolio) selectTabs('portfolioTab');	
			
			this.setStoryState(2);
			
			$('.sectionBound').css('display','none');
			$('.topOfPagePaginationLinks').css('display','block');
			$('#subTitleContainer').css('display','block');
			$('#bodyGalleryContainer').fadeIn('fast');
		break;
		
		case 'viewImages':
			if (pPage.toplevel == 1 && !this.pfolio) selectTabs('portfolioTab');	
			this.setStoryState(3);
			$('.sectionBound').css('display','none');
			$('#galleryTextContainer, #sectionButtonsContainer3, #photographerStoriesList').fadeIn('fast');
			if(content.media.length){
				this.loadLargeImageWithDissolve();
			}
		break;
		
		case 'photographerPfStories':
				if (pPage.toplevel == 1 && !this.pfolio) selectTabs('storiesTab');	
				this.setStoryState(4);
				$('#storiesPage').fadeIn('slow');
		break; 
	}
}

panosPage.prototype.loadLargeImageWithDissolve =function(){
	var bigPic = $('#bigPicture');
	bigPic.css('background-image','');		
	var imagePath = this.previewPath2+content.media[this.currentPhoto].ref+'.jpg'
	
	var showLoader = setTimeout(function(){
		bigPic.css('background-image','url(/images/24-1.gif)');		
	},500)
	panosPage.dissolveimg = new Image(); 
	panosPage.dissolveimg.onload = function(){//preload it. 
		clearTimeout(showLoader);
		bigPic.css({display:'none'});
		bigPic.css('background-image','url('+panosPage.dissolveimg.src+')').fadeIn('fast');	
	}
	panosPage.dissolveimg.src = this.previewPath2+content.media[this.currentPhoto].ref+'.jpg';
	 
	this.bigImageCaption()
}
panosPage.prototype.bigImageCaption = function(){
		var galleryCustomCaptionContainer= $('#galleryCustomCaptionContainer');

		if($('#divGalleryText').css('display')=='none') $('#divGalleryText').css('display','block')

		if(!galleryCustomCaptionContainer.length){
		$('body').append('<div id="galleryCustomCaptionContainer" class="sectionBound"><div id="caption_gtitle"></div><div id="caption_subtitle"></div><div id="caption_subsubtitle"></div><div id="caption_gtext"></div></div>');
		galleryCustomCaptionContainer = $('#galleryCustomCaptionContainer'); 
		galleryCustomCaptionContainer
	 		.mouseover(function(){$('#galleryCustomCaptionContainer *:not(a)').css('color','black')})
 			.mouseout(function(){$('#galleryCustomCaptionContainer *').css('color','#9ba096')});
		var pos = $('#galleryCustomPropsContainer').offset();
		if(this.toplevel == '1'){//photographerspages
	 		$('#caption_gtitle').css({'display':'none'});
	 		$('#caption_subtitle').css({'paddingTop':'0px'});
	 	}
		galleryCustomCaptionContainer.css({position:'absolute',top:pos.top+'px',left:pos.left+'px',width:'210px',height:'400px',zIndex:100,background:'white'})
 		$('#galleryCustomCaptionContainer *').css('color','#9ba096');
 	}
 	$('#caption_gtitle').html($('#gtitle>.galleryTitle').html());
	$('#caption_subtitle').html($('#custom4Container_'+content.media[this.currentPhoto].ref).text().toLowerCase())
	$('#caption_subsubtitle').html($('#custom5Container_'+content.media[this.currentPhoto].ref).html())
	$('#caption_gtext').html($('#largeCaption_'+content.media[this.currentPhoto].ref).html())
	countryTransform('#caption_subtitle');
	galleryCustomCaptionContainer.css('display','block');
	
}
panosPage.prototype.photographerStories = function(d,tempPname){//the d argument contains the data. 
	var glCustomDataHolder={}; 
	if (!$('#storiesPage .indexImageBox').length){
		var x;
		var sp = $('#storiesPage'); 
		var aPs = [];
		var ps = $('#photographerStoriesList');
		//var p = this.currentPhotographer!=0 ? this.currentPhotographer : tempPname;
		$('#photographerStoriesList').append('<p><b>'+$('#titleContainer h1').text()+' stories</b></p>')
		for (x in d){
			glCustomDataHolder[d[x].id] = {'title':d[x].title,'desc':d[x].desc};
			xgid = (d[x].xChildren.length?'crossLinkContainer_':'')+'xgid_'+d[x].parentid+'_'+d[x].id+'_'+d[x].glbid;
			bgid = 'bottomLink_'+(d[x].xChildren.length?'crossLinkContainer_':'')+'xgid_'+d[x].parentid+'_'+d[x].id+'_'+d[x].glbid;
			if (sp.length){
				sp.append(
					'<div class="indexImageBox">'+
						'<div class="indexImageBoxThumbnail" id="'+xgid+'" style="background-image: url('+this.thumbPath+d[x].ref+'.jpg)">'+
						'</div>'+
					'</div>');
			}
			aPs.push('<a href ="#" id="'+bgid+'" class="clickableLive bottomStoryLink">'+d[x].title+'</a>');
			this.drawGalleryIndexOverlay($('.indexImageBox :last').get(0),glCustomDataHolder,d[x].id);
		}
		ps.append('<div id="bottomStoryLinksContainer">'+aPs.join('&nbsp;&nbsp;|&nbsp;&nbsp; ')+'</div>');
	}
}

panosPage.prototype.drawHomePage = function(templates,stories){
	var x,tpl; 
	this.drawTiles(stories,templates);
	$('#homeTpl_'+templates).fadeIn('slow'); 
	$('#pageFooterOuter').fadeIn('slow');
	if ($.browser.msie && $.browser.version.substr(0,1) == 6)	$('#pageFooterOuter').css('display','inline');
	$('#preloaderImage').css('display','none');
}

panosPage.prototype.setFrontBoxdata=function(el,oDataRow,redrawForAdmin){
		//set frontbox values
		this.assignApp();
		var e=$(el);    
		var h;
		
		e.find('.head > img').attr('src','/images/home/'+curApp.homeCatImages[oDataRow.category]);
		h = e.find('.headLine, .headLine2')
			.html(oDataRow.headLine)
		e.find('.author').html(oDataRow.author);

		e.find('.imgHolder').css('backgroundImage','url(/artwork/grid/'+oDataRow.imag+')');
		e.data('link',oDataRow.linkedTo);
		$('#'+el.id+' > .thumbnail').unbind('click');
		$('#'+el.id+' > .thumbnail').click(function(){window.parent.location.href=$(el).data('link')});
		
		
		if(typeof(redrawForAdmin)=='object') {
			e.find('.adminButton').unbind();
			redrawForAdmin.attachAdminHandlers(el.id);
		}
		/*reposition authorname*/
}

panosPage.prototype.drawTiles=function(stories,iTplName){
	var x; 
	var sTplName = 'homeTpl_'+iTplName;
	this.assignApp();
	$('#'+sTplName+' .frontbox').each(function(){
		x = '30'+this.id.split('_')[1];
		curApp.setFrontBoxdata(this,stories[x]);
	});
}

panosPage.prototype.getFrontBoxData=function(el){
		var im = $(el).find('.head > img').attr('src').split('\/')[3]; 
		for(var x in this.homeCatImages ){
			if (this.homeCatImages[x] == im) var cat = x;
		}
		var he = $(el).find('.headLine').html();
		var au = $(el).find('.author').html();      
		try {
			var bg = $(el).find('.imgHolder').css('backgroundImage').split('\/')[3].replace(/url\(|\)|"|'/g,'');
		} catch (err){
			var bg ='';
		}
		var li = $(el).data('link');
		return {imag:bg,category:cat,headLine:he,author:au,linkedTo:li};
}

panosPage.prototype.drawPortfolioTopNavigation=function(){ 
	/* photographer pages top-navigation gl-images template */

	$('#titleContainer').html('<h1>'+authOptions[this.currentPhotographer]+'</h1>');
	$('#breadCrumb').append('<div id="photographersTabs"><ul><li id="biographyTab" class="pTabs"></li><li id="portfolioTab" class="pTabs"></li><li id="storiesTab" class="pTabs"></li></ul></div>');
	$('.pTabs').click(function(){
		if ($(this).hasClass('selected') && (this.id != 'storiesTab' && this.id != 'portfolioTab')) return; 
		panosClickHandler(this);
	}).mouseover(function(){
		$(this).addClass('over');
	}).mouseout(function(){
		$(this).removeClass('over');
	})

	var photographerList = [];
	for (x in authOptions){
	 photographerList.push('<li id="photographerPortfolio_' + x + '" onclick="panosClickHandler(this)">' + authOptions[x] + '</li>');
	}
	$('#photographersPortfolioDropdownList').html('<ul>'+photographerList.join("\n")+'</ul>');

	$('#photographerSectionTopNav').css({display:'block'});
	$('#photographerDropdown').click(function(event){
		var clickfunction = function (){
			$(document).unbind('click',clickfunction);
			if($('#photographerDropdown').hasClass('active')){
					$('#photographerDropdown').removeClass('active');
					$('#photographersPortfolioDropdownList').slideUp('fast');
			}
		}
		
		event.stopPropagation();
		switch (this.id){
			case 'photographerMap':
				$(this).addClass('active');
			break;
			case 'photographerDropdown':
				if($(this).hasClass('active')){
					$(this).removeClass('active');
					$('#photographersPortfolioDropdownList').slideUp('fast');
					$(document).unbind('click',clickfunction);
				}else{
					$(document).unbind('click',clickfunction);
					$(document).click(clickfunction);
					$(this).addClass('active');
					$('#photographersPortfolioDropdownList').slideDown('fast');
				}
			break;
		}
	});

	switch(this.storyState){
		case 1: 
			$('#biographyTab').addClass('selected');
			break;
		case 2: 
			$('#portfolioTab').addClass('selected');
			break;
		case 3:	
			$('#portfolioTab').addClass('selected');
			break;
		case 4:	
			$('#storiesTab').addClass('selected');
		break;
	}	
	$('.topNavigation').css({display:'block'});

}

panosPage.prototype.drawTopNavigation=function(){
	if (this.toplevel =='1'){ /* portfolio page photographers section */
		this.drawPortfolioTopNavigation();
		return;
	}
	/* gl-images topnavigation */

	var photographerList = [];
	for (var x in authOptions) photographerList.push('<li id="photographerGaleries_' + x + '" class="photographerGaleries_dropdownLink"><a href="#">' + authOptions[x] + '</a></li>');
	$('#photographersDropdownList').html('<ul>'+photographerList.join("\n")+'</ul>');
	
	if ($.browser.msie && navigator.userAgent.indexOf('Trident')!==-1){
		/* solves ie8 css hover bug */
		$('#photographersDropdownList li')
			.mouseover(function(){
				this.style.background = '#666666';
				this.style.color = 'white';
			})
			.mouseout(function(){
				this.style.background = 'transparent';
				this.style.color = 'transparent';
			})
	}
	
	if (typeof(this.currentPhotographer)!='undefined' && this.currentPhotographer!=0){ 
		$('#titleContainer').html('<h1>'+authOptions[this.currentPhotographer]+'</h1>');
		$('#storiesByPhotographer').addClass('selected');
	}else{
		$('#titleContainer').html('<img src="/images/us/stories.gif" alt="stories" />');
		$('#viewAllStories').addClass('selected');
	}
	
	$('#photographersDropdownList li a, #photographersDropdownList li').click(function (){
		var spName = this.tagName == 'A' ? this.parentNode.id.split('_')[1] : this.id.split('_')[1]; 
		$.post('/bin/panos2.dll/go?',{a:"disp", t:'site\\dummy.html',_pname:spName,si:pPage.si},function(){
			parent.location.href='/bin/panos2.dll/go?a=disp&t=gi-loader.html&loadgroup=13&_tlid=2&_yp1=0&_yp2=0&_yp8=0&_men=menu_1&_m=1&_s=0&_ml=Stories&_sl=all stories&si='+pPage.si;
		});					
	})
	
	$('#storyTreeSelector a').click(function(event){
		event.stopPropagation();
		
		function clickfunction(){
			$(document).unbind('click',clickfunction);
			if ($('#storiesByPhotographer').hasClass('active')){
					$('#storiesByPhotographer').removeClass('active');
					$('#photographersDropdownList').slideUp('fast');
			}
		}
		
		switch (this.id){
			case 'viewAllStories':
				if(pPage.currentPhotographer==="0" && document.body.id == 'galleryIndex') return; //no photographer filter active so no need to remove it. 
				
				$(this).addClass('active');
				$.post('/bin/panos2.dll/go?',{a:"disp", t:'site\\dummy.html',_pname:'',si:pPage.si},function(){
						parent.location.href='/bin/panos2.dll/go?a=disp&t=gi-loader.html&loadgroup=13&_tlid=2&_yp1=0&_yp2=0&_yp8=0&_men=menu_1&_m=1&_s=0&_ml=Stories&_sl=all stories&si='+pPage.si;
				});
			break;
			case 'storiesByPhotographer':
				if ($(this).hasClass('active')){
					$(this).removeClass('active');
					$('#photographersDropdownList').slideUp('fast');
					$(document).unbind('click',clickfunction);
				}else{
					$(document).click(clickfunction);
					$(this).addClass('active');
					$('#photographersDropdownList').slideDown('fast');
				}
			break;
		}
	})
	$('#storyTreeSelector').css('display','block');
}
		

panosPage.prototype.galleryIndexPageInit=function(){
	if (this.loadgroup !="5"){
		this.drawTopNavigation();
	}else{
		$('#photographerSectionTopNav').css({display:'block'});
	}
	$('#pageFooterOuter').fadeIn('slow');
}

panosPage.prototype.photographersPageInit=function (loadgroup){/* for gi-index template*/
	//alert(loadgroup)
	$('#linkToggleToolboxC, #galleryTOC').css({display:''})
	var photographersList = [],contributorsList = [],oPhotographers = {},hasPortfolio = ''; 
	
	$('#galleryIndex').prepend('<img id="photographersHeading" src="/images/css/photographers-pages.gif" />');

	for (var x in jGroups.data)	oPhotographers[jGroups.data[x].title]=1;	
	
	showHideIndexLookupCustom = {}
	for (var x in authOptions){
		hasPortfolio = oPhotographers[authOptions[x].name] ? ' hasPortfolio' : ' noPortfolio';
		if (authOptions[x].name.indexOf('&')===-1) {
			if (authOptions[x].photographerbiglist == ""){
				contributorsList.push('<li class="contributors'+hasPortfolio+'"><a class="photographersName" name="'+x+'">'+authOptions[x].name+'</a> <span class="city">'+authOptions[x].city+'</span> <span class="country" '+(authOptions[x].country != 'UK' && authOptions[x].country !="USA" ? '' : 'style="text-transform:uppercase"' )+'>'+authOptions[x].country.toLowerCase()+'</span></li>'); 
			}else{
				photographersList.push('<li class="photographers'+hasPortfolio+'" ><a class="photographersName" name="'+x+'">'+authOptions[x].name+'</a> <span class="city">'+authOptions[x].city+'</span> <span class="country" '+(authOptions[x].country != 'UK' && authOptions[x].country !="USA" ? '' : 'style="text-transform:uppercase"' )+'>'+authOptions[x].country.toLowerCase()+'</span></li>');
				// try to load the custom thumbnail from the artwork folder - if not found just use keep the current one. 
				showHideIndexLookupCustom[authOptions[x].name] = new Image(); 
				showHideIndexLookupCustom[authOptions[x].name].onerror = function(newimg){// if the thumbnail image is not present in the artwork folder delete the image object from the lookup table
					return function(){
						showHideIndexLookupCustom[newimg] = null
					}
				}(authOptions[x].name)
				showHideIndexLookupCustom[authOptions[x].name].src = '/artwork/blowup/'+x+'_T.jpg';
			}
		}
	}

	contributorsList.splice(Math.ceil(contributorsList.length/2),0,'</ul><ul class="contributorsList">');
	
	infradoxGallery.TOC_changeGroup(loadgroup, false, 'rollOverContainer', 'indexImageBox', 'indexImageBoxThumbnail', 'indexImageBoxCaption');
	
	$('.indexThumbnailsBody img').eq(0).remove();
	$('.indexThumbnailsBody').append('<ul id="photographersList">'+photographersList.join("\n")+'</ul>');
	$('.indexThumbnailsBody').append('<ul class="contributorsList">'+contributorsList.join("\n")+'</ul>');
	$('#rollOverContainer').css({width:'1px', height:'1px', overflow:'hidden'});
	
	$('.photographers a').mouseover(function(){showHideIndexImage('show',this.parentNode,0)});
	$('.photographers a').mouseout(function(){showHideIndexImage('hide',this.parentNode,0)});
	$('.photographers a').mousemove(function(ev){moveIndexImage(ev,this.parentNode)});
	
	$('.hasPortfolio a').click(function(){
		if (hC.guest) portfolioLink = this.href; //store as global for later loading when large image is clicked
		
		$(this).addClass('hasPortfolio'); getImage(this);
		
		return false; 
	});
	$('.noPortfolio a').click(function(){getImage(this);});
	
	
	showHideIndexLookup = null
	showHideIndexTimer = setInterval(function(){
		if($('b').length){
			clearInterval(showHideIndexTimer);
			showHideIndexLookup = {};
			$('.hasPortfolio').each(function(){
				if (this.firstChild && this.firstChild.firstChild){
					var sName = this.firstChild.firstChild.nodeValue;
					var el = this; 
					var $el = $(this);
					$('b').each(function(){
					  if(this.firstChild.nodeValue == sName){
					  	indexBox = this.parentNode.parentNode; 
					  	showHideIndexLookup[sName] = indexBox;
					  	// first set the links id to use for the gallery link :
					  	el.firstChild.id = indexBox.firstChild.id.replace('xgid','phot');
					  	if (hC.guest) el.firstChild.href = '/stories/'+hC.tlid+'-'+indexBox.firstChild.id.replace('xgid_','').replace(/_/g,'-')+'-'+el.firstChild.name+'/'+hC.urisafe($(el.firstChild).text());
					  	return false;
					  }
					});
				}
			});
		}
	},500)
}

panosPage.prototype.setCurrentPhoto = function(n){
	if (n!=this.currentPhoto) this.currentPhoto =n;
	$.post('/bin/panos2.dll/go?',{a:"disp", t:'site\\dummy.html',_currentPhoto:n,si:this.si});
	this.showCurrentPhotoBox();
}

panosPage.prototype.setPfolio= function(n,callback){
	if (n!=this.pfolio)	this.pfolio =n;

	setCookie('pfolio',n,1);

	if (typeof(callback) == 'function') callback();
}

panosPage.prototype.showGlbItemCount = function (){
	var n =	this.pageData.data.results.count;
	
	$('#itemCountContainer').text(n +' images');
	$('#itemCountContainer2').text(n);
}

panosPage.prototype.showCurrentPhotoBox =function(){
	if (!infradoxState.props) return;
	var p =  infradoxState.props.data.page.no-1 //.data.page.no - 1;
	var itemsPerPage = $('#dropdownItemsPerPage__ li').eq(this.lastKnowStyleOption).text();
	
	var m = (this.currentPhoto+1) + (p * itemsPerPage);
	$('#currentPhotoContainer').text(m);
}

panosPage.prototype.lightboxItemsPageInit=function(){
	$('input[type=checkbox]').each(function(){setcustomCheckbox(this)});
	if(this.lightboxOptionsOpen){
		$('#lightboxTools').addClass('opened');
	}
}

panosPage.prototype.galleryItemsPageInit=function(){
	$('#leftRightContainer a').click(function(){
		$('#descHolder').css({display:'none'})
		
		if($(this).hasClass('active') || !content.media.length) return false;
		$(this).addClass('active');
		var el = this; 
		setTimeout(function(){ /* disable the button for half a second to make sure it isn't clicked continuously */
			$(el).removeClass('active');
		},500)
		switch(this.id){
			case'bigImageSkip_left':
				if (parseInt(pPage.currentPhoto)>0){
					pPage.setCurrentPhoto(pPage.currentPhoto-1);
			
				}else{
					var last = true; 
					if (!$('.previous').length) return false; 
					pPage.paginationCallback=function(){
						pPage.setCurrentPhoto(content.media.length-1);
						$('#bigImageSkip_left').click();
						$('#bigPicture').css('background-image','url('+pPage.previewPath2+content.media[pPage.currentPhoto].ref+'.jpg)').fadeIn('fast');
						this.bigImageCaption();
					}
					infradoxState.previous();
				}
			break; 
			case'bigImageSkip_right':
				if (parseInt(pPage.currentPhoto)+1 < content.media.length)	{
					pPage.setCurrentPhoto(pPage.currentPhoto+1);
				}else{
					if (!$('.next').length) return false; 
					var last = true; 
					pPage.paginationCallback=function(){
						pPage.setCurrentPhoto(0);
						$('#bigPicture').css('background-image','url('+pPage.previewPath2+content.media[pPage.currentPhoto].ref+'.jpg)').fadeIn('fast');
						this.bigImageCaption();
					}
					
					infradoxState.page(parseInt($('.currentPageText').eq(0).val())+1);
					//infradoxState.next();
				}
			break;		
		}
		
		if (content.media[pPage.currentPhoto]&& !last){
				pPage.loadLargeImageWithDissolve();
		}
		return false;
	})
	
	this.drawTopNavigation();
	
		switch(this.storyState){
			case 1: 
				this.panosGalleryItems('front');
				break;
			case 2: 
				this.panosGalleryItems('viewThumbs'); 
				break;
			case 3:	
				this.panosGalleryItems('viewImages'); 
				break;
			case 4:	
				this.panosGalleryItems('photographerPfStories'); 
			break;
		}	
	
	/*BOTTOM LIST*/ 
	
	if (this.toplevel =='1'){
		this.photographerStories(jPhotographerGroups.data);
	} 
}

function toJson(obj) {
 switch (typeof obj) {
  case 'object':
   if (obj) {
    var list = [];
    if (obj instanceof Array) {
     for (var i=0;i < obj.length;i++) {
      list.push(toJson(obj[i]));
     }
     return '[' + list.join(',') + ']';
    } else {
     for (var prop in obj) {
      list.push('"' + prop + '":' + toJson(obj[prop]));
     }
     return '{' + list.join(',') + '}';
    }
   } else {
    return 'null';
   }
  case 'string':
   return '"' + obj.replace(/(["'])/g, '\\$1') + '"';
  case 'number':
  case 'boolean':
   return new String(obj);
 }
}
function removeModalLayer(elementOnTopId){
	$('#modallayer').fadeOut('fast',function(){$('#modallayer').remove()});
	$('#'+elementOnTopId).removeClass('viewable');
}

function showModalLayer(elementOnTopId){
	var page=infradoxApp.getPageSize();
	var e=infradoxApp.createDomElement({type:"DIV",id:"modallayer"},document.getElementById('toolBoxColumn'));
	e.style.width = page[0]+'px';
	e.style.position="absolute";
	e.style.top=0+"px";
	e.style.left=0+"px";
	e.style.right=0+"px";
	e.style.height=9000+"px";
	e.style.zIndex=1000;
	$(e).click(function(){removeModalLayer(elementOnTopId)});
	e.style.backgroundColor="white";
	
	infradoxApp.changeOpacity(e,80);
	//showWaitId=setTimeout(_displayTCSNodeChildren, 20);
}		
function searchResultsPageInit(){
	var optionArray=[];
	/* searchPage: */
	$('#searchWithinText')
	.focus(function(){
		this.value="";
	})
	.val('search within results')

	for(var x in authOptions){
		optionArray[x]='<option id="author_A'+authOptions[x].authValue+'" value="A'+authOptions[x].authValue+'">'+authOptions[x].authName+'</option>';
		arrAuthorValues.push('A'+authOptions[x].authValue);
		arrAuthNames.push(authOptions[x].authName);
	}
	$('#author').append(optionArray.join("\n"));
}

function panosFilters(){
	var correlation, allChecked={radio_orientation:true,radio_color:true},x;
	$('#orientationRadioContainer input, #colorRadioContainer input').each(function(){
		var ids = this.id.split('_')
		if (this.id !=='radio_orientation' && this.id !=='radio_color'){
			correlation = $('#'+ids[1]+'_'+ids[2]).attr('checked');
			$(this).attr('checked',correlation);
			if(correlation) {
				allChecked[ids[0]+'_'+ids[1]]=false; }
			$(this).change(function(){
				$('#_toolsection_'+ids[1]+' input').attr('checked',false);
				$('#'+ids[1]+'_'+ids[2]).attr('checked',this.checked);
			})
		}
	}) 
	for (x in allChecked){
		$('#'+x)
			.attr('checked',allChecked[x])
			.change(function(){
				if(this.checked){
					$('#_toolsection_'+this.id.split('_')[1]+' input').attr('checked',false);
				}
			})
	}
	$('#yearInput').change(function(){
		if($.trim(this.value)!==''){
			/* if the yearinput is filled in  - check for four digits. */
			if (!this.value.match(/^[0-9]{4}$/)) {
				this.focus();
				alert('Please use a 4 digit year to filter the results for a particular year (eg 1999, 2003)');
				this.value ='';
				return false; 
			}
			$('#year_1').attr('checked',true);
			infradoxFilters._filters.settings[3].options[1]='Y'+this.value;
		}else{
			$('#year_1').attr('checked',false);
		}
	});
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString())+ "; path=/";
}
 
function getCookie(c_name){
if (document.cookie.length>0){
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1){ 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
	return false;
}

function defaultCookieValues(){
	if (defaultCookieSettings) return;
	setCookie('pfolio',0,2);
	defaultCookieSettings = true; 
}

function countryTransform(){//return;
	if (!arguments.length){var selector = '.custom4Container'}else{var selector = arguments[0]}
	var pattern = /(\sof|the\s)/g; 
	var pattern2 = /(\sand the|\sand)/g;
	$('.custom4Container').each(function(){ 
		$this= $(this);
		tx = $this.text(); 
		if(tx.length && tx !='USA'){
			this.innerHTML = tx.toLowerCase().replace(pattern2," &amp; ").replace(pattern,'<span class="lc">'+"$1"+'</span>').replace('saint','st');
		}
		$this.css('visibility','visible');
	});
}


var hC = {
	"domReadyFired":false,
	
	"urisafe":function(sString){
		return escape(sString.replace(/\s/g,'-').replace(/[^a-zA-Z0-9-]/,''))
	},
	"urlStringGet":function(){
		var rv = {},s=[];
		var gets = location.href.match(/[a-z|A-Z|0-9-_]+=[a-z|A-Z|0-9-_]+/g);
		if (gets){
			var l = gets.length; 
			for(var i =0; i<l; i++){
				s = gets[i].split('='); 
				rv[s[0]]=s[1];
			}
		}
		return rv; 
	},

	"suggestions":function(searchF){
		var that = this; 
		oSuggest = new infradoxSuggest(searchF.quicksearchtext, new infradoxSuggestionProvider('autosuggest.ajax'));
		oSuggest.methods.onneedsuggestionbox = function(oControl) {
			
			var e=(parent !== self ? parent.frames[1].infradoxApp.getElement(parent.resultspanel.document.body.id) : document.body)
			if(!e) return null;
			
			oSuggestionsBox = parent.resultspanel ? new parent.resultspanel.infradoxBox(e) : new infradoxBox(e);
			oSuggestionsBox.classes('suggestionsBoxContainer','suggestionsBoxBar','suggestionsBoxPanel','closeMe','suggestionsBoxFooterPanel');
			
			oSuggestionsBox.settings.width = 208;
			oSuggestionsBox.settings.height = 0;
			
			oSuggestionsBox.settings.offsetX = 760;
			oSuggestionsBox.settings.offsetY = 58;
		
			oSuggestionsBox.settings.title = ''; //sConst_KeywordSuggestions;
		
			oSuggestionsBox.settings.multilabel="Refine search"; 
			oSuggestionsBox.settings.golabel=" go "; // you can use a button instead by changing the css (background image)
		
			oSuggestionsBox.methods.onclose = function(){
				oSuggestionsBox.hide()
				$('#mainmenuTopSuggestionbar').css('display','none');
				//parent.frames[1].$(window).unbind('scroll',moveTheSuggestions);
			}
			
			oSuggestionsBox.create();
			$('.suggestionsBoxBar').append('<div class="closeThis clickableLive" id="closeThisKeywordContainer"></div>')
			
			//parent.frames[1].$(window).scroll(moveTheSuggestions);
		
			return oSuggestionsBox;
		}
		oSuggest.methods.onclicksuggestion = function(suggestionText, oControl, oBox, oSuggest, multiple) {
			var suggestions;
			if(multiple) {
				suggestions = oSuggest.getSelected(1);
				if(!suggestions.length) {
					alert('<#SERVER TAG=CONSTANT NAME=cNoWords>');
					return;
				} else {
					if(suggestions.length>15) {
						alert('<#SERVER TAG=CONSTANT NAME=cTooManyWords> 15');
						return;	
					} else suggestionText = suggestions.join(' OR ');
				}
			}
			oControl.value = suggestionText;
		
			// must do this to fix IE bug
			oSuggest.suggestionsBox=null;
			oSuggestionsBox=null;
			oBox.close();
			
			that.searchModule.doSearch();
			$('#mainmenuTopSuggestionbar').css('display','none');
		}
		oSet = oSuggest.settings; 
		oSet.title = sConst_QuickSearchSuggestions;
		oSet.maximumsuggestions = 40;
		oSet.minimumlength = 2;
		oSet.multiselect=0;
		oSet.nosuggestionshide=1;
		oSet.enabled = 1//(<#CUSTOMPERSISTENT TAG=IDCCUSTOM_SIS DEFAULT=1>==1?true:false);
	},
	"quickSearch" : function(){
		var that = this;
		var searchForm ='<form id="searchForm" name="searchForm"><div class="searchInputContainer"><input type="text" autocomplete="off" size="20" value="quick search" id="quicksearchtext" name="quicksearchtext" class="search"/></div><div id="linkQuickSearch"></div></form>';
		
		$('#coverUp').append(searchForm); 
		
		var searchF = $('form[name=searchForm]').get(0);
		var qst = searchF.quicksearchtext;
		var $lqs = $('#linkQuickSearch');
		infradoxEnterKeyHandler.relay(qst, 'linkQuickSearch', function(){$lqs.trigger('click')}); 
		oSearch = new infradoxSearch(cfg.blankfilters);
		
		$lqs.click(function(){hC.searchModule.doSearch()});
		$(qst).click(function(){this.value=''});
		this.suggestions(searchF);
		
		var search = function() {
			oSearch = infradoxObjectManager.getInstance('infradoxSearch');
			oSearch.settings.territory = {required:cfg.reqterr ,set:(that.terr?1:0)};
			oSearch.settings.filterstring = oSearch.settings.filterresetstring;

			oSearch.settings.targetparent = true; 
			oSearch.settings.within = false 
			
			oSearch.settings.auxparameters = '&_sis='+(oSuggest.settings.enabled?'1':'0');
			oSearch.settings.words = [document.forms['searchForm'].quicksearchtext.value];
			oSearch.settings.disablefastphrase = !cfg.search.fastphrase.quickenabled; // ignore on quick search?
									
			document.forms['searchForm'].quicksearchtext.blur(); // remove focus
			oSearch.search(false); 
		}
		return {
			doSearch:function(){
				search();	 
			} 
		}
	},
	domReady : function(){
		if (this.domReadyFired) return; 
		this.domReadyFired=true; 
	
		if ($(document.body).hasClass('menuPage')){
				this.menu.draw(this.fakeTopFrame({	
				sHTML:"",omitUserInfo:true}));
				this.searchModule = this.quickSearch();
		}				
	}
}

hC.setSettings = function(){
	for (var x in arguments[0]) hC[x] = arguments[0][x];
}

hC.isNumeric = function(nr){
	return ( (typeof (nr) === typeof(1)) && (null !== nr) && isFinite(nr));
}

hC.checkPreviewPagination = function(){
	var oC = parseInt($('#currentPageText').val());
	var oT = $('#totalPages'); 
	
	if (!oC || !hC.isNumeric(parseInt(oT.text())) || !hC.isNumeric(oC) || parseInt(oT.text())<oC){ 
		$('.navigationLinks').css('display','none');
		$('.navButton').css('marginTop','1px')
	}
}


hC.fakeTopFrame = function(){
	var d = document.createElement('div');
	var params = arguments[0];
	var sHTML =  params.sHTML;
	if(!params.omitUserInfo){
		if (hC.guest){			
			sHTML+='<div id="userInfo"><a id="linkLogin" class="linked" href="/myaccount/">'+this.login+'</a> |	<a id="linkRegister" class="linked" href="/register/">'+this.register+'</a></div>';
		} else {
			sHTML+='<div id="userInfo"><a id="linkAccount" class="linked" href="/">'+hC.username+'</a> |	<a id="linkLogin" class="linked" href="/">'+this.logout+'</a></div>';
		}
	}
	d.className="masthead";
	$(d).append(sHTML);	
	var bd = $('body .masthead'); 
	if (!bd.length){
		document.body.appendChild(d); 	
	}	else{
		bd.replaceWith(d);
	}
	return d; 
}

hC.enForceFrames = function(){
	if(!hC.guest && parent && parent !== top) top.location ='/'; //prevent multiple nestings when errors happen
	
	if (hC.guest || top !== self ) return false; // what is below happens only when user is not a guest and this is a frameless page 
	var ud= 'go?a=disp&_yp1=0&_yp2=0&_yp8=0';
	var u = '',cp;
	var iA = infradoxApp; 
	switch(document.body.id){
		case 'searchResults': u = ud + '&t=sr-loader.html&_max=2'; break;
		case 'previewPage': u = ud + '&t=preview-loader.html&nr='+(previewParams.totalpag > 1 ? previewParams.pagnr : 1  )+'&ir='+previewParams.ref; break; 
		case 'homePage': u = ud + '&t=home-loader.html&_max=0&_maxlb=0&si=';	break;
		case 'galleryItems': u = ud+'&t=gl-loader.html&_storyState=1&_tlid='+hC.tlid+'&groupid='+hC.groupId+'&galleryid='+hC.galleryId+'&glbid='+hC.glbid+'&si=&_currentPhoto=0'
		
		'&t=gl-loader.html&groupid='+hC.groupId+'&galleryid='+hC.galleryId+'&glbid='+hC.glbid+'&page=&_max=2'; break;
		case 'lightbox': u+='&t=lb-loader.html&_maxlb=2'; break;
	}
	if (u.length > ud.length)	{ iA.loadParent(iA.completeURL(u), false)
		return true;
	}
	 return false;
}

	
hC.menu = (function(){
	var subMenuItems = {};
	var timer=0; 
	var submenuhide = function(el){	}
	var menArr = infradoxApp.men.split('_'); 

	var setActive = function(menuId,submenuId){
		$('#nav a').removeClass('active');
		$('#men_'+menuId).addClass('selected');
		if(submenuId) $('#sub_'+menuId+'_'+submenuId).addClass('active'); 
	}
		
	var setCurrentActive = function(){
		menArr = infradoxApp.men.split('_'); 
		setActive(menArr[1],menArr[2]);
	}	

	var menuHandlerRelay = function() {
		var spec = this.className.split(' ');
		if(!hC.guest){
			switch(spec[0]){
				case "menuBox":
					(top.frames[0] || window).menuHandler(this.className.split(' ')[1].replace(/menuBox/,'menu'));
				break;
				case"sub":
					(top.frames[0] || window).menuHandler(this.id.toString().replace('sub_men','submenu'));
				break;
			}
		}else if(hC.guest){
			if ($.inArray('newslink',spec)!==-1){
				top.location.href = this.childNodes[0].href+'?sgn=' + (hC.guest?'n':'y');
			}else{
				top.location.href = this.childNodes[0].href
			}
		}
		return false
	}
	return {
		draw:function(parentEl){
			var p,timer={};
			var topoffset = 75;
			var sHTML = 
			 	'<div id="coverUp">'+
			 		'<div id="shadow"></div>'+
					'<a href="/"  target="_top"><img alt="Panos" src="/images/panner/25logo.gif" id="topcompimg" /></a>'+
					'<div id="panosmenu">'+
						'<ul id="nav">'+
							'<li id="news" class="menuBox news_menu_0 newslink"><a target="_top" id="men_0" href="/news/">news</a></li>'+
							'<li id="stories" class="menuBox menu_1"><a target="_top" id="men_1" href="/stories/">stories</a></li>'+
							'<li id="photographers" class="menuBox menu_7"><a target="_top" id="men_7" href="/photographers/">photographers</a></li>'+
							'<li id="aboutus" class="menuBox menu_8"><a target="_top" id="men_8" href="/aboutus/">about us</a></li>'+
							'<li id="search" class="menuBox menu_2"><a target="_top" id="men_2" href="/search/">search</a></li>'+
							'<li id="lightbox" class="menuBox menu_4"><a target="_top" id="men_4" href="/myaccount/">lightbox</a></li>'+
							'<li id="myaccount" class="menuBox menu_3"><a target="_top" id="men_3" href="/myaccount/">my account</a></li>'+
							'<li id="shop" class="menuBox menu_9"><a  target="_top"id="men_9" href="/shop/">shop</a></li>'+
							'<li id="contact" class="menuBox menu_10"><a target="_top"  id="men_10" href="/contactus/">contact us</a></li>'+
							'<li id="'+(hC.guest?'signin':'signout')+'" class="menuBox menu_6"><a target="_top" id="men_6" href="/myaccount/">'+(hC.guest?'sign in':'sign out')+'</a></li>'+
							(hC.ad?'<li id="admin" class="menuBox menu_11"><a href="#" id="men_11">admin</a></li>':'')
						'</ul>'+
					'</div>'+
				'</div>';
			
			$(parentEl).append('<div class="mainMenuContainer">'+sHTML+'</div>'); 
	
			/*submenus*/
			for (var i = 0; i < menu.main.length; i++){
				if (menu.main[i].submenu.length) subMenuItems['men_'+menu.main[i].id] = menu.main[i].submenu;
			}
			
			$('#nav li a')
				.each(function(){
					if(typeof(subMenuItems[this.id]) != 'undefined'){
						subArray = ['<div id="subMenuContainer_'+this.id+'" class="subMenuContainer"><ul>'];	
						for(var i = 0; i < subMenuItems[this.id].length; i++){
							if (subMenuItems[this.id][i].hide) continue;
							subArray.push('<li id="sub_'+this.id+'_'+subMenuItems[this.id][i].id+'" class="sub '+(subMenuItems[this.id][i].blog?'newslink':'')+'"><a target="_top" class="sub" href="'+subMenuItems[this.id][i].u+'">'+subMenuItems[this.id][i].item+'</a></li>')
						}
						subArray.push('</ul></div>');
						$('.masthead').append(subArray.join("\n"));
						subArray=[];
					}
				})
				.parent()
		/* topmenu mouseovers  */
				.mouseover(function(){
					var c = this.childNodes[0];
					$(c).addClass('selected');
					var oSubContainer = $('#subMenuContainer_'+c.id);
					if(!oSubContainer.length) return; 
					oSubContainer.css('left',$(this).offset().left+'px');
					if (timer[c.id]) clearTimeout(timer[c.id]);
					timer[c.id] = setTimeout(function(){
						oSubContainer
							.stop()
							.animate({top:(topoffset)+'px'},200, "", function(){});
					},10);
				})
				.mouseout(function(){
					var c =this.childNodes[0]; 
					var oSubContainer = $('#subMenuContainer_'+c.id);
					if (timer[c.id]) clearTimeout(timer[c.id]);
					var el = this;
					timer[c.id] = setTimeout(function(){
						if (menArr[1] !== c.id.split('_')[1]) $(c).removeClass('selected'); //conditional makes sure that active menu item stays selected 	
						oSubContainer
							.stop()
							.animate({top:-100+'px'},200, "", function(){
							
							});
					},100);
				})	
				.click(menuHandlerRelay)
		/* submenuhandlers */	
		$('.subMenuContainer li')
			.mouseover(function(){
				var p = $(this).parent().parent().get(0); 
				
				var pid = p.id.replace('subMenuContainer_','');
				if (timer[pid]) {
					clearTimeout(timer[pid]);
				}
				$(this).addClass('hover');
			})
			.mouseout(function(){
				var p = $(this).parent().parent().get(0); 
				var pid = p.id.replace('subMenuContainer_','');
				$(this).removeClass('hover')
				$('#'+pid).parent().mouseout();
			})
			.click(menuHandlerRelay);
			setCurrentActive();
		}
	}
})()

