var ocultar_webmail = true;
var mostrar_webmail = false;
var cargando_ajax = false;
var habilitar_ajax = true;

if(typeof ie == "undefined")
{
	var ie = $.browser.msie;
}

$(document).ready(function()
{	
	/* ################# FANCYBOX ################################## */
	
	$(".fbox_test_solunet").fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 500,
		'height': 300,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$(".fbox_test_speedtest").fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 450,
		'height': 250,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_chat').fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 425,
		'height': 400,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_factura_electronica').fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 620,
		'height': 400,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_detalle_saldo').fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 620,
		'height': 500,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_contacto').click(function()
	{
		titulo = $(this).attr('title');
		href = $(this).attr('href');
		if(href.indexOf('?')==-1)
			href+='?fancybox=1';
		else
			href+='&fancybox=1';
			
		$.fancybox({
			'padding' : 0,
			'type' : 'iframe',
			'width': 620,
			'height': 370,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'centerOnScroll'	: true,
			'href'	: href,
			'title'	: titulo
		});
		return false;
	});
	
	activar_fbox_ajax();

	/* ################ IMAGEN HOVER  ############################## */
	
	$('.imagen_hover').live({
		mouseover: function()
		{
			if($(this).attr('alt'))
			{	
				$(this).data('src', $(this).attr('src'));
				$(this).attr('src', $(this).attr('alt'));
			}
		},
		mouseout: function()
		{
			if($(this).attr('alt'))
				$(this).attr('src',$(this).data('src'));
		}
	});
	
	/* ############### MENU ######################################## */
	
	$('#menu .links li .fondo').each(function()
	{
		$(this).css('width',$(this).parent().outerWidth()+'px');
		$(this).append('<img src="http://www.solunet.com.ar/images/solapa-borde-izq.png" class="png solapa_izq" />');
		$(this).append('<img src="http://www.solunet.com.ar/images/solapa-borde-der.png" class="png solapa_der" />');
		$(this).append('<div class="png solapa_arr"></div>');
		$(this).children('.solapa_arr').css('width',$(this).parent().outerWidth()-38+'px');
	});
	
	$('#menu .links li a').hover(function()
	{
		if(! $(this).parent().hasClass('activo'))
			$(this).parent().children('.fondo').css('top','-34px');
	},function()
	{
		if(! $(this).parent().hasClass('activo'))
			$(this).parent().children('.fondo').css('top','0');
	});
	
	/* ############## SUBMENU HOME ############################### */
	
	$('#submenu .test-solunet a, #submenu .test-speedtest a').mouseover(function()
	{
		$(this).parent().css('background-image', 'url(/images/icon-test-hover.png)');
	});	
	$('#submenu .test-solunet a').mouseout(function()
	{
		$(this).parent().css('background-image', 'url(/images/icon-test.png)');
	});
	$('#submenu .test-speedtest a').mouseout(function()
	{
		$(this).parent().css('background-image', 'url(/images/icon-test2.png)');
	});
	
	/* ############## CAJA WEB-MAIL ############################## */
	
	$('#submenu .webmail').mouseenter(function()
	{
		ocultar_webmail = false;
	});
	$('#submenu .webmail').mouseleave(function()
	{
		ocultar_webmail = true;
		setTimeout('f_ocultar_webmail()', 200);
	});
	$('#submenu .webmail a').mouseover(function()
	{
		if($('#webmail-box').css('display')=='none')
		{
			$('#webmail-box').animate({height: 'toggle'}, 400);
			$('#submenu .webmail').css('background', 'url(/images/icon-mail-hover.png) no-repeat 7px 0');
		}
	});
	$('#submenu .webmail a').click(function()
	{
		$('#webmail-box input[name=usuario_webmail]').focus();
	});
	$('#webmail-box').mouseenter(function()
	{
		ocultar_webmail = false;
	});
	$('#webmail-box').mouseleave(function()
	{
		ocultar_webmail = true;
		setTimeout('f_ocultar_webmail()', 200);
	});
	$('#webmail-box .cerrar a').click(function()
	{
		ocultar_webmail = true;
		mostrar_webmail = false;
		f_ocultar_webmail();
	});
	$('#webmail-box input[name=usuario_webmail], #webmail-box input[name=password_webmail]').focus(function()
	{
		mostrar_webmail = true;
	});
	$('#webmail-box input[name=usuario_webmail], #webmail-box input[name=password_webmail]').blur(function()
	{
		mostrar_webmail = false;
	});
	
	/* ########################### HOME ################### */
	
	$('#promociones #promo1').hover(function()
	{
		$(this).css('background', 'url(/images/Home/promo-1-hover.jpg) no-repeat');
	}, function()
	{
		$(this).css('background', 'url(/images/Home/promo-1.jpg) no-repeat');
	});
	
	$('#promociones #promo2').hover(function()
	{
		$(this).css('background', 'url(/images/Home/promo-2-hover.jpg) no-repeat');
	}, function()
	{
		$(this).css('background', 'url(/images/Home/promo-2.jpg) no-repeat');
	});
	
	$('#promociones #promo3').hover(function()
	{
		$(this).css('background', 'url(/images/Home/promo-3-hover.jpg) no-repeat');
	}, function()
	{
		$(this).css('background', 'url(/images/Home/promo-3.jpg) no-repeat');
	});
	
	$('#formulario .contratar_hosting').live({
		click: function()
		{
			$('#form_contratar').submit();
		}
	});
	
	$('#tipo_facturacion').live({
		change: function()
		{
			mostrar_cuit();
		}
	});
	
	$('.cargar').live({
		click: function()
		{
			href=$(this).attr('href');
			href+='?slide=1';
			cargar(href, '#ajax');
			return false;
		}
	});
	
	if($('#login-ciu').val()=='' || $('#login-ciu').val()=='Ingresa con tu CIU')
		$('#login-ciu').val('Ingresa con tu CIU').addClass('default');
	
	$('#login-ciu').focus(function()
	{
		if($('#login-ciu').hasClass('default'))
		{
			$(this).val('');
			$('#login-ciu').removeClass('default');
		}
	});
	
	$('#login-ciu').blur(function()
	{
		if($(this).val()=='')
			$('#login-ciu').val('Ingresa con tu CIU').addClass('default');
	});
	
});

