var popupBoxOffsetFromMouse=[-5,-5];
if (document.getElementById || document.all){
	document.write('<div id="popupBoxModalBackground" style="position: absolute; visibility: hidden; left: 0px; top: 0px; z-index: 50"></div>');
}
function showPopupBox(popupElement, e, popupResetCallback, isModal){
	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	
	movePopupBox(popupElement, e);
	popupElement.style.visibility="visible";
	if ( isModal && popupResetCallback ){
		document.getElementById('popupBoxModalBackground').onclick = function (modalE){
			popupResetCallback(popupElement, modalE);
			popupElement.style.visibility = 'hidden';
			document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
		};
		document.getElementById('popupBoxModalBackground').style.visibility = 'visible';
	}
}
function hidePopupBox(popupElement){
	if ( typeof popupElement == 'string' ){
		popupElement = document.getElementById(popupElement);
	}
	popupElement.style.visibility="hidden";
	document.getElementById('popupBoxModalBackground').style.visibility = 'hidden';
}
function movePopupBox(popupElement, e){
	var xcoord = popupBoxOffsetFromMouse[0];
	var ycoord = popupBoxOffsetFromMouse[1];
	var docwidth = getDocWidth();
	var docheight = getDocHeight();
	if (typeof e != "undefined"){
	
		var x = 0;
		var y = 0;	
		
		if(e.pageX || e.pageY) {
			x = e.pageX;
			y = e.pageY;
		} else if (e.clientX || e.clientY) {
			x = e.clientX;
			y = e.clientY;
		
		
		}
		
				
		if (docwidth - x < popupElement.offsetWidth + xcoord){
			xcoord = x - xcoord - popupElement.offsetWidth;
		} else {
			xcoord += x;
		} 
					
		if (docheight + getTrueBody().scrollTop - y < popupElement.offsetHeight + ycoord){
			ycoord = y - ycoord - popupElement.offsetHeight;
		} else {
			ycoord += y;
		}
	} else if (typeof window.event != "undefined"){
	
		if (docwidth - event.clientX < popupElement.offsetWidth + xcoord){
			xcoord = event.clientX - xcoord - popupElement.offsetWidth + getTrueBody().scrollLeft;
		} else {
			xcoord += event.clientX + getTrueBody().scrollLeft;
		}
		if (docheight - event.clientY < popupElement.offsetHeight + ycoord){
			ycoord = event.clientY - ycoord - popupElement.offsetHeight + getTrueBody().scrollTop;
		} else {
			ycoord += event.clientY + getTrueBody().scrollTop;
		}
	}	else {
		return;
	}
	
	popupElement.style.left = xcoord+"px"
	popupElement.style.top = ycoord+"px"
}
var SIDE_TOP = 1;
var SIDE_BOTTOM = 2;
var SIDE_LEFT = 4;
var SIDE_RIGHT = 8;
var QUADRANT_TOP_LEFT = SIDE_TOP | SIDE_LEFT;
var QUADRANT_TOP_RIGHT = SIDE_TOP | SIDE_RIGHT;
var QUADRANT_BOTTOM_LEFT = SIDE_BOTTOM | SIDE_LEFT;
var QUADRANT_BOTTOM_RIGHT = SIDE_BOTTOM | SIDE_RIGHT;
function whichQuadrant(pageX, pageY, pointX, pointY){
	var quadrant = 0;
	var halfX = pageX/2;
	var halfY = pageY/2;
	if ( pointX < halfX ){
		quadrant |= SIDE_LEFT;
	} else {
		quadrant |= SIDE_RIGHT;
	}
	if ( pointY < halfY ){
		quadrant |= SIDE_TOP;
	} else {
		quadrant |= SIDE_BOTTOM;
	}
	return quadrant;
}
function getDocWidth(){
	return (document.all? getTrueBody().scrollLeft+getTrueBody().clientWidth : pageXOffset+window.innerWidth-15);
}
function getDocHeight(){
	return (document.all? Math.min(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.min(window.innerHeight));
}
function getTrueBody(){
	return ( (!window.opera && document.compatMode && document.compatMode!="BackCompat") || window.opera)? document.documentElement : document.body
}
function debugOnClickEventHandler(e){
	s = typeof e + ":\n";
	s += 'type = ' + e.type + "\n";
	s += 'target = ' + e.target + "\n";
	s += 'layerX = ' + e.layerX + "\n";
	s += 'layerY = ' + e.layerY + "\n";
	s += 'pageX = ' + e.pageX + "\n";
	s += 'pageY = ' + e.pageY + "\n";
	s += 'screenX = ' + e.screenX + "\n";
	s += 'screenY = ' + e.screenY + "\n";
	s += 'which = ' + e.which + "\n";
	s += 'modifiers = ' + e.modifiers + "\n";
	alert(s);
}
var offsetfrommouse=[15,15];

var displayduration=0;
var currentimageheight = 270;
if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}
function gettrailobj(){
if (document.getElementById)
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}
function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}
function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function showtrail(imagename,title,description,showthumb,height,filetype, width){
	if (height > 0){
		currentimageheight = height;
	}
	document.onmousemove=followmouse;
	cameraHTML = '';

	
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
	newHTML = newHTML + '<h5>' + title + '</h5>';
	newHTML = newHTML + '<h3>'+description.replace(/\[[^\]]*\]/g, '') +'</h3>';
	if (showthumb > 0){
		newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;">';
		if(filetype == 8) {
			newHTML = newHTML +	'<object width="380" height="285" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">';
			newHTML = newHTML + '<param name="movie" value="video_loupe.swf">';
			newHTML = newHTML + '<param name="quality" value="best">';
			newHTML = newHTML + '<param name="loop" value="true">';
			newHTML = newHTML + '<param name="FlashVars" value="videoLocation=' + imagename + '&bufferPercent=25">';
			newHTML = newHTML + '<EMBED SRC="video_loupe.swf" LOOP="true" QUALITY="best" FlashVars="videoLocation=' + imagename + '&bufferPercent=25" WIDTH="380" HEIGHT="285">';
			newHTML = newHTML + '</object></div>';
		} else {
			newHTML = newHTML + '<img src="' + imagename + '"';
			if ( filetype == 1 && height > 0 && width > 0 ){
				newHTML = newHTML + ' height="' + height + '" width="' + width + '"';
			}
			newHTML = newHTML + ' border="0"/></div>';
		}
	}
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
}
function showtrailBatch(imagename,title,filetype){
	document.onmousemove=followmouseBatch;
	cameraHTML = '';
	newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;" id="trailInnerDiv">';
	newHTML = newHTML + '<h2>' + title + '</h2>';
	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;">';
	if(filetype == 8) {
		newHTML = newHTML +	'<object width="380" height="285" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">';
		newHTML = newHTML + '<param name="movie" value="video_loupe.swf">';
		newHTML = newHTML + '<param name="quality" value="best">';
		newHTML = newHTML + '<param name="loop" value="true">';
		newHTML = newHTML + '<param name="FlashVars" value="videoLocation=' + imagename + '">';
		newHTML = newHTML + '<EMBED SRC="video_loupe.swf" LOOP="true" QUALITY="best" FlashVars="videoLocation=' + imagename + '" WIDTH="380" HEIGHT="285">';
		newHTML = newHTML + '</object></div>';
	} else {
		newHTML = newHTML + '<img src="' + imagename + '" border="0"></div>';
	}
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="inline";
	gettrailobj().position="absolute";
	currentimageheight = $('trailInnerDiv').offsetHeight;
	
}
function hidetrail(){
	gettrailobj().innerHTML = " ";
	gettrailobj().display="none"
	document.onmousemove=""
	gettrailobj().left="-500px"
}
function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400;
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
		
			if ( document.body ){
				scrollTop = Math.max(truebody().scrollTop, document.body.scrollTop);
			} else {
				scrollTop = truebody().scrollTop;
			}
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - scrollTop));
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 380){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 400;
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
function followmouseBatch(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	var trailInnerDiv = $('trailInnerDiv');
	var currentimageheight = trailInnerDiv.offsetHeight;
	var currentimagewidth = trailInnerDiv.offsetWidth;
	scrollPos = Position.realOffset(truebody());
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 400;
		} else {
			xcoord += e.pageX;
		}
		if ((e.pageY - scrollPos[1]) + currentimageheight > docheight){
			ycoord = -ycoord + (e.pageY - currentimageheight);
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (event.clientX + currentimagewidth > docwidth){
			xcoord = -xcoord + ((event.clientX + scrollPos[0]) - currentimagewidth);
		} else {
			xcoord += (event.clientX + scrollPos[0]);
		}
		if (event.clientY + currentimageheight > docheight){
			ycoord = -ycoord + ((event.clientY + scrollPos[1]) - currentimageheight);
		} else {
			ycoord += (event.clientY + scrollPos[1]);
		}
	}
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
function AddCheckedFilesToLighbox(formName, fieldName){
	fileIDs = '';
	fileIDFields = document[formName][fieldName];
	for (i=0; i<fileIDFields.length; ++i){
		if ( fileIDFields[i].checked ){
			if ( fileIDs.length ){
				fileIDs += ',';
			}
			fileIDs += fileIDFields[i].value;
		}
	}
	window.open('popup_add_to_lightbox.php?DontRedirect=1&id='+fileIDs,
		'Popup', 'scrollbars=yes,width=400,height=500');
}
var SearchBarBetaAjax = Class.create();
SearchBarBetaAjax.prototype = {
	preDisambigChoices: new Array,
	currentPreDisambigCheck: 0, 
	initialize: function(context) {
		this.colorSelector='Simple';
		this.tagHint = new IS_TagHint({
			textHintBoxID: 'SearchBarTextHintBox',
			textHintLoadingBoxID: 'SearchBarTextHintLoadingBox',
			textFieldID: 'SearchBarText',
			languageFieldID: 'SearchBarLanguage',
			textDisambiguationFieldID: 'TopSearchTextDisambiguation'
		});
	},
	
	
	loadEvents: function() {
		this.searchBarTextObserver();
		
	
		var fileTypes = new Array('Image','Illustration [Vector]','Flash','Video');
		fileTypes.each(function(type, index) {
			$("SearchBarFileType"+type).observe('click', function() {
				this.toggleFileType(type);
			}.bind(this));
		}.bind(this));
		
		$('SearchBarForm').observe('submit', this.searchBarFormOnSubmit.bind(this));
		
		$('SearchBarSubmitImage').observe('click', function() {
			return this.searchBarFormOnSubmit();
		}.bind(this));
		
		$('SearchBarAdvancedToggle').observe('click', function() {		
			this.toggleSearchBar(false);
		}.bind(this));
		
		$('SearchBarHelpToggle').observe('click', function() {
			window.open('popup_search_tips.php#basic','Popup','scrollbars=yes,width=700,height=470');
		});
		
	
	
	
		if( $('SearchWithin') ) {
		
		
		
		
			$('SearchBarSortBy').observe('change', function() {
				this.setSortBy($F('SearchBarSortBy'), true); 
				if ( $('SearchWithinCheckbox') ){ 
					$('SearchWithinCheckbox').checked = true; 
					this.setSearchWithin('');
				} else if ($('FO_SearchWithInCheckbox')){
					$('FO_SearchWithinCheckbox').checked = true; 
					this.setSearchWithin('FO_');
				}
				return this.searchBarFormOnSubmit();
			}.bind(this));
		}
		else{
			$('SearchBarSortBy').observe('change', function() {
				this.setSortBy($F('SearchBarSortBy'), false);
			}.bind(this));
		}
		
		if($('SearchWithin')){
			$('SearchWithinCheckbox').observe('click', function(){
				this.setSearchWithin('');
			}.bind(this));
		}else if($('FO_SearchWithin')){
			$('SearchWithinCheckbox').observe('click', function(){
				this.setSearchWithin('FO_');
			}.bind(this));
		}
		
		
	},
	
	searchBarFormOnSubmit: function(event) {
		if(TopsearchFormValidate()) { 			
			$('TopSearchFileTypeSizePrice').value = $F('SearchBarFileTypeSizePrice');
			$('TopSearchOrder').value = $F('SearchBarOrder');
			$('TopSearchText').value = this.getTextValue($('SearchBarText'), $('SearchBarTipText'));
			
			$('topsearch').submit();
		} 
		Event.stop(event);
		return false;
	},
	
	searchBarTextObserver: function() { 
		if ($('SearchBarText')) {
		
		
			$('SearchBarText').setAttribute('autocomplete', 'off');
			
		
			if ($F('SearchBarText') == '') $('SearchBarText').value = $F('SearchBarTipText');
			
			Event.observe('SearchBarText', 'keydown', function(e) {
				if ($F('SearchBarText').length >= 3) searchBarAjax.tagHint.getHintsFromPartialTagOnKeydown(e);
			});
			
			Event.observe('SearchBarText', 'keyup', function(e) {
				if ($F('SearchBarText').length >= 3) searchBarAjax.tagHint.getHintsFromPartialTagOnKeyup(e);
				else searchBarAjax.tagHint.resetHintBox();
			});
			
			Event.observe('SearchBarText', 'focus', function(e) {
				if ($F('SearchBarText') == $F('SearchBarTipText')) {
					$('SearchBarText').value = '';
					$('SearchBarText').style.color = '#000';
				} else searchBarAjax.tagHint.getHintsFromPartialTag();
			});
			Event.observe('SearchBarText', 'blur', function(e) {
				if ($F('SearchBarText') == '') {
					$('SearchBarText').value = $F('SearchBarTipText');
					$('SearchBarText').style.color = '#999';
				}
				searchBarAjax.tagHint.resetHintBox(250);
			});
		}
	},
	toggleFileType: function(selectedFileType) {
	
		if(!$("SearchBarFileTypeImage").checked && !$("SearchBarFileTypeFlash").checked && !$("SearchBarFileTypeIllustration [Vector]").checked && !$("SearchBarFileTypeVideo").checked) {
			$("SearchBarFileType"+selectedFileType).checked = true;
			return;
		}
		
	
	
		var fileTypeSizePrice = $F('SearchBarFileTypeSizePrice').evalJSON(true);
		
	
		var newFileTypeSizePrice = new Array();
		
	
	
		var hasVideo = 0;
		
	
		fileTypeSizePrice.each(function(fileType){
			
		
			if(fileType.type == selectedFileType){
				if(fileType.type=='Image'){
					fileType.size = ($('SearchBarFileType'+selectedFileType).checked ? 'All' : 'None');
				}
			
				else if(fileType.type=='Video') {
					hasVideo++;
					fileType.size = ($('SearchBarFileType'+selectedFileType).checked ? 'All' : 'None');
				}
				else{
					fileType.priceOption = ($('SearchBarFileType'+selectedFileType).checked ? 'All' : 'None');
				}
			}
			
		
			if(fileType.type != 'Video' || (hasVideo <= 1 && fileType.type == 'Video')){
				newFileTypeSizePrice.push(fileType);
			}
		});
		
		var fileTypeSizePriceJsonString = Object.toJSON(newFileTypeSizePrice);
		
	
		$('SearchBarFileTypeSizePrice').value = fileTypeSizePriceJsonString;		
		
	
		if(typeof(filtersAndOptions) != "undefined") {
			fileTypeSizePrice.each(function(fileType){
				switch(fileType.type) {
					
				
					case 'Image':
						var type = "FO_Image"
						$(type).value = fileType.size;
						filtersAndOptions.imageOnChange();
						filtersAndOptions.params['FO_FileType'].value[type].value = fileType.size;
						break;
						
					case 'Flash':
						var type = "FO_Flash";
						$(type).value = fileType.priceOption;
						filtersAndOptions.flashOnChange();
						filtersAndOptions.params['FO_FileType'].value[type].value = fileType.priceOption;
						break;
						
					case 'Illustration [Vector]':
						var type = "FO_Illustration";
						$(type).value = fileType.priceOption;
						filtersAndOptions.illustrationOnChange();
						filtersAndOptions.params['FO_FileType'].value[type].value = fileType.priceOption;
						break;
						
					case 'Video':	
						switch (fileType.size) {
							case 'All 4_3':
							case 'None 4_3':
							case 'PAL':
							case 'DV':
							case 'NTSC':
								var type = "FO_Video4_3";
								$(type).value = fileType.size;
								filtersAndOptions.video43OnChange();
								filtersAndOptions.params['FO_FileType'].value[type].value = fileType.size;
								break;	
							case 'All 16_9':
							case 'None 16_9':
							case 'HD 720':
							case 'HD 1080':
								var type = "FO_Video16_9";
								$(type).value = fileType.size;
								filtersAndOptions.video169OnChange();
								filtersAndOptions.params['FO_FileType'].value[type].value = fileType.size;
								break;	
							case 'All':
							case 'None':
							
								var type = "FO_Video4_3";
								$(type).value = fileType.size+' 4_3';
								filtersAndOptions.video43OnChange();
								
								filtersAndOptions.params['FO_FileType'].value[type].value = fileType.size+' 4_3';
								var type = "FO_Video16_9";
								$(type).value = fileType.size+' 16_9';
								filtersAndOptions.video169OnChange();
								filtersAndOptions.params['FO_FileType'].value[type].value = fileType.size+' 16_9';
								break;
						}
					default:
						var type = "";
						break;
				}
			});
		}
		
	
	
		if($("toolPortfolioLink")) {
			var rExp = new RegExp("(.*)fileTypeSizePrice=(.*?)&(.*)", "i");
			var o = $("toolPortfolioLink")
			var matches = o.href.match(rExp);
			o.href=matches[1]+"fileTypeSizePrice="+encodeURI(fileTypeSizePriceJsonString)+"&"+matches[3];
		}
		
	
		var url = "ajax_class_creator.php";
		var params = "ajax_action=saveFileType&ajax_class=searchbarbeta&fileTypeSizePrice="+fileTypeSizePriceJsonString;
		var myAjax = new Ajax.Request
			(
				url, 
				{ 
					method: "get", 
					parameters: params,
					onComplete: this.toggleFileTypeCompleted.bind(this),
					onFailure: this.failed.bind(this)
				}
			);
	},
	
	toggleFileTypeCompleted: function(req) {
			
		var data = req.responseText;
		
	}, 
	
	setSortBy: function(value, skipAJAX) {
		if ( !skipAJAX ){
			skipAJAX = false;
		}
		$('SearchBarOrder').value=value;
		if ( skipAJAX == false ){
			var url = "ajax_class_creator.php";
			var params = "ajax_action=SetSortBy&ajax_class=searchbarbeta&sortBy="+value;
			var myAjax = new Ajax.Request
				(
					url, 
					{ 
						method: "get", 
						parameters: params,
						onComplete: this.setSortByCompleted.bind(this),
						onFailure: this.failed.bind(this)
					}
				);	
		}
	},
	
	setSortByCompleted: function(req) {
		var data = AjaxUtil.receiveArray(req.responseText);
		
		if($("FO_Sort")) {
			$("FO_Sort").value = data.orderString;
		}
		
		if($("toolPortfolioLink")) {
			var rExp = new RegExp("(.*)order=(.*?)&(.*)", "i");
			var o = $("toolPortfolioLink")
			var matches = o.href.match(rExp);
			o.href=matches[1]+"order="+encodeURI(data.orderID)+"&"+matches[3];
		}
	},
	
	failed: function(req) {
	
		return false;
	},
	setHiddenSearchFormFields: function(filters){
		for ( i in filters ){
		
			$(i).value = filters[i];
		}
	},
	getTextValue: function(obj, tipObj){
		if ( obj.value == tipObj.value ){
			return '';
		} else {
			return obj.value;
		}
	},
	
	toggleSearchBar: function(toSimple) {
		var containerBasic = $('SearchBarContainerBasic');
		var containerAdvanced = $('SearchBarContainerAdvanced');
		var advancedSearchLoading = $('AdvancedSearchLoading');
	
		if(toSimple) {
			containerBasic.show();
			togglePopup(containerAdvanced);
			advancedSearchLoading.hide();
			
		} else {
			advancedSearchLoading.show();
			containerBasic.hide(); 
			
		
			if(typeof(filtersAndOptions) === "undefined") {
				LazyLoad.loadJS("/js/ajax_searchfiltersandoptionsbeta.js", this.initAdvancedSearch.bind(this));
			}
			else {
				advancedSearchLoading.hide();
				togglePopup(containerAdvanced);
			}			
		}
	},
	
	initAdvancedSearch:function() {
		filtersAndOptions = new SearchFiltersAndOptionsBetaAjax('FileSearch');
	},
	
	setSearchWithin:function(prefix) {
		if(prefix=="FO_") {
			var isWithin = $("FO_SearchWithinCheckbox").checked;
			$("SearchWithinCheckbox").checked = isWithin;
		} else {
			var isWithin = $("SearchWithinCheckbox").checked;
		
		
		
			if($("FO_SearchWithinCheckbox")) {
				$("FO_SearchWithinCheckbox").checked = isWithin;
			}
		}
		if(isWithin) {
			this.setHiddenSearchFormFields($(prefix+"SearchWithinContract").value.evalJSON(true));
		} else {
			this.setHiddenSearchFormFields($(prefix+"SearchWithinNew").value.evalJSON(true));			
		}
	},
	SearchBarFormSubmit: function(){
		return this.SearchBarFormSubmitGetDisambig();
	},
	SearchBarFormSubmitGetDisambig: function(){
		var searchText = $('SearchBarText');
		var chosenTerms = Array();
		this.currentPreDisambigCheck++;
		var url = "ajax_class_creator.php";
		var params = "ajax_action=getDisambiguation&ajax_class=searchbarbeta" +
			"&searchText=" + this.replacePunctuationAndWhitespace(searchText.value) +
			"&checkNumber=" + this.currentPreDisambigCheck +
			"&preDisambigChoices=" + this.preDisambigChoices.join(',') +
			"";
		var myAjax = new Ajax.Request
			(
				url, 
				{ 
					method: "get", 
					parameters: params,
					onComplete: this.SearchBarFormShowDisambig.bind(this),
					onFailure: this.failed.bind(this)
				}
			);
		ajaxWin.show({
      'title':'',
      'hdrIcon':'/images/loading.gif',
      'hdrTxtClass':'',
      'hdrTxt':'',
      'cntnt':'',
      'footer':'',
      'wdth':300,
			'cnclFunc': 'searchBarAjax.cancelPreDis(' + this.currentPreDisambigCheck + '); '
		});
		return false;
	},
	cancelPreDis: function(checkNumber){
		if(this.currentPreDisambigCheck == checkNumber){
			this.currentPreDisambigCheck++;
		}
	},
	SearchBarFormShowDisambig: function(req){
	
		var data = AjaxUtil.receiveArray(req.responseText);
		if(Number(data.checkNumber) !== Number(this.currentPreDisambigCheck)){
			return false;
		}
		if(data.tags && data.tags.length > 0){
			ajaxWin.show(data.html);
			return false;
		}
		if(TopsearchFormValidate()){
			var filters = $('SearchBarCopySearchBarFiltersJSON').value.evalJSON(true);
			for ( i in filters){
				$(i).value = eval(filters[i]);
				continue; 
				alert(i + ' = ' + eval(filters[i]));
			}
			$('topsearch').submit()
		}
		return false;
	},
	hideDisambig: function(){
		var preDisambiguation = $('SearchBarPreDisambiguation');
		preDisambiguation.style.display = 'none';
	},
	setPreDisambig: function(id, checked){
		var searchBarForm = $('topsearch');
		var inputField = $(id);
		if(!inputField){
			inputField = document.createElement("input");
			inputField.setAttribute("type", "hidden");
			inputField.setAttribute("name", id);
			inputField.setAttribute("id", id);
			searchBarForm.appendChild(inputField);
		}
		if(checked){
			inputField.value = 'true';
			this.preDisambigChoices.push(id);
		}else{
			inputField.value = 'false';
			this.preDisambigChoices = this.preDisambigChoices.without(id);
		}
	},
	replacePunctuationAndWhitespace: function (string){
   
    string = string.replace(/\n+/g, ' ');
    string = string.replace(/\r+/g, ' ');
   
    string = string.replace(/(\s|_|\.)+/g, ' ');
   
    string = string.replace(/(,|\(|\)|\.|\?|!|\||\+|\\|\/|=|"|:|;)+/g, ',');
    return string;
  },
	dummy: function(){
		return false;
	}
};
document.observe('dom:loaded', function() {
	searchBarAjax = new SearchBarBetaAjax(); 
	searchBarAjax.loadEvents();
});
sfHover = function() {
	var sfEls = $$('.sosfh li');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
Event.observe(window, 'load', function() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	if ($('acctDetailsContent')) {
		$('acctDetailsSelector').update($('acctDetailsContent').innerHTML);
		$('acctDetailsTemp').remove();
		buildPopupIFrame($("acctDetailsSelector"), true);
		
		$('acctDetails').onmouseover = $('acctDetailsSelector').onmouseover;
		$('acctDetails').onmouseout = $('acctDetailsSelector').onmouseout;
		
		$('acctDetailsSelector').hide();
		$('acctDetailsSelector').style.left = $('acctDetails').offsetLeft+'px';
		$('acctDetailsSelector').style.top = $('acctDetails').offsetTop + $('acctDetails').getHeight() +'px';
		
		if ($('acctDetailsSelectorIFrame')) {
			$('acctDetailsSelectorIFrame').style.left = $('acctDetails').offsetLeft+'px';
			$('acctDetailsSelectorIFrame').style.top = $('acctDetails').offsetTop + $('acctDetails').getHeight() +'px';
			$('acctDetailsSelectorIFrame').style.width = $('acctDetailsSelector').getWidth()+'px';
			$('acctDetailsSelectorIFrame').style.height = $('acctDetailsSelector').getHeight()+'px';
			$('acctDetailsSelectorIFrame').style.zIndex = $('acctDetailsSelector').zIndex -1;
		}
	}
});
