$(function() { 
	
	$("#slideshow-content").cycle({
			fx:     'scrollHorz',
			timeout: 10000,
			cleartype:  1, cleartypeNoBg: true // enable cleartype corrections 
	});
	
	$('a#back-to-top').click(function() { //smooth scroll to top button
		$.scrollTo(0, 800);
		return false;
	});
	
	// $('a.watch-now').click(function() { //video lightbox
	// 	$('#hidden-video').lightbox_me({centered: true});
	// 	return false;
	// });

	set_current_class();
	
	correct_main_nav_hover();
	
	if($('body').hasClass('parent-pageid-24') || $('body').hasClass('parent-pageid-17')) {
		procedures_sub_nav();
	}

});

function correct_main_nav_hover() {
	/**
	 * check if li currently hovered on is current, 
	 * if not find current li and remove current class
	 */
	$('#main-nav li').hover(function() {
		if(!$(this).hasClass('current')) {
			$('#main-nav li.current').removeClass('current');
		}
	});
	/**
	 * make sure that one li always has a current class style 
	 * after hover() and susequent mouseleave()
	 */
	$('#main-nav li').mouseleave(function() {
		set_current_class();
	});
}

function set_current_class(){
	$(current_li()).addClass('current');
}

function current_li(){
	var page = $('#var_for_js').html().replace(/^\s+|\s+$/g,"");
	var li;
	if(page=='2') {
		li=	"li.second";
	} else if(page=='24') {
		li=	"li.third";
	} else if(page=='17') {
		li=	"li.fourth";
	} else if(page=='470') {
		li=	"li.fifth";	
	} else if(page=='20') {
		li=	"li.sixth";
	} else{
		li="li.first";
	}
	return '#main-nav '+li;
}

function procedures_sub_nav() {		
	/**
	 *	get pathname and break it up by '/' to get the current page slug
	 */
	var pathname = window.location.pathname;
	var path_parts = pathname.split('/');
	var this_page = path_parts[path_parts.length - 2];
	
	/**
	 *	determine which section the current page is in
	 */
	var p_index = pathname.indexOf("procedures/");
	var ba_index = pathname.indexOf("before-and-after/");
	
	/**
	 *	determine video and before-and-after paths based on the current page path
	 */
	if(p_index > 0) {
		var b_a_path = pathname.replace('procedures/','before-and-after/')
	} else if(ba_index > 0) {
		var b_a_path = window.location.pathname;
	}
	
	var before_and_after_link = '<li><a href="' + b_a_path + '">Before & After</a></li>';
	
       if( (pathname.indexOf("breast-lift") > 0) || (pathname.indexOf("breast-augmentation") > 0) ) {
           var links = '';
	} else {
           var links = '<ul class="procedures-links">' + before_and_after_link  + '</ul>';
       }
       
	$('#sidebar #subnav ul li.current_page_item a').after(links);			
	
	if(ba_index > 0) {
		$('#sidebar #subnav ul li.current_page_item ul li:first-child').addClass('current_page_item');
		$('#sidebar #subnav ul li.page_item.current_page_item > a').css('background','none');
	}
}
