if(typeof console === "undefined") {
	console = { log: function() { } };
}

$(document).ready(function(){

	// REGIONS
	$(".region-list").hide();
	$(".region").click(function(){
		$(this).toggleClass("active").next().slideToggle(0);
	});
	
	// COUNTRY
	$(".country-list").hide();
	$(".country").click(function(){
		$(this).toggleClass("active").next().slideToggle(0);
	});

	// FORM LIGHTBOX
	$(".physician").colorbox({iframe:true, width:502, height:765, scrolling: false, overlayClose: false});
	$(".patient").colorbox({iframe:true, width:502, height:642, scrolling: false, overlayClose: false});
	
	// PRESS LIGHTBOX
	//$(".press").colorbox();
	$("a[rel='mag_oprah']").colorbox();
	$("a[rel='mag_elle']").colorbox();
	$("a[rel='mag_marie']").colorbox();
	$("a[rel='mag_allure']").colorbox();
	$("a[rel='mag_mens']").colorbox();
	$("a[rel='mag_vie']").colorbox();	
	$("a[rel='town_and_country']").colorbox();	
	$("a[rel='w']").colorbox();	
	$("a[rel='elevate']").colorbox();	
	

	// TEAM BIOS
	$('.our-team .bio').wrapInner('<div></div>');
	$("a.team").click(function(){
		
		var bio = $(this).parent().next(".bio");
			
		var summary = $(this).parent();

		if(bio.hasClass('open')) {
			bio.slideUp('fast');
			bio.removeClass('open');
			summary.removeClass('open');
		} else {
			$('p.summary').removeClass('open');
			$('div.bio').slideUp('fast').removeClass('open');
			
			bio.slideDown('fast');
    		bio.addClass('open');
    		summary.addClass('open');
		}
		return false;
  	}); 
		
	// CAROUSELS
	if ($('.carousel-items').length > 0) {
		$(".carousel-items").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev"
		});
	}
	if ($('.carousel-items-alt').length > 0) {
		$(".carousel-items-alt").jCarouselLite({
			btnNext: ".next-alt",
			btnPrev: ".prev-alt"
		});
	}

	// PATIENT THUMBS
	$('.patients ul li a').removeAttr('href');
	$('.patients ul li a').click(
		function() {
			var currentBigImage = $('#photo img').attr('src');
			var newBigImage = $(this).attr('rel');
			switchImage(newBigImage, currentBigImage);
		},
		function() {}
	);
	
	$('.patients ul li a').click(function() {
		$(this).addClass('on');
		$(this).removeClass('off');
		$('.patients ul li a').not(this).addClass('off');
    	$('.patients ul li a').not(this).removeClass('on');
	});

	function switchImage(imageHref, currentBigImage) {
		 
		var theBigImage = $('#photo img');
		
		if (imageHref != currentBigImage) {
		
			theBigImage.fadeOut(250, function(){
				theBigImage.attr('src', imageHref).fadeIn(250);
			});
						
		}
		
	}
	
});
