try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}


/*	PIP Consultation Request Validation
*/function pipDecision(f) {
	var msg='';
	var existing=false;
	for(var i=0; i<f.existing.length; i++) {
		if (f.existing[i].checked) {
			existing=f.existing[i];
		}
	}
	if (!existing) msg+='\n - Are you an Existing Patient';
	if (!f.fName.value) msg+='\n - First Name';
	if (!f.sName.value) msg+='\n - Surname';
	if (!f.email.value) msg+='\n - Email';
	if (!f.tel.value) msg+='\n - Telephone Number';
//	if (f.add1.value) msg+=' - Address\n';
//	if (f.add2.value) msg+=' - City\n';
	if (!f.pCode.value) msg+='\n - Postcode';
	if (!f.decision.options[f.decision.selectedIndex].value) msg+='\n - Decision';
	if ((existing.value=='false') && (f.decision.options[f.decision.selectedIndex].value=='PIPRemovalOnly')) {
		msg+='\n\n`'+f.decision.options[f.decision.selectedIndex].text+'` is only available in cases where you are one of our Breast Enlargement Patients';
	}
	if (msg!='') {
		alert('The following fields are required:'+msg);
		return false;
	}
	return true;
}



/**	Tabbed Content
 *	e.g.
 *	$('').tabbed();
 *
 *	ToDo's
 *	 - Use styles so that can be transitioned
 */
(function($){

// Pop Up Content
// Appends to document.body by default
	$.popUpContent=function(url,param,appendTo,iFrame){
		iFrame=iFrame||false;
		param=param||{};
		url=url||document.location.href;
		appendTo=appendTo||document.body;
		function updatePopUpContent(data) {
			var el=$('<div class="popUpContentWrapper" />').appendTo(appendTo);
			var fScreen=$('<div class="fScreen"/>').appendTo(appendTo);
			var closePopUp=$('<a href="#" class="close" title="Close">Close</a>').appendTo(el).click(function() {el.remove();fScreen.remove();return false;});
			$('<div class="popUpContentContent">'+data+'<div>').appendTo(el);
		}
		if (iFrame){
			if(typeof(param)=='object') {
				var tmpParam='';
				for(var k in param) {
					tmpParam=k+'='+param[k]+'&'+tmpParam;
				}
				param='?'+tmpParam;
			}else{
				param = (param.indexof('?')==0) ? param : '?'+param;
			}
			updatePopUpContent('<iframe src="'+url+param+'" frameborder="0">');
		}else{
			$.get(url,param,updatePopUpContent,'html');
		}
		return false;
	}





	$.fn.tabbed=function(custom){
		this.custom=custom || {};
		this.config={
				tabs:'ul.articleTabs a',
				contents:'section',
				activeClass:'activeTab',
				hiddenClass:'hiddenTab',
				animateHeight:true,
				animateHeightTime:800,
				contentWrap: '<div class="sectionWrap" />'
			};
		this.config=$.extend(this.config,this.custom);

		this.config.tabEls=this.find(this.config.tabs).parent();
		this.config.tabWrapper=this.config.tabEls.parent();
		
		this.config.contentEls=this.find(this.config.contents);
		if (this.config.contentWrap) {
			this.contentWrapper=this.config.contentEls.wrapAll(this.config.contentWrap).parent();
		} else {
			this.contentWrapper=this.config.contentEls.parent();
		}
		this.config.contentEls.css({position:'absolute'});

        this.change=function(nxtActive,that) {
        	var active=0;
        	that.config.tabEls.each(function(i,el){
        		if (el==nxtActive) {
        			active=i;
        			$(el).removeClass(that.config.hiddenClass);
        			$(el).addClass(that.config.activeClass);
        		} else {
        			$(el).removeClass(that.config.activeClass);
        			$(el).addClass(that.config.hiddenClass);
        		}
			});
// Possible improve using the '#' value from the tab and the id of the section
			that.config.contentEls.each(function(i,el) {
				if (active==i) {
        			$(el).removeClass(that.config.hiddenClass);
        			$(el).addClass(that.config.activeClass);
// Not needing the extra height of the tabs as wrapper just wraps content now
//        			var newHeight=that.config.tabWrapper.height()+$(el).height();
        			var newHeight=$(el).height();
        			if (that.config.animateHeight) {
	        			that.contentWrapper.animate({height:newHeight},that.config.animateHeightTime);
	        		} else {
						that.contentWrapper.height(newHeight);
					}
        		} else {
        			$(el).removeClass(that.config.activeClass);
        			$(el).addClass(that.config.hiddenClass);
				}
			});
        	return false;
        };
        
		this.init=function(that) {
//			console.log(that.config);
			that.config.tabEls.each(function(i,el) {
				var useClass = (i==0) ? that.config.activeClass : that.config.hiddenClass;
				$(el).addClass(useClass);
			});
			that.config.contentEls.each(function(i,el) {
				if (i==0) {
					$(el).addClass(that.config.activeClass);
// This method was causing issue on IE8, possibly due to rendering time
//					that.wrapper.height(that.config.tabWrapper.height()+$(el).height());					
					that.change(that.config.tabEls[i],that);
				} else {
					$(el).addClass(that.config.hiddenClass);
				}
				
			});

			that.config.contentEls.width(that.contentWrapper.width());	//	This is due to the fact absolute position width 100% includes the padding of the parent
			that.config.tabEls.click(function() {return that.change(this,that)});
		};
		this.init(this);
	}
})(jQuery);


