/*

*/
function fnc_nav_principal_init() {
	$('#nav_principal ul').hide();
	$('#nav_principal li a').click(function() {
		$(this).next().slideToggle('normal');
	});
}


/*

*/
function fnc_nav_principal_show_current() {
	$('#nav_principal li').each(function() {
		if($('a',this).attr('href') == str_section_file + '.php') {
			$(this).parent().show();
		}
	});
}


/*

*/
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}


/*

*/
function fnc_validate_email(str_email) {
	var email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return email_regex.test(str_email);
}


/*

*/
function fnc_hide_element(str_element_id) {
	$(str_element_id).slideUp("fast");
}


/*

*/
function fnc_validar_registro() {
	var fields_validated = 0;
	var fields_to_validate = 10;
	// get variables
	var str_name = $("input#name").val();
	var str_year = $("select#year").val();
	var str_month = $("select#month").val();
	var str_day = $("select#day").val();
	var str_pob = $("input#pob").val();
	var str_address = $("input#address").val();
	var str_telephone = $("input#telephone").val();
	var str_mobile = $("input#mobile").val();
	var str_email = $("input#email").val();
	var str_institution = $("input#institution").val();
	var int_interest = $("input:checked").length; 
	if (str_name != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_year != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_month != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_day != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_pob != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_address != '') {
		fields_validated = fields_validated + 1;
	}
	if (str_telephone != '') {
		fields_validated = fields_validated + 1;
	}
	/*if (str_mobile != '') {
		fields_validated = fields_validated + 1;
	}*/
	if (str_email != '') {
		if (fnc_validate_email(str_email)) {
			fields_validated = fields_validated + 1;
		}
	}
	if (str_institution != '') {
		fields_validated = fields_validated + 1;
	}
	if (int_interest > 0) {
		fields_validated = fields_validated + 1;
	}
	if (fields_validated == fields_to_validate) {
		return true;
	}
	else {
		$('#div_registro_msg').html('<a href="javascript:fnc_hide_element(\'#div_registro_msg\');" class="lnk_registro_msg">Debes llenar todos los campos marcados con *</a>');
		$('#div_registro_msg').slideDown('fast');
		return false;	
	}
}

/*

*/
function fnc_horizontal_scroller(str_item_class) {
	//Get our elements for faster access and set overlay width
	var div = $('div.horizontal_scroller'),
				ul = $('ul.horizontal_scroller'),
				// unordered list's left margin
				ulPadding = 15;
	var divWidth = div.width(); //Get menu width
	div.css({overflow: 'hidden'}); //Remove scrollbars
	var lastLi = ul.find('li:last-child'); //Find last image container
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
}

function fnc_colorbox_next() {
	$.colorbox.next();
}


/*

*/
$(document).ready(function(){
	fnc_nav_principal_init();
	fnc_nav_principal_show_current();
	fnc_horizontal_scroller('horizontal_scroller');
	$('a.colorbox').colorbox({rel:'colorbox', transition:"fade"});
	$(".colorbox_inline").colorbox({rel:"manuales", inline:true, width:"650px"})
});
