var key = '';
if(top.location.host=='localhost')
	key = 'ABQIAAAA1msWLonPjpoFNqVyH_UiDhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQzHjR0ovcBzZF_8h_qI2FFuMtg3A';
else if(top.location.host=='medexpress.vizualize.com:81')
{
	key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRQlgqCvL7r5vmcrgY0hdly8GwioChRaH05tpBGXl3SZYFcelDks6r0Ang';
	//key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRSlDDJ79CzlZ8osgxTbiI6zJDLbVxQpV2xtgf6IeEZPIB5n7jPNtzsExQ';
}
else if(top.location.host=='medexpress.ctpboston.com')
	key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRTgXsJvLlBO5_UC9q_G5qFIBO_3chR1mmyiPzy39IET2KB9hvwsmOvSuw';
else if(top.location.host=='medexpress.com')
	key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRRGH1T2Dq8n3AREiK6xvAmmO9WM9BRVQMzvmNzM_CDRxfxyyLiXf9D7GQ';
else if(top.location.host=='greatcarefast.com')
	key = 'ABQIAAAAb0ojaEijSjheRtqVKI7wfhR6YaBFtThmn7_1lwquDeU7FS1xtBQ0OhK2zZboAYoYdlLlvNMsZN-eVw';
else if(top.location.host=='www.medexpress.com')
	key = 'ABQIAAAAv8Knl2Cv7shbLEELAWoRVRTfHEd5lJDjWdkmBOTSd8hDu1Mp2RRntguECuobG4J0PZFLETGM_LWLJg';
else if(top.location.host=='66.216.4.18')
	key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRQRKp3qxrNCdn2jtWpbAqleXrCZwxQMeUchexMUDv0PP6TaRW9828GcYw';
else if(top.location.host=='stagingserver')
	key = 'ABQIAAAAiawZwOuHXXKi2UR4YJMHpxTvTdUhvRAlU8CQ4124as71tC0q_BQ0UK133bKnafBVbsIQc221tklP0A';
else if(top.location.host=='stagingserver.medexpress.com')
	key = 'ABQIAAAApSPlTR8gsLUqRmWEeJ4bHRTnXOHdG3ZXgDhagecMAx6YctGy8RRKgKJrY1Z9KVphFk481TeUJCUibA';
	
$(document).ready(function() {
    if (typeof (ie6) != 'undefined') {
        fixIE();
    }
    if (typeof (ie) != 'undefined') {
        $('.bread').corner({
            tl: { radius: 12 },
            tr: { radius: 12 },
            bl: { radius: 12 },
            br: { radius: 12 },
            antiAlias: true,
            autoPad: true,
            validTags: ["div"]
        });
        $('.lnav').corner({
            tl: { radius: 12 },
            tr: { radius: 12 },
            bl: { radius: 12 },
            br: { radius: 12 },
            antiAlias: true,
            autoPad: true,
            validTags: ["div"]
        });
        $('.content').corner({
            tl: { radius: 12 },
            tr: { radius: 12 },
            bl: { radius: 12 },
            br: { radius: 12 },
            antiAlias: true,
            autoPad: true,
            validTags: ["div"]
        });
        $('.box').corner({
            tl: { radius: 10 },
            tr: { radius: 10 },
            bl: { radius: 10 },
            br: { radius: 10 },
            antiAlias: true,
            autoPad: true,
            validTags: ["div"]
        });
        $('#nav ul li ul li:last-child').css('border-bottom','0');
		$('#nav ul li ul li:first-child').css('border-top','0');

    }
    
    if (navigator.appVersion.indexOf("Win")!=-1) {
    	if ($.browser.mozilla)
    	{
    		$('body').css('font-family', '"Helvetica Neue", HelveticaNeue, Arial, Helvetica, sans-serif');
    		$('.featuredBox h2 a').css('letter-spacing', 'normal');
    	}
    }
    
   	if($('#headerimgs').length) {
		var loaded = 0;
		for(x in photos) {
			$('<img />').attr('src', photos[x].image).load(function() {
				if(loaded>1)
				{
					rotate();
				}
				loaded++;
				
			});
		}
	}


    $('.contactForm input:text, .contactForm textarea, .searchbox, #findcenter').focus(function() {
        if (this.value == this.defaultValue)
        { this.value = ''; }
    }).blur(function() {
        if (this.value == '')
        { this.value = this.defaultValue; }
    });

    $('.bread li a').append(" &raquo;");

    if ($('.faq').length) {
        $('.faq h4').click(function() {
            $(this).next('p').slideToggle();
        });
    }

    $('form').submit(function() {
        if (($('#searchbox').val() != 'Search' || $('#findcenter').val() == 'Enter a City and State or Zip')) {
            $('#searchbutton').click();
        }
        else if ($('#findcenter').val()!=null && $('#findcenter').val() != 'Enter a City and State or Zip') {
                $('#findcenterbutton').click();
                return false;
        }
        else if ($('#findDiffCenter').val() != null && $('#findDiffCenter').val() != "Find a different center") {
            FindCenters('findDiffCenter');
            return false;
        }
    });
    
    if($('#searchbox2').length)
    {
    	var query = top.location.pathname;
    	query = query.split('/');
    	query = query[1].split('.');
    	$('#searchbox2').val(query[0]);
    }

    if ($('#map_canvas').length) {

        $.getScript('http://maps.google.com/maps?file=api&async=2&v=2&sensor=false&callback=placeMap&key=' + key);
        $(window).unload(function() {
            GUnload();
        });
    }

    $('a.fancy').fancybox({
        'autoDimensions': true,
        'width': 700,
        'padding': 18,
        'cyclic': true,
        'showNavArrows': false
    });

    $("a[href$=.flv]").each(function() {
        $(this).attr('href', '/flv/p.swf?movie=' + $(this).attr('href'));
    });

    $("a[href$=.flv]").fancybox({
        'type': 'swf',
        'autoDimensions': false,
        'autoScale': false,
        'padding': 18,
        'width': 640,
        'height': 480 + 25,
        'swf': {
            'allowFullScreen': 'true',
            'FlashVars': 'autoload=on&autoplay=on&volume=70'
        }
    });

    $('.fancycenter').fancybox({
        'content': '<form action="/CenterResults.aspx" method="get" id="fancyform"><h3>Find a Center Now</h3><input type="text" value="Enter a City and State or Zip" id="fancyfindcenter" name="s"><input type="button" onclick="FindCenters(\'fancyfindcenter\');" id="fancyfindcenterbutton" value="Go"></form>',
        'width': 230,
        'height': 80,
        'autoDimensions': false,
        'autoScale': false,
        'gotoClick': true,
        'hideOnOverlayClick': false,
        'padding': 0,
        'overlayShow': false,
        'onComplete': function() {
            $('#fancyform').submit(function() {
                if ($('#fancyfindcenter').val() != 'Enter a City and State or Zip') {
                    $('#fancyfindcenterbutton').click();
                }
                return false;
            });
            $('#fancyfindcenter').focus(function() {
                if (this.value == this.defaultValue)
                { this.value = ''; }
            }).blur(function() {
                if (this.value == '')
                { this.value = this.defaultValue; }
            });
        }
    });
    
	/*$('a.confirm').click(function() {
		if(!confirm("You are about to leave MedExpress, is this ok?"))
		{ return false; }
	});*/
	
	if($('.ddlcenter').length)
	{
		var temp = $('.ddlcenter option').clone();
		var selClass = $('.ddlstate option:selected').attr('class');
		$('.ddlcenter option:enabled').detach();
		if(selClass != null && selClass != '')
		{
			$('.ddlcenter').append($(temp).filter('.'+selClass));
			$('.ddlcenter option.pleaseselect').detach();
		}
		
		$('.ddlstate').change(function() {
			selClass = $('.ddlstate option:selected').attr('class');
			$('.ddlcenter option').detach();
			$('.ddlcenter').append($(temp).filter('.'+selClass));
		});
	}
});

