// absl.js
//ATM Branch & Service Locator

/*
 * *****************************************************************************
 * 
 * COPYRIGHT. HSBC HOLDINGS PLC 2007. ALL RIGHTS RESERVED.
 *
 * This software is only to be used for the purpose for which it has been
 * provided. No part of it is to be reproduced, disassembled, transmitted,
 * stored in a retrieval system nor translated in any human or computer
 * language in any way or for any other purposes whatsoever without the
 * prior written consent of HSBC Holdings plc.
 * 
 *******************************************************************************
 */

//(function($){
ABSLObject={
	debug : false, // turn debugging on/off. Set to false in production.

//Declare all used variables, we will initialize later
	markers :[],
	icons : [],
	contents :[],
	map:null,
	bounds:null,
	requestData:null,
	geocoder:null,
	contextPath:null,
	autoFocus:true,
	locale:null,
	browser_locale:null,
	wabURL:null,
	tafURL:null,
	jq_retrieve:null,
	jq_timeout:null,
	jq_request_error:null,
	jq_max_nearest:null,
	default_location:null,
	geocode_zoom_level:null,
	showLargeMapControl:null,
	showMapTypeControl:null,
	theSearchText:null,
	services_selected:null,
	windowFocus : false, // only enabled when window is shown
	clickList : false,
	newWindow : false,	
	movestart:false, zoomend:false, moveend1:false, moveend2:false, moveend3:false, moveend4:false, //events
	
	//Global indicators for zoom behaviour
	singleSelectMode : false,
	currentMarker : null,
	currentIndex : -1,
	
	/* Debug logging (if enabled). */
	log: function () {
		if (this.debug) {
			console.log.apply('', arguments);
		}
	},
	
	
	__init : function(argsObj) {
		this.locale=argsObj.Locale;
		this.contextPath=argsObj.ContextPath;
		this.wabURL=argsObj.WABContact;
		this.tafURL=argsObj.tafURL;
		this.jq_retrieve=argsObj.jq_retrieve;
		this.jq_timeout=argsObj.jq_timeout;
		this.jq_request_error=argsObj.jq_request_error;
		this.jq_max_nearest=argsObj.jq_max_nearest;
		this.default_location=argsObj.default_location;
		this.geocode_zoom_level=argsObj.geocode_zoom_level;
		this.showLargeMapControl=argsObj.showLargeMapControl;
		this.showMapTypeControl=argsObj.showMapTypeControl;
		this.theSearchText=this.default_location;
		this.services_selected=argsObj.services_selected;
		this.browser_locale=argsObj.browser_locale;

		// If Google supports the browser GBrowserIsCompatible()

		this.log("Callling Init");
		if (GBrowserIsCompatible()) {

			// Initialize the ATM locator
			this.__setupMap();
			this._initCustomWindow(); // Initialize the Custom Window
			// Set the default data to the heart of 
			var input = $("#searchInput");
			var country = $("#search_country");
				if (input.val() == '' && country.val()=='' ) { // If value is empty
					//input.val('Toronto'); // Default the address bar to Vancouver, CA
					input.val(this.default_location); // Default the address bar to Vancouver, CA
				}
			//console.log(this.wabURL);

			this.search();
		} else {
			// Browser is not compatible, display error message
			alert("Sorry, the Google Maps API is not compatible with this browser");
		}

	}, // END __init
	
	/* Setup the Map Controls */
	__setupMap : function() {

		// Setup map_convas div as Google Map v2
		this.map = new GMap2(document.getElementById('map_canvas'));

		// Create the map controls
		//console.log("showLargeMapControl : "+ this.showLargeMapControl);
		if(this.showLargeMapControl == 'true'){
			this.map.addControl(new GLargeMapControl());
		}

		//console.log("showMapTypeControl : "+ this.showMapTypeControl);
		if(this.showMapTypeControl == 'true'){
			this.map.addControl(new GMapTypeControl());
		}
		this.map.addControl(new GOverviewMapControl());
		this.map.addControl(new GScaleControl());
		
		// Initialize view, we'll override this later
		this.map.setCenter(new GLatLng(0,0), 8);

		// Define custom icons
		var icon = new GIcon(G_DEFAULT_ICON); // start with defaults, than override
		icon.image = this.contextPath+"/file?path=images/"+"search.png";
		icon.shadow = this.contextPath+"/file?path=images/"+"search_shadow.png";
		icon.iconSize = new GSize(25, 44);
		icon.shadowSize = new GSize(59, 45);
		icon.iconAnchor = new GPoint(13, 44);
		icon.infoWindowAnchor = new GPoint(14, 0);
		icon.printImage = this.contextPath+"/file?path=images/"+"search_print.gif";
		icon.printShadow = this.contextPath+"/file?path=images/"+"search_printshadow.gif";
		icon.transparent = this.contextPath+"/file?path=images/"+"search_transparent.png";

		ABSLObject.icons['search'] = icon; // store as search icon
		// Define ATM Icon
		icon = new GIcon(G_DEFAULT_ICON); // start with defaults, than override
		icon.image = this.contextPath+"/file?path=images/"+"atm.png";
		icon.shadow = this.contextPath+"/file?path=images/"+"atm_shadow.png";
		icon.iconSize = new GSize(33, 46);
		icon.shadowSize = new GSize(76, 46);
		icon.iconAnchor = new GPoint(7, 47);
		icon.infoWindowAnchor = new GPoint(17, 0);
		icon.printImage = this.contextPath+"/file?path=images/"+"atm_print.gif";
		icon.printShadow = this.contextPath+"/file?path=images/"+"atm_printshadow.gif";
		icon.transparent = this.contextPath+"/file?path=images/"+"atm_transparent.png";
		icon.imageMap = [11,32,15,39,26,41,29,35,32,27,33,6,29,1,4,0,2,6,3,33,2,41,6,46,10,40,15,41];
		ABSLObject.icons.atm = icon; // store as atm icon

		//Define Branch Icon
		icon = new GIcon(G_DEFAULT_ICON); // start with defaults, than override
		icon.image = this.contextPath+"/file?path=images/"+"branch.png";
		icon.shadow = this.contextPath+"/file?path=images/"+"branch_shadow.png";
		icon.iconSize = new GSize(37, 61);
		icon.shadowSize = new GSize(96, 61);
		icon.iconAnchor = new GPoint(32, 61);
		icon.infoWindowAnchor = new GPoint(19, 0);
		icon.printImage = this.contextPath+"/file?path=images/"+"branch_print.gif";
		icon.printShadow =this.contextPath+"/file?path=images/"+"branch_printshadow.gif";
		icon.transparent =this.contextPath+"/file?path=images/"+"branch_transparent.png";
		icon.imageMap = [30,61,37,49,36,9,32,1,1,14,2,45,27,49,32,60];
		ABSLObject.icons.branch = icon; // store as branch icon

		// Create geocoder
		this.geocoder = new GClientGeocoder();

	}, // END __setupMap

	
	/*Log user activity to Webtrends*/
	logToWebTrends : function(){
		var params=ABSLObject.retreiveLogValues();
		WTLogger.log(params);
	},
	
	//Retrieve WebTrends Logging information like search features, search text etc..
	retreiveLogValues : function(){
	//this.log('Logging user activity');
	var search_type='';
	var search_features='';
	// Serialize Search Options
	$("#addressform input").each(function() {
			var field = $(this);
			if(field.attr('checked') != undefined) {
					if(field.attr('name').indexOf("location_type")!=-1){
							search_type+=field.val() + ';';
						}else{
							search_features+=field.val() + ';';
						}
				}
		});
		var index=-1;
		if((index=search_type.lastIndexOf(';'))!=-1){
			search_type=search_type.substring(0,index);
		}
		if((index=search_features.lastIndexOf(';'))!=-1){
			search_features=search_features.substring(0,index);
		}

		//Log to WebTrends
		var params=new Array();
		params["search_type"]=search_type;
		params["search_features"]=search_features;
		params["search_text"]=$("#searchInput").val()+' '+$("#search_country").val();
		return params;
	},
	
/* Create Custom Info Window */
	_initCustomWindow : function() {  
	//this.log('Adding Custom Window to Stage');
		
		// add the info window to the view
		this.$window = $(document.createElement("div"))
			.attr('id','info')
			.html('<div class="wrap"></div>')
			.hide()
			.appendTo(ABSLObject.map.getPane(G_MAP_FLOAT_SHADOW_PANE)) // append to google maps pane
			.parent().css({ 'z-index' : '999' }) // set the parent z-index to front
			.end(); // end the chain
		
		this.$windowOffset = { 
			'left' : 20,
			'top' : ABSLObject.$window.height()
		};
		
		// add the image window to the view
		this.$imgWindow = $(document.createElement("div"))
			.attr('id','imgDiv')
			.html('<div class="imgWrap"></div>')
			.hide()
			.appendTo(ABSLObject.map.getPane(G_MAP_FLOAT_SHADOW_PANE)) // append to google maps pane
			.parent().css({ 'z-index' : '1000' }) // set the parent z-index to front			
			.end(); // end the chain
		
		this.$imgWindowOffset = { 
			'left' : 20,
			'top' : ABSLObject.$imgWindow.height()
		};
		//console.log("ABSLObject.$imgWindow.height:"+ ABSLObject.$imgWindow.height());
	},
	
		
		/* Fetch the Response data from the server
		 */
	__fetchXmlData : function() {

		//Clear the message area
		$("#infoMessages").html("");

		/* Read the data from xml with Google Ajax */
		var XMLDataPath = this.contextPath+'/ABSLFCServlet' + '?' + ABSLObject.requestData;
		GDownloadUrl(XMLDataPath, function(data, responseCode) {
			if(responseCode == 200) {
			var filtered_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
             data.replace(/"(\\.|[^"\\])*"/g, ''))) &&
		         eval('(' + data + ')');
				
				ABSLObject.jsonResponse = filtered_JSON_object;// Load data into ATM Locator
				
					//Check for validation error flow
				var valErrMsg = ABSLObject.jsonResponse.infoMessage;
				if(valErrMsg != undefined){
					ABSLObject.__displayValidationMsg(valErrMsg);
					ABSLObject.removeMask();
				}else {
					ABSLObject.__build(); // Build the ATM Locator
					$(".results_loader").remove(); // Remove the loading indicator
					ABSLObject.logToWebTrends();
					ABSLObject.__checkMaximumExceeded(ABSLObject.jsonResponse);
				}
				
			} else if(responseCode == -1) { 
				alert(ABSLObject.jq_timeout);
			} else { 
				alert(ABSLObject.jq_request_error);
			}
		});
		
	},

