$(function()
{
	$('#mod-latest-news').jScrollPane();
	$('#box-larga-cont').jScrollPane();
	$('#not-int-box').jScrollPane();
	$('#hist-cont-texto-izq').jScrollPane();
	$('#hist-cont-texto-der').jScrollPane();
	$('#pil-cont-texto').jScrollPane();
	$('#pil-int-cont-texto').jScrollPane();
	$('#prot-cont-texto').jScrollPane();
	$('#zona-com-cont-texto').jScrollPane();
	$('#mod-events-description').jScrollPane();
	$('#mod-events-tickets-scroll').jScrollPane();
	/*$('#mod-events-map-scroll').jScrollPane();*/
	$('#mod-events-shedule-scroll').jScrollPane();
	$('#carr-int-scroll-prog-medios').jScrollPane();
	$('#tech-cont-texto').jScrollPane();
	$('#tech-cont-glossary').jScrollPane();
	$('#ninos-cont-texto').jScrollPane();

	$("#search").placeHolder({
		"text"           : "Buscar",
		"active"         : "#DDD",
		"placeholder"    : "#989898"
	});
	
	$('#carrusel-bandera-larga').jcarousel({
		scroll: 4,
		animation: 'slow',
		auto: 10,
		wrap: 'both'
	});
	
	$('#tech-banderas').jcarousel({
		scroll: 3,
		animation: 'slow',
		auto: 10,
		wrap: 'both'
	});
	
	$('#pilotos-carrusel').jcarousel({
		scroll: 5,
		animation: 'slow',
		auto: 10,
		wrap: 'both'
	});
	
	$("a.galeria-fotos").colorbox({
		rel:'galeria-fotos',
		opacity:0.6,
		current: "{current} de {total}",
		previous:"Siguente",
		next:"Anterior",
		close: "X"
	});
	
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
});

$(document).ready(function() {
	$("#login_").click(function () {
		if ($("#mod_loginform").is(":hidden")) {
			$("#mod_loginform").slideDown("slow");
		} else {
			$("#mod_loginform").slideUp("slow");
		}
	});
	$(".cerrar").click(function () {
		if ($("#mod_loginform").is(":hidden")) {
			$("#mod_loginform").slideDown("slow");
		} else {
			$("#mod_loginform").slideUp("slow");
		}
	});
});



function showContent(divID){
	
	if($("#"+divID).css("display") == "none"){
		$("#"+divID).show("fast");
	}
	else{
		$("#"+divID).hide("fast");
	}
}




function slideUpRacingCalendar(){
	
	slide_distance = 60; 
	slide_limit = rcalitems - 3;
	
	if(slide_limit >= rcalcurr_item ){
		$("#events-calendar-list-events-container").animate({"top": "-="+slide_distance+"px"}, "slow");
		rcalcurr_item = rcalcurr_item + 1;
	}
	
}


function slideDownRacingCalendar(){
	
	slide_distance = 60;
	slide_limit = 2;
	
	if(slide_limit <= rcalcurr_item ){
		$("#events-calendar-list-events-container").animate({"top": "+="+slide_distance+"px"}, "slow");
		rcalcurr_item = rcalcurr_item - 1;
	}
	
}



function loadCalendarItem(itemID, version){
	
	$("#events-calendar-lead").fadeOut("fast");
	
	$.post("modules/mod_carrera_home/loadCalendarItem.php", { itemID: itemID, version: version }, 
				function(data){ 
						
						$("#events-calendar-lead").replaceWith(data);
						$("#events-calendar-lead").hide();
						$("#events-calendar-lead").fadeIn("fast");
								
				});
	
}


/*********************************
* Multimedia Functions
*********************************/

function mmhViewTab(tab){
	
	if(tab == "pictures"){
		$("#mmh-videos").hide();
		$("#mmh-pictures").fadeIn("slow");
		$("#mmh-tab-picture").addClass("selected");
		$("#mmh-tab-video").removeClass("selected");
	}
	else{
		$("#mmh-pictures").hide();
		$("#mmh-videos").fadeIn("slow");
		$("#mmh-tab-picture").removeClass("selected");
		$("#mmh-tab-video").addClass("selected");
	}
	
}



function mmvViewItem(itemID){
	
	$('html,body').animate({scrollTop: 212}, 1000);
	
	$.post("modules/mod_multimedia/view-item.php", { itemID: itemID}, 
				function(data){ 
						
						$("#mmv-details").replaceWith(data);
						$("#mmv-details").height($("#mod-multimedia-view").height() + 50);
						$("#mmv-details").hide();
						$("#mmv-details").fadeIn("fast");
								
				});
	
	
}


function mmvCloseItem(){
	$("#mmv-details").fadeOut("fast");
}
