function carrusel_initCallback(carousel) {
    jQuery('.feat_right_arrow').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('.feat_left_arrow').bind('click', function() {
        carousel.prev();
        return false;
    });
};

$(document).ready(function() {
	$(".parent").corner();
	$(".parentNews").corner();
	$(".search_injuries").corner();
	
	/* Round Corner */
	//$("#footer").corner("cc:#B4D8E8 tl tr");
	$(".subitem").prepend("- ");
	$('.prettyVideo').prettyPhoto({
		show_title: false
	});
	$('.lightbox').prettyPhoto({
		animation_speed: 'fast',
		slideshow: false,
		autoplay_slideshow: false,
		opacity: 0.80,
		show_title: false,
		allow_resize: false,
		counter_separator_label: '/',
		theme: 'facebook',
		modal: false,
		overlay_gallery: true,
		keyboard_shortcuts: true
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'fast',
		slideshow: false,
		autoplay_slideshow: false,
		opacity: 0.80,
		show_title: false,
		allow_resize: false,
		counter_separator_label: '/',
		theme: 'facebook',
		modal: false,
		overlay_gallery: true,
		keyboard_shortcuts: true
		
	});
	//$("a[rel^='prettyVideo']").prettyPhoto();
	
	if ($.browser.msie){
		$("#banner_left_section object").attr('width', '245');
	}
	
	if (($.browser.msie) && (jQuery.browser.version == "6.0")){
		$(".header_img").attr("src", "/img/logo.gif");
		$(".phone_img").attr("src", "/img/phone.gif");
		$(".submit input").attr("src", "/img/send.gif");
	}
	
	if ($.browser.safari){
		$("#banner_left_section object").attr('width', '245');
	}
	
	$('.swap_img').hover(function(){
		var t = $(this);
		src = t.attr('src');
		var newImg = src.substring(src.lastIndexOf('/'), src.lastIndexOf('.')) + '-hover.png';
                var newSrc = src.substring(0,src.lastIndexOf('/')) + newImg;
		t.attr('src', newSrc);
	}, function(){
		var t = $(this);
		src = t.attr('src');
		var newImg = src.substring(src.lastIndexOf('/'), src.lastIndexOf('.')-6) + '.png';
                var newSrc = src.substring(0,src.lastIndexOf('/')) + newImg;
		t.attr('src', newSrc);
	});
	
	$('.corporativo ul li:first').addClass('first-item');
	$('.corporativo ul li:last').addClass('last-item');
		
	$('#items_content li:first').next().addClass('active');
	$('ul#box_center_cont > li').hide();
	$('ul#box_center_cont > li:first').next().show();
	$('.box_center').removeClass('bg_lesiones');

	$('#items_content li a').click(function(){
		$('#items_content li').removeClass('active');
		$(this).parent('li').addClass('active');
		var current = $(this).attr('href');
		var target = current.split('#') 
		showContent(target[1]);
		$('.box_center').removeClass('bg_lesiones');
		if ( target[1] == 'lesiones'  ){
			$('.box_center').addClass('bg_lesiones');	
		}
		return false;
	});
	
	var subspecialities = ["columna", "pie", "rodilla", "cadera", "mano", "hombro", "codo"];
	var randomKey = (Math.floor(Math.random()*7));
	
	$('.sub_hit .line_ind').hide();
	//$('.sub_columna > .line_ind').show();
	$('.sub_'+subspecialities[randomKey]+' > .line_ind').show();
	$('.content_sub').hide();
	//$('.cont_columna').show();
	$('.cont_'+subspecialities[randomKey]).show();
	$('.sub_hit > span').show();
	//$('.sub_columna > span').hide();
	$('.sub_'+subspecialities[randomKey]+' > span').hide();
	
	$('.sub_hit > span').click(function(){
		var nose = $(this).parent().attr('class');
		var split = nose.split('sub_hit sub_')
		//alert(split[1]);
		$('.content_sub').hide();
		$('.cont_'+split[1]).fadeIn(300);
		$('.sub_hit > .line_ind').hide();
		$(this).next('.line_ind').show();
		$('.sub_hit > span').show();
		$(this).hide();
	});
	
	$("#carrusel").jcarousel({
		scroll: 1,
		auto: 8,
		animation: 'fast',
		vertical: false,
		wrap: 'circular',
		initCallback: carrusel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	$(".gal_video").live('click',function(){
		var video_id = $(this).attr('rel');
		var video_image = $(this).attr('rel2');
		var is_vimeo = $(this).attr('rel3');
		var link = '';
		if(is_vimeo == 1){
			link = 'http://vimeo.com/'+video_id;
		}
		if(is_vimeo == 0){
			link = 'http://www.youtube.com/watch?v='+video_id;
		}
		$(".video_content a").attr('href', link);
		$("image_play").parent().attr('href', link);
		$(".video_content a.video_view").children().attr('src', video_image);
		$(".image_video_active").removeClass("image_video_active").addClass("image_video");
		$(this).removeClass("image_video").addClass("image_video_active");
		
	});
	
});

function showContent(activo){
	if (!$('#cont_'+activo).is(':visible')){
		$('ul#box_center_cont > li').fadeOut(150);
		$('#cont_'+activo).delay(150).fadeIn(150);
	}
}
