
$('document').ready(function(){

	$('.square li,.circle li').prepend('&#8226;&nbsp;');

	// ie7 hack	
	act=0;
	if($.browser.msie&&$.browser.version=='7.0'){
		$('.contentHeader').css({paddingTop:'5px'});
		$('.slidePaso').css({top:'-13px',paddingBottom:'0px'});
		$('.contInfoSlide:eq(1),.contInfoSlide:eq(1)').hide();
	}
	
	$('.conHand').live('mouseover mouseout', function(event) {
		if($.browser.msie&&$.browser.version=='7.0'){
			if(event.type == 'mouseover'){
				a=$('.conHand').index(this);
				$('.conHand').each(function(e){if(a!=act){$(this).next().find('div,img').fadeOut(300);}});
				$('.conHand').eq(a).next().find('div,img').fadeIn(300);
				act=a;
			}else{}
		}
	});
	
	// Validar formulario contacto 
	$('.valid').live('click',function(){
		var tForm = $(this).parents('form');
		var tReq = tForm.find('.must');
		tReq.parent().removeClass('error');
		tReq.each(function(){if (($(this).attr('type') == 'checkbox' && !$(this).is(':checked')) || $(this).val()=='' || $(this).attr("title")==$(this).val() || ($(this).attr('name')=='email' && !checkEmail($(this).val()))) $(this).parent().addClass('error'); });
		if (tReq.parent().hasClass('error')) return !$('.contentOk p.error').fadeIn();
		tForm.submit();
	});
   
	function checkEmail(d){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return filter.test(d);
	}

	if (enviado) {
		$.fn.colorbox({html:'<p style="margin:0 0 31px 25px;">'+enviado+'</p>', open:true});
	}

	$(".colorbox").colorbox({
		onComplete:function(){
			$('#mycarousel').jcarousel();
			if($.browser.msie){
				a=$('#mycarousel li').width();
				$('#mycarousel li img').css('width',a+'px');	
			}
		},
		scrolling:false
	});

	/* Abrimos enlaces en pagina nueva validando xHTML Strict */
	$('.newpage').click(function(e){
		e.preventDefault();
		window.open($(this).attr("href"));
		return false;
	});

// Ancla by Cedric Dugas *** http://www.position-absolute.com ***
	anchor = {
		init : function() {
			$("a.anchorLink").click(function () {
			elementClick = $(this).attr("href");
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
			return false;
		});
		}
	}

    // Efecto campos formulario
	$("input").live('click',function(){if($(this).attr("title")==$(this).val())$(this).val("");});
	$("input").live('blur',function(){if(!$(this).val())$(this).val($(this).attr("title"));});
	$(".comment").click(function(){if($(this).attr("title")==$(this).val())$(this).val("");});
	$(".comment").blur(function(){if(!$(this).val())$(this).val($(this).attr("title"));});

	// Efecto paso de input a password
    $('.password-clear').live('focus',function() {
        $('.password-clear').hide();
        $('.pass').show();
        $('.pass').focus();
    });
    $('.pass').live('blur',function() {
        if($('.pass').val() == '') {
            $('.password-clear').show();
            $('.pass').hide();
        }
    });

	/* Imprimir pagina */
	$('#imprimir').click(function(){
		window.print();
		return false;
	});
	
	/* Validar usuarios */
	
	$('#login').live('submit',function(){
		$.post('inc/validar.php',{user:$('#user').val(),pass:$('#password').val()}, function(rdata){
			if (rdata == 'error') {
				return !$('#login p.error').fadeIn();
			}
			return window.location.href='index.php';
		});
		return false;
	});
	
	/* Logout */
	
	$('.logout').click(function(){
		$.post('inc/validar.php',{logout:true}, function(rdata){
			if (rdata == 'logout') {
				return window.location.href='index.php';
			}
		});
		return false;
	});
	
	
	/* Loginbox */
	
	$('.loginbox a').live('click',function(){
		return !$.fn.colorbox.next();
	});
	
	/* Nuevo usuario */
	
	$('#newuser').live('submit',function(){
		$.post('inc/newuser.php',{login:$('#login').val(),password:$('#password').val(),email:$('#email').val()}, function(rdata){
			return !$('h4.msg').html(rdata);
		});
		return false;
	});
	
	
	/* Nuevo post */
	
	$('.showWritePost').live('submit',function(){
		$.post('inc/newitem.php',{action:'post',name:$('#postName').val(),forum:$('#forumId').attr('class')}, function(rdata){
			$('p.msg').html(rdata);
			$('.showWritePost').delay(2000).slideUp();
			return !location.reload(true);
		});
		return false;
	});
	
	/* Nuevo comentario */
	
	$('.showWriteComment').live('submit',function(){
		$.post('inc/newitem.php',{action:'comment',text:$('#commentText').val(),postID:$('#postId').attr('class'),forum:$('#fId').attr('class')}, function(rdata){
			$('p.msg').html(rdata);
			$('.showWriteComment').delay(2000).slideUp();
			return !location.reload(true);
		});
		return false;
	});
	
	/* Eliminar */
	
	$('.deleteItem').click(function(){
		var iteID = this.id.split('-');
		var action = iteID[0];
		var id = iteID[1];
		if (confirm('Está seguro?')){
			$.post('inc/deleteitem.php',{action:action,id:id}, function(rdata){
				$('p.msg').html(rdata);
				return !location.reload(true);
			});
		}
		return false;
	});

	// Efecto acordeon cabecera home
	$(".test4").hrzAccordion({eventTrigger:"mouseover",openOnLoad:"1",handlePositionArray: "left,left,right,right,right"});

// Efecto ocultar y mostrar escribir comentario.
    $('.writeComment, .writePost').click(function(e){
	   $('p.msg').html('');
	   $('.showWritePost textarea').val('Post*');
       $('.showWriteComment textarea').val('Comentario*');
	   e.preventDefault();
	   $('.showWriteComment, .showWritePost').slideToggle(500);
        return false;
    });

// Mostrar imagen grande al hacer click en el carousel de showroom //
	$('.jcarousel-item img').live('click',function(){
		var bigsrc = $(this).attr('src');
		var bigcont = $('.bigImage img');
		$('.jcarousel-item img').css('border','none');
		$(this).css('border','1px solid #ccc');
		if (bigcont.attr('src') != bigsrc) {
			bigcont.fadeOut(100, function(){$(this).attr('src',bigsrc).fadeIn(500);});
		}
		return false;
	});

// Efecto mostrar politica privacidad en registro
	$('.showLopd').live('click',function(){
		$('.lopd').slideToggle('fast', function(){
			return !$.fn.colorbox.resize();
		});
	});
	
// Pestañas

	$('.juegoPest li a').click(function(){
		$('.juegoPest li a').removeClass('select');
		$(this).addClass('select');
		$('.tab').hide();
		return !$('.'+this.id).fadeIn('slow');
	});

	return false;
	
// Recaptcha clean

}); /* End DOMReady */

var RecaptchaOptions = {
   theme : 'clean'
};
