/* imagezoom */
(function(a){a.fn.ImageZoom=function(g){g=a.extend({zoomLimit:1,renderScale:0.5,zoomOutLimit:0.5},g);return this.each(function(){function k(){}function m(){var c=parseInt(b.css("left"));if(isNaN(c))c=0;var e=parseInt(b.css("top"));if(isNaN(e))e=0;a(".jqzoom").width()<=i*g.zoomLimit?b.stop(true,false).animate({width:a(".jqzoom").width()+300,left:c-150,top:e-150},500):k();return false}function n(){var c=parseInt(b.css("left"));if(isNaN(c))c=0;var e=parseInt(b.css("top"));if(isNaN(e))e=0;if(a(".jqzoom").width()>= 400){b.stop(true,false).animate({width:a(".jqzoom").width()-300,left:c+150,top:e+150},500);return false}}var b=a(this),i=b.width(),h=i*g.renderScale;if(h<500)h=500;b.width(h);b.parent().css({overflow:"hidden"});a(this).fadeIn(600);a(".zoomerNav").fadeIn("slow");h=function(c){if(a(this).data("mousemove")){var e=c.clientX-a(this).data("mouseX"),f=c.clientY-a(this).data("mouseY"),d=a(this).position();e=d.left+e;f=d.top+f;a(this).css({left:e,top:f});a(this).data("mouseX",c.clientX);a(this).data("mouseY", c.clientY);c.preventDefault()}};a(this).dblclick(function(){});a(this).mousedown(function(c){a(this).data("mousemove",true);a.browser.msie&&a(this).css({cursor:"url(../../../_assets/images/maps/grabbing.cur)"});a.browser.mozilla?a(this).css({cursor:"-moz-grabbing"}):a(this).css({cursor:"url(../../../_assets/images/maps/grabbing.cur)"});a(this).data("mouseX",c.clientX);a(this).data("mouseY",c.clientY);c.preventDefault()});a(this).mouseup(function(){a(this).data("mousemove",false);a.browser.msie&&a(this).css({cursor:"url(../../../_assets/images/maps/grab.cur)"}); a.browser.mozilla?a(this).css({cursor:"-moz-grab"}):a(this).css({cursor:"url(../../../_assets/images/maps/grab.cur)"})});a(this).mouseout(function(){a(this).data("mousemove",false);a.browser.msie&&a(this).css({cursor:"url(../../../_assets/images/maps/grab.cur)"});a.browser.mozilla?a(this).css({cursor:"-moz-grab"}):a(this).css({cursor:"url(../../../_assets/images/maps/grab.cur)"})});a(this).mouseout(h);a(this).mousemove(h);a(".btn_plus").click(function(){m();return false});a(".btn_minus").click(function(){n(); return false});(function(c){function e(d){var l=[].slice.call(arguments,1),j=0;d=c.event.fix(d||window.event);d.type="mousewheel";if(d.wheelDelta)j=d.wheelDelta/120;if(d.detail)j=-d.detail/3;l.unshift(d,j);return c.event.handle.apply(this,l)}var f=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var d=f.length;d;)this.addEventListener(f[--d],e,false);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var d=f.length;d;)this.removeEventListener(f[--d], e,false);else this.onmousewheel=null}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}})})(jQuery);b.bind("mousewheel",function(c,e){if(e>0){a(".jqzoom").width()<=i*g.zoomLimit?b.stop(true,false).animate({width:a(".jqzoom").width()+100,left:parseInt(b.css("left"))-50,top:parseInt(b.css("top"))-50},300):k();return false}if(e<0){a(".jqzoom").width()>=200&&b.stop(true,false).animate({width:a(".jqzoom").width()- 100,left:parseInt(b.css("left"))+50,top:parseInt(b.css("top"))+50},300);return false}});a(".btn_up").click(function(){b.stop(false,true).animate({top:parseInt(b.css("top"))+200},500);return false});a(".btn_dn").click(function(){b.stop(false,true).animate({top:parseInt(b.css("top"))-200},500);return false});a(".btn_left").click(function(){b.stop(false,true).animate({left:parseInt(b.css("left"))+200},500);return false});a(".btn_right").click(function(){b.stop(false,true).animate({left:parseInt(b.css("left"))- 200},500);return false});a(".btn_home").click(function(){b.stop(false,true).animate({width:i*g.renderScale,left:"10%",top:0},800);return false});a("#printrecord").click(function(){window.print();return false})})}})(jQuery);
/* mediaslider */
(function(e){e.fn.mediaSlider=function(c){c=e.extend({startSlide:1,fadeSpeed:500,autoFade:false,pauseOnHover:true,fadeTimeout:3E3,usePager:true,thumbNav:true,pagerThumbsToShow:7,pagerSlideBy:7,pagerSlideTime:500,pagercurrentSlidePage:1,pagerUsePageNav:false,pagerNavHolder:".navHolder"},c);return this.each(function(){function v(a){b.find(".mediaSliderPanels li a[rel='"+a+"'] img").length||jQuery('<img style="display:none" />').attr("src",n[a]+"&amp;random="+(new Date).getTime()).load(function(){jQuery(this).appendTo(b.find(".mediaSliderPanels li a[rel='"+ a+"']")).fadeIn()})}function o(a){v(a);var h=b.find("li a.currentPanel").parent("li");b.find("ul.thumbs li").removeClass("currentNavPanel").find("span.current_slide").remove();b.find("ul.thumbs li a[rel='"+parseInt(a)+"']").parent("li").addClass("currentNavPanel").append("<span class='current_slide'></span>");b.find("ul.mediaSliderPanels > li a[rel='"+parseInt(a)+"']").parent("li").css({"z-index":h.css("z-index")-1,display:"block"});h.fadeOut(c.fadeSpeed,function(){h.children("a").removeClass("currentPanel"); b.find("ul.mediaSliderPanels > li a[rel='"+parseInt(a)+"']").addClass("currentPanel")})}function p(){if(killAutoPlay){jQuery("a.thumb_play").removeClass("playing");l=1;killAutoPlay=false;q()}else{var a=b.find("li.currentNavPanel a").attr("rel");if(a==m){a=1;g(1);d=1;f(1)}else{a++;if(a==c.pagerThumbsToShow*d+1){g(d*c.pagerSlideBy+1);d++;f(d)}}return o(a)}}function w(){var a=b.find("li.currentNavPanel a").attr("rel");if(a==1){a=m;g((j-1)*c.pagerSlideBy+1);d=j;f(m)}else{if(a-1==c.pagerThumbsToShow*(d- 1)){d--;g(c.pagerSlideBy*(d-1)+1);f(d)}a--}return o(a)}function q(){return clearInterval(s)}function t(){return s=setInterval(p,parseInt(c.fadeTimeout))}function f(a){a>1&&b.find("a.thumb_page_back").removeClass("inactive");a==1&&b.find("a.thumb_page_back").addClass("inactive");a==j&&b.find("a.thumb_page_next").addClass("inactive");a<j&&b.find("a.thumb_page_next").removeClass("inactive");b.find("ul.slidingNavPager li a").removeClass("current");b.find("ul.slidingNavPager li a[rel='"+a+"']").addClass("current")} function g(a){b.find(".thumbs_wrapper").animate({scrollLeft:u*(a-1)},c.pagerSlideTime)}function x(a){b.find(".thumbs_wrapper").scrollLeft(u*(a-1))}var b=jQuery(this),m=0,k="\n<ul class='mediaSliderPanels'>",n=[];n[0]="";b.find("ul.thumbs").children("li").each(function(a){if(a==c.startSlide-1){jQuery(this).addClass("currentNavPanel").append("<span class='current_slide'></span>");k+="\n<li style='z-index:"+parseInt(9999-a)+";position:absolute;'>\n\t<a class='currentPanel' title='Click to see the full-size photos' rel='"+ parseInt(a+1)+"' href='#'>";k+="<img src='"+jQuery(this).children("a").attr("href")+"' alt='Click to see the full-size photos' class='first_image' />"}else k+="\n<li style='z-index:"+parseInt(9999-a)+";position:absolute;display:none;'>\n\t<a rel='"+parseInt(a+1)+"' href='#'>";k+="</a>\n</li>";n[parseInt(a+1)]=jQuery(this).children("a").attr("href");jQuery(this).children("a").addClass("mediaSlide_"+parseInt(a+1)).attr("rel",parseInt(a+1));m++});k+="</ul>";b.prepend(k);if(m<=1){e("li.view_all_photos").remove(); e("ul.thumbs").remove();e("div.gallery_controls").remove();e("a.currentPanel").removeClass("currentPanel").css("cursor","default");e("div.property_images_fader").removeClass("unopened")}var l=1,s="";c.pauseOnHover&&b.find("ul.mediaSliderPanels").hover(function(){return q()},function(){if(l!=1)return t()});b.find("a.thumb_play").click(function(){if(l==1){jQuery(this).addClass("playing");l=0;t()}else{jQuery(this).removeClass("playing");l=1;q()}return false});b.find("a.currentPanel:not(div.unopened a.currentPanel)").live("click", function(){p();return false});var u=parseInt(b.find(".thumbs li").outerWidth())+parseInt(b.find(".thumbs li").css("margin-right")+parseInt(b.find(".thumbs li").css("margin-left"))),j=Math.ceil(b.find(".thumbs li").length/c.pagerSlideBy),d=c.pagercurrentSlidePage;b.find(".thumbs a").click(function(){var a=b.find("li.currentNavPanel"),h=jQuery(this).attr("rel");a.children("a").attr("rel")!=h&&o(h);return false});b.find("a.thumb_next").click(function(){p();return false});b.find("a.thumb_back").click(function(){w(); return false});if(j>1){var r="<ul class='slidingNavPager'>";for(i=1;i<j+1;i++)r+="<li><a href='#' rel='"+i+"' title='Go directly to page "+i+"'>&#149;</a></li>";r+="</ul>";c.pagerUsePageNav&&e(c.pagerNavHolder).append(r);e("a.scrollNext").show()}b.find("a.thumb_page_next").click(function(){if(!jQuery(this).hasClass("inactive")){g(d*c.pagerSlideBy+1);d++;f(d)}return false});b.find("a.thumb_page_back").click(function(){if(!jQuery(this).hasClass("inactive")){d--;g((d-1)*c.pagerSlideBy+1);f(d)}return false}); b.find("ul.slidingNavPager li a").click(function(){var a=e(this).attr("rel");g((a-1)*c.pagerSlideBy+1);d=a;f(d);return false});x((d-1)*c.pagerSlideBy+1);f(d)})}})(jQuery);
/* flash version detector */
var isIE=navigator.appVersion.indexOf("MSIE")!=-1?true:false,isWin=navigator.appVersion.toLowerCase().indexOf("win")!=-1?true:false,isOpera=navigator.userAgent.indexOf("Opera")!=-1?true:false; function ControlVersion(){var a,c;try{c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");a=c.GetVariable("$version")}catch(g){}if(!a)try{c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");a="WIN 6,0,21,0";c.AllowScriptAccess="always";a=c.GetVariable("$version")}catch(b){}if(!a)try{c=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");a=c.GetVariable("$version")}catch(f){}if(!a)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");a="WIN 3,0,18,0"}catch(e){}if(!a)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); a="WIN 2,0,0,11"}catch(d){a=-1}return a} function GetSwfVer(){var a=-1;if(navigator.plugins!=null&&navigator.plugins.length>0){if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]){a=navigator.plugins["Shockwave Flash"+(navigator.plugins["Shockwave Flash 2.0"]?" 2.0":"")].description.split(" ");var c=a[2].split("."),g=c[0];c=c[1];var b=a[3];if(b=="")b=a[4];if(b[0]=="d")b=b.substring(1);else if(b[0]=="r"){b=b.substring(1);if(b.indexOf("d")>0)b=b.substring(0,b.indexOf("d"))}a=g+"."+c+"."+b}}else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6")!= -1)a=4;else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5")!=-1)a=3;else if(navigator.userAgent.toLowerCase().indexOf("webtv")!=-1)a=2;else if(isIE&&isWin&&!isOpera)a=ControlVersion();return a} function DetectFlashVer(a,c,g){versionStr=GetSwfVer();if(versionStr==-1)return false;else if(versionStr!=0){if(isIE&&isWin&&!isOpera){tempArray=versionStr.split(" ");tempString=tempArray[1];versionArray=tempString.split(",")}else versionArray=versionStr.split(".");var b=versionArray[0],f=versionArray[1],e=versionArray[2];if(b>parseFloat(a))return true;else if(b==parseFloat(a))if(f>parseFloat(c))return true;else if(f==parseFloat(c))if(e>=parseFloat(g))return true;return false}} function AC_AddExtension(a,c){return a.indexOf("?")!=-1?a.replace(/\?/,c+"?"):a+c}function AC_Generateobj(a,c,g){var b="";if(isIE&&isWin&&!isOpera){b+="<object ";for(var f in a)b+=f+'="'+a[f]+'" ';for(f in c)b+='><param name="'+f+'" value="'+c[f]+'" /> ';b+="></object>"}else{b+="<embed ";for(f in g)b+=f+'="'+g[f]+'" ';b+="> </embed>"}document.write(b)} function AC_FL_RunContent(){var a=AC_GetArgs(arguments,".swf","movie","clsid:d27cdb6e-ae6d-11cf-96b8-444553540000","application/x-shockwave-flash");AC_Generateobj(a.objAttrs,a.params,a.embedAttrs)} function AC_GetArgs(a,c,g,b,f){var e={};e.embedAttrs={};e.params={};e.objAttrs={};for(var d=0;d<a.length;d+=2)switch(a[d].toLowerCase()){case "classid":break;case "pluginspage":e.embedAttrs[a[d]]=a[d+1];break;case "src":case "movie":a[d+1]=AC_AddExtension(a[d+1],c);e.embedAttrs.src=a[d+1];e.params[g]=a[d+1];break;case "onafterupdate":case "onbeforeupdate":case "onblur":case "oncellchange":case "onclick":case "ondblClick":case "ondrag":case "ondragend":case "ondragenter":case "ondragleave":case "ondragover":case "ondrop":case "onfinish":case "onfocus":case "onhelp":case "onmousedown":case "onmouseup":case "onmouseover":case "onmousemove":case "onmouseout":case "onkeypress":case "onkeydown":case "onkeyup":case "onload":case "onlosecapture":case "onpropertychange":case "onreadystatechange":case "onrowsdelete":case "onrowenter":case "onrowexit":case "onrowsinserted":case "onstart":case "onscroll":case "onbeforeeditfocus":case "onactivate":case "onbeforedeactivate":case "ondeactivate":case "type":case "codebase":e.objAttrs[a[d]]= a[d+1];break;case "id":case "width":case "height":case "align":case "vspace":case "hspace":case "class":case "title":case "accesskey":case "name":case "tabindex":e.embedAttrs[a[d]]=e.objAttrs[a[d]]=a[d+1];break;default:e.embedAttrs[a[d]]=e.params[a[d]]=a[d+1]}e.objAttrs.classid=b;if(f)e.embedAttrs.type=f;return e};
/* propertycontrol */
/*
	code below this Should go back to sources/propertycontrol.js
	for archival, then this file should be minified
*/
var streetViewOn = 0;
var propertyControlLatitude = 0;
var propertyControlLongitude = 0;

