jQuery.noConflict(); 

var map;
var gdir;
var geocoder = null;
var addressMarker;

function load() {

	
	if (GBrowserIsCompatible()) {      
		map = new GMap2(document.getElementById("location_map"));
		var point = new GLatLng(54.633114,-1.317372);

		gdir = new GDirections(map, document.getElementById("directions"));
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
		GEvent.addListener(gdir, "error", handleErrors);

		map.setCenter(point, 15);
		marker = createMarker(point);
		map.addOverlay(marker);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
	}
}

function createMarker(point) {
		var marker = new GMarker(point);
		return marker;
	}    

function setDirections(fromAddress, point, locale) {
	gdir.load("from: " + fromAddress + " to: " + point,
						{ "locale": locale });
	marker.hide();
}

function handleErrors(){
 if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	 alert("Sorry, we couldn't find your address. Please make sure you have typed it in correctly, or try your postcode.\n\nError code: " + gdir.getStatus().code);
 else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
 
 else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
 else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

 else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	
 else alert("An unknown error occurred.");
 
}

function onGDirectionsLoad(){ 
			// Use this function to access information about the latest load()
			// results.
			// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}

jQuery(document).ready(function() {
	  jQuery("#page").corner();
	  jQuery('.news-ticker-list').cycle({
	  		timeout: 5000,
	  		pause: 1
	  });
	  jQuery('.right-photo').cycle({
	  		timeout: 4500,
	  		speed: 2000
	  });

	  
	jQuery("img.rounded").load( function () {
		var img = jQuery(this);
		// build wrapper
		var wrapper = jQuery('<div class="rounded_wrapper"></div>');
		wrapper.width(img.width());
		wrapper.height(img.height());
		
		// move CSS properties from img to wrapper
		wrapper.css('float', img.css('float'));
		img.css('float', 'none')
		
		wrapper.css('margin-right', img.css('margin-right'));
		img.css('margin-right', '0')
	
		wrapper.css('margin-left', img.css('margin-left'));
		img.css('margin-left', '0')
	
		wrapper.css('margin-bottom', img.css('margin-bottom'));
		img.css('margin-bottom', '0')
	
		wrapper.css('margin-top', img.css('margin-top'));
		img.css('margin-top', '0')
	
		wrapper.css('display', 'block');
		img.css('display', 'block')
	
		// wrap image
		img.wrap(wrapper);
		
		// add rounded corners
		img.after('<div class="tl"></div>');
		img.after('<div class="tr"></div>');
		img.after('<div class="bl"></div>');
		img.after('<div class="br"></div>');
	});
	
	jQuery("img[title=Forward]").fadeTo(10, 0.3);
	jQuery("img[title=Back]").fadeTo(10, 0.3);
		sfHover = function() {
	    var sfEls = document.getElementById("nav").getElementsByTagName("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"), "");
	        }
  		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	
	jQuery('#interactive_map').zoommap({
		// Width and Height of the Map
		width: '740px',
		height: '500px',
			
		//Misc Settings
		blankImage: '/wp-content/themes/wynyard/images/blank.gif',
		zoomDuration: 600,
		bulletWidthOffset: '17px',
		bulletHeightOffset: '17px',
		
		//ids and classes
		zoomClass: 'zoomable',
		popupSelector: 'div.popup',
		popupCloseSelector: 'a.close',
		
		//Return to Parent Map Link
		showReturnLink: true,
		returnId: 'returnlink',
		returnText: 'return to main map',
		
		//Initial Region to be shown
		map: {
			id: 'wynyardpark',
			image: '/wp-content/themes/wynyard/images/base_map.jpg',
			data: '/wp-content/themes/wynyard/map-data.php?type=map',
			maps: [
			{
				id: 'wynyardzoom',
				parent: 'wynyardpark',
				image: '/wp-content/themes/wynyard/images/zoom_map.jpg',
				data: '/wp-content/themes/wynyard/map-data.php?type=zoomed',
				width: '288px',
				height: '193px',
				top: '307px',
				left: '426px'
				/* More maps can be nested
				maps : [ ]
				*/
			}
			]
		}
	});
	
	
	if (jQuery("body").hasClass('archive')){
		if (!(jQuery("body").hasClass("date"))){
			if (!(jQuery("body").hasClass("category"))){
				jQuery(".page-item-12").removeClass("current_page_parent");
				jQuery(".page-item-8").addClass("current_page_parent");
			}
		}		
	}
	
	if (jQuery("body").hasClass("single-wynavailability")){
		jQuery(".page-item-12").removeClass("current_page_parent");
		jQuery(".page-item-8").addClass("current_page_parent");
	}
	
	if (jQuery(".taxonomy-drilldown-dropdowns").length > 0){
	
		jQuery(".taxonomy-drilldown-dropdowns li:last").css('display','none');
		
		jQuery(".taxonomy-drilldown-dropdowns select.floorsizes").change(function(){
			jQuery(".taxonomy-drilldown-dropdowns li:nth-child(2)").css('display','none');
			jQuery(".taxonomy-drilldown-dropdowns li:last").css('display','block');
		});
		
		jQuery(".taxonomy-drilldown-dropdowns select.numberofpeople").change(function(){
			jQuery(".taxonomy-drilldown-dropdowns li:first").css('display','none');
			jQuery(".taxonomy-drilldown-dropdowns li:last").css('display','block');
			jQuery(".taxonomy-drilldown-dropdowns select.spacetype option[value='warehouse']").remove();
		});
		
		if (jQuery(".taxonomy-drilldown-dropdowns select.floorsizes").val() != ''){
			jQuery(".taxonomy-drilldown-dropdowns li:nth-child(2)").css('display','none');
			jQuery(".taxonomy-drilldown-dropdowns li:last").css('display','block');
		}
		
		if (jQuery(".taxonomy-drilldown-dropdowns select.numberofpeople").val() != ''){
			jQuery(".taxonomy-drilldown-dropdowns li:first").css('display','none');
			jQuery(".taxonomy-drilldown-dropdowns li:last").css('display','block');
			jQuery(".taxonomy-drilldown-dropdowns select.spacetype option[value='warehouse']").remove();
		}
	
	}
	
	if (jQuery(".alert").length > 0){
		jQuery(".alert .close").click(function(){
			jQuery(this).parent().slideUp();
		});
	}

});




