$(document).ready(function(){
	$.ajaxSetup ({
		'cache': false,
		'beforeSend' : function(xhr) {
			try{
				xhr.overrideMimeType('text/html; charset=iso-8859-1');
			}
			catch(e){}
		}
	});
	menu();
	realiza();
	clientes();
	productos();
	carrousel();
	show_turis();
	scroll_menu();
	
});
function menu(){
	$("#nav li").prepend("<span></span>");
	$("#nav li").each(function(){
		var linkText = $(this).find("a").html();
		$(this).find("span").show().html(linkText);
	});
	$("#nav li").hover(function(){
		$(this).find("span").stop().animate({marginTop: "-40"}, 250);
	}, function(){
		$(this).find("span").stop().animate({marginTop: "0"}, 250);
	});
	$("#submenu").hover(function(){
		$(this).find("ul").fadeIn(400);
		$(this).find("#prod_publi").css({"background": "#162c9b", "color": "#ffffff"});
	}, function(){
		$(this).find("ul").fadeOut(80);
		$(this).find("#prod_publi").css({"background": "#ffffff", "color": "#162c9b"});
	});
}
function realiza(){
	$("#nav a").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeOut();
	});
	$("#somos").click(function(e){
		e.preventDefault();
		$("#first").html("Qui&eacute;nes Somos");
		$('#title').animate({width:'360px'},{queue:false,duration:500});
		$('#slider').animate({top:'0px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'0px'},{queue:false,duration:650});
	});
	$("#clientes").click(function(e){
		e.preventDefault();
		$("#first").html("Clientes");
		$('#title').animate({width:'200px'},{queue:false,duration:500});
		$('#slider').animate({top:'-390px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'-470px'},{queue:false,duration:650});
	});
	$("#productos").click(function(e){
		e.preventDefault();
		$("#first").html("Nuestros Productos");
		$('#title').animate({width:'430px'},{queue:false,duration:500});
		$('#slider').animate({top:'-780px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'-940px'},{queue:false,duration:650});
		$('.car').animate({top:'120px'});
		if($('#slide_window').css("left") != "-450px")
			$('#slide_window').animate({left:'-450px'}).animate({top:'0px'});
		else
			$('#slide_window').animate({top:'0px'});
	});
	$("#casos").click(function(e){
		e.preventDefault();
		$("#first").html("Casos de &Eacute;xito");
		$('#title').animate({width:'380px'},{queue:false,duration:500});
		$('#slider').animate({top:'-1170px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'-1410px'},{queue:false,duration:650});
		$("#casos_menu #primer_caso").trigger("click")
	});
	$("#contacto").click(function(e){
		e.preventDefault();
		$("#first").html("Contacto");
		$('#title').animate({width:'310px'},{queue:false,duration:500});
		$('#slider').animate({top:'-1560px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'-1880px'},{queue:false,duration:650});
	});
	$("#tienda").click(function(e){
		e.preventDefault();
		$("#first").html("Compra en L&iacute;nea");
		$('#title').animate({width:'390px'},{queue:false,duration:500});
		$('#slider').animate({top:'-1950px'},{queue:false,duration:1000});
		$('#slider_right').animate({top:'-2350px'},{queue:false,duration:650});
	});
}
function clientes(){
	$("#vert img:first-child, #right_clientes img:first-child").fadeIn("fast");
	$("#item_clientes a").click(function(e){
		e.preventDefault();
		var aux = ".img_"+ $(this).attr("id")
		$("#vert img, #right_clientes img").fadeOut("fast");
		$(aux).fadeIn("fast");
	});
}
function productos(){
	$("#nav a").click(function(e){
		var pie = $(this).attr('id');
		if(pie=="productos"){
			$('#foot').animate({bottom:'00px', height: '110px'},{queue:false,duration:700});
		}else{
			$('#foot').animate({bottom:'10px', height: '20px'},{queue:false,duration:500});
			$('.car').animate({top:'120px'},{queue:false,duration:400});
		}
	});
	$("#nav_prod a, .ini, .sub_ini").click(function(e){
		var rela = "#"+ $(this).attr("rel")
		$("#right_productos img").fadeOut("fast");
		$(rela).fadeIn("fast");
		$(".gral").trigger("click");
	});
	$.ajaxSetup ({
		'cache': false,
		'beforeSend' : function(xhr) {
			try{
				xhr.overrideMimeType('text/html; charset=iso-8859-1');
			}
			catch(e){}
		}
	});
	$(".control a").click(function(e){
		e.preventDefault();
		var txt = "txt/"+ $(this).attr("id")+".php";
		$(this).parent().next().html('<img src="img/loading.gif" alt="" id="loading" />').load(txt);
		$(this).siblings().removeClass("active");
		$(this).addClass("active");
	});
	/*menus y submenus*/
	$(".top").click(function(e){
		e.preventDefault();
		var go = "#prod_"+$(this).attr("rel")
		$("#productos").trigger("click");
		setTimeout('$("'+go+'").trigger("click");', 600);
	});
	$("#prod_turis, #main_tur").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeIn();
		$('.car').animate({top:'120px'});
		$('#carousel_3').animate({top:'-220px'});
		if($('#slide_window').css("top") != "-310px")
			$('#slide_window').animate({top:'-310px'}).animate({left:'0px'});
		else
			$('#slide_window').animate({left:'0px'});
	});
	$("#prod_publi, #main_pub").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeOut();
		$('.car').animate({top:'120px'});
		if($('#slide_window').css("top") != "-310px")
			$('#slide_window').animate({top:'-310px'}).animate({left:'-450px'});
		else
			$('#slide_window').animate({left:'-450px'});
	});
	$("#prod_impre, #main_impr").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeIn();
		$('.car').animate({top:'120px'});
		$('#carousel_1').animate({top:'0px'});
		if($('#slide_window').css("top") != "-310px")
			$('#slide_window').animate({top:'-310px'}).animate({left:'-900px'});
		else
			$('#slide_window').animate({left:'-900px'});
	});
	/*para los submenus*/
	$("#tarj, #tarj_int, #main_tarj").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeIn();
		$('.car').animate({top:'120px'});
		$('#carousel_2').animate({top:'-110px'});
		if($('#slide_window').css("left") != "-450px")
			$('#slide_window').animate({left:'-450px'}).animate({top:'-620px'});
		else
			$('#slide_window').animate({top:'-620px'});
	});
	$("#ilim, #ilim_int, #main_ilim").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeIn();
		$('.car').animate({top:'120px'});
		$('#carousel_4').animate({top:'10px'});
		if($('#slide_window').css("left") != "-450px")
			$('#slide_window').animate({left:'-450px'}).animate({top:'-930px'});
		else
			$('#slide_window').animate({top:'-930px'});
	});
	$("#media, #media_int, #main_medi").click(function(e){
		e.preventDefault();
		$("#foot_inst").fadeIn();
		$('.car').animate({top:'120px'});
		$('#carousel_5').animate({top:'10px'});
		if($('#slide_window').css("left") != "-450px")
			$('#slide_window').animate({left:'-450px'}).animate({top:'-1240px'});
		else
			$('#slide_window').animate({top:'-1240px'});
	});
	/*terminan submenus*/
}
function carrousel(){
	$("#carousel_1, #carousel_2, #carousel_3").CloudCarousel({		
		reflHeight: 20,
		reflGap:1,	
		xPos:390,
		yPos:15,
		buttonLeft: $('#but3'),
		buttonRight: $('#but4'),
		FPS:30,
		yRadius:20,
		xRadius: 400,
		autoRotate: 'left',
		autoRotateDelay: 2000,
		speed:0.2,
		mouseWheel:true,
		bringToFront:true
	});	
}
function show_turis(){
	$(".show_impre_v").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 299,
		'height'			: 500,
		'scrolling'			: 'no'
	});
	$(".show_impre_h").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 440,
		'height'			: 335,
		'scrolling'			: 'no'
	});
	$(".show_tarje_v").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 299,
		'height'			: 510,
		'scrolling'			: 'no'
	});
	$(".show_tarje_h").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 440,
		'height'			: 370,
		'scrolling'			: 'no'
	});
	$(".show_turis").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'titlePosition'		: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
								return '<span style="color:#162c9b">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
							}
	});
	$(".show_ilim_v").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 328,
		'height'			: 487,
		'scrolling'			: 'no'
	});
	$(".show_ilim_h").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 447,
		'height'			: 358,
		'scrolling'			: 'no'
	});
	$("#carousel_5 a").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.75,
		'overlayColor'		: '#000',
		'padding'			: 0,
		'type'				: 'iframe',
		'width'				: 440,
		'height'			: 365,
		'scrolling'			: 'no'
	});
}
function scroll_menu(){
	var div = $('#menu_cont'),
		ul = $('#item_casos ul'),
		ulPadding = 8;
	var divWidth = div.width();
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
	
	$("#item_casos ul a").click(function(e){
		e.preventDefault();
		var caso = $(this).attr('href');
		$("#casos_content").html('<img src="img/loading.gif" alt="" id="loading" />').load("txt/"+caso+".php");
	});
	
}
