// JavaScript Document
$(document).ready(function(){
						   
//PRELOAD IMAGES						   
var preloadImages = ['images/background-nav-full-active.gif','images/last-in-nave-menu-active.gif','images/banner-nav-ul-bg-full.png','images/sholder-image-active.jpg','images/knee-image-active.jpg'];
var imgs = [];
for (var i=0; i<preloadImages.lenght; i++){
	imgs[i] = new Image();
	imgs[i].src = preloadImages[i];
}

//HOME PAGE
$(".hiddentext").hide();

$("#readmore").live('click', function(){ 
	$(".hiddentext").slideDown("fast");	
	$(this).hide();
	return false;
});


//FADING CYLE
if($("#banner div").hasClass("slideshow")){	
	$('.slideshow').cycle({
				fx: 'fade',
				pager: '#scrollnav div',
				activePagerClass: 'active',
				pagerAnchorBuilder: function(idx, slide) {
				  ++idx;
				
				  return '<a href="#"><span>'+idx+'</span></a>';
   		}
	});
}//END OF IF STATMENT
			
			//FADE OUT
		    $('#quotesliderContainer').cycle({
				fx: 'fade'
			});



//SCROLLABLE

	$(".scrollable").scrollable({ circular: true, speed:600})
	.autoscroll({interval:6000,autoplay:true})
	.navigator({navi:"#scrollnav div"});

	$("#scrollnav div a").each(function(i){
		i++;	
		$(this).html("<span>"+ i +"</span>");
	});
	
//DROPDOWN

//** HOVER MENU **/
	var megaConfig = {
     interval: 50,
     sensitivity: 4,
	  over: addMega,
	 timeout: 200,
     out: removeMega
    };

$("li.mega").hoverIntent(megaConfig);


$('.submenu li.activeslide').toggle(function(){
	$(this).find('ul').slideDown();
	$(this).children('a').addClass("active");
  }, function(){
	$(this).find('ul').slideUp();
	$(this).children('a').removeClass("active");
});

$('.submenu li ul a').click(function(event){
 	event.stopImmediatePropagation();
});



///ABOUT US
$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		if($("#"+trgt).offset()){
			var target_offset = $("#"+trgt).offset();
			var target_top = target_offset.top;
		}
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
});


//MEDIA
	// setup button action. it will fire our overlay 
	var videobox = $("#overlay1").overlay({
			
			
		
			// some mask tweaks suitable for modal dialogs
			mask: {
				color: '#fff',
				opacity: 0.7
			},
		
	
			// when overlay is opened, load our player
			onLoad: function() {
				 
			},
			
			// when overlay is closed, unload our player
			onClose: function() {
				$f().unload();
			}
			
			
		}).data("overlay");
				
	
	$(".video").click(function(){
		var thishref = $(this).attr("href");
		//flowplayer(".player","_lib/swf/flowplayer-3.2.7.swf").ipad();
		var player = $f("player", "_lib/swf/flowplayer-3.2.7.swf",{
			// clip properties 
			clip: {url:thishref}
		}).ipad();
		videobox.load();	
		return false;		
	});	

///////////FORM SHIT

$("#requesttform").submit(function(){
		
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		var phone = $("#phone").val();
		var email = $("#email").val();
		//GET RADIO BUTTON
		var appointmenttype = $(".appointmenttype:checked").val();
		var requireconsultation = "";
		
		$(".checkboxform").each(function(){
			if($(this).is(':checked')){
				requireconsultation +=$(this).val();
				requireconsultation +=", ";
			}
				
		})
		
		
		var comments = $("#comments").val();
		
		var emailok = validate(email);	
		
		if((emailok==true) && (email != "")){
		
		var data = {firstname:firstname, lastname:lastname, phone:phone, email:email, appointmenttype:appointmenttype, requireconsultation:requireconsultation, comments:comments}
		
		//XML HERE
			$.ajax({
					type: "POST",
					url: "ajax/request.php",
					data: data,
					dataType: "json",
					success: function(data){
					  	if(data["error_msg"] =="0"){
							$("#msg").html("<strong>Your request has been sent. </strong> One of our representative will contact you as soon as possible. Thank you!").show();
							$(".error").hide();
							$("#firstname").val("");
							$("#lastname").val("");
							$("#email").val("");
							$("#phone").val("");
							$("#comments").val("");
							$(".checkboxform").attr('checked', false);
						
						}else{
						$(".error").html("<strong class='error'>Please provide a valid email</strong>").show();
						}
					}//SUCCESS ENDS
			});//END OF AJAX CALL
		}else{
			$(".error").html("<strong class='error'>Please provide a valid email</strong>").show();
		}
		//SEE IF THERE IS A VALUE SEND 
		
	return false;
});


