// JavaScript Document

$(document).ready(function() {
	$("#scrollUp").css({top:150})
	if($(window).height()>document.body.clientHeight){
		$("#scrollUp").stop().animate({
			top: document.body.clientHeight - 162
		 },1000);
	}else{
		 $("#scrollUp").stop().animate({
			top: $(window).height()+$(window).scrollTop() - 162
		 },1000);
	}

	$('#scrollUp').click(function(){
		$('html, body').animate({
			scrollTop: $('body').offset().top
		}, 1000);
	});
		
    var topPadding = 162;
	$(window).resize(function() {
		if($(window).height()>document.body.clientHeight){
			 $("#scrollUp").stop().animate({
				top: document.body.clientHeight - topPadding
			 },1000);
		}else{
			 $("#scrollUp").stop().animate({
				 top: $(window).height()+$(window).scrollTop() - topPadding
			 },1000);
		}
	});
    $(window).scroll(function() {			
		$("#scrollUp").stop().animate({
			top: $(window).height()+$(window).scrollTop() - topPadding
		},1000);
   });

	var elh=document.body.clientHeight
	if(elh>564+1029){
		$("#bk2").show();
	$("#bk2").css({
		top: (elh-1029)
	});
	}else{
		$("body").css({backgroundImage: "url(../style/bkgFull.jpg)"}) 
	}
	
	$('#subServ').bind('mouseenter',function(){
		 $(this).slideDown();
	 });
	$('#subServ').bind('mouseleave',function(){
		 $(this).slideUp('fast');
	 });
	$('#servBtn').bind('mouseenter',function(){
		 $('#subServ').slideDown();
	 });
	$('.boton a').bind('mouseenter' ,function(){
		if($(this).attr('href')=='./Servicios'||$(this).attr('href')=='../Servicios' ){
			$('#subServ').slideDown();
		}else if($(this).attr('href')!='./Servicios'&& $(this).attr('href')!='../Servicios' ){
			$('#subServ').slideUp('fast');
		}
	});
	$('.boton a,.sbboton a').bind('mouseenter' ,function(){
		$(this).parent().fadeTo("slow", 0.33);
	});
	$('.boton a').bind('mouseleave' ,function(){
		if($(this).attr('href')!='./Servicios'&&$(this).attr('href')!='../Servicios' ){
			$('#subServ').slideUp();
		}
	});
	$('.boton a,.sbboton a ').bind('mouseleave' ,function(){
		$(this).parent().fadeTo("slow", 1);
	});
	
	$('.cotizer').bind('click' ,function(){
		$('#legales').before("<div class='lb-back'></div>");
		$('.lb-back').fadeTo(0,0);
		$('.lb-back').fadeTo('fast',0.9,function(){
			$('#cotizerL').fadeIn();
		});		
	});
	$('#legales').bind('click' ,function(){
		$('#legales').before("<div class='lb-back'></div>");
		$('.lb-back').fadeTo(0,0);
		$('.lb-back').fadeTo('fast',0.9,function(){
			$('#terminosL').fadeIn();
		});		
	});
	$('#cerrarL').bind('click' ,function(){
		$('#terminosL').fadeOut('normal');
		$('.lb-back').fadeTo('normal',0,function(){
			$('.lb-back').remove();
		});
			
			//$('.lb-back').fadeTo("slow",0.6);
		
	});
	$('#cerrarcL').bind('click' ,function(){
		$('#cotizerL').fadeOut('normal');
		$('.lb-back').fadeTo('normal',0,function(){
			$('.lb-back').remove();
		});
		
	});
	$('#cvirt td').bind('mouseenter' ,function(){
		$(this).fadeTo("fast", 0.5);
	});

	$('#cvirt td').bind('mouseleave' ,function(){
		$(this).fadeTo("normal", 1);
	});
	$('#scrollUp').bind('mouseenter' ,function(){
		$(this).fadeTo("fast", 0.5);
	});

	$('#scrollUp').bind('mouseleave' ,function(){
		$(this).fadeTo("normal", 1);
	});
	$('#facebook').click(function(){
		window.open("http://www.facebook.com/pages/Entorno-Web/226428357204");
	});
	$('#twetter').click(function(){
		window.open("http://www.twitter.com/entornoweb");
	});
	$('#rss').click(function(){
		window.open("http://feeds.feedburner.com/entornoweb");
	});
	$('#sendCotiz').click(function(){
		if($('#cotNombre').val()==''){
			alert('El nombre es requerido');
		}else if($('#cotEmail').val()==''){
			alert('El email es requerido');
			
		}else if($('#cotPhone').val()==''){
			alert('El telefono es requerido');
			
		}else{
		var cotData='nombre='+$('#cotNombre').val()+'&email='+$('#cotEmail').val()+'&phone='+$('#cotPhone').val()+'&localidad='+$('#cotLocal').val()+'&objetivo='+$('#cotObjetivo').val()+'&tipo='+$('input[name=tipo]:checked').val()+'&admin='+$('input[name=admin]:checked').val()+'&nosec='+$('input[name=nosec]:checked').val()+'&espanol='+$('input[name=espanol]:checked').val()+'&ingles='+$('input[name=ingles]:checked').val()+'&otro='+$('input[name=otro]:checked').val()+'&havecont='+$('input[name=havecont]:checked').val()+'&host='+$('input[name=host]:checked').val()+'&date='+$('#date').val()+'&dateEnd='+$('#dateEnd').val()+'&adicional='+$('#adicional').val();
		$.ajax({
  				type: "POST",
   				url: "http://www.entornoweb.com.mx/scripts/cotizacion.php",
   				data: cotData,
  				success: function(msg){
					alert(msg);
					/*$('#addform').slideUp('NORMAL');
					$('#upload_button').slideDown('NORMAL');
					$("#addDataBtn").slideUp();*/
								
   				}
 			});	
		
		}
	});
	
	

});