function strip(html)
{
	if(html)
		return html.replace(/<.*?>/g, '+');
}


function placeMap() {
	if (GBrowserIsCompatible() && typeof(startlat) != 'undefined') {
		var map = new GMap2(document.getElementById("map_canvas"));
		map.removeMapType(G_HYBRID_MAP);
		map.removeMapType(G_SATELLITE_MAP);
		map.setCenter(new GLatLng(startlat, startlong), 7);
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl3D());
		
		/*var cafeIcon = new GIcon();
		cafeIcon.image = "http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|996600";
		cafeIcon.shadow = "http://chart.apis.google.com/chart?chst=d_map_pin_shadow";
		cafeIcon.iconSize = new GSize(12, 20);
		cafeIcon.shadowSize = new GSize(22, 20);
		cafeIcon.iconAnchor = new GPoint(6, 20);
		cafeIcon.infoWindowAnchor = new GPoint(5, 1);
		// Set up our GMarkerOptions object literal
		markerOptions = { icon:cafeIcon };*/
		var prefix = 'MedExpress | ';
		if(typeof(locations) != 'undefined') {
			var i;
			for (i in locations) {
				var point = new GLatLng(locations[i][0], locations[i][1]);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				if(locations[i][2].indexOf("Doctor")!=-1)
				{
					var thisprefix = '';
				}
				else
				{
					var thisprefix = prefix;
				}
				marker.bindInfoWindowHtml('<div class="marker"><strong>' + thisprefix +locations[i][2]+'</strong><br />'+locations[i][3]+'<br />'+locations[i][4]+'<br /><a target="_blank" href="http://maps.google.com/maps?q='+locations[i][0]+","+locations[i][1]+'">Get Directions</a></div>');
				
				/*var tabs = new Array(
						new GInfoWindowTab('Info','<div class="marker">'+locations[i][2]+'</div>'),
						new GInfoWindowTab('Directions','<div class="marker">'+locations[i][2]+'</div>')
					);
				marker.bindInfoWindowTabsHtml(tabs);*/
			}
		}
		else if(typeof(locationSingle) != 'undefined')
		{
			map.setZoom(12);
			var point = new GLatLng(locationSingle[0], locationSingle[1]);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			if(locationSingle[2].indexOf("Doctor")!=-1)
			{
				prefix = '';
			}
			marker.openInfoWindowHtml('<div class="marker"><strong>' + prefix +locationSingle[2]+'</strong><br />'+locationSingle[3]+'<br />'+locationSingle[4]+'<br /><a target="_blank" href="http://maps.google.com/maps?q='+locationSingle[0]+","+locationSingle[1]+'">Get Directions</a></div>');
		}
	}
}

//Find a center functionality function
function FindCenters(txtSearch) {
    searchText = document.getElementById(txtSearch).value;
    var newURL = "CenterResults.aspx?s=" + searchText;
    window.location = newURL;
}

function ChangeActionPage(txtsearchctl) {

    searchText = document.getElementById(txtsearchctl).value;
    var newURL = "/search.aspx?search=" + searchText;
    form1 = document.getElementById('mainForm');
    if (form1 == null) {
        form1 = document.getElementById('aspnetForm');
    }
    if (form1 != null) {
        form1.setAttribute("action", newURL);
    }
    
}
