	  $(document).ready(function(){
	 
	//in 2009siteplugins.asp as well to stop flicker
	$("#conditionSearchPanel").hide();

	if ($("#UE_REFERRER").val() != "Other" && $("#UE_REFERREDFROMOTHER").val() != "Other" && $("#regReferrer").val() != "Other") {
		$("#hiddenref").hide();
	}
	
	if ($('#UE_CORPORATEMEDICAL_YES:checked').val() == null) {
	 $("#hiddenprov").hide();
	}
	
	
	if ($('#UE_REQUEST_TYPE3:checked').val() == null) {
	 $("#hiddenother").hide();
	}
		
	$(".conditionSearchLink").click(function () {
		if (navigator.appVersion.indexOf("MSIE 6.0") > 0) {
			$("select").hide();
		}
		$("#conditionSearchPanel").show();
		$('html, body').animate({scrollTop:0}, 'slow');
    })
	
	$(".closebutton a").click(function () {
		$(this).parent("div").parent("div").parent("div").hide();
		$("select").show();
    })
    
    //var boxHeight = $("#conditionSearchPanel").height();
    var boxWidth = $("#conditionSearchPanel").width();
    //var screenHeight = document.body.clientHeight;
    var screenWidth = document.body.clientWidth;      
    
    var positionLeft = (Math.round(screenWidth/2)) - (Math.round(boxWidth/2));
    //var positionTop = (Math.round(screenHeight/2)) - (Math.round(boxHeight/2));
    
    $("#conditionSearchPanel").css("position", "absolute");
    $("#conditionSearchPanel").css("top", "150px");
    $("#conditionSearchPanel").css("left", positionLeft + "px");
    
    // Removing Non JS Links
    $(".tabbedPanel .headerMenu .tabs a").attr("href","javascript:void(0);");
    $(".conditionSearchLink").attr("href","javascript:void(0);");
	  	
	// Tabbed Panels
	$(".tabbedPanel .headerMenu .tabs a").click(function(){
        $(this).closest(".tabbedPanel").find(".content").children().hide();
        var contentID = $(this).parent().attr("id").replace("Tab","Content");
        $(this).parent().siblings().removeClass("current");
        $(this).parent().addClass("current");
        $("#" + contentID).show();
        $("#" + contentID + " .items li").removeClass("current");
        $("#" + contentID + " .items li:first").addClass("current");
        $("#" + contentID + " .image img").hide();
        $("#" + contentID + " .image img:first").show();
    });
    
    // News and Events Hover
    $(".tabbedPanel .items .hoverable a").mouseover(function(){
        $(".tabbedPanel .items .hoverable a").parent().removeClass("current");
        $(this).parent().addClass("current");
        var imgID = $(this).parent().attr("id").replace("item","image");
        $("#" + imgID).siblings().hide();
        $("#" + imgID).show();
    });
    
	// Accordian
    $(".accordian .panel .content").hide();
    $(".accordian .panel .header a").click(function(){
        var paneldiv = $(this).parent().parent();
        if (paneldiv.find(".content").length > 0) {
            if (paneldiv.hasClass("openpanel")) {
                paneldiv.removeClass("openpanel");
                paneldiv.find(".content").hide();
            } else {
                paneldiv.addClass("openpanel");
                paneldiv.find(".content").show();
            }
        }
    });
    
    /* Input Prompt Text*/
    $("input[type=text]").click(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).css("color","#4c4c4c");
        }
    });
    
    $("input[type=text]").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).css("color","#4c4c4c");
        }
    });
    
    $("input[type=text]").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
            $(this).removeAttr("style");
        }
    });
    
    $("#UE_REFERRER, #UE_REFERREDFROM, #regReferrer").change(function () {
	    if ($(this).val() == "Other") {
		    $("#hiddenref").show("slow");
	    } else {
		    $("#UE_REFERRER_OTHER").attr('value', '');
		    $("#UE_REFERREDFROMOTHER").attr('value', '');
		    $("#regReferrerOther").attr('value', '');
		    $("#hiddenref").hide("slow");
	    }
    });
    
    $("#UE_CORPORATEMEDICAL_YES").click(function () {
		    $("#hiddenprov").show("slow");
    });
    
    $("#UE_CORPORATEMEDICAL_NO").click(function () {
		    $("#UE_INSURANCEPROVIDER").attr('value', '');
		    $("#hiddenprov").hide("slow");
    });
    
    
	var showOther = false;  
	
    $("#UE_REQUEST_TYPE3").click(function () {
	    if (showOther == false) {
		    $("#hiddenother").show("slow");
		    showOther = true;
	    } else {
		    $("#hiddenother").hide("slow");
		    $("#hiddenother textarea").val('');
		    showOther = false;
	    }    
    });
    
    // Video toggling
    $(".changeVideoLink").click(function () {
        
        var videoPath = "/_system/mediafiles/" + $(this).attr("title").toLowerCase().replace(" ","_") + ".flv";
        loadSWF(videoPath, "flash_content");
      
        
    });
    
    // Rotating Images
    $('.rotatingimage').cycle('fade',3000); /* changed to 3 seconds for homepage */
    $('.consultant_rotatingimage').cycle('fade');
    
    // remove blank paragraphs
    $("p").each(function () {
	  if ($(this).html() == '&nbsp;') {
		$(this).hide();
	  }
    });
    $("h2").each(function () {
	  if ($(this).html() == '&nbsp;') {
		$(this).hide();
	  }
    });
    $("h1").each(function () {
	  if ($(this).html() == '&nbsp;') {
		$(this).hide();
	  }
    });
    
    addQuicklinks();
	
	// Tooltips
    $("#siteSelector a").tooltip({
        track: true,
        delay: 250,
        showURL: false,
        fixPNG: true,
        opacity: 0.95,
        left: 15,
        top: 0
    });
    
    
  });
  
  