var overlayapi = $(".signuppopup").overlay({
			mask: {
					// you might also consider a "transparent" color for the mask
					color: '#000',
			
					// load mask a little faster
					loadSpeed: 200,
			
					// very transparent
					opacity: 0.4,
					
					onBeforeLoad: function() {
							$("#msg").hide();
							$(".error").hide();
							$("#firstname").val("");
							$("#lastname").val("");
							$("#email").val("");
							$("#phone").val("");
							$("#comments").val("");
							$(".checkboxform").attr('checked', false);
					}
				}				
	}).data("overlay");

	
	
$(".popupforms").overlay({
			mask: {
					// you might also consider a "transparent" color for the mask
					color: '#000',
			
					// load mask a little faster
					loadSpeed: 200,
			
					// very transparent
					opacity: 0.4
			}				
});


$('.intoverlay').live('click', function() {
	overlayapi.load();
	return false;
});


///FIND TOOLTIP WORDs


//ALL THE ARRAYS
var AcromionBoneArray =['Acromion Bone','A feature on the shoulder blade that forms the highest point on the shoulder and is square in shape.'];

var AllograftArray =['Allograft','The transplant of an organ or tissue from one individual to another of the same species.'];

var AnteriorCruciateLigamentArray = ['Anterior Cruciate Ligament (ACL)','A ligament that connects the lower end of the thigh bone to the top of the lower leg bone.']; 

var ArthritisArray = ['Arthritis', 'The inflammation of one or more joints that result in pain, swelling, stiffness and limited movement.'];

var ArthroscopicSurgeryArray =['Arthroscopic Surgery','A minimally invasive surgical procedure in which an examination and sometimes treatment of damage of the interior of a joint is performed using an arthroscope, a type of endoscope that is inserted into the joint through a small incision.'];

var BoneSpurArray =['Bone Spur','A bony growth that forms on normal bone as the body tried to repair itself by building extra bone in response to pressure, rubbing or stress that continues over a long period of time.'];

var BursitisArray =['Bursitis','A painful condition that affects the small fluid-filled pads (bursae) that act as cushions among the bones and the tendons and muscles near the joints. Bursitis occurs when a bursa becomes inflamed'];

var ImpingementSyndromeArray =['Impingement Syndrome','A painful condition that affects the small fluid-filled pads (bursae) that act as cushions among the bones and the tendons and muscles near the joints. Bursitis occurs when a bursa becomes inflamed'];

var TendonopathyArray =['Tendonopathy','A painful condition that affects the small fluid-filled pads (bursae) that act as cushions among the bones and the tendons and muscles near the joints. Bursitis occurs when a bursa becomes inflamed'];

var CartilageArray =['Cartilage','Smooth, white tissue that covers the ends of bones where they come together to form joints. It allows the bones to glide over each other with very little friction.'];

var ChondroitinArray =['Chondroitin','Joint supplement that helps reduce osteoarthritis pain.'];

var CryocuffArray =['Cryocuff','A device that combines the therapeutic benefits of controlled compression to minimize swelling, and cold to minimize pain after surgery.'];

var DeltoidArray =['Deltoid','A muscle located in the shoulder.'];

var DiscoidMeniscusArray =['DiscoidMeniscus','An abnormally shaped meniscus in the knee that a patient is born with, which is more prone to injury.'];

var FemoralNerveBlockArray =['Femoral Nerve Block',' An injection of a local anesthetic into the groin that is usually used for operations on the knee.'];