function getHash() {
	return window.location.hash.substring(1);
}

function initPropertyMapping() {
		var panorama;
		var maplat = propertyControlLatitude;
		var maplong = propertyControlLongitude;
		var mapYaw = "0";
		var mapPitch = "0";
		var mapZoom = "0";
		var currentStreetViewId = "PropertyStreetview";
		var currentMapId = "PropertyMap";
		if (GBrowserIsCompatible()) { 
			function createMarker(point,html) {
			var gicon = new GIcon(G_DEFAULT_ICON, "/css/images/house_icon.png");
			gicon.iconSize = new GSize(21, 31);
			var marker = new GMarker(point, gicon);
			//GEvent.addListener(marker, "click", function() {
			//	marker.openInfoWindowHtml(html);
			//});
				return marker;
			}
			var streetViewFound = 1;
			// Display the map, with some controls and set the initial location 
			var map = new GMap2(document.getElementById(currentMapId));
			map.addControl(new GSmallMapControl());
			//map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(maplat,maplong),15);
			var point = new GLatLng(maplat,maplong);
			var marker = createMarker(point)
			map.addOverlay(marker);
			$('li.display_gmap').show();
			var flashInstalled = DetectFlashVer(10, 0, 0);
			//alert('flash is ' + flashInstalled);
			if (flashInstalled) {
				$('li.display_streetview').show();
				if (streetViewOn == 0) {
					streetViewOn = 1;
					var streetOverlay = new GStreetviewOverlay();	
					panorama = new GStreetviewPanorama(document.getElementById(currentStreetViewId));
					function handleNoPano(errorCode)
					{
					 //Error Code 600 => NO_NEARBY_PANO
					 if (errorCode == 600) 
						{    
							streetViewFound = 0;
							//handle no street view
							$('li.display_streetview').hide();
						}  
					}
					GEvent.addListener(panorama, "error", handleNoPano);  
					panorama.setLocationAndPOV(point, {yaw:mapYaw, zoom: mapZoom, pitch:mapPitch});
				};
			};
		}
		// display a warning if the browser was not compatible
		else {
		  alert("Sorry, the Google Maps API is not compatible with this browser");
		}
}