__checkMaximumExceeded : function (jsonResponse){

	if(jsonResponse.exceedMaximum){
		var htmlText = "";
		htmlText += "<IMG src='";
		htmlText += ABSLObject.contextPath+"/images/error.gif";
		htmlText += "' />";
		htmlText += "&nbsp;";
		htmlText += ABSLObject.jq_max_nearest;	
		$("#infoMessages").html(htmlText);
	}
},

__displayValidationMsg : function (msg){

		var htmlText = "";
		htmlText += "<IMG src='";
		htmlText += ABSLObject.contextPath+"/images/error.gif";
		htmlText += "' />";
		htmlText += "&nbsp;";
		htmlText += msg;	
		$("#infoMessages").html(htmlText);
},


/* Build the ATM Locator with the JSON Objects */
	__build : function() {

	//this.log('Building ATM Locator');
		this.log("Exceeded :"+this.jsonResponse.exceedMaximum);
	
		//reset the singleSelectInfo
		ABSLObject.singleSelectMode = false;
		ABSLObject.currentMarker = null;
		ABSLObject.currentIndex = -1;
	
		// Clear the markers
		
		ABSLObject.map.clearOverlays();
		// Add marker with options pulled from icons['search'] object
		ABSLObject.markers['search'] = new GMarker(ABSLObject.searchPoint, { icon:ABSLObject.icons['search'] });
		ABSLObject.map.addOverlay(ABSLObject.markers['search']);

		ABSLObject.index = 0;
		// Create Bounds we'll use later to set the zoom
		this.bounds = new GLatLngBounds();
		this.bounds.extend(this.searchPoint);
		this.locale=this.jsonResponse.locale;
		$('#results').empty().append('<ul></ul>'); // empty out the results
		$('#results').hide();
		
		if(this.jsonResponse.results.length==0){
			this.map.setCenter(this.searchPoint);
			this.removeMask();
			this.addZoomAndDragListener();
			
			//PCL Phase I Updates begin
			alert(jQRequestError);
			//PCL Phase I Updates end
		}else{
			//Plot the points on Google using resultant JSON object
	        for(var i=0;i<this.jsonResponse.results.length;++i){
			ABSLObject.index=i;
	        	//console.log('found a location');
	        	// Get important pieces of JSON Data
	        	var branch=this.jsonResponse.results[i].location;
	        	
			var locationId = branch.locationId;
	        	var latitude =  branch.address.lat;
	        	var longitude = branch.address.lng;
	        	var distance = branch.distance;
			var name = branch.name;
			var content = branch.address.postalAddress+", "+branch.address.city+", "+
						(branch.address.province!=null?branch.address.province+", ":"")+
						(branch.address.postalCode!=null?branch.address.postalCode+", ":"")+
						branch.address.country;
			var letter = String.fromCharCode("A".charCodeAt(0) + ABSLObject.index);
			var color = 'red';
			
			// Create a Point with the lat and lng attributes of the marker
			var point = new GLatLng(latitude, longitude);
	
	
	          // Set up our GMarkerOptions object
	          //console.log("NAME : "+ unescape(branch.name));
	          var markerOptions = {icon:ABSLObject.createIcon(branch.type),title:unescape(branch.name)};
	          var marker = new GMarker(point, markerOptions);
	          
	          if(ABSLObject.map.getZoom()>=parseInt(this.geocode_zoom_level)){
	          	 //console.log("parsed zoom : "+ABSLObject.map.getZoom());
			     //plot car parks & subways
			     if(branch.addInfo && branch.addInfo.geocodes)
			     for(var n=0;n<branch.addInfo.geocodes.length;++n){
				  	 var geocode=branch.addInfo.geocodes[n];
				  	 if(0!=geocode.lat && geocode.lng!=0){
					  	var splMarkerOptions,splMarker;
					  	var splPoint=new GLatLng(geocode.lat, geocode.lng);
					  	 splMarkerOptions = {icon:ABSLObject.createSpecialIcon(geocode.imageName),clickable:false};
					  	 splMarker=new GMarker(splPoint, splMarkerOptions);	
					  	 ABSLObject.bounds.extend(splPoint);
					  	 ABSLObject.map.addOverlay(splMarker); // Place the marker on the map
					  	 }
				     }//end of for
		        }
				// Create the marker using the coordinates
				ABSLObject.bounds.extend(point); // add point to the bounds
				// Add open window event to the marker
				//marker.bindInfoWindowTabs(ABSLObject.createInfoTabWindow(branch),null);
				//this.log("Assigning index value: "+ABSLObject.index);
				marker.index = ABSLObject.index;
				GEvent.addListener(marker, "click", function() {
					ABSLObject.removeZoomAndDragListener();
					//ABSLObject.timeout = setTimeout("ABSLObject.addZoomAndDragListener()", 2500);
					//ABSLObject.log("Calling "+ABSLObject.index+" marker");
					ABSLObject.selectMarker(this.index);
				});
				
				ABSLObject.map.addOverlay(marker); // Place the marker on the map
				//this.log("Storing marker :"+ABSLObject.index);
				ABSLObject.markers[ABSLObject.index] = marker; // Store marker in markers array
				
				ABSLObject.markers[marker.index] = marker; // store marker
				ABSLObject.contents[marker.index] = ABSLObject._buildHTML(branch); // build and store content
			}//End of the for loop
		}
		

	// If not points are found just add the listener
		if (this.jsonResponse.results.length == 0) {  //ABSLObject.log('No points found.');
			ABSLObject.timeout = setTimeout("ABSLObject.addZoomAndDragListener()", 2500);
			
		}		

		// Check if we are done building the appliationthis.jsonResponse.results.length == ABSLObject.index
		if (this.jsonResponse.results.length > ABSLObject.index) {  //ABSLObject.log('We are done setting up locations');

		$('#results').slideDown('slow');
		$("#results li")
			.mouseover(function() { 
				$(this).addClass('over');
			})
			.mouseout(function() { 
				$(this).removeClass('over');
			})
			.click(function() {
				$("#results li.selected").removeClass('selected');
				$(this).addClass('selected');
			});
			ABSLObject._focus();
			ABSLObject.addZoomAndDragListener();
			this.map.currentBounds = this.map.getBounds();
			this.map.originalCenter = this.map.getCenter();
			this.map.savePosition();
			this.removeMask();					
		} //End of the check
			

		
	}, // END __build	
	
	addMask : function() {
		$('#mask').css({ opacity: 0.8 }).show();
	},
	
	removeMask : function() {
		$('#mask').fadeOut();
	},
	
	createIcon : function(imgName){
		var icon=ABSLObject.icons[imgName];
		if(null==icon){
			icon = new GIcon(G_DEFAULT_ICON); // start with defaults, than override
			icon.image = this.contextPath+"/file?path=images/"+imgName+".png";
			icon.shadow = this.contextPath+"/file?path=images/"+imgName+"_shadow.png";
			icon.iconSize = new GSize(33, 46);
			icon.shadowSize = new GSize(76, 46);
			icon.iconAnchor = new GPoint(7, 47);
			icon.infoWindowAnchor = new GPoint(17, 0);
			icon.printImage = this.contextPath+"/file?path=images/"+imgName+"_print.gif";
			icon.printShadow = this.contextPath+"/file?path=images/"+imgName+"_printshadow.gif";
			icon.transparent = this.contextPath+"/file?path=images/"+imgName+"_transparent.png";
			icon.imageMap = [11,32,15,39,26,41,29,35,32,27,33,6,29,1,4,0,2,6,3,33,2,41,6,46,10,40,15,41];
			ABSLObject.icons[imgName]=icon;
		 }
		return icon;
	},
	
	createSpecialIcon :function(imgName){
	
	var icon=ABSLObject.icons[imgName];
	if(null==icon){
	// Create a "tiny" marker icon
		var icon = new GIcon();
		icon.image = this.contextPath+"/file?path=images/"+imgName;
		icon.shadow = this.contextPath+"/file?path=images/"+"shadow.png";
		icon.printImage = this.contextPath+"/file?path=images/"+imgName
		icon.printShadow = this.contextPath+"/file?path=images/"+imgName
		//icon.transparent = this.contextPath+"/file?path=images/"+"atm_transparent.png";
	    icon.iconSize = new GSize(35, 35);
		icon.shadowSize = new GSize(52, 35);
	    icon.iconAnchor = new GPoint(9, 35);
	    icon.infoWindowAnchor = new GPoint(9, 2);
	    icon.infoShadowAnchor = new GPoint(18, 25);    
	    ABSLObject.icons[imgName]=icon;
	    }
	    
		return icon;
	},
	
	
	/* Set the selected item on the results sidebar */
	selectMarker : function(index) {
		ABSLObject.selectedIndex = index;
		$("#results li.selected").removeClass('selected');
		$("#results #marker" + index).addClass('selected');

		//PCL Phase I Updates begin
		
		ABSLObject.currentMarker = this.markers[index];
		ABSLObject.currentIndex = index;
		var point = ABSLObject.currentMarker.getPoint();
		ABSLObject.bounds = new GLatLngBounds();
        ABSLObject.bounds.extend(point);
     	ABSLObject.map.clearOverlays();
        ABSLObject.map.addOverlay(ABSLObject.currentMarker);
        ABSLObject.map.addOverlay(ABSLObject.markers['search']);

	

        //Set the flag to true
        ABSLObject.singleSelectMode = true;
        
     	//Add the subways and car parks (if already present)
		var branch = ABSLObject.jsonResponse.results[index].location;
        if(ABSLObject.map.getZoom()>=parseInt(ABSLObject.geocode_zoom_level)){
		     if(branch.addInfo && branch.addInfo.geocodes)
		     for(var n=0;n<branch.addInfo.geocodes.length;++n){
			  	 var geocode=branch.addInfo.geocodes[n];
			  	 if(0!=geocode.lat && geocode.lng!=0){
				  	var splMarkerOptions,splMarker;
				  	var splPoint=new GLatLng(geocode.lat, geocode.lng);
				  	 splMarkerOptions = {icon:ABSLObject.createSpecialIcon(geocode.imageName),clickable:false};
				  	 splMarker=new GMarker(splPoint, splMarkerOptions);	
				  	 ABSLObject.bounds.extend(splPoint);
				  	 ABSLObject.map.addOverlay(splMarker); // Place the marker on the map
				}
			 }//end of for
		 }//End of if
        

		//PCL Phase I Updates end
		
		this._openCustomWindow();
		
		/*if(invoke) {
			ABSLObject.invokeMarker(index);
		}*/
		
	}, // END setMarker
	
	
	/* Show the marker content from external source */
	invokeMarker : function(index){
	
		GEvent.trigger(ABSLObject.markers[index], "click");
		
	}, // END invokeMarker
	
	/* Search using the address in the main input */
	search : function() {
		
	if($('#addressform input[name="service"]').is(':checked')) {
			$('#button_advanced').removeClass('off');
			var filterText = '<span>'+this.services_selected+':</span> ';
			var innerText = '';
			$('#addressform input[name="service"]:checked').each(function() {
					var tf=jQuery.trim($(this).next().text());
					innerText += tf + ' | ';
			});
			innerText = jQuery.trim(innerText);
			filterText += (innerText.length > 57 ?
				innerText.substring(0, 57) + '...' :
				innerText.substring(0, innerText.length-2)); 
			$('#filter_text').html(filterText);
		} else {
			$('#button_advanced').addClass('off');
		    $('#filter_text').empty();
		}

		var addresswithoutcountry = $("#searchInput").val();
		var country = $("#search_country").val();
		this.theSearchText = $("#searchInput").val()+' '+$("#search_country").val();
		this.addMask();
		// Auto focus and hide the infowindow		
		this.autoFocus = true;
		this.$window.hide();
		this.$imgWindow.hide();
		var address = addresswithoutcountry+' '+country;

		//PCL Phase I validation updates begin 
	   address = address.replace(/(<|>)/g, '');
       //PCL Phase I validation updates end	   

		this.geocoder.getLatLng( 
			address, // geocode address
			function(point) {
				if (point) {
					ABSLObject.removeZoomAndDragListener(); // make sure reposistion doesn't fire.
					// Set the search point
					ABSLObject.searchPoint = point;
					$('#results').empty().append('<ul></ul>'); // empty out the results
					// Request data from server
					ABSLObject.sendRequest();
				} else {
					ABSLObject.removeMask();
					$('#results').empty().append('<ul></ul>'); // empty out the results
					alert(ABSLObject.jq_timeout);
				}
			}
		)
		
	}, // END search