// Quicklinks function 
function addQuicklinks () {
	var strQuicklinks = '';
	if ($("h2.facilityname").html()) {
		strQuicklinks = addBacktoTops("facility");
	}
	else if ($("h2.consultantname").html()) {
		strQuicklinks = addBacktoTops("consultant");
	}
	else if ($("h2.eventtime").html()) {
		strQuicklinks = addBacktoTops("event");
	}

	if (strQuicklinks != "") {
		$(".quicklinkscontainer").show();
		$(".quicklinks").html(strQuicklinks);
		$(".quicklinks").columnize({columns: 2});
		if ($("h2.eventtime").html()) {
		    $("#eventItemContent").append('<p><a href="#top">Back to top</a></p>');
	    } else {
		    $("#contentarea").append('<p><a href="#top">Back to top</a></p>');
		}
	}
			
	if ($(".pagelinks").html()) {
		strQuicklinks = addBacktoTops("page");
		$("#contentarea").append('<p><a href="#top">Back to top</a></p>');
		$(".pagelinks").html(strQuicklinks);
	}
};

function addBacktoTops (pagetype) {
		var strQuicklinks = '';
		var x = 0;
		$("h2").each(function(i){
			
			if (pagetype == "facility" || pagetype == "consultant" || pagetype == "event") {
				x=2;
			}
			
			if ( !$(this).hasClass("facilityname") && !$(this).hasClass("consultantname") && !$(this).hasClass("quicklink") && !$(this).hasClass("eventtime")) {
				
				if ($(this).html() != '&nbsp;') {
					
					var newheader = '';					
					// add in anchor
					if (i > x) {
						newheader = newheader + '<p><a href="#top">Back to top</a></p>';
					}
					newheader = newheader + '<a name="heading' + i + '"></a><h2>' + $(this).html() + '</h2>';
					var linktext = $(this).html();
					linktext = linktext.replace("<br>","");
					linktext = linktext.replace("<BR>","");
					$(this).replaceWith(newheader);
					
					//build a quicklinks list
					strQuicklinks = strQuicklinks + '<a href="#heading' + i + '">' + linktext + '</a>';
				}
			}
		});
		
		return strQuicklinks;
};


// Bookmark this page (IE ONLY)
function bookmarkpage(pagetitle) {
    var browser = navigator.appName;
    if (browser.indexOf("Microsoft") > -1) {
	    var bookmarktitle = pagetitle;
	    var bookmarkurl = window.location;
	    window.external.AddFavorite(bookmarkurl, bookmarktitle);
    } else {
	    alert("Sorry, this function only works in Internet Explorer");
    }
};

//Locations panel validation

function validateLocationForm(form) {
    with (form) {
        if (region.value == "0") {
            $("#regionValidation").fadeIn("slow");
            $("#regionValidation").animate({
                opacity:1
                }, 1500, function(){
                $("#regionValidation").fadeOut("slow", function() {
                    region.focus();
                });                
            });
            return false;
        } else {
            return true;
        }
    }
}

function validateConsultantForm(form) {

    //prepair the form values for post
    if($("#Surname").val() == $("#Surname").attr("title"))
    {
        $("#Surname").val("");
    }
}

function isObject(targetID){

   var isFound = false;
   var el = document.getElementById(targetID);
   
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
   
      isFound = true;
   
   }
   
   return isFound;
}

function replaceSwfWithEmptyDiv(targetID){

   var el = document.getElementById(targetID);
   
   if(el){
   
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);
 
      //Remove the SWF
      swfobject.removeSWF(targetID);
   
      //Give the new DIV the old element's ID
      div.setAttribute("id", targetID);
      
   }
   
}


function loadSWF(url, targetID){

   //Check for existing SWF
   if(isObject(targetID)){
   
      //replace object/element with a new div
      replaceSwfWithEmptyDiv(targetID);
      
   }
     
   //Embed SWF
   if (swfobject.hasFlashPlayerVersion("7")) {
   
      //var attributes = { data: url, width:"222", height:"167" };
     // var params = {};
      //var obj = swfobject.createSWF(attributes, params, targetID);
      
        var flashvars = new Object();
        flashvars.vidSrc = url; 
        var params = new Object();
        params.wmode = "transparent";
        params.base = "/include";
        var attributes = new Object(); 

      swfobject.embedSWF("/include/flv_player_4_3.swf", "flash_content", "222", "167", "9.0.0", null, flashvars, params, attributes); 
      
      
      
   
   }
   
}

