$(document).ready(function(){
	$.preloadCssImages();
	if(($.browser.msie) && ($.browser.version > 7)) {
		$('#hmImg1').delay(2000).animate({
			opacity: 1
		  }, 4000, function() {
			$(this).fadeOut('slow');		
			$('#hmImg2').animate({
				opacity: 1
			  }, 5000, function() {
					$('#hmImg2').fadeOut('slow');					
					$('#hmImg3').animate({opacity: 1}, 7000, function(){});		
			  });
		});
		$('#hmImg2Text').hide();
		$('#hmImg3Text').hide();		
		$('#hmImg1Text').delay(2000).animate({
			opacity: 1
		  }, 4000, function() {
			$(this).fadeOut('slow');
			$('#hmImg2Text').show();
			$('#hmImg2Text').animate({
				opacity: 1
			  }, 5000, function() {
					$('#hmImg2Text').fadeOut('slow');
					$('#hmImg3Text').show();
					$('#hmImg3Text').animate({opacity: 1}, 7000, function(){});		
			  });
		});
	}
	else{
		$('#hmImg1').delay(2000).animate({
			opacity: 1
		  }, 4000, function() {
			$(this).fadeOut('slow');
			$('#hmImg2').animate({
				opacity: 1
			  }, 5000, function() {
					$('#hmImg2').fadeOut('slow');
					$('#hmImg3').animate({opacity: 1}, 7000, function(){});		
			  });
		});
		
		$('#hmImg1Text').delay(2000).animate({
			opacity: 1
		  }, 4000, function() {
			$(this).fadeOut('slow');
			$('#hmImg2Text').animate({
				opacity: 1
			  }, 5000, function() {
					$('#hmImg2Text').fadeOut('slow');
					$('#hmImg3Text').animate({opacity: 1}, 7000, function(){});		
			  });
		});
	}
	
	$('#footer').css("height","20px");
	
	$("#footer").hover(
			  function () {
				  $(this).stop(true);
				  $(this).animate({
					    height: '196px'
				   }, 200, function() {
				   			});
			  }, 
			  function () {
				  $(this).stop(true);
				  $(this).animate({
					    height: '20px'
				   }, 600, function() {
				   			});
			    
			  }
			);
	
	 var curntPage = $('#footerCurntPage').text();
	 $('#footer .bottom-bar .pagesNavigation li').each(function(){
		if($(this).children().attr("title") == curntPage){			
			$('#footer .bottom-bar .pagesNavigation ul li').removeClass("activePage");
			$(this).addClass("activePage");
		}
	});
	
	if(jQuery.jScrollPane) { 
		jQuery('.ourPhilosophy .mainContent, .ourLab .mainContent ').jScrollPane({scrollbarWidth:14, scrollbarMargin:20, dragMaxHeight:100});
		jQuery('.nyuLectures').jScrollPane({scrollbarWidth:14, scrollbarMargin:200, dragMaxHeight:200});				
	}
	
	// Coding for methodology page
	$('.navElem').click(function(){
		var elemId = $(this).attr("id");
		elemId = "#"+elemId+"Page";		
		$('.methodPage').fadeOut(1000);
		$(elemId).fadeIn(1000);
	});	
	// End code for Methodology
	
	// Code for Register Page
	if(jQuery().validate)
	{
		$('#dentistRegisterForm').validate({
			 errorLabelContainer: "#errorMsgBox",
			 wrapper: "li",			 
			 highlight: function(element, errorClass) {
			 $(element).css({'border':'2px dashed red', 'background':'#FFF3D2'});
		  	 }
		});
    }	
	// End Code for Register Page
	
	// Code for Our Dentists Page
	if(jQuery().validate)
	{
		$('#searchDentist').validate({
			 errorLabelContainer: "#errorMsgBox",
			 wrapper: "li",			 
			 highlight: function(element, errorClass) {
			 $(element).css({'border':'2px dashed red', 'background':'#FFF3D2'});
		  	 }
		});
    }	
	// End Code for Our Dentists Page
	
	// Code for Oral Design Foundation
	
	var timeoutID = window.setTimeout(OdfAnimation, 3000);
	
	function OdfAnimation(){
		$('#slidePage1 .firstLine').animate({opacity: 0}, 500, function(){});
		$('#slidePage1 .secondLine').delay(500).animate({opacity: 0}, 500, function(){});
		$('#bgImg').delay(1000).fadeOut(500,function(){
			$('.slidePage').hide();
			var slideBg = $('#slidePage2 img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");
			var imgSrc = $('#logoGray').attr("src");
			$('#logo a img').attr("src",imgSrc);
			$('#slidePage2').show();
			$(this).fadeIn(1000).show();
		});
		
		$('#slidePage2 .firstLine').delay(3500).animate({opacity: 0}, 500, function(){});
		$('#slidePage2 .secondLine').delay(4000).animate({opacity: 0}, 500, function(){});
		$('#bgImg').delay(3000).fadeOut(500,function(){
			$('.slidePage').hide();
			var slideBg = $('#slidePage3 img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");
			var imgSrc = $('#logoWhite').attr("src");
			$('#logo a img').attr("src",imgSrc);
			$('#slidePage3').show();
			$(this).fadeIn(1000).show();			
		});
		
		$('#slidePage3 .firstLine').delay(6500).animate({opacity: 0}, 500, function(){});
		$('#bgImg').delay(2000).fadeOut(500,function(){
			$('.slidePage').hide();
			var slideBg = $('#slidePage4 img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");
			var imgSrc = $('#logoGray').attr("src");
			$('#logo a img').attr("src",imgSrc);
			$('#slidePage4').show();			
			$(this).fadeIn(1000).show();
		});
		
		$('#slidePage4 .firstLine').delay(9500).animate({opacity: 0}, 500, function(){});
		$('#slidePage4 .secondLine').delay(10000).animate({opacity: 0}, 500, function(){});
		$('#bgImg').delay(3000).fadeOut(500,function(){
			$('.slidePage').hide();
			slideBg = $('#section1Page img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");
			$('#section1Col').addClass('active');
			$('#section1Page').show();
			$(this).fadeIn(1000).show();			
		});	
		
	}// end of OdfAnimation
	
	$('#section1Col').click(function(){
		$("div").stop(true);
		$('#section2Col').removeClass('active');
		$(this).addClass('active');
		$('#bgImg').fadeOut(500,function(){
			$('.slidePage').hide();				
			$('#section2Page').hide();
			slideBg = $('#section1Page img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");			
			$('#section1Page').show();
			$(this).fadeIn(1000).show();
		});				
	});
	
	$('#section2Col').click(function(){
		$("div").stop(true);
		$('#section1Col').removeClass('active');
		$(this).addClass('active');
		$('#bgImg').fadeOut(500,function(){
			$('#section1Page').hide();
			$('.slidePage').hide();				
			slideBg = $('#section2Page img').attr("src");
			$('#bgImg').css("background-image", "url("+slideBg+")");			
			$('#section2Page').show();
			$(this).fadeIn(1000).show();
		});	
	});
	// End Code for Oral Design Foundation
	
	
	//Code for Before and After Section
	var timeOutId = window.setTimeout(BaAnimation, 3000);
	
	function BaAnimation(){
		$('#wrapper #BAslide1 .leftText1, #wrapper #BAslide1 .rightText').fadeOut(200);
		$('#wrapper #BAslide1 .leftText2').delay(800).fadeIn(200);
		$('#wrapper #BAslide1 .textBox').delay(1000).fadeOut(200);
		$('#wrapper #BAslide1').delay(2500).fadeOut(500);
		$('#wrapper #BAslide2').delay(3000).fadeIn(500);
		$('#wrapper #BAslide2 .topText').delay(4000).fadeIn(500);
		$('#wrapper #BAslide2 .bottomText').delay(4500).fadeIn(500);
		$('#wrapper #BAslide2').delay(4000).fadeOut(500);
		$('#wrapper #BAslide3').delay(4500).fadeIn(500);
		$('#wrapper #BAslide3 .descText').delay(9000).fadeIn(500);
		$('#wrapper #BAslide3').delay(6000).fadeOut(500);
		$('#wrapper .BAmainContainer').delay(6500).fadeIn(500);
		$('#wrapper .BAmainContainer .pageTitle').delay(12000).fadeIn(500);
		$('#wrapper .BAmainContainer #BaGroup1').delay(13000).fadeIn(500);
		$('#wrapper .BAmainContainer #BaGroup2').delay(13500).fadeIn(500);
		$('#wrapper .BAmainContainer #BaGroup3').delay(14000).fadeIn(500);
		$('#wrapper .BAmainContainer #BaGroup4').delay(14500).fadeIn(500);
		$('#wrapper .BAmainContainer #BaGroup5').delay(15000).fadeIn(500);		
	}
	
	$('.PGButton').click(function(){
		clearTimeout(timeOutId);
		$('.imgProgress span').text("1");
		Cufon.refresh();
		$("#wrapper .BAslides").clearQueue().fadeOut(1000,function(){
			$(this).hide();
			$('#wrapper .BAmainContainer').delay(500).fadeIn(500);
			$('#wrapper .BAmainContainer .pageTitle').delay(1000).fadeIn(500);
			$('#wrapper .BAmainContainer #BaGroup1').delay(1500).fadeIn(500);
			$('#wrapper .BAmainContainer #BaGroup2').delay(2000).fadeIn(500);
			$('#wrapper .BAmainContainer #BaGroup3').delay(2500).fadeIn(500);
			$('#wrapper .BAmainContainer #BaGroup4').delay(3000).fadeIn(500);
			$('#wrapper .BAmainContainer #BaGroup5').delay(3500).fadeIn(500);
		});				
	});
	
	$('#wrapper .BaGroupSection .infoHeader .PGButton').click(function(){
		$('.BaGroupSection').fadeOut(500);
		$('.imgSet').hide();
		$('#BaMainPage').delay(500).fadeIn(1000);	
	});
	
	$('.BaGroup').click(function(){
		var id = $(this).attr("id");
		id = "#"+id+"Section";
		$('#wrapper .BaGroupSection .infoHeader .imgPrev').hide();
		$('#BaMainPage').fadeOut(500,function(){
			var imgSet = id+" .content .imgSet1";
			$(id).fadeIn(500, function(){
				$(imgSet).fadeIn(500,function(){
					$('#wrapper .BaGroupSection .infoFooter').fadeIn(200);
					var imgSetStr = id+" .content .imgSet";
					if($(imgSetStr).length > 0){
						$('#wrapper .BaGroupSection .infoHeader .imgNext').show();
					}
				});
			});
		});		
	});
	
	$('#wrapper .BaGroupSection .infoHeader .imgNext').click(function(){
		var idnum = $('.imgSet').filter(":visible").attr("class").split(" ")[0].substring(6);
		idnum++;
		var newClass = "."+"imgSet"+idnum;
		var countId = $(this).parent().parent().attr("id");
		var statusId ="#"+countId+" .imgProgress span";		
		countId = "#"+countId+" .content";
		var size = $(countId).find(".imgSet").size();
		$(statusId).text(idnum);
		Cufon.refresh();
		$('.imgSet, .infoFooter').fadeOut(500);		
		$(newClass).delay(1500).fadeIn(500);
		$('.infoFooter').delay(1500).fadeIn(500);
		$('.imgPrev').delay(1500).fadeIn(500);		
		if(idnum == size){
			$('.imgNext').hide();
		}
		else{
			$('.imgNext').show();
		}							
	});
	
	$('#wrapper .BaGroupSection .infoHeader .imgPrev').click(function(){
		var idnum = $('.imgSet').filter(":visible").attr("class").split(" ")[0].substring(6);
		idnum--;
		var newClass = "."+"imgSet"+idnum;
		var countId = $(this).parent().parent().attr("id");
		var statusId ="#"+countId+" .imgProgress span";		
		countId = "#"+countId+" .content";
		var size = $(countId).find(".imgSet").size();
		$(statusId).text(idnum);
		Cufon.refresh();
		$('.imgSet').fadeOut(500);		
		$(newClass).delay(1500).fadeIn(500);
		$('.imgNext').delay(1500).fadeIn(500);		
		if(idnum == 1){
			$('.imgPrev').hide();
		}
		else{
			$('.imgPrev').show();
		}	
	});
	
	//End Code for Before and After Section
	
	//Code for Press Releases
	
	$('#newsPageNext').click(function(){
		$('#newsPagePrev').show();
		var leftVal = $('#newsPage1').css('left').replace(/[^-\d\.]/g, '');		
		if(leftVal >= -840){
			$('#newsPage1').animate({
				left: '-=840'		    
				}, 500, function() {
		    // Animation complete.
			});
		
			$('#newsPage2').animate({
				left: '-=840'		    
				}, 500, function() {
		    // Animation complete.
			});
			
			$('#newsPage3').animate({
				left: '-=840'		    
				}, 500, function() {
		    // Animation complete.
			});
		}
		if(leftVal == -840){
		  $(this).hide();
		}
	});
	
	$('#newsPagePrev').click(function(){
		$('#newsPageNext').show();
		var leftVal = $('#newsPage3').css('left').replace(/[^-\d\.]/g, '');
		console.log(leftVal);
		if(leftVal <= 840){	
			$('#newsPage1').animate({
				left: '+=840'		    
			}, 500, function() {
		    // Animation complete.
			});
			
			$('#newsPage2').animate({
				left: '+=840'		    
			}, 500, function() {
		    // Animation complete.
			});
			
			$('#newsPage3').animate({
				left: '+=840'		    
			}, 500, function() {
		    // Animation complete.
			});
		}
		if(leftVal == 840){
		  $(this).hide();
		}
	});
	
	// End code for Press Release
	
	
	//Code for Testimonials
		$('#testmNav .testmTitle').delay(1000).animate({ opacity: 1}, 500, function(){});	
		$('#testm1').delay(1500).animate({ opacity: 1}, 500, function(){});
		$('#testm2').delay(1700).animate({ opacity: 1}, 500, function() { });
		$('#testm3').delay(1900).animate({ opacity: 1}, 500, function() { });
		$('#testm4').delay(2100).animate({ opacity: 1}, 500, function() { });
		$('#testm5').delay(2300).animate({ opacity: 1}, 500, function() { });
		$('#testm6').delay(2500).animate({ opacity: 1}, 500, function() { });
		$('#testm7').delay(2700).animate({ opacity: 1}, 500, function() { });
		
		$('.testmLink').click(function(){
			var id= $(this).attr('id');
			var pageNum = parseInt((id.substring(5)));
			id = "#"+id.substring(0,5) + "Page" + id.substring(5);
			var varBgUrl = $(id).find("img").attr("src");
			$('#testmNav').fadeOut(500,function(){
				$('#testmBgImg').fadeOut(500,function(){
					$(this).css("background-image", "url("+varBgUrl+")");
					$(this).fadeIn(500,function(){
						if(pageNum!=1){
							$('.testmPage #testmBgImg .single-block .testmPage .testmArea .testmNav .testmPrev').show();
						}
						
						if(pageNum!=7){
							$('.testmPage #testmBgImg .single-block .testmPage .testmArea .testmNav .testmNext').show();
						}
						$(id).fadeIn(500);
					});
				});
			});				
		});
		
		$('.testmPage #testmBgImg .single-block .testmPage .testmArea .testmNav .testmPrev').click(function(){
			var idnum = $(this).parent().parent().parent().attr('id');
			var curPage = "#"+idnum;
			$(curPage).fadeOut(500).hide();
			idnum = parseInt(idnum.substring(9));
			idnum--;
			var id = "#testmPage"+idnum;
			var varBgUrl = $(id).find("img").attr("src");
			$('#testmBgImg').fadeOut(500,function(){
				$(this).css("background-image", "url("+varBgUrl+")");
				$(this).fadeIn(500,function(){
					$(id).fadeIn(500);
				});
			});
		});
		
		$('.testmPage #testmBgImg .single-block .testmPage .testmArea .testmNav .testmNext').click(function(){
			var idnum = $(this).parent().parent().parent().attr('id');
			var curPage = "#"+idnum;
			$(curPage).fadeOut(500).hide();
			idnum = parseInt(idnum.substring(9),10);
			idnum++;
			var id = "#testmPage"+idnum;
			var varBgUrl = $(id).find("img").attr("src");
			$('#testmBgImg').fadeOut(500,function(){
				$(this).css("background-image", "url("+varBgUrl+")");
				$(this).fadeIn(500,function(){
					$(id).fadeIn(500);
				});
			});
		});
	//End Code for Testimonials
		
	//Code for Lecture Schedule
		$('#navNyu').click(function(){
			if(!($(this).hasClass("active"))){
				$('.intLecturesBlock, .ppLecturesBlock').fadeOut(500);
				$('.nyuLecturesBlock').fadeIn(500);
				$(this).addClass("active");
				$('#navInt, #navPP').removeClass("active");
			}
		});
		
		$('#navInt').click(function(){
			if(!($(this).hasClass("active"))){
				$('.nyuLecturesBlock, .ppLecturesBlock').fadeOut(500);
				$('.intLecturesBlock').fadeIn(500,function(){
					$('.intLectures').jScrollPane({scrollbarWidth:14, scrollbarMargin:200, dragMaxHeight:200});	
				});
				//jQuery('.intLectures').jScrollPane({scrollbarWidth:14, scrollbarMargin:200, dragMaxHeight:200});	
				$(this).addClass("active");
				$('#navNyu, #navPP').removeClass("active");
			}
		});
		
		$('#navPP').click(function(){
			if(!($(this).hasClass("active"))){
				$('.intLecturesBlock, .nyuLecturesBlock').fadeOut(500);
				$('.ppLecturesBlock').fadeIn(500);
				$(this).addClass("active");
				$('#navInt, #navNyu').removeClass("active");
			}
		});
		
	//End Code for Lecture Schedule	
		
	// Code for Contact Us Page		
		if(jQuery().validate)
		{
			$('#contactPageForm').validate({
				 errorLabelContainer: "#errorMsgBox",
				 wrapper: "li",			 
				 highlight: function(element, errorClass) {
				 $(element).css({'border':'2px dashed red', 'background':'#FFF3D2'});
			  	 }
			});
	    }
	// End Code for Contact Us Page	
	
		
	
	//Code for Case Studies
		$('.case-pgl-menu li').click(function(){
			Cufon.refresh();			
		});	
		
	// End Code for Case Studies	
}); //End Of Ready;
$(window).load(function() {
/*Check URL parameter 'showId' and load appropriate ID */
	var showIdName = '#'+getURLParameter('showId');	
	jQuery(showIdName).trigger('click');
	
	/*end Check URL parameter 'showId' and load appropriate ID */
if(jQuery.jScrollPane) {
	jQuery('.ppLectures').show().jScrollPane({scrollbarWidth:14, scrollbarMargin:200, dragMaxHeight:200});
}
});

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}
