$(document).ready(function(){
	$("a.tipped img[title]").tooltip({effect: "fade",opacity: 0.9});
	//$("area[title]").tooltip({effect: "fade",opacity: 0.9});
	$("#scroller").scrollable({circular: true,speed: 2000}).autoscroll({ autoplay: true });
});

$(document).ready(function() {
    //Tooltips
    $(".tip_trigger").hover(function(){
        tipName = "#"+$(this).attr('rel');
        tip = $(tipName);
        tip.show(); //Show tooltip
    }, function() {
        tip.hide(); //Hide tooltip
    }).mousemove(function(e) {
        var mousex = e.pageX + 20; //Get X coodrinates
        var mousey = e.pageY + 20; //Get Y coordinates
        var tipWidth = tip.width(); //Find width of tooltip
        var tipHeight = tip.height(); //Find height of tooltip

        //Distance of element from the right edge of viewport
        var tipVisX = $(window).width() - (mousex + tipWidth);
        //Distance of element from the bottom of viewport
        var tipVisY = $(window).height() - (mousey + tipHeight);

        if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
            mousex = e.pageX - tipWidth - 20;
        } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
            mousey = e.pageY - tipHeight - 20;
        }
        //Absolute position the tooltip according to mouse position
        tip.css({  top: mousey, left: mousex });
    });
});

$(document).ready(function() {
  if ( $(".userEmail").length ) {
      // variables, which will be replaced
      var at = ' AT ';
      var dot = ' DOT ';
      // function, which replaces pre-made class
      $('.userEmail').each(function () {
        var addr = $(this).text().replace(at, '@').replace(dot, '.');
        $(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
        $(this).remove();
      });
    }
});

$(document).ready(function(){
	$('ul.filter a').click(function() {
		$('ul.filter .current').removeClass('current');
		$(this).parent().addClass('current');

		var filterVal = $(this).text().toLowerCase();
		
        switch(filterVal)
        {
            case 'clarus lifesciences i, l.p.':
                filterVal = 'fundi';
                break;
            case 'clarus lifesciences ii, l.p.':
                filterVal = 'fundii';
                break;
            case 'diagnostics & tools':
                filterVal = 'diagnostics-tools';
                break;
            case 'medical device':
                filterVal = 'medical-device';
               break;
        }

		if(filterVal == 'all') {
			$('ul.portfolio li.hidden').removeClass('hidden');
		} else {
			$('ul#portfolio li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).addClass('hidden');
				} else {
					$(this).removeClass('hidden');
				}
			});
		}
		return false;
	});
});

$(document).ready(function(){
	$('#slideshow').bxSlider({
		mode: 'fade',
    	captions: true,
    	auto: true,
    	controls: false
	});
});

$(document).ready(function(){
	$("a[rel]").overlay({
		mask: {
			color: '#fff',
			loadSpeed: 200,
			opacity: 0.7
		},
	});
});

$(document).ready(function() {
	$('h6 a').click(function() {
		$('.collapse').toggle(400);
		return false;
	});
	$('h6 a.filterA').click(function() {
		$('.collapseA').toggle(400);
		return false;
	});
	$('h6 a.filterB').click(function() {
		$('.collapseB').toggle(400);
		return false;
	});
	$('h6 a.filterC').click(function() {
		$('.collapseC').toggle(400);
		return false;
	});
	$('h6 a.filterD').click(function() {
		$('.collapseD').toggle(400);
		return false;
	});
	$('h6 a.filterE').click(function() {
		$('.collapseE').toggle(400);
		return false;
	});
});

$(document).ready(function(){
    var name = $('#teamMemberName').text().toLowerCase();
    
    $('.subnav .wrap ul').each(function () { 
        var found = false;
        $(this).find('li').each(function () {
            if(name.indexOf($(this).find('a').text().toLowerCase()) != -1) {
                $(this).addClass('current');
                found = true;
            }
        }); 
        
        if(found) {
            $(this).attr("style", "display: block");
        }       
    });
});
