var notitim;
Cufon.replace('h1, h2, h3, ul.menu a', {hover:true});
var sopstat;

$(function(){
	Cufon.now();
	
	var option = {
		resizeLgImages: true,
		displayNav: true,
		handleUnsupported : 'remove',
		keysClose: ['c', 27], 
		players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']
	};
	Shadowbox.init(option);
	
	pngfix();

	$('#msg').css('visibility','visible').css('left',Math.round(($(window).width()-$('#msg').outerWidth())/2)+'px').hide();
	
	$(document).click(function() {
		$('#msg_txt').hide();
    	$('#msg').fadeOut(200);
	});
	$('#lbut').click(function(e) {
		e.stopPropagation();
	});
	$('#sbut').click(function(e) {
		e.stopPropagation();
	});
	
	
	var wt=0;
	var e=$('.noti_item');
	for(var i=0;i<e.length;i++) {
		wt+=$(e[i]).outerWidth(true);
	}
	$('#noti_slide').css('width',wt);
	
	$('#noti_izq').click(function() {
		noti_izq();
	});
	
	$('#noti_der').click(function() {
		noti_der();
	});
	
	$('#noti_slide_c').hover(function() {
		clearTimeout(notitim);
	}, function() {
		notitim=setTimeout(noti_der,5000);
	});
	
	notitim=setTimeout(noti_der,5000);
	
	sopstat=false;
	$('#sop_showhide').click(function() {
		if(!sopstat) {
			sopstat=true;
			$('#soporte').stop().animate({width:272},500,'swing');
		} else {
			sopstat=false;
			$('#soporte').stop().animate({width:39},500,'swing');
		}
	}).hover(function() {
		if(!sopstat) $(this).click();
	}, function() { });
	
	setTimeout(showsop,30000);
});
function showsop() {
	if(!sopstat) $('#sop_showhide').click();
}
function noti_izq() {
	var sc=$('#noti_slide_c');
	var s=$('#noti_slide');
		
	var w=sc.innerWidth();
	var wt=s.outerWidth();
		
	if(wt<=w) return;
		
	var x=s.position().left;
	var paso=s.children('.noti_item').outerWidth(true);
		
	var nx=x+paso;
	if(nx>0) nx=0-(wt-w);
		
	s.stop().animate({left:nx+'px'},500,'swing');
	
	clearTimeout(notitim);
	notitim=setTimeout(noti_der,5000);
}
function noti_der() {
	var sc=$('#noti_slide_c');
	var s=$('#noti_slide');
		
	var w=sc.innerWidth();
	var wt=s.outerWidth();
		
	if(wt<=w) return;
		
	var x=s.position().left;
	var paso=s.children('.noti_item').outerWidth(true);
		
	var nx=x-paso;
	if(nx<(0-(wt-w))) nx=0;

	s.stop().animate({left:nx+'px'},500,'swing');
	
	clearTimeout(notitim);
	notitim=setTimeout(noti_der,5000);
}
function _msg(q) {
	$('#msg_txt').hide().html(q);
	$('#msg').fadeIn(500,function() {
		$('#msg_txt').fadeIn(300);
	});
}

function login() {
	_msg("Verifique los datos ingresados.");
}
function busc() {
	_msg("El buscador estará habilitado a la brevedad. Disculpe las moletias.");
}

function _contacto_ok() {
	_msg("Su mensaje ha sido enviado, nos contactaremos<br />con usted a la brevedad. Muchas gracias.");

	var f=document.fcont;
	f.nombre.value='';
	f.email.value='';
	f.telefono.value='(Cód área) - Número';
	f.mensaje.value='';
	
	if($('input#empresa').length) {
		f.empresa.value='';
		f.ciudad.value='';
	}
}
function _contacto_err(q) {
	_msg(q);
}

function pngfix() {
	if($.browser.msie) {
		var elements=$('div, a, span, input, textarea');
		var bg,nam,bgp,pos;
		for(var i=0;i<elements.length;i++) {
			bg=$(elements[i]).css("background-image");
			if(bg.indexOf(".png")!=-1) {
				bgp=bg.split("/");
				nam=bgp[bgp.length-1];
				bgp=nam.split(".");
				nam=bgp[0];
				$(elements[i]).css("zoom",1).css("display","block").css("background-image","url('/images/x.gif')").css("background","transparent").css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src=/images/"+nam+".png)");
			}
		}
		/*elements=$('input,textarea');
		for(var i=0;i<elements.length;i++) {
			$(elements[i]).css("opacity",0.9);
		}*/
	}
}