/* Open Custom Info Window */
	_openCustomWindow : function() { 
		//this.log('Opening Custom Info Window # ' + this.selectedIndex);
		
		this.map.savePosition();
		
		var marker = this.markers[this.selectedIndex];
		var point = this.map.fromLatLngToDivPixel(marker.getPoint());
		var iconOffset = new GPoint(
			marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x,
			marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y
		);

		this.$window
			.hide()
			.css({
				left: point.x - iconOffset.x - ABSLObject.$windowOffset.left + 'px', 
				top: point.y - iconOffset.y - ABSLObject.$windowOffset.top + 'px'
			})
			.find('.wrap').html(ABSLObject.contents[ABSLObject.selectedIndex]).end()
			.fadeIn("fast");
		
		this.windowFocus = true;
		this.removeZoomAndDragListener();
		
		this._focus();
		var branch=ABSLObject.jsonResponse.results[ABSLObject.selectedIndex].location;
		if((branch.addInfo != null) && (branch.addInfo.imageName != null)){
	
			this.$window.find('.hImage').hover(function(e){ 
				
				var marker = ABSLObject.markers[ABSLObject.selectedIndex];
				var point = ABSLObject.map.fromLatLngToDivPixel(marker.getPoint());
				var iconOffset = new GPoint(
					marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x,
					marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y
				);
	
				var _html=ABSLObject.contextPath+'/file?path=images/'+branch.addInfo.imageName;
				var iconSize = ABSLObject.markers[ABSLObject.selectedIndex].getIcon().iconSize;
				//Currently only supporting Icon widths of 33 & 37 only
				var reducedWidth=(iconSize.width==33?10:33);
				if($.browser.msie && $.browser.version==6){
					reducedWidth=(iconSize.width==33?11:38);
				}
				
				ABSLObject.$imgWindow
					.hide()
					.css({
						left:point.x - reducedWidth +ABSLObject.$window.width()+ 'px', 
						top: point.y - iconOffset.y-ABSLObject.$window.height()+'px'
					})
					.find('.imgWrap').html("<img id='branchImage' src='"+_html+"'/>").end()
					.fadeIn("slow");
				},
			
			function(){
				ABSLObject.$imgWindow.fadeOut();
			}); 

		}
		
		this.$window.find('.close').click(function() {
			$("#results li.selected").removeClass('selected');
			ABSLObject.$window.fadeOut();
			ABSLObject.removeZoomAndDragListener();
			ABSLObject.moveend1 = GEvent.addListener(ABSLObject.map, "moveend", function() {
				GEvent.removeListener(ABSLObject.moveend1);
				ABSLObject.log("Close triggered on info box");
				ABSLObject.addZoomAndDragListener();
			});
			if (ABSLObject.clickList) {
				ABSLObject.clickList = false;
				if(ABSLObject.singleSelectMode){
					ABSLObject.map.panTo(ABSLObject.currentMarker.getPoint());
				}else{
					ABSLObject.map.panTo(ABSLObject.map.originalCenter);
				}
			} else {
				ABSLObject.map.returnToSavedPosition();
			}
			return false;
		});
		
		this.$window.find('.content:gt(0)').hide(); // hide all content items except first
		this.$window.find('.nav li:eq(0)').addClass('selected'); // add class selected to first nav item
		
		var navItems = this.$window.find('.nav li');
		
		navItems.hover(function() {
			$(this).addClass('hover');
		},function() {
			$(this).removeClass('hover');
		});
		
		navItems.click(function() {
			ABSLObject.$window.find('.nav li').removeClass('selected');
			$(this).addClass('selected');
		});
		
		$('#info .nav li a').click(function() {
			var $nav = $(this).parents('ul.nav:first');
			$nav.find('li').removeClass('selected');
			$(this).parent().addClass('selected');
			
			var active = this.id.replace('info_','');
			$nav.parent()
				.find('div.content').hide().end()
				.find('.'+active).fadeIn();
		});
		
		/* Disable pan and zoom on info window */
		$('#info').mousedown(function(e){
			e.returnValue = false; // ie6
			e.stopPropagation();
		});
		$('#info').mousemove(function(e){
			e.returnValue = false; // ie6
			e.stopPropagation();
		});
		
	},
		
	// Zoom and Center from the Bounds
	_focus : function() {
	
	 this.log("In foucus method");
		if (this.autoFocus) {   	
			//this.log('Auto focusing view based on locations.');
			if (this.zoomend != false) {
				GEvent.removeListener(this.zoomend);
			}
			
			//PCL Updates begin
			this.map.setCenter(this.bounds.getCenter(), this.map.getBoundsZoomLevel(this.bounds));
			//PCL Updates end
			
			this.zoomend = GEvent.addListener(this.map, 'zoomend', function() {
				ABSLObject.log("Reposition @ zoomend event");
				ABSLObject.$window.hide();
				ABSLObject.$imgWindow.hide();
				ABSLObject.map.savePosition();

				//PCL Updates
				ABSLObject.log("Single select mode :"+ABSLObject.singleSelectMode);
				
				//Call the servlet only in non-singleselect mode
				if(ABSLObject.singleSelectMode == false){
					ABSLObject.log("called reposition");
					ABSLObject.reposition(true);
				}else{
					var point = ABSLObject.currentMarker.getPoint();
					ABSLObject.log(point);
					ABSLObject.map.setCenter(point);
					
					//Add the subways and car parks
					var branch = ABSLObject.jsonResponse.results[ABSLObject.currentIndex].location;
			        if(ABSLObject.map.getZoom()>=parseInt(ABSLObject.geocode_zoom_level)){
					     if(branch.addInfo && branch.addInfo.geocodes)
					     for(var n=0;n<branch.addInfo.geocodes.length;++n){
						  	 var geocode=branch.addInfo.geocodes[n];
						  	 if(0!=geocode.lat && geocode.lng!=0){
							  	var splMarkerOptions,splMarker;
							  	var splPoint=new GLatLng(geocode.lat, geocode.lng);
							  	 splMarkerOptions = {icon:ABSLObject.createSpecialIcon(geocode.imageName),clickable:false};
							  	 splMarker=new GMarker(splPoint, splMarkerOptions);	
							  	 ABSLObject.bounds.extend(splPoint);
							  	 ABSLObject.map.addOverlay(splMarker); // Place the marker on the map
							}
						 }//end of for
					 }//End of if
				}
				//PCL Updates end
			});
			this.autoFocus = false;
		}
		
		if (ABSLObject.windowFocus) {  	//this.log('Focusing on info window.');
			
			var markerOffset = this.map.fromLatLngToDivPixel(
				this.markers[this.selectedIndex].getPoint()
			);
			
			var mapNE = this.map.fromLatLngToDivPixel(
				this.map.getBounds().getNorthEast()
			);
			
			var iconSize = this.markers[this.selectedIndex].getIcon().iconSize;
			var panRight = mapNE.x - (markerOffset.x + this.$window.width()+ this.$imgWindow.width()); 
			var panUp = mapNE.y - (markerOffset.y - iconSize.height - parseInt(this.$window.css('height')) - 62);

			//console.log("Pan Right "+panRight+" Pan Up "+panUp);
			this.moveend2 = GEvent.addListener(ABSLObject.map, "moveend", function() {
				ABSLObject.map.currentBounds = ABSLObject.map.getBounds();
				ABSLObject.log("Reposition @ moveend2 event");
				GEvent.removeListener(ABSLObject.moveend2);
				ABSLObject.addZoomAndDragListener();
			});
			
			this.map.panBy(new GSize (panRight,panUp));
			
			this.windowFocus = false;
		}
			
	},
	
	/* Build the HTML to go in the results and info window */
	_buildHTML : function (branch) {   //this.log('Building marker ' + this.index + ' infowindow HTML');
		/* Add a results item that invokes marker dialog */
		var index = this.index;
		$(document.createElement('li')) // create list item
			.attr('id', 'marker' + index) // set id
			.click(function(){
				ABSLObject.clickList = true;
				ABSLObject.log("In click"+index);
				ABSLObject.selectMarker(index); // Open appropriate window
				
				var params=ABSLObject.retreiveLogValues();
				params["selectedFromResult"]=branch.name;
				//Log to webtrends
				WTLogger.log(params);
			})
			.html( // set contents of list item
				'<a ><h4>'+branch.name+' - ' + branch.address.postalAddress + '</h4>' + 
				branch.name + ' - ' + branch.distance + '</a>'
			)
			.appendTo('#results ul'); // Attach it to the results panel

		/* Create the window content HTML */ 
		var html = '';
		var infoWndTab = '';

		infoWndTab +='<ul class="nav">' +
				'<li><a id="info_type">' + branch.links.details_tab + '</a></li>';
				
		if(branch.services != null){
			infoWndTab += '<li><a id="info_services">'+ branch.links.service_tab +'</a></li>';
			if(branch.WorkHrs != null) {
				infoWndTab += '<li><a id="info_hours">'+ branch.links.timing_tab +'</a></li>';
			}
			infoWndTab += '</ul>';
		}else if(branch.WorkHrs != null) {
			infoWndTab += '<li><a id="info_hours">'+ branch.links.timing_tab +'</a></li>'
			infoWndTab += '</ul>';
		}else{
			infoWndTab += '</ul>';
		}				
		
		html += infoWndTab +'<a class="close">close</a>';
		html += '<div class="content type">' +	this.createBranchImageWindow(branch) + '</div>';
		
		if(branch.services != null){
			html += '<div class="content services">' +	this.createInfoServicesWindow(branch) + '</div>';
			if(branch.WorkHrs != null){
				html += '<div class="content hours">' + this.createWorkingsWindow(branch) + '</div>';
			}
		}else if(branch.WorkHrs != null){
			html += '<div class="content hours">' + this.createWorkingsWindow(branch) + '</div>';
		}
//		this.log("the locale : " + this.locale);
//		this.log("the font size : " + $("#info div.info_contents").css('font-size'));		
		return html;
	},
	
	/* Reposition the location objects whenever the user drags or zooms the map*/
	reposition : function(force) {
		this.log(force);
		if (force || ABSLObject.isDrag(this.map.currentBounds, this.map.getBounds())) { 
			this.log('Reposition event fired.');
			var mapBounds = this.map.getBounds();
			var SW = mapBounds.getSouthWest();
			var NE = mapBounds.getNorthEast();
			var SWLat = SW.lat();
			var SWLng = SW.lng();
			var NElat = NE.lat();
			var NELng = NE.lng();
			var advOptions = ABSLObject.createQuery();
	
			ABSLObject.requestData = 'pd_st=pdst&event=cmd_ajax&'+advOptions+'cLat=' + ABSLObject.searchPoint.lat() + '&cLng=' + ABSLObject.searchPoint.lng() + '&bottomLeftLat=' + SWLat + '&bottomLeftLng=' + SWLng + '&topRightLat=' + NElat + '&topRightLng=' + NELng+'&LOCALE='+this.locale+'&';
			//console.log("Fetching new XML: " + ABSLObject.data);
			
			ABSLObject.removeZoomAndDragListener();
			this.addMask();
			ABSLObject.__fetchXmlData();
			this.removeMask();
		}
	},
	
		
	/* Build the request url and send to the server */
	sendRequest : function() {
	
		ABSLObject.autoFocus = true;
		// Initialize variables
		ABSLObject.requestData = null; // clear the data
		
		if (ABSLObject.searchPoint == null) {
			alert('Error: The search point has not been set.');
		} else {
			// Build query string from search point
			var advOptions = ABSLObject.createQuery();
			ABSLObject.requestData = 'pd_st=pdst&event=cmd_ajax&'+advOptions+'cLat=' + ABSLObject.searchPoint.lat() + '&cLng=' + ABSLObject.searchPoint.lng()+'&LOCALE='+this.locale+'&rand='+Math.random()+'&pd_ed=pded';
		}
		
		// Fetch XML from the server
		ABSLObject.__fetchXmlData();
		
	}, // END sendRequest

	/*Create the query string */
	createQuery : function(){
	var qs="";

	// Serialize Search Options
	$("#addressform input").each(function() {
			var field = $(this);
			if(field.attr('checked') != undefined) {
						qs+=field.attr('name')+"="+field.val() + '&';
				}
		});
	var address = $("#searchInput").val();
	var country = $("#search_country").val();
	qs+='address='+escape(address)+'&';
	qs+='search_country='+escape(country)+'&';
	this.log("Query:"+qs)
	return qs;
	},
	
	createLinksWindow : function(location){		
		var _div='<div align="left" style="overflow:auto;height:120px;width:435px;" ><ul style="list-style: url('+this.contextPath+'/images/styles/arrow_solid_red2.gif)">'
		//_div+= '<li><a target="_blank" rel="external" href="'+ this.contextPath + '/ABSLFCServlet?cmd_driving_directions_popup=&locationId='+ location.locationId + '">Get Directions</a></li>';
		_div+= '<li><a href="#"'+' onclick=ABSLObject.popExternalLinkWindow("'+ this.contextPath +'/ABSLFCServlet?cmd_driving_directions_popup=&locationId='+location.locationId +'",'+'"DriveInPuneCity"'+',"width=425,height=200,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no")'+'>Get Driving Directions</a>';
		_div+= '</ul></div>';
		return _div;
	},	
	
	/* Build the info of this branch with an image */
	createWorkingsWindow : function(location){
	var _div = '';
	var td_html = '';
	var td_html_center = '';
	var td_close = '</td></tr>';
	var td_red = '<tr style="color:red"><td>';	
		_div += '<div align="left" class="info_workhours" ><table width="95%">';
		td_html = '<tr><td width="32%">';
		td_html_center = '</td><td align="center" width="34%">';
		td_red = '<tr style="color:red"><td width="32%">';
	_div+='<tr><td colspan="3"><div class="service_header">'+location.links.hours+'</div></td></tr>';
	_div+='<tr><th width="32%">&nbsp;</th><th width="34%" align="center">'+location.links.lobby_txt+'</th><th width="34%" align="center">'+location.links.driveThru_text+'</th></tr>';
	var lobby;//=location.WorkHrs.lobby;
	var drivethru;//=location.WorkHrs.driveThru;

	if(location.WorkHrs){
		lobby=location.WorkHrs.lobby;
		drivethru=location.WorkHrs.driveThru;
		_div+=td_html+location.WorkHrs.Monday+td_html_center+lobby.monday+td_html_center+drivethru.monday+td_close;
		_div+=td_html+location.WorkHrs.Tuesday+td_html_center+lobby.tuesday+td_html_center+drivethru.tuesday+td_close;
		_div+=td_html+location.WorkHrs.Wednesday+td_html_center+lobby.wednesday+td_html_center+drivethru.wednesday+td_close;
		_div+=td_html+location.WorkHrs.Thursday+td_html_center+lobby.thursday+td_html_center+drivethru.thursday+td_close;
		_div+=td_html+location.WorkHrs.Friday+td_html_center+lobby.friday+td_html_center+drivethru.friday+td_close;
		_div+=td_html+location.WorkHrs.Saturday+td_html_center+lobby.saturday+td_html_center+drivethru.saturday+td_close;
		_div+=td_html+location.WorkHrs.Sunday+td_html_center+lobby.sunday+td_html_center+drivethru.sunday+td_close;
	}
	_div+='</table></div>';
	_div+='<div style="margin:5px"></div>';
	return _div;
	},

	/* Build the info of this branch with an image */
	createBranchImageWindow : function(location){
		var _div='';//<div id="customInfoWindow" "overflow=auto">';

		_div+='<div class="info_contents">';
		_div +='<div style="height:14px; padding-right:20px; margin-top:6px;" align="right">';
			if(location.links.email_branch.length > 0){
			_div+= '<a href="#" style="padding:0px 10px 0px 0px;" onclick=ABSLObject.popExternalLinkWindow("'+ this.contextPath + '/ABSLFCServlet?cmd_email_popup=&mail_mode=locmail&init=true&locationId='+ location.locationId +'&flow=js&localeStr='+this.locale+'",'+'"EmailBranchDetails"'+',"width=425,height=220,toolbar=no,left=0,top=0,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no")'+'><img border="0" src="'+this.contextPath+'/images/infowindow/mail.jpg" /></a>';
			}
			if(location.links.print_details.length > 0){
				_div+= '<a href="#" style="padding:0px 10px 0px 0px;" onclick=ABSLObject.popExternalLinkWindow("'+ this.contextPath + '/ABSLFCServlet?cmd_get_url=&locationId='+ location.locationId +'&flow=js&localeStr='+this.locale+'&browserLocale='+this.browser_locale+ '",'+'"PrintLocationDetails"'+',"width=980,height=600,left=0,top=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes")'+'><img border="0" src="'+this.contextPath+'/images/infowindow/print.jpg" /></a>';
			}
		_div +='</div>'; 
		if((location.addInfo!=null) && (location.addInfo.institution!=null)){
				_div+=''+ '<div class="head" align="left"><h4>'+ location.addInfo.institution + '</h4><h5><b>'+ unescape(location.name) +'</b></h5></div>';
		}else{
			_div+='<div class="head" align="left"><h4>'+unescape(location.name)+ '</h4></div>'
		}
		
		//_div+='<table width="94%" border="1"><tr>';
		//if((location.addInfo != null) && (location.addInfo.imageName != null))
		//if(location.addInfo.imageName.length>0){
		//	_div+='<td valign="top"><IMG border="0" src="'+this.contextPath+'/file?path=images/'+location.addInfo.imageName+'"/></td>'; 
		//}
		
		_div+='<div class="head" align="left"><h5>'+location.address.postalAddress+', '+location.address.city+', '+
			 	((location.address.province!=null)?location.address.province+', ':'')+((location.address.postalCode!=null)?location.address.postalCode+', ':'')+location.address.country;
		_div+='</h5></div>';
		if((location.addInfo != null) && (location.addInfo.imageName != null)){
			_div+='<div id="text_content" style="color:red; width:90%; height: 18px; vertical-align: top;" align="right"><u class="hImage">'+ location.links.view_branch_image + '</u></div>';
		}else{
			_div+='<div id="text_content" >&nbsp;</div>';		
		}
		//_div+='<span class="hsbc_logo">HSBC</span>';onmouseover=ABSLObject.mouseOver("'+_html+'") onmouseout=ABSLObject.mouseOut() 
		//_div+='</td></tr></table>';
		
		if(location.addInfo!=null){
			if((location.addInfo.landmark!=null) || (location.addInfo.callOutText!=null)) {
				_div+='<div class="note" align="left">';
				if(location.addInfo.landmark!=null){
					_div+= location.addInfo.landmark;
				}			
				if(location.addInfo.callOutText!=null){
					if(location.addInfo.landmark!=null) { _div+='<br/>'; }
					_div+= location.addInfo.callOutText;
				}
				_div+='</div>';
			}	
		}		
		
		// changed back to original
		
		if(location.contacts != null ){
			if(location.contacts.length > 0){
				//_div+='<hr style="border: 1px thin dashed #e8e8ef; width: 200px;" align="left"/>';
				_div+='<table width="98%" border="0">';
				for(var i=0;i<location.contacts.length;++i){
				var s= location.contacts[i].split("|");
					_div+='<tr><td align="left"  width="35%"><div  align="left" class="tel">' + s[0]+'</div></td><td width="65%" align="left" ><div align="left" class="tel">' + s[1] + '</div></td></tr>'
				}
				_div+='</table>';
			}
		}
		
		if(location.links.tell.length > 0){
			_div+='<div align="left" style="height:15px;"><a id="text_content" align="left" style="padding-left:10px; color: red;" href="#"'+' onclick=ABSLObject.popExternalLinkWindow("'+ this.contextPath + '/ABSLFCServlet?cmd_email_popup=&mail_mode=taf&&locationId='+ location.locationId + '&tafURL='+ this.tafURL+'&searchText='+escape(this.theSearchText).replace(/%u/g,"\\q")+ '&localeStr='+ this.locale +'",'+'"TellAFrriend"'+ ',"width=425,height=220,left=0,top=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no")'+'>'+location.links.tell+'</a><br/></div>';
		}
		if(location.links.sms_branch.length > 0){
			_div+='<div align="left" style="height:15px;"><a id="text_content" align="left" style="padding-left:10px; color: red;" href="#"'+' onclick=ABSLObject.popExternalLinkWindow("'+ this.contextPath + '/ABSLFCServlet?cmd_sms_popup=&locationId='+ location.locationId +'&flow=js&localeStr='+this.locale+ '",'+'"SMSBranchDetails"'+',"width=425,height=220,left=0,top=0,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no")'+'>'+location.links.sms_branch+'</a><br/></div>';
		}
		if(location.links.make_appointment.length > 0){
			_div+='<div align="left" style="height:15px;"><a id="text_content" align="left" style="padding-left:10px; color: red;" href="'+ this.wabURL + '">'+location.links.make_appointment+'</a></div>';
		}
		_div+='</div>';
		//this.log(_div);
		return _div;
	},
	
	/* Build the services info of this branch*/
	createInfoServicesWindow : function(location){
	var _div = '';
	//var _div = '<div style="height:20px;">&nbsp;</div>';
	if(location.links.show_facilities != null){
//		_div+='<div id="text_content" style="margin-top: 8px; padding-left: 10px; text-align: left;">';
//
//		_div+='&nbsp;';
//		//for(var i=0;i<location.facilities.length;++i){
//		//_div+=location.facilities[i];
//		//_div+=((i+1)<location.facilities.length)?', ':' ';
//		//}
//		_div+='</div>';
	}

	_div +='<div class="info_services">';
	if(location.links.show_facilities == null){
		_div +='<div style="height:15px;">&nbsp;</div>';
	}
	_div +='<table width="100%"><tr><td align="left"><div class="service_header">'+location.links.available_srvcs+'</div></td></tr></table>';
	_div +='<ul>'
	//_div+='<h5>'+location.links.available_srvcs+'</h5>';
	for(var i=0;i<location.services.length;++i){
	_div+='<li>'+location.services[i]+'</li>'
	}
	_div+='</ul></div>';
	_div+='<div style="margin:5px"></div>';
	//_div += this.createLinks(location);
	//this.log(_div);
	return _div;
	},
	
	isDrag : function(bounds, boundsCompare) {
		var multiplier = 0.08; // 0.1 means that you have to drag the map more than 10% to qualify for a drag
		var centerCompare = boundsCompare.getCenter();
		var center = bounds.getCenter();
		var span = bounds.toSpan();
		if (centerCompare) {
			var deltaX  = Math.abs(center.lng() - centerCompare.lng());
			var deltaY  = Math.abs(center.lat() - centerCompare.lat());
			var boundsX = span.lng();
			var boundsY = span.lat();
			if((deltaX > multiplier * boundsX) || (deltaY > multiplier * boundsY)) {
				return true;
			}
		}
		return false;
	},
				
	addZoomAndDragListener : function() {
	//ABSLObject.log('Adding reposition listener');
	this.removeZoomAndDragListener();
	
	this.movestart = GEvent.addListener(ABSLObject.map, "movestart", function() {
			ABSLObject.map.currentBounds = ABSLObject.map.getBounds();
			//ABSLObject.log('setting start');
		});
		
		this.moveend4 = GEvent.addListener(ABSLObject.map, "moveend", function() {
			
			//PCL Updates begin
			ABSLObject.log("addZoomAndDragListener's moveend call back");
			ABSLObject.log(ABSLObject.singleSelectMode);
			if(ABSLObject.singleSelectMode == false){
				ABSLObject.reposition();
			}else{
				//Clear any error messages
				$("#infoMessages").html("");
			
				//Clear and repopulate the results section
				$('#results').empty().append('<ul></ul>');
				var branch=ABSLObject.jsonResponse.results[ABSLObject.currentIndex].location;
				ABSLObject.index = ABSLObject.currentIndex;
				ABSLObject.contents[0] = ABSLObject._buildHTML(branch); // build and store content
				
			}
			//PCL Updates end
		});
	},
	
	removeZoomAndDragListener : function() {  
	 //ABSLObject.log('Removing reposition listener');
		if (ABSLObject.movestart != false) {
			GEvent.removeListener(ABSLObject.movestart);
		}
		if (ABSLObject.moveend1 != false) {
			GEvent.removeListener(ABSLObject.moveend1);
		}
		if (ABSLObject.moveend2 != false) {
			GEvent.removeListener(ABSLObject.moveend2);
		}
		if (ABSLObject.moveend3 != false) {
			GEvent.removeListener(ABSLObject.moveend3);
		}
		if (ABSLObject.moveend4 != false) {
			GEvent.removeListener(ABSLObject.moveend4);
		}
	},
	
	popExternalLinkWindow : function(_theURL,wndName,wndSettings){
		newWindow = window.open(_theURL,wndName,wndSettings);
		if(window.focus())
			newWindow.focus();
		newWindow.focus();
		if("EmailBranchDetails"==wndName){
				var params=ABSLObject.retreiveLogValues();
				params["emailResult"]="/absl/email/";
				//Log to webtrends
				WTLogger.log(params);			
		}
	}
}//END ABSLObject

