var oa={
	tabDefTop:'-50px',
	tabDownTime:300,
	tabUpTime:400,
	modalDownTime:600,
	modalUpTime:400,
	panelUpTime:600,
	panelDownTime:500,
	ajaxData:'',
	ajaxTarget:'',
	ajaxFadeInTime:400,
	ajaxAction:null,
	curObject:null,
	tabName:null
};

oa.showTrans=function(num){num==1?$('#trans').show():$('#trans').hide();}

oa.tabFunction=function(obj){
	oa.showTrans(1);
	$('#modal').css({top:-1*$('.oaModal').height(),left:.5*($(window).width()-$('.oaModal').width())}).animate({top:0},oa.modalDownTime,function(){
		oa.ajaxData='tabCall&tab='+$(obj).attr('id');
		oa.ajaxTarget='#modalContent';
		oa.ajaxAction=1;
		oa.ajax();
		oa.tabName=$(obj).attr('id');
	});
}

oa.panelFunction=function(num){
	oa.showTrans(1);
	var x='PHP';
	if(num==2)
		x='DATABASES';
	else if(num==3)
		x='ACTIONSCRIPT';
	else if(num==4)
		x='JAVASCRIPT';
	$('.brownContent h1').html(x+'<br/><span class="negro3">Resources & Samples</span>');
	$('#content').css({top:$('.pie').height()-50,left:.5*($('.pie').width()-$('.oaModal').width())}).animate({top:$('.pie').height()-$('#content').height()},oa.panelUpTime,function(){
		oa.ajaxData='panelCall&panel='+num;
		oa.ajaxTarget='#panelContent';
		oa.ajaxAction=1;
		oa.ajax();
	});
}

oa.closeModal=function(num){
	oa.showTrans(0);
	if(num==1){
		$('#modal').animate({top:-1*$('.oaModal').height()},oa.modalUpTime,function(){
			$('#modalContent').html('');
		});
	}
	else if(num==2){
		$('#content').animate({top:$('#body').height()},oa.panelDownTime,function(){
			$('#panelContent').html('');
		});
	}
}

oa.detailResource=function(str){
	window.open(httpServer+str,'_blank');
}

oa.sendMail=function(obj){
	var x=0;
	var y;
	$('.myInput').each(function(i){
		if($.trim($(this).val())==''){
			x++;
			$('.bgColor').eq(i).css({backgroundColor:'#ffc'});
			$('.alert').eq(i).show();
			if(x==1)
				y=i;
		}
		else{
			$('.bgColor').eq(i).css({backgroundColor:'#fff'});
			$('.alert').eq(i).hide();
		}
	});
	if(x>0){
		$('.mandatory').eq(y).focus();
	}
	else{
		if(!validarEmail($('#email').val())){
			$('.validate').show();
			$('.bgColor').eq(1).css({backgroundColor:'#ffc'});
			$('#email').focus();
		}
		else{
			$(obj).attr('disabled','disabled');
			oa.curObject=obj;
			$('.loader').show();
			oa.ajaxData='sendMessage'+serializarClase('myInput');
			oa.ajaxTarget='#panelContent';
			oa.ajaxAction=2;
			oa.ajax();
		}
	}
}

oa.ajax=function(){
	$.ajax({
		type:'POST',
		url:'php/ajax.php',
		data:'type='+oa.ajaxData,
		success:function(msg){
			if(oa.ajaxAction==1){
				$(oa.ajaxTarget).html(msg);
				if(oa.tabName=='news')
					$.getScript('js/oaScrollbar.js');
				$('.modalContent').fadeIn(oa.ajaxFadeInTime);
			}
			else if(oa.ajaxAction==2){
				if(msg=='OK'){
					alert('Your message was sent..\nThanks!');
					oa.closeModal(1);
				}
				else{
					alert("ERROR - System can't send your message\nTry it again later.."+msg);
					$(oa.curObject).removeAttr('disabled');
					$('.loader').hide();
				}
			}
		}
	});
}
//contact
function contactMe(str){
	alert(str)
	if(str=='skype')
		$('#aSkype').trigger('click');
}

//generics
function validarEmail(str){var regex=/^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gob|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;return regex.test(str);}
function encoder(str){/* just replace next symbols: @ * / + */var neo=str;neo=neo.replace(/\@/g,'vo_signo_arroba');neo=neo.replace(/\*/g,'vo_signo_por');neo=neo.replace(/\//g,'vo_signo_entre');neo=neo.replace(/\+/g,'vo_signo_mas');return neo;}function serializarClase(nombreClase){var serie='';$('.'+nombreClase).each(function(){serie+='&'+$(this).attr('id')+'='+escape(encoder($.trim($(this).val())));});return serie;}function addZero(num){if(num<10){return '0'+num;}else{return num;}}

$(function(){
	$('.oaTab').each(function(){
		$(this).mouseover(function(){
			$(this).animate({top:0},oa.tabDownTime);
		});
		$(this).mouseout(function(){
			$(this).animate({top:oa.tabDefTop},oa.tabUpTime)
		});
		$(this).click(function(){
			oa.tabFunction(this);
		});
	});
	$('.verImagen').live('mouseover',function(){
		var x=$(this).attr('title');
		$('#oaThumb img').attr('src','imagenes/screenshot_'+x+'.jpg');
		$('#oaThumb').css({top:-1*$('#oaThumb').height(),left:.5*($(window).width()-$('#oaThumb').width())}).show().animate({top:10},300);});
	$('.verImagen').live('mouseout',function(){$('#oaThumb').fadeOut(150);});
	oaHorizontalMenu.init();
});