function cargar(href, obj)
{
	if(habilitar_ajax)
	{
		transicion_out('izq', function()
		{
			cargando_ajax = true;
			setTimeout("f_cargando_ajax()", 100);
			$(obj).load(href,function()
			{
				cargado_ajax();
				transicion_in(obj);
			});
		}, obj);
	}
}

function transicion_out(sentido, callback, obj)
{
	var valor;
	var ancho = $(obj).outerWidth();
	if(sentido=='izq')
		valor = '-='+ancho+'px';
	else
		valor = '+='+ancho+'px';
	$(obj).parent().css('height', $(obj).outerHeight()+'px');
	$(obj).css('position','absolute').animate({ 'left': valor }, { duration:500, easing: 'easeOutCirc', complete: function()
	{	
		if(sentido=='izq')
			$(obj).css('left',ancho+'px');
		else
			$(obj).css('left','-'+ancho+'px');
			
		if(typeof callback == 'function')
		{
			callback.call();
		}
	}});
}

function transicion_in(obj)
{	
	$(obj).parent().css('height', $(obj).outerHeight()+'px');
	$(obj).animate({ 'left': '0px' }, {duration:500, easing: 'easeInCirc', complete: function()
	{
		$(obj).css('position', 'static');
		$(obj).parent().css('height','auto');
		habilitar_ajax = true;
		activar_fbox_ajax();
	}});
}

function f_cargando_ajax()
{	
	if(cargando_ajax)
	{
		$('#cargando').show();
		$('body').css('cursor', 'wait');
	}
}

function cargado_ajax()
{
	cargando_ajax = false;
	$('#cargando').hide();
	$('body').css('cursor', 'auto');
}

function f_ocultar_webmail()
{
	if(ocultar_webmail && ! mostrar_webmail)
	{
		$('#webmail-box').animate({height: 'hide'}, 400);
		$('#submenu .webmail').css('background', 'url(/images/icon-mail.png) no-repeat 7px 5px');
	}
}

function activar_fbox_ajax()
{
	$('.fbox_consulta_mail').fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 500,
		'height': 320,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_consulta_mail_countries').fancybox({
		'padding' : 0,
		'type' : 'iframe',
		'width': 620,
		'height': 350,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$(".fbox_img").fancybox({
		'padding' : 0,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'centerOnScroll'	: true
	});
	
	$('.fbox_contrato').click(function()
	{
		href = $(this).attr('href');
		if(href.indexOf('?')==-1)
			href+='?fancybox=1';
		else
			href+='&fancybox=1';
			
		titulo = $(this).attr('title');	
		
		$.fancybox({
			'padding' : 0,
			'type' : 'iframe',
			'width': 620,
			'height': 690,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'centerOnScroll'	: true,
			'href'	: href,
			'title' : titulo
		});
		return false;
	});
	
	if(ie && $.browser.version<7)
	{
		$('img, input[type=image]').each(function()
		{
			src = $(this).attr('src');
			if(src.indexOf('.png')!=-1)
				$(this).addClass('png');
		});
	}
}

function mostrar_cuit()
{
	if ($('#tipo_facturacion').val() != 'Cons. Final' && $('#tipo_facturacion').val() != '')
		document.getElementById('cuit').style.visibility='visible';
	else
		document.getElementById('cuit').style.visibility='hidden';
}