/**	Auto Scroller for news Ticker
 */
(function($){
	$.fn.autoScroll=function(custom) {
		custom=custom || {};
		this.config={
			speed:1000
			,delayStart:100
			,distance:this.height()
		};
		var that=this;
		this.config=$.extend(this.config,custom);
		this.restartScroll=function() {
			that.css({'margin-top':0});
			that.scroll(that);
		}
		this.init = function(that) {
// Duplicates the list and appends it so that will appear as is constant and no interuptions
			var duplicate = that.children().clone();
			that.append(duplicate);
			that.scroll(that);
		}
		this.scroll = function() {
			var useSpeed=that.config.speed;
			var marginTop=parseFloat(that.css('marginTop'));
			if (marginTop!=0) {	// Adjust speed to compensate for distance already traveled
				var diff=parseFloat(that.css('marginTop'))/parseFloat(that.config.distance);
				useSpeed=useSpeed*(1+diff);
			}
			that.animate({'margin-top':'-'+that.config.distance+'px'},useSpeed,'linear',that.restartScroll);
		}
		this.init(this);
		this.mouseover(function(){$(this).stop();});
		this.mouseout(function(e) {that.scroll();});
	}
})(jQuery);




/**	countTo jQuery Plugin
 */
(function(a){a.fn.countTo=function(b){b=a.extend({},a.fn.countTo.defaults,b||{});var c=Math.ceil(b.speed/b.refreshInterval),d=(b.to-b.from)/c;return a(this).each(function(){function i(){g+=d;f++;a(e).html(g.toFixed(b.decimals));if(typeof b.onUpdate=="function"){b.onUpdate.call(e,g)}if(f>=c){clearInterval(h);g=b.to;if(typeof b.onComplete=="function"){b.onComplete.call(e,g)}}}var e=this,f=0,g=parseFloat(b.from),h=setInterval(i,b.refreshInterval)})};a.fn.countTo.defaults={from:0,to:100,speed:1e3,refreshInterval:100,decimals:0,onUpdate:null,onComplete:null}})(jQuery);





/**	fancyForm, replaces elements with divs, that can then be styled
 *	e.g.
 *	$('input[type=checkbox],input[type=radio]').fancyForm();
 */
(function(a){a.fn.fancyForm=function(a){a=a||{};var b={checked:"checked",unchecked:"unChecked",prefix:"input_",applied:"fancyFormApplied",focus:"focus",element:"label",element2:"div"};b=$.extend(b,a);this.focus(function(){this.focused=true});this.blur(function(){this.focused=false});this.each(function(a,d){var e=d.parentNode;if(d.id==""){d.id="fancyFormUnique_"+Math.floor(Math.random()*11)}var f=d;var g=b.element;while(f!=document.body){f=f.parentNode;if(f.nodeName.toUpperCase()=="LABEL"){if(f.htmlFor==d.id){g=b.element2;clickEl=f;break}}}var h=document.createElement(g);if(g.toUpperCase()=="LABEL"){h.htmlFor=d.id}clickEl=clickEl||h;var i=d.type;var j=d.checked?b.checked:b.unchecked;h.className=b.prefix+i+" "+j;var k=function(a){if(d.checked){$(h).removeClass(b.unchecked);$(h).addClass(b.checked)}else{$(h).removeClass(b.checked);$(h).addClass(b.unchecked)}};var l=function(a){if(d.focused){$(h).addClass(b.focus)}else{$(h).removeClass(b.focus)}};jQuery(d).change(k);jQuery(d).focus(l);jQuery(d).blur(l);jQuery(d).addClass(b.applied);e.appendChild(h)})}})(jQuery);


/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};