$(document).ready(function() {
var argsObj={showMapTypeControl:showMapTypeControl,ContextPath:ContextPath,EncodedSessionNameSpace:EncodedSessionNameSpace,Locale:LOCALE,WABContact:_action,tafURL:_tafaction,jq_retrieve:jQretrieve,jq_timeout:jQtimeout,jq_request_error:jQRequestError,jq_max_nearest:jQMaxNearest,default_location:defaultLocation,geocode_zoom_level:geocodeZoom,showLargeMapControl:showLargeMapControl,services_selected:servicesSelected,browser_locale:BROWSER_LOCALE};
	// Initialize the ATM Locator
	ABSLObject.__init(argsObj);


	
	// Attach events to the buttons
	$("#button_search").click(function() {
		//Clear the message area
		$("#infoMessages").html("");

		ABSLObject.search();
		return false;
	});
	
	// Override Search Form
	$("#addressform").submit(function() { 
		ABSLObject.search();
		return false;
	});
	

	// Override Help Link
	$("#helplink").click(function() { 

		ABSLObject.popExternalLinkWindow(""+ ABSLObject.contextPath + "/ABSLFCServlet?cmd_help=&LOCALE="+ ABSLObject.locale +"","Help","top= 20,left=5,width=1000,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no");
		return false;
	});
	
	
	
	/*$("a").click(function() { 
		if($(this).attr('rel') == "external"){
			popupExtWnd($(this).attr('href'),'xyz','width=800,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
			return false; 
		}
	});*/
	
	$('#button_advanced').click(function() {
		//ABSLObject.log("Clicked on the advanced search");
		if($('#search2 div.popup:visible').length == 0) {
			$('#search2 div.popup').slideDown();
		} else {
			$('#search2 div.popup').slideUp();
		}
		return false;
	});

	$('#button_refine').click(function(){
		ABSLObject.addMask();
		//ABSLObject.log("Attaching listener for button_refine");
		$('#search2 div.popup').slideUp(null, function(){
			ABSLObject.search();
		}); 
	});
	
	$('body').click(function(e) {
		if($(e.target).parents('div.popup').length == 0){
			$('div.popup:visible').slideUp();
		}
	});
		
	$('body').unload(function() {
		GUnload();
	});	
	

});
//})(jQuery); // end jQuery wrapper
// When document is loaded


// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
/*var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();*/