var GlenoidArray =['Glenoid','Bone that comprises the socket portion of the shoulder.'];

var GlucosamineArray =['Glucosamine','Joint supplement that helps reduce osteoarthritis pain.'];

var HamstringArray =['Hamstring','The group of muscles that run along the back of the thigh.'];

var LabrumArray =['Labrum','A rim of cartilage on the shoulder joint.'];

var MagneticResonanceImagingArray =['Magnetic Resonance Imaging (MRI)','A medical imaging technique used in radiology to visualize detailed internal structures to identify problems such as injuries inside the body.'];

var MeniscectomyArray =['Meniscectomy','The surgical removal of all or part of a torn meniscus - a common knee joint injury.'];

var MeniscusArray = ['Meniscus', 'The wedge-shaped piece of cartilage that acts as a "shock absorber" between the thighbone and shinbone. It protects the cartilage that covers the ends of the bones and helps the knee to easily bend and straighten.'];

var OsteochondritisArray =['Osteochondritis Dissecans (OCD)','A joint condition in which a piece of cartilage, along with a thin layer of the bone beneath it, comes loose from the end of a bone. It is caused by a reduced blood flow to the end of a bone and most often occurs in young men after a joint injury.'];

var OsteotomyArray =['Osteotomy','A surgical procedure where a bone is realigned. This causes a shift in weight from an area where there is damaged cartilage to an area where there is more or healthier cartilage.'];

var PatellarArray =['Patellar Tendon','A tendon that connects the top of the shin bone to the bottom of the kneecap. It works with the muscles in the front of the thigh (quadriceps) to straighten the leg.'];

var PathologyArray =['Pathology','Diagnosis and/or disease.'];

var PectoralisArray =['Pectoralis Major','A thick, fan-shaped muscle, located at the chest. It makes up the bulk of the chest muscles in the male and lies under the breast in the female.'];

var RotatorCuffArray = ['Rotator cuff', 'The network of four muscles and several tendons that form a covering around the top of the upper arm bone (humerus). The rotator cuff holds the humerus in place in the shoulder joint and enables the arm to rotate.'];

var SubacromialArray =['Subacromial Bursa','A small, fluid-filled sac that lies between the rotator cuff and the under-surface of the acromion bone in the shoulder.'];

var TendonitisArray =['Tendonitis','The inflammations of tendons in the body.'];

var ViscoArray =['Visco-supplementation','The injection of a fluid, such as hyaluronic acid, to supplement or replace the natural synovial fluid in the knee joint.'];



//ALL TAGS IN ONE BIG ARRAY

var allwordstofind = [AcromionBoneArray,AllograftArray,AnteriorCruciateLigamentArray,ArthritisArray,ArthroscopicSurgeryArray,BoneSpurArray,BursitisArray,ImpingementSyndromeArray,TendonopathyArray,CartilageArray,ChondroitinArray,CryocuffArray,DeltoidArray,DiscoidMeniscusArray,FemoralNerveBlockArray,GlenoidArray,GlucosamineArray,HamstringArray,LabrumArray,MagneticResonanceImagingArray,MeniscectomyArray,MeniscusArray,OsteochondritisArray,OsteotomyArray,PatellarArray,PathologyArray,PectoralisArray,RotatorCuffArray,SubacromialArray,TendonitisArray,ViscoArray];



tooltipstuff(allwordstofind);



//////////POST _ SURGERY SECTION