// Recursive Merging 2 objects
function MergeRecursive(obj1, obj2) {
	for (var p in obj2) {
		try {
			// Property in destination object set; update its value.
			if ( obj2[p].constructor==Object ) {
				obj1[p] = MergeRecursive(obj1[p], obj2[p]);
			} else {
				obj1[p] = obj2[p];
			}
		} catch(e) {
			// Property in destination object not set; create it and set its value.
			obj1[p] = obj2[p];
		}
	}
	return obj1;
}

/*	Dynamic Map Data
 */
var locations = {};

locations['surgicare'] = [
	{"title":"Birmingham",
		"address":"Surgicare Birmingham\r\nMG Physiotherapists\r\n22 George Road\r\nEdgbaston\r\nBirmingham\r\nB15 1PJ",
		"lat":"52.471541",
		"lon":"-1.914094",
		"link":"/our-clinics-and-hospitals/our-clinics/birmingham.html"
	},
	{"title":"Bristol",
		"address":"SurgiCare Bristol\r\n2 Clifton Park\r\nClifton\r\nBristol\r\nBS8 3BS",
		"lat":"51.4580063",
		"lon":"-2.6195849",
		"link":"/our-clinics-and-hospitals/our-clinics/bristol.html"
	},
	{"title":"Cardiff",
		"address":"SurgiCare Cardiff\r\n277 Cyncoed Road\r\nCyncoed\r\nCardiff\r\nCF23 6PA",
		"lat":"51.5247207",
		"lon":"-3.165249",
		"link":"/our-clinics-and-hospitals/our-clinics/cardiff.html"
	},
	{"title":"Glasgow",
		"address":"SurgiCare Glasgow\r\n9 Clairmont Gardens\r\nGlasgow\r\nG3 7LW",
		"lat":"55.8668551",
		"lon":"-4.2780573",
		"link":"/our-clinics-and-hospitals/our-clinics/glasgow.html"
	},
	{"title":"Leeds",
		"address":"SurgiCare Leeds\r\nThe Lawrence Clinic\r\n4-6 Greenside\r\nPudsey\r\nLeeds\r\nLS28 8PU",
		"lat":"53.791828",
		"lon":"-1.671856",
		"link":'/our-clinics-and-hospitals/our-clinics/leeds.html'
	},
	{"title":"Liverpool",
		"address":"SurgiCare Liverpool\r\n19 Rodney Street\r\nLiverpool\r\nL1 9EH",
		"lat":"53.3992991",
		"lon":"-2.974125",
		"link":"/our-clinics-and-hospitals/our-clinics/liverpool.html"
	},
	{"title":"London",
		"address":"The Triangle\r\n5 - 17 Hammersmith Grove\r\nLondon\r\nW6 0LG",
		"lat":"51.494544",
		"lon":"-0.226264",
		"link":"/our-clinics-and-hospitals/our-clinics/london.html"
	},
	{"title":"London (Central)",
		"address":"HB Health Clinic\r\n12 Beauchamp Place\r\nKnightsbridge\r\nLondon\r\nSW3 1NQ",
		"lat":"51.497749",
		"lon":"-0.165163",
		"link":'/our-clinics-and-hospitals/our-clinics/london-central.html'
	},
	{"title":"Manchester",
		"address":"SurgiCare Manchester\r\nParkway House\r\nPalatine Road\r\nManchester\r\nM22 4DB",
		"lat":"53.407767",
		"lon":"-2.262197",
		"link":"/our-clinics-and-hospitals/our-clinics/manchester.html"
	},
	{"title":"Newcastle",
		"address":"SurgiCare Newcastle\r\nTowers Avenue\r\nJesmond\r\nNewcastle upon Tyne\r\nNE2 3QE",
		"lat":"54.9976287",
		"lon":"-1.6080777",
		"link":"/our-clinics-and-hospitals/our-clinics/newcastle.html"
	},
];
locations['ziering'] = [
	{"title":"Bristol",
		"address":"SurgiCare Bristol\r\n2 Clifton Park\r\nClifton\r\nBristol\r\nBS8 3BS",
		"lat":"51.4580063",
		"lon":"-2.6195849",
		"link":"/our-clinics-and-hospitals/our-clinics/bristol.html"
	},
	{"title":"Cardiff",
		"address":"SurgiCare Cardiff\r\n277 Cyncoed Road\r\nCyncoed\r\nCardiff\r\nCF23 6PA",
		"lat":"51.5247207",
		"lon":"-3.165249",
		"link":"/our-clinics-and-hospitals/our-clinics/cardiff.html"
	},
	{"title":"Glasgow",
		"address":"SurgiCare Glasgow\r\n9 Clairmont Gardens\r\nGlasgow\r\nG3 7LW",
		"lat":"55.8668551",
		"lon":"-4.2780573",
		"link":"/our-clinics-and-hospitals/our-clinics/glasgow.html"
	},
	{"title":"Leeds",
		"address":"SurgiCare Leeds\r\nThe Lawrence Clinic\r\n4-6 Greenside\r\nPudsey\r\nLeeds\r\nLS28 8PU",
		"lat":"53.791828",
		"lon":"-1.671856",
		"link":'/our-clinics-and-hospitals/our-clinics/leeds.html'
	},
	{"title":"Liverpool",
		"address":"SurgiCare Liverpool\r\n19 Rodney Street\r\nLiverpool\r\nL1 9EH",
		"lat":"53.3992991",
		"lon":"-2.974125",
		"link":"/our-clinics-and-hospitals/our-clinics/liverpool.html"
	},
	{"title":"London",
		"address":"The Triangle\r\n5 - 17 Hammersmith Grove\r\nLondon\r\nW6 0LG",
		"lat":"51.494544",
		"lon":"-0.226264",
		"link":"/our-clinics-and-hospitals/our-clinics/london.html"
	},
	{"title":"Manchester",
		"address":"SurgiCare Manchester\r\nParkway House\r\nPalatine Road\r\nManchester\r\nM22 4DB",
		"lat":"53.407767",
		"lon":"-2.262197",
		"link":"/our-clinics-and-hospitals/our-clinics/manchester.html"
	},
	{"title":"Newcastle",
		"address":"SurgiCare Newcastle\r\nTowers Avenue\r\nJesmond\r\nNewcastle upon Tyne\r\nNE2 3QE",
		"lat":"54.9976287",
		"lon":"-1.6080777",
		"link":"/our-clinics-and-hospitals/our-clinics/newcastle.html"
	},
	{'title':'Belfast',
		'address':'Belfast Clinic\r\n126 High Street\r\nHolywood\r\nBelfast\r\nBT18 9HW',
		'lat':'54.639384',
		'lon':'-5.837955'
	},
	{'title':'Cambridge',
		'address':'Cambridge Park Hospital\r\n43 Cambridge Road\r\nWimpole\r\nRoyston\r\nSG8 5QD',
		'lat':'52.130867',
		'lon':'-0.032079'
	},
	{'title':'Dublin',
		'address':'Dublin Clinic\r\n30 Kildare Street\r\nDublin\r\nIreland',
		'lat':'53.340251',
		'lon':'-6.255599'
	},
	{'title':'Exeter',
		'address':'Exeter Clinic\r\n31 – 32 Southernhay East\r\nExeter\r\nEX1 1NS',
		'lat':'50.722333',
		'lon':'-3.525624'
	},
	{'title':'Nottingham',
		'address':'Nottingham Clinic\r\n2 North Road\r\nWest Bridgford\r\nNottingham\r\nNG2 7NH',
		'lat':'52.927569',
		'lon':'-1.135698'
	},
	{'title':'Sheffield',
		'address':'Sheffield Clinic\r\nYork Street\r\nSheffield\r\nS1 2AN',
		'lat':'53.3828',
		'lon':'-1.4682'
	},
	{'title':'Southampton',
		'address':'Southampton Clinic\r\nAvenue House\r\n37-38 The Avenue\r\nSouthampton\r\nSO17 1XN',
		'lat':'50.918504',
		'lon':'-1.403489'
	}
];

