// JavaScript Document

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
// JavaScript Document
    // wrap as a jQuery plugin and pass jQuery in to our anoymous function
    (function ($) {
        $.fn.cross = function (options) {
            return this.each(function (i) { 
                // cache the copy of jQuery(this) - the start image
                var $$ = $(this);
                
                // get the target from the backgroundImage + regexp
                var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');

                // nice long chain: wrap img element in span
                $$.wrap('<span style="position: relative;"></span>')
                    // change selector to parent - i.e. newly created span
                    .parent()
                    // prepend a new image inside the span
                    .prepend('<img>')
                    // change the selector to the newly created image
                    .find(':first-child')
                    // set the image to the target
                    .attr('src', target);

                // the CSS styling of the start image needs to be handled
                // differently for different browsers
                if ($.browser.msie) {
            $$.css({
                'position' : 'absolute', 
                'left' : 0,
                'background' : ''
            });
        }

        else if ($.browser.mozilla) {
            $$.css({
                'position' : 'absolute', 
                'left' : 0,
                'background' : '',
                'top' : this.offsetTop
            });
                } else if ($.browser.opera && $.browser.version < 9.5) {
                    // Browser sniffing is bad - however opera < 9.5 has a render bug 
                    // so this is required to get around it we can't apply the 'top' : 0 
                    // separately because Mozilla strips the style set originally somehow...                    
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : '',
                        'top' : "0"
                    });
                } else { // Safari
                    $$.css({
                        'position' : 'absolute', 
                        'left' : 0,
                        'background' : ''
                    });
                }

                // similar effect as single image technique, except using .animate 
                // which will handle the fading up from the right opacity for us
                $$.hover(function () {
                    $$.stop().animate({
                        opacity: 0
                    }, 250);
                }, function () {
                    $$.stop().animate({
                        opacity: 1
                    }, 250);
                });
            });
        };
        
    })(jQuery);
    
    // note that this uses the .bind('load') on the window object, rather than $(document).ready() 
    // because .ready() fires before the images have loaded, but we need to fire *after* because
    // our code relies on the dimensions of the images already in place.
    $(window).bind('load', function () {
        $('img.fade').cross();
    });
 
 //------------------------START functions needed for the Schedule an Appointment drop down ----------------------------------
$(document).ready(function(){
        $('#scheduleApt').click(function(e) {
            e.stopPropagation();
        });
        $(document).click(function() {
			if(state == 1){						   
            	dropDownWindow();
			}
        });
    });


var state = 0;

function dropDownWindow () {

		if(state == 0){
			
			 document.getElementById('scheduleBottom1').style.backgroundImage = 'url(../common/schedule_bottom1B.png)';
			 document.getElementById('scheduleBottom3').style.display = '';
			 document.getElementById('scheduleContent').style.display = '';
			 
			 $('#scheduleBottom2').animate({ height: 400 }, 500, function() {
			// Animation complete.
				});
			 state = 1;
		} else {
			
			 
			 $('#scheduleBottom2').animate({ height: 0 }, 500, function() {
			// Animation complete.
			 document.getElementById('scheduleBottom1').style.backgroundImage = 'url(../common/schedule_bottom1A.png)';
			 document.getElementById('scheduleBottom3').style.display = 'none';
			 document.getElementById('scheduleContent').style.display = 'none';
			 document.getElementById('scheduleSuccess').style.display = 'none';
				});
			state = 0;
		}
}

function scheduleSendMsg() {
	document.getElementById('scheduleBtn').style.display = 'none';
	document.getElementById('scheduleLoading').style.display = '';
	
	nameFirst = document.form69.nameFirst.value;
	nameLast = document.form69.nameLast.value;
	phone = document.form69.phone.value;
	email = document.form69.email.value;
	message = document.form69.message.value;
	conPhone = document.form69.conPhone.checked;
		if(conPhone){ conPhone = 1;} else { conPhone = 0; }
	conEmail = document.form69.conEmail.checked;
		if(conEmail){ conEmail = 1;} else { conEmail = 0; }
	
theUrl = "../common/scheduleSendMsg.php?nameFirst=" + nameFirst + "&nameLast=" + nameLast + "&phone=" + phone + "&email=" + email + "&message=" + message + "&conPhone=" + conPhone + "&conEmail=" + conEmail;

 $.ajax({
  url: theUrl,
  cache: false,
  success: function(html){
 			pageTracker._trackPageview("/scheduleSuccess");
		 $('#scheduleContent').fadeOut('slow', function() {
			  $('#scheduleBottom2').animate({ height: 100 }, 500, function() {											
					$('#scheduleSuccess').fadeIn('slow', function() {
							setTimeout("dropDownWindow()", 1500);
					});
			  });
		 });
	
  }
 });

}
 //------------------------END functions needed for the Schedule an Appointment drop down ----------------------------------