$(".findcontent").click(function(){
				  $(".sidemenu li").removeClass("active");
				  $(this).parent("li").addClass("active");
					var $newcontent="";
					var titleneed = $(this).text();
					var url = $(this).attr("href");
				    var parts = url.split("#!");
				    var $idneeded = parts[1];
					//$("#postsurgeryloadcontent").fadeOut("fast");
				    $.ajax({
						type: "GET",
						url: "xml/post-surgery-content.xml",
						
						success: function(xml) {
						  $(xml).find('topic').each(function(){
						  		var id = $(this).attr('id');
								if(id==$idneeded)
									$newcontent = $(this).find('text').text();
							});<!--END OF XML-->
						 $("#postsurgeryloadcontent").html($newcontent).fadeIn("slow");
						 $("#titletochange").text(titleneed);
						 Cufon.replace('.title',{fontFamily:'tradebold',letterSpacing:"-1.5px"});
						 tooltipstuff(allwordstofind);
						 $(".email[title]").tooltip({
							cancelDefault: true,
							 effect: 'slide',
							 offset:[16, 0],
							onShow: function() {
							},
							onHide: function(){
							}
						});<!-- END OF TOOL TIP -->
						 
					 }<!--END OF SUCCESS-->
					
					});<!--END OF AJAX-->
					
					$.history.load(this.href.replace(/^.*#/, ''));
					
					return false;
			});

//INT 
		if($("body").hasClass('postsurgery')){
				  	var newsubtiltename;
					var $newcontent;
					var url =	document.location.href;
					var parts = url.split("#!");
					var $idneeded = parts[1];
					 if($idneeded !=""){
						 
						 $(".link").each(function(){
								 if($(this).attr("href")==("#!"+$idneeded)){
										newsubtiltename = $(this).text();
										$(".sidemenu li:first").removeClass("active");
										 $(this).parent().addClass("active");
								}
						  });
						 
						 $.ajax({
								type: "GET",
								url: "xml/post-surgery-content.xml",
								success: function(xml) {
									  $(xml).find('topic').each(function(){
											var id = $(this).attr('id');
											if(id==$idneeded)
												$newcontent = $(this).find('text').text();
										});<!--END OF XML-->
									 	$("#postsurgeryloadcontent").html($newcontent).fadeIn("slow");
										$("#titletochange").text(newsubtiltename);
										Cufon.replace('.title',{fontFamily:'tradebold',letterSpacing:"-1.5px"});
										 tooltipstuff(allwordstofind);
										 $(".email[title]").tooltip({
											cancelDefault: true,
											 effect: 'slide',
											 offset:[16, 0],
											onShow: function() {
											},
											onHide: function(){
											}
										});<!-- END OF TOOL TIP -->
									
								 }<!--END OF SUCCESS-->
								
							});<!--END OF AJAX-->
						}//End of if
				}//LAST IF



///////////////////FOOTER STUFF
$.addthis();

$("#privacy").click(function(){
	openlink();
	
	return false;
	
});


//TESTIMAOLS
$("#quotesliderContainer").click(function(){
	window.location = "about-us.php#testimonials"
});




}); // end of ready() function




////////////////////*FUNCTIONS*/




//FOR HOVER
function addMega(){
 	$(this).find(".submenu").slideDown("fast");
}
function removeMega(){
	$(this).find(".submenu").slideUp("fast");
}

/*******************FOR EMAIL */
/////FUNCTION FOR EMAIL CHECK
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
	  return true;
	}
}


///POPUP
function openlink(){	
	myRef = window.open('disclaimer.html','mywin',
'left=20,top=20,width=960,height=800,toolbar=0,resizable=0');
}



////////////TOOL TIP CONTENT
function tooltipstuff(allwordstofind){

//LOOP ARRAYS
$("p").each(function(){
	_str_msg = $(this).html();
	
	$.each(allwordstofind, function(key, value) {
	 	var wordtowrap = allwordstofind[key][0];
		var contenttofillitwith = allwordstofind[key][1];

		//REGEXP FOR ALL
		reg = new RegExp('\\b' + wordtowrap + '\\b' , 'i');
		
		_str_msg = _str_msg.replace(reg, function($1){
          	return('<a class="dynaimctag" rel="'+ key +'">'+$1+'</a>');
		});
		
		
	 });//END OF EACH
		
	$(this).html(_str_msg);

});



//PLACE IT ON THE STUFF THAT NEED IT
$(".dynaimctag").each(function(){
		$(this).addClass("email");
		var key = $(this).attr("rel");
		$(this).attr("title","<div>"+allwordstofind[key][1]+"</div>");		
});




/////TOOLTIPS
$(".email[title]").tooltip({
			cancelDefault: true,
			 effect: 'slide',
			 offset:[16, 0],
			onShow: function() {
			},
			onHide: function(){
			}
});


}//endoffunction search