var distance = function (f, i, e, h) {
	var g = 3959;
	var k = (e - f) * Math.PI / 180;
	var b = (h - i) * Math.PI / 180;
	var m = Math.pow(Math.sin(k / 2), 2) + Math.cos(f * Math.PI / 180) * Math.cos(e * Math.PI / 180) * Math.pow(Math.sin(b / 2), 2);
	var l = 2 * Math.asin(Math.sqrt(m));
	var j = g * l;
	return j
};


/*
 */
function clinicMap(title,el) {
	if (typeof(el).toLowerCase()=='string') {
		el=document.getElementById(el);
	}
	if (!el) {
		return;
	}
	for(var i in locations.clinics) {
		if (locations.clinics[i].title==title) {
			break;
		}
		i++;
	}
	if (i>locations.clinics.length) {
		return;
	}
	var mapOptions={
		zoom: 12,
		center: new google.maps.LatLng(locations.clinics[i].lat,locations.clinics[i].lon),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	var map = new google.maps.Map(el,mapOptions);
	var icon = new google.maps.MarkerImage('/images/google-maps/surgicare.png',
		new google.maps.Size(61,35),
		new google.maps.Point(0,0),
		new google.maps.Point(30,50)
	);
	var shadow =  new google.maps.MarkerImage('/images/google-maps/surgicare-shadow.png',
		new google.maps.Size(79,35),
		new google.maps.Point(0,15),
		new google.maps.Point(30,35)
	);

	var markerObj = {
		position: mapOptions.center,
		map: map,
		shadow: shadow,
		icon: icon,
		title: locations.clinics[i].title
	};
	var marker = new google.maps.Marker(markerObj);
}







/*
 */
function googleMap(config) {
	var that=this;
	var map;
	var init = function(config) {
		if (typeof(config.elId).toLowerCase()=='string') {config.el=document.getElementById(config.elId)}
		if (!config.el) {
//			alert('Unable to load map to:\n - '+config.el+'\n - '+config.elId+'\n'+typeof(config.elId));
			return;
		}
		var mapOptions={
			zoom: 5,
			center: new google.maps.LatLng(54.367759,-0.878906),	// centers near Liverpool
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		if (typeof(config.mapOptions)=='object') {mapOptions=MergeRecursive(mapOptions,config.mapOptions)}
		
		that.map = new google.maps.Map(config.el,mapOptions);
		that.icons={};

		if (config.icons) {
			for(var i in config.icons) {
				that.icons[i] = {};
				that.icons[i].icon = new google.maps.MarkerImage(config.icons[i].image,
					config.icons[i].iconSize,
					config.icons[i].iconAnchor,
					config.icons[i].infoWindowAnchor);
				if (config.icons[i].shadow) {
					that.icons[i].shadow =  new google.maps.MarkerImage(config.icons[i].shadow,
						config.icons[i].shadowSize,
						config.icons[i].shadowAnchor,
						config.icons[i].infoShadowAnchor);
				}
			}
		}
// A default icon using googles beach flag
//alert('icons');
//console.log(that.icons);
		if (!that.icons['default']) {
			that.icons={'default':{}};
			that.icons['default']['icon'] = new google.maps.MarkerImage('http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag.png',
				new google.maps.Size(20,32),
				new google.maps.Point(0,0),
				new google.maps.Point(0,32));
			that.icons['default']['shadow'] = new google.maps.MarkerImage('http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png',
				new google.maps.Size(37,32),
				new google.maps.Point(0,0),
				new google.maps.Point(0,32));
		}
//console.log(that.icons);
		for(var i in config.points) {
			var marker = that.createMarker(config.points[i]);
		}
	}

	this.createMarker = function (point) {
//		var myLatLng = new google.maps.LatLng(point.lat, point.lng);
		var myLatLng = new google.maps.LatLng(point.lat, point.lon);
		var icon = (point.icon) ? point.icon : 'default';
		icon = (that.icons[icon]) ? icon : 'default';
		var markerObj = {
			position: myLatLng,
			map: that.map,
			shadow: that.icons[icon].shadow,
			icon: that.icons[icon].icon,
			title: point.title
		};
		var marker = new google.maps.Marker(markerObj);
	}
	init(config);
}


function loadMap() {
	var config = {
		elId: 'lgGoogleMap',
		useLg: true,
		useType: true,
		mapOptions: {
			center:new google.maps.LatLng(54,-3),
			zoom:(window.googleMapZoom) ? window.googleMapZoom : 5,
			mapTypeId:google.maps.MapTypeId.ROADMAP
		},
		icons:{}
/*		icons: {
			'default': {
				image: '/images/google-maps/surgicare.png',
				shadow: '/images/google-maps/surgicare-shadow.png',
				iconSize: new google.maps.Size(61,35),
				shadowSize: new google.maps.Size(79,35),
				iconAnchor: new google.maps.Point(0,0),
				shadowAnchor: new google.maps.Point(0,15),
				infoWindowAnchor: new google.maps.Point(30,50),
				infoShadowAnchor: new google.maps.Point(30,35)
			}
		},
		points: locations.clinics*/
	};
	if($(document.body).hasClass('ziering')) {
		config.points=locations.ziering;
		config.icons['default']={
			image: '/images/google-maps/ziering-map-icon.png',
			shadow: '/images/google-maps/ziering-map-icon-shadow.png',
			iconSize: new google.maps.Size(61,35),
			shadowSize: new google.maps.Size(79,55),
			iconAnchor: new google.maps.Point(0,0),
			shadowAnchor: new google.maps.Point(0,15),
			infoWindowAnchor: new google.maps.Point(30,50),
			infoShadowAnchor: new google.maps.Point(30,35)
		}
	} else {
		config.points=locations.surgicare;
		config.icons['default']={
			image: '/images/google-maps/surgicare.png',
			shadow: '/images/google-maps/surgicare-shadow.png',
			iconSize: new google.maps.Size(61,35),
			shadowSize: new google.maps.Size(79,35),
			iconAnchor: new google.maps.Point(0,0),
			shadowAnchor: new google.maps.Point(0,15),
			infoWindowAnchor: new google.maps.Point(30,50),
			infoShadowAnchor: new google.maps.Point(30,35)
		}
	}
	var gMap = new googleMap(config);
}


/*	Scripts to run after page load
 */
jQuery(function() {
/**
 */
$('.tabbedArticle').tabbed();

/** BMI Calculator
 */
$('.bmi-calculator').each(function(i,el) {
// Start Height/Weight
	var height=70;
	var weight=168;
	var maxHeight=84;	// 7'
	var maxWeight=406;	// 29st
	var minHeight=42;	// 3'6"
	var minWeight=70;	// 5st
// height
	var heightDisp = $(el).find('.height span');
	var heightSlideWrap = $(el).find('.height .area');
// weight
	var weightDisp = $(el).find('.weight span');
	var weightSlideWrap = $(el).find('.weight .area');
// bmi
	var bmiSlideWrapper = $(el).find('.bmi-container');
	var bmiSlide = $(el).find('.bmi-container .bmi');

	var update = function() {
		procHeight=height;
		procWeight=weight;
		if(isNaN(procHeight)){procHeight=1}
		if(isNaN(procWeight)){procWeight=1}
		l=Math.max(procHeight,1);
		n=Math.max(procWeight,1);

		var bmi=parseFloat((procWeight*703)/(procHeight*procHeight));
		bmi=Math.max(Math.min(bmi,50),15);

		heightDisp.text(Math.floor(height/12)+'’'+(height-Math.floor(height/12)*12)+'”');
		weightDisp.text(Math.floor(weight/14)+'st '+(weight-Math.floor(weight/14)*14)+'lbs');

		var p=401;
		var o="#9c0000";
		if(bmi<=18.4){
			p=0;o="#dddd00"
		}else{
			if(bmi<=25){
				p=100;o="#00dd00"
			}else{
				if(bmi<=30){
					p=200;o="#dddd00"
				}else{
					if(bmi<=40){
						p=300;o="#dd0000"
					}
				}
			}
		}
		bmiSlide.animate({left:p,"background-color":o});
		bmiSlide.countTo({from:bmiSlide.text(),to:bmi,speed:300});
	}
	update();
	heightSlideWrap.slider({min:minHeight, max:maxHeight, value: height, change: function(e,ui) {height=ui.value;update();}});
	weightSlideWrap.slider({min:minWeight, max:maxWeight, value: weight, change: function(e,ui) {weight=ui.value;update();}});
});

/*	Load Full Map
 */	loadMap();

/**	Use Fancy Forms
 */	$('input[type=checkbox],input[type=radio]').fancyForm();

/*	Load Dynamic Map
 */	$("form#location-search").each(function(i,el){
		var f,i,e;
		var d=$($('#'+el.id+" input")[0]);
		var h=$('#'+el.id+" p");
		var c=d.val();
		f=$('#dynMap');
		f.css({opacity:0,'z-index':-1});
		h.height(h.height());
		if ($(document.body).hasClass('ziering')) {
			config={
				icon: "/images/google-maps/ziering-map-icon.png",
				shadow: "/images/google-maps/ziering-map-icon-shadow.png"
			}
		} else {
			config={
				icon: "/images/google-maps/surgicare.png",
				shadow: "/images/google-maps/surgicare-shadow.png"
			}
		}
		$(el).bind("submit",function(m){
				var k=(!i);
				var j=d.val();
				if(j.length>0){
					if(k){
						i=new google.maps.Map(f[0],{zoom:8,center:new google.maps.LatLng(53.836322,-2.208252),mapTypeId:google.maps.MapTypeId.ROADMAP,mapTypeControl:false});
					}
					var l=new google.maps.LatLngBounds();
					if ($(document.body).hasClass('ziering')) {
						var useLoc= 'ziering';
					} else {
						var useLoc= 'surgicare';
					}
					if(k&&typeof locations=="object"&&locations[useLoc]){
						var clinics=locations[useLoc];
						$(clinics).each(function(ind,el){
							var r=new google.maps.LatLng(el.lat,el.lon);
							var title=el.link===false?el.title:'<a href="'+el.link+'">'+el.title+'</a>';
							var address=nl2br(el.address);
							var q=new google.maps.InfoWindow({content:'<div class="googleInfoWindow"><b>'+title+'</b><br>'+address+'</div>',maxWidth:140});
							var o=new google.maps.Marker({map:i,position:r,title:el.title,icon:config.icon,shadow:new google.maps.MarkerImage(config.shadow,null,null,new google.maps.Point(32,35))});
							google.maps.event.addListener(o,"click",function(){q.open(i,o)})
						})
					}
					var n=new google.maps.Geocoder();
					n.geocode({address:j,region:"GB"}, function(p,o){
							if(o==google.maps.GeocoderStatus.OK){
								if(d.val()!=c){
//console.log('write cookie for '+d.val());
//									Cookie.write("location",d.val())
									$.cookie("location",d.val());
								}
								if(e){
									e.setMap();
									e=new google.maps.Marker({map:i,position:p[0].geometry.location,title:"Your location"})
								}else{
									e=new google.maps.Marker({map:i,position:p[0].geometry.location,title:"Your location"})
								}
								l.extend(p[0].geometry.location);
								if ($(document.body).hasClass('ziering')) {
									var useLoc= 'ziering';
								} else {
									var useLoc= 'surgicare';
								}
								if(typeof locations=="object"&&locations[useLoc]){
									var r=9999999;
									var q=false;
									$(locations[useLoc]).each(function(){
//console.log(this);
										var t=distance(p[0].geometry.location.lat(),p[0].geometry.location.lng(),this.lat,this.lon);
										if(t<r){r=t;q=this}
									});
									if(q){
										l.extend(new google.maps.LatLng(q.lat,q.lon))
									}
								}
								if(k){
									i.setCenter(l.getCenter());i.fitBounds(l)
								}else{
									i.panTo(l.getCenter())
								}
							}
						}
					);
					if(k){
// c
f.css({'z-index':1});
f.animate({opacity:1},1000);
						if(j==c){
							h.css({height:f.height()-10+'px',opacity:0});
						}else{
							h.animate({height:f.height()-10+'px',opacity:1});
						}
					}
				}else{
					$.cookie("location",null);
					if(!k){
						f.animate({opacity:0},{duration:1000,complete:function() {$(this).css({'z-index':-1});i=null}});
					}
				}
				return false;
			}
		);
		if(c.length>0){
			$(this).submit();
			return false;
		}
	});
});

function nl2br (str, is_xhtml) {   
	var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
	var ret=(str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
//	console.log(str+'\n-------\n'+ret);
	return ret;
}






/**	jQuery Plugins
 *	transitions
 */
(function(a){a.fn.listTrans=function(b){this.config={interval:3e3,duration:1e3,focusClass:"active"};config=a.extend(this.config,b);switch(this.config.trans){case"S":this.config.trans="z-index";this.config.exit="";break;case"T":this.config.trans="top";break;case"B":this.config.trans="bottom";break;case"R":this.config.trans="right";break;case"L":default:this.config.trans="left";break}switch(this.config.exit){case"T":this.config.exit="top";break;case"B":this.config.exit="bottom";break;case"R":this.config.exit="right";break;case"L":this.config.exit="left";break;default:this.config.exit="";break}this.config.exit=this.config.exit==null?"":this.config.exit;this.config.midZ=+this.config.midZ>0?this.config.midZ:11;this.config.topZ=+this.config.topZ>0?this.config.topZ:12;if(this.config.trans=="z-index"){this.config.transObjs={nxtA:{"z-index":this.config.topZ,display:"block",opacity:0},nxtB:{opacity:1},nxtC:{"z-index":this.config.midZ},curA:{"z-index":this.config.midZ},curB:{opacity:0}}}else{this.config.dist=this.config.trans=="right"||this.config.trans=="left"?"-"+this.width()+"px":"-"+this.height()+"px";var c=this.config.trans;this.config.transObjs={nxtA:{"z-index":this.config.topZ,display:"block",top:"auto",left:"auto",right:"auto",bottom:"auto"},nxtB:{},nxtC:{"z-index":this.config.midZ},curA:{},curB:{}};this.config.transObjs.nxtA[this.config.trans]=this.config.dist;this.config.transObjs.nxtB[this.config.trans]=0;if(this.config.exit.match(/(top|bottom|left|right)/)){curA={top:"auto",left:"auto",right:"auto",bottom:"auto"};curB={top:"auto",left:"auto",right:"auto",bottom:"auto"};curA[this.config.exit]=0;curB[this.config.exit]=this.config.dist;this.config.transObjs["curA"]=curA;this.config.transObjs["curB"]=curB}}var d={"z-index":this.config.midZ,position:"absolute",display:"none"};d[this.config.trans]=0;a(this.children()).css(d);a(this.children()[0]).css({"z-index":this.config.topZ,display:"block"});this.current=0;var e=this;if(e.config.nav){a(e.config.nav).mouseenter(function(){e.stopTimer()}).mouseleave(function(){e.startTimer()}).find("li").click(function(){var b=0;b=a(this).index();e.fade(e,b);e.startTimer()})}a(this).mouseenter(function(){e.stopTimer()}).mouseleave(function(){e.startTimer()}).find("li").click(function(){var b=0;b=a(this).index();e.fade(e,b)});this.fade=function(b,c){var d=b.children();var e=b.current;var f=e+1>=d.length?0:e+1;var f=typeof c=="undefined"?f:c;if(e==f)return;a(d[e]).css(b.config.transObjs.curA);a(d[f]).css(b.config.transObjs.nxtA);a(d[f]).animate(b.config.transObjs.nxtB,b.config.duration,"linear",function(){a(this).css(b.config.transObjs.nxtC);if(a(this).prev().length>0){a(this).prev().css({display:"none"})}else{a(this).siblings().last().css({display:"none"})}});a(d[e]).animate(b.config.transObjs.curB,b.config.duration,"linear");b.current=f;if(b.current>=d.length){b.current=0}if(b.config.nav){a(b.config.nav).find("li").removeClass(b.config.focusClass);a(a(b.config.nav).find("li")[f]).addClass(b.config.focusClass)}b.startTimer()};this.stopTimer=function(){clearTimeout(e.timer)};this.startTimer=function(){clearTimeout(e.timer);e.timer=window.setTimeout(function(){e.fade(e)},e.config.interval)};e.startTimer()}})(jQuery);
//(function(a){a.fn.listTrans=function(b){b.interval=+b.interval>0?b.interval:3e3;b.duration=+b.duration>0?b.duration:1e3;switch(b.trans){case"S":b.trans="z-index";b.exit="";break;case"T":b.trans="top";break;case"B":b.trans="bottom";break;case"R":b.trans="right";break;case"L":default:b.trans="left";break}switch(b.exit){case"T":b.exit="top";break;case"B":b.exit="bottom";break;case"R":b.exit="right";break;case"L":b.exit="left";break;default:b.exit="";break}b.exit=b.exit==null?"":b.exit;b.midZ=+b.midZ>0?b.midZ:11;b.topZ=+b.topZ>0?b.topZ:12;if(b.trans=="z-index"){b.transObjs={nxtA:{"z-index":b.topZ,display:"block",opacity:0},nxtB:{opacity:1},nxtC:{"z-index":b.midZ},curA:{"z-index":b.midZ},curB:{}}}else{b.dist=b.trans=="R"||b.trans=="L"?"-"+this.width()+"px":"-"+this.height()+"px";var c=b.trans;b.transObjs={nxtA:{"z-index":b.topZ,display:"block",top:"auto",left:"auto",right:"auto",bottom:"auto"},nxtB:{},nxtC:{"z-index":b.midZ},curA:{},curB:{}};b.transObjs.nxtA[b.trans]=b.dist;b.transObjs.nxtB[b.trans]=0;if(b.exit.match(/(top|bottom|left|right)/)){curA={top:"auto",left:"auto",right:"auto",bottom:"auto"};curB={top:"auto",left:"auto",right:"auto",bottom:"auto"};curA[b.exit]=0;curB[b.exit]=b.dist;b.transObjs["curA"]=curA;b.transObjs["curB"]=curB}}var d={"z-index":b.midZ,position:"absolute",display:"none"};d[b.trans]=0;a(this.children()).css(d);a(this.children()[0]).css({"z-index":b.topZ,display:"block"});this.current=0;var e=this;this.fade=function(c){var d=c.children();var e=c.current;var f=e+1>=d.length?0:e+1;a(d[e]).css(b.transObjs.curA);a(d[f]).css(b.transObjs.nxtA);a(d[f]).animate(b.transObjs.nxtB,b.duration,"linear",function(){a(this).css(b.transObjs.nxtC);if(a(this).prev().length>0){a(this).prev().css({display:"none"})}else{a(this).siblings().last().css({display:"none"})}});a(d[e]).animate(b.transObjs.curB,b.duration,"linear");c.current++;if(c.current>=d.length){c.current=0}window.setTimeout(function(){c.fade(c)},b.interval)};window.setTimeout(function(){e.fade(e)},b.interval)}})(jQuery);

