// JavaScript Document
$(document).ready(function() {
	//Menu desplegable
	theRotator();
	$("#menu ul li ul").hide();	
	$("#menu ul li span.current").addClass("open").next("ul").show();
	$("#menu ul li span").click(function(){	
		$(this).next("ul").slideToggle("slow").parent("li").siblings("li").find("ul:visible").slideUp("slow");
		$("#menu ul li").find("span").removeClass("open");
		$(this).addClass("open");
	});
	
	$("a.switch_thumb").toggle(function(){
	  $(this).addClass("swap"); 
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").addClass("thumb_view"); 
		 });
	  }, function () {
      $(this).removeClass("swap");
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").removeClass("thumb_view");
		});
	}); 						   

			$('#name').keyup(usercheck);
			$('#email').blur(validateEmail);

$("#conle").change(function(){  
         if($(this).is(":checked")){  
		$('#pass2Info').removeClass("error");
		$('#pass2Info').html('<img src="imgcss/ok.png" width="16" height="16" alt="Correcto" /> Acepto las Condiciones legales');

         }else{  
			$('#pass2Info').addClass("error");
			$('#pass2Info').html('<img src="imgcss/cancel.png" width="16" height="16" alt="Cancel" /> Debes Aceptar las Condiciones');
         }  
     });  

});  

function theRotator() {
	$('div#rotatorder ul li').css({opacity: 0.0});
	$('div#rotatorder ul li:first').css({opacity: 1.0});
	setInterval('rotate()',10000);
}
function rotate() {	
	var current = ($('div#rotatorder ul li.show')?  $('div#rotatorder ul li.show') : $('div#rotatorer ul li:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotatorder ul li:first') :current.next()) : $('div#rotatorder ul li:first'));	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
function usercheck(){	
var username = $('#name').val();
if(username == "" || username.length < 4){
		$('#nameInfo').html('<img src="imgcss/cancel.png" width="16" height="16" alt="Cancel" /> Minimo 4 Caracteres');
		$('#name').addClass("error");
}else{

jQuery.ajax({
   type: "POST",
   url: "con_imtv/check.php",
   data: 'username='+ username,
   cache: false,
   success: function(response){
	if(response == 1){
			$('#name').addClass("error");
			$('#nameInfo').html('<img src="imgcss/cancel.png" width="16" height="16" alt="Cancel" /> Usuria ya Creado');
	}else{
			$('#name').removeClass("error");
			$('#nameInfo').html('<img src="imgcss/ok.png" width="16" height="16" alt="Correcto" /> ok..');
	     }
	}

});
}



}
//validation functions
	function validateEmail(){
		//testing regular expression
		var a = $("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			$('#email').removeClass("error");
			//emailInfo.text("Valid E-mail please, you will need it to log in!");
			$('#emailInfo').html('<img src="imgcss/ok.png" width="16" height="16" alt="Correcto" /> ok..');
			$('#emailInfo').removeClass("error");
//		$('#email').css('border', '3px #090 solid');
		
			return true;
		}
		//if it's NOT valid
		else{
			$('#email').addClass("error");
 			$('#emailInfo').addClass("error");
			$('#emailInfo').html('<img src="imgcss/cancel.png" width="16" height="16" alt="Cancel" /> Email No Valido');			
			return false;
		}
	}
