jQuery(document).ready(function(){
	
	/* Script navegacion */
	
	var login = 0;
	var id_nav = 0;
	jQuery('#nav ul > li').hover(
	  function(){
	
		  login = !jQuery(this).find('.nav_img').hasClass('no_login') ? 0 : 1;
	
		  if(login){
			  jQuery(this).find('.subnav').css('visibility','hidden');
			  jQuery(this).parents('#nav').find('#content_form').css('visibility','visible');
			  jQuery(this).find('.arrow_nav').show();
			  jQuery(this).find('.nav_img').addClass('over');
			  id_nav = jQuery(this).attr('id');
			  return false;
		  }
	 	  jQuery(this).find('.subnav').css('visibility','visible');
	     jQuery(this).find('.arrow_nav').show();
	     jQuery(this).find('.nav_img').addClass('over');
		  
	  },
	  function(){
		  if(login){
			  jQuery(this).find('.arrow_nav').hide();
	     	  jQuery(this).find('.nav_img').removeClass('over');
			  jQuery(this).parents('#nav').find('#content_form').css('visibility','hidden');
			  return false;
		  }
			  jQuery(this).find('.subnav').css('visibility','hidden');
			  jQuery(this).find('.arrow_nav').hide();
			  jQuery(this).find('.nav_img').removeClass('over');
		  }
	);
	
	$('#content_form').hover(
		function(){
			jQuery(this).css('visibility','visible');
			jQuery('#nav li#' + id_nav).find('.arrow_nav').show();
			jQuery('#nav li#' + id_nav).find('.nav_img').addClass('over');
		},
		function(){
			jQuery(this).css('visibility','hidden');
			jQuery('#nav li#' + id_nav).find('.arrow_nav').hide();
			jQuery('#nav li#' + id_nav).find('.nav_img').removeClass('over');
		}
	);
	
	jQuery('#print').click(function(){
          window.print()
		  return false;
      });
	
	jQuery('.target').attr('target','_blank');
	
	jQuery('a[rel$=\'external\']').attr("target","_blank");
	
	if (jQuery.browser.safari) {
		jQuery('textarea').css('resize', 'none');
		jQuery('input.text').css('resize', 'none');
	}

	jQuery('.list_sidebar li').hover(function(){
	  jQuery(this).find('ul').show();
	},function(){
		jQuery(this).find('ul').hide();
	});
	
	jQuery('#nav_top > li').hover(
		function(){
			jQuery(this).find('a').addClass('over');
			jQuery(this).find('.subnav_level1').show();
		},
		function(){
			jQuery(this).find('a').removeClass('over');
			$(this).find('.subnav_level1').hide();
		}
	);
	
	jQuery('.subnav_level1 > li').hover(
		function(){
			jQuery(this).find('a').addClass('over_sub');
			jQuery(this).find('.subnav_sec').show();
		},
		function(){
			jQuery(this).find('a').removeClass('over_sub');
			$(this).find('.subnav_sec').hide();
		}
	);
	
	$('.subnav_list li a').hover(
		function(){
			$(this).parent('li').find('ul').show();
			$(this).addClass('over_sub');
   	},
		function(){
			$(this).parent('li').find('ul').hide();
			$(this).removeClass('over_sub');
		}
	);
	
	$('.subnav_list ul.subnav_sec').hover(
		function(){
			$(this).show();
			$(this).parent('li').find('a:first').addClass('over_sub');
   	},
		function(){
			$(this).hide();
			$(this).parent('li').find('a:first').removeClass('over_sub');
		}
	);
	
	var cont_index = 0;
	
	$('.subnav_list').each(function(){
		cont_index = $(this).find('ul li.clearfix').length;
		$(this).find('ul li.clearfix').each(function(){
			$(this).css('z-index',cont_index);
			$(this).find('a:first').css('width',$(this).find('a:first').width());
			$(this).find('ul:first').css('left',$(this).find('a:first').width() + 18);
			cont_index = cont_index - 1;
		});
		cont_index = 0;
	})
	
	/* Galeria */
	
	var TotalImages = jQuery('#gallery_box img').length;
	var InfoIni = jQuery('#gallery_box img:first').attr('alt');
	var DescIni = jQuery('#gallery_box img:first').attr('title');
	
	i = 0;
	
	jQuery('#gallery_box img:first').show();
	jQuery('#gallery_info p').html(InfoIni);
	jQuery('#gallery_desc p').html(DescIni);
			
      jQuery('#gallery_box img').each(function (i) {
		 j = i + 1;
		 jQuery('#control').append('<span>' + j + '</span>');
      });
	  
	  jQuery('#control span:first').addClass('active');
	  
	  jQuery('#control span').click(function () {
		varIndex = jQuery(this).eq(i).index();
		$('#gallery_box img').hide();
		$('#gallery_box img').eq(varIndex).fadeIn();
		var Info = $('#gallery_box img').eq(varIndex).attr('alt');
		var Desc = $('#gallery_box img').eq(varIndex).attr('title');
		jQuery('#gallery_info p').html(Info);
		jQuery('#gallery_desc p').html(Desc);
		jQuery('#control span').removeClass('active');
		jQuery(this).addClass('active');
		});
	  
	  // $('.home .list_dotted li').each(function(){
		  // $(this).attr("style","height:"+($(this).find(' .list_left span p').height()+$(this).find('.list_left .meta').height()+$(this).find('.list_left .title_list').height()+10)+'px');
	  // });
	  
	  /* Others */
	  
	  $('#btn_contact_send').click(function(){
	       sendForm('contact_form');
	       return false;
	    });

    function testEnterKey()
    {
      if (event.keyCode == 13)
      {
        event.cancelBubble = true;
        event.returnValue = false;
        Form1.Button2.click();
      }
    }
    
    $('#alumno_login_password').keypress(function(event) {
      if (event.which == '13') {
         $('#alumno_login_button').click();
      }
    });
    
    $('#padre_login_password').keypress(function(event) {
      if (event.which == '13') {
         $('#padre_login_button').click();
      }
    });
    
    $('#personal_login_password').keypress(function(event) {
      if (event.which == '13') {
         $('#personal_login_button').click();
      }
    });

	  $('#alumno_login_button').click(function() {
	       var username = jQuery('#alumno_login_username').val();
	           username = jQuery.trim(username);
	       var password = jQuery('#alumno_login_password').val();
	           password = jQuery.trim(password);
	       if(username!='' && password!=''){
	           $('#form_login_alumno').addAjaxLoader();
	           $.ajax({
	                async: true,
	                type: "POST",
	                url:  RELATIVE_PATH+"ajax/_ajax_login.php",
	                data:  "opc=sendLoginFormAlumno&username="+username+"&password="+password,
	                success: function(data){
	                   if(parseInt(data)==0){
	                       showAlertMessage(txt_wrong_username, 'error', true);
	                   }
	                   else{
	                	   window.location=RELATIVE_PATH+'homes/show/section/12';
	                   }
	                   $('#form_login_alumno').removeAjaxLoader();
	                }
	            });
	      }
	      else{
	    	  showAlertMessage(txt_wrong_username, 'complete los campos requeridos!', true);
	      }
	  });
	  
	  $('#padre_login_button').click(function() {
	       var username = $('#padre_login_username').val();
	       var password = $('#padre_login_password').val();
	       if(username!='' && password!=''){
	           $('#form_login_padre').addAjaxLoader();
	           $.ajax({
	                async: true,
	                type: "POST",
	                url:  RELATIVE_PATH+"ajax/_ajax_login.php",
	                data:  "opc=sendLoginFormPadre&username="+username+"&password="+password,
	                success: function(data){
	                   if(parseInt(data)==0){
	                       showAlertMessage(txt_wrong_username, 'error', true);
	                   }
	                   else{
	                	   window.location=RELATIVE_PATH+'homes/show/section/14';
	                   }
	                   $('#form_login_padre').removeAjaxLoader();
	                }
	            });
	      }
	      else{
	    	  showAlertMessage(txt_wrong_username, 'complete los campos requeridos!', true);
	      }
	  });
	  
	  $('#personal_login_button').click(function() {
	       var username = jQuery('#personal_login_username').val();
	           username = jQuery.trim(username);
	       var password = jQuery('#personal_login_password').val();
	           password = jQuery.trim(password);
	       if(username!='' && password!=''){
	           $('#form_login_personal').addAjaxLoader();
	           $.ajax({
	                async: true,
	                type: "POST",
	                url:  RELATIVE_PATH+"ajax/_ajax_login.php",
	                data:  "opc=sendLoginFormPersonal&username="+username+"&password="+password,
	                success: function(data){
	                   if(parseInt(data)==0){
	                       showAlertMessage(txt_wrong_username, 'error', true);
	                   }
	                   else{
	                	   window.location=RELATIVE_PATH+'homes/show/section/15';
	                   }
	                   $('#form_login_personal').removeAjaxLoader();
	                }
	            });
	      }
	      else{
	    	  showAlertMessage(txt_wrong_username, 'complete los campos requeridos!', true);
	      }
	  });
	  
	  $('#btn_logout').click(function() {
	         $.ajax({
	            async: true,
	            type: "POST",
	            url:  RELATIVE_PATH+"ajax/_ajax_login.php",
	            data:  "opc=logout",
	            success: function(){
	               window.location=RELATIVE_PATH;
	            }
	        });
	    });


// HOME SLIDE

	$('#slideshow-div').rsfSlideshow({
		interval: 10,
		transition: 500,
		controls: {
			index: {
				auto: true,
				active_class: 'rs-active'
			}
		}
	});
	
	txtArrey = [];
	
	$("ol.slides li span").each(function(){
		txtArrey.push($(this).html());
	});

	$(".rs-controls a").each(function(){
		$(this).click(function() {
			click = $(this).text();
			$('#gallery_desc').html( txtArrey[click-1] );
		});
	});

	$('#slideshow-div').bind('rsPreTransition', function(slide) {
		slideItem = $('.rs-active').text();
		$('#gallery_desc').html( txtArrey[slideItem-1] );
	});

});