$(function() {

	//Defaults
	var photoDefaultView = 1; 
	var streetViewShown = 0;
	var floorPlanShown = 0;
	var mapShown = 0;
	var propCastShown = 0;
	var propCastOnPage = false;
	if ($('li.propcast').length > 0 ) { propCastOnPage = true };
	
	$(".property_images_fader").mediaSlider();
	$("li.view_all_photos a").text("view all photos ("+$("ul.thumbs li").length+")" );

	//hide full descriptions, show on click
	/*$(".full_desc").hide();
	$(".view_full_desc").click(function(){
		$(".full_desc").slideDown("slow");
		$(this).find("span").hide();
		//$(this).hide();
		return false;
	})*/
	
	//"view all photos" carousel	
	$("li.view_all_photos a").click(function () {
		if(mapShown == 1) {
			hideMap();
		};
		if(streetViewShown == 1) {
			hideStreetView();
		};								  
		if (photoDefaultView == 1) {
			showMainPhotos();	
		}
		else {
			hideMainPhotos();
		}
		
		return false;	
	});
	
	//View streetview
	$(".display_streetview a").click(function(){
		if (streetViewShown == 0){
			showStreetView();
		}
		else {
			hideStreetView();
		}
		return false;
	});
	
	//View map
	$(".display_gmap a").click(function(){
		if(mapShown == 0) {
			showMap();
		}
		else {
			hideMap();	
		}
		return false;
	});
	
	
	//View propcast
	$(".view_propcast a").click(function(){
		if (propCastShown == 0){
			showPropCast();
		}
		else {
			hidePropCast();
		}
		return false;
	});
	
	if(getHash()=="propcast") { 
		showPropCast();
	 };
	
	
	
	/*$(".view_floorplan a").click(function(){
		if(photoDefaultView == 0) {
			hideMainPhotos();
		};
		if(mapShown == 1) {
			hideMap();
		};
		if(streetViewShown == 1) {
			hideStreetView();
		};
		
		if(floorPlanShown ==0) {
			showFloorPlans();
		}
		else {
			hideFloorPlans();
		}
		return false;
	});*/
	
	$("div.unopened a.currentPanel").live("click", function(){
		if (photoDefaultView == 1) {
			showMainPhotos();	
		}
	});
	
	$("a.main_photos_close").click(function() {
		hideMainPhotos();
		return false;	
	});
	
	function showMainPhotos () {
		hidePropCast();
		$("ul.mediaSliderPanels li a").attr('title','Click to see the next photo');
		$("ul.mediaSliderPanels img").attr('title','Click to see the next photo');
		$("a.main_photos_close").fadeIn();
		$("span.current_slide").fadeIn();
		$("div.gallery_controls").fadeIn(); //IE7
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.photos").show();
		$(".property_images").fadeOut("normal", function(){
					$(".property_images_fader").removeClass("unopened");
					$(".property_images").fadeIn();
			}
		);
		$("li.view_all_photos a").text("return to normal view");
		photoDefaultView = 0;
	}

	function hideMainPhotos () {
		$("ul.mediaSliderPanels li a").attr('title','Click to see the full photos');
		$("ul.mediaSliderPanels img").attr('title','Click to see the full photos');
		killAutoPlay = true;
		$("a.main_photos_close").fadeOut();
		//IE7
		$("div.gallery_controls").fadeOut();
		$("span.current_slide").fadeOut();
		//EndIE7
		$(".property_images").fadeOut("normal", function(){
					$(".property_images_fader").addClass("unopened");
					$(".property_images").fadeIn();
			}
		);
		
		$("li.view_all_photos a").text("view all photos ("+$("ul.thumbs li").length+")" );
		photoDefaultView = 1;
	}

	function showMap() {
		//hideFloorPlans();
		hideStreetView();
		hidePropCast();
		$("ul.property_functions > li").hide();
		$("ul.property_functions li.map").show();
		$("li.display_gmap a").text("hide map");
		initPropertyMapping();
		mapShown = 1;
	}
	
	function hideMap() {
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.photos").show();
		$("li.display_gmap a").text("display map");
		mapShown = 0;
	}
	
	function showStreetView() {
		//hideFloorPlans();
		hideMap();
		hidePropCast();
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.streetview").show();
		$("li.display_streetview a").text("hide street view");	
		streetViewShown = 1;
	}
	
	function hideStreetView() {
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.photos").show();
		$("li.display_streetview a").text("display street view");	
		streetViewShown = 0;
	}
	
	function showPropCast () {
		if (!propCastOnPage) { return };
		var ua = navigator.userAgent;
		var isiPad = ua.match(/iPad/i) != null;
		var isiPod = ua.match(/iPod/i) != null;
		var isiPhone = ua.match(/iPhone/i) != null;
		var currentPage = 'http://' + window.location.hostname + window.location.pathname;
	
		hideMap();
		$("ul.property_functions > li, a.main_photos_close").hide();
		$("ul.property_functions > li.propcast").show().css('display','block');
		$("li.view_propcast a").text("close propcast video");
		propCastShown = 1;
		pageTracker._trackEvent("Propcast", "Opened", window.location );    

		
		//workaround for ios bug whereby video
		//won't load if hidden on page-load
		if (isiPad || isiPod || isiPhone) {
		
			if(getHash()=="propcast") { return };			
			currentPage += '#propcast';
			window.location.href = currentPage;
			window.location.reload(true);
			return;
		};
	

	}
	
	function hidePropCast () {
		if (!propCastOnPage) { return };
		stopVideo();
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.photos").show();
		$("li.view_propcast a").text("watch propcast video");	
		propCastShown = 0;
	}
	
	/*
	function showFloorPlans () {
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.floorplans").show();	
		//$('.jqzoom').ImageZoom({ zoomLimit: 1, renderScale: 0.2});
		$(".view_floorplan a").text("hide floorplans");
		floorPlanShown = 1;
	}
	
	function hideFloorPlans () {
		$("ul.property_functions > li").hide();
		$("ul.property_functions > li.photos").show();
		$(".view_floorplan a").text("view floorplans");
		floorPlanShown = 0;
	}
	
	//floorplan modifications
	$(".floor_plans_nav a").click(function() {
		$(".floor_plans_nav a").removeClass("current");
		$("img.jqzoom").attr("src", $(this).attr("href"));
		$(this).addClass("current");
		return false;
	});
*/
});
