////////// DESPLEGABLES MENU

$(document).ready(function(){
	
	$(document).pngFix();

	$("ul.submenu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.menu li span,a#tecnologia,a#soluciones").click(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.submenu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.submenu").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	

});


////////// FOTOS FANCY
$(document).ready(function(){
	$("a.fotofancy[rel]").fancybox({
		'zoomSpeedIn'		: 500, 
		'zoomSpeedOut'		: 200, 
		'overlayShow'		: true,
		'easingIn'			: 'easeOutBack',
		'easingOut'			: 'easeInBack',
		'overlayOpacity'	: 0.20,
		'centerOnScroll'	: true
	});	

})

////////////// Modal ////////////////


function abrirModal (idbloque, url) {
	
	$('#'+idbloque).modal({
		close: true,
		overlayId: 'fw_overlay',
		containerId: 'fw_contenedor',
		onOpen: fw.open,
		onClose: fw.close
	});
	if(url){
		if (idbloque == "modalUso"){
			$('#destino').attr({
				src: url
			});
		}else
		if  (idbloque == "modalRegistro"){
			$('#destino2').attr({
				src: url
			});
		}
	}
}

function cerrarModal(dialog) {
	dialog.data.fadeOut(200, function () {
		dialog.container.fadeOut(200, function () {
			dialog.overlay.fadeOut(200, function () {
				$.modal.close();
			});
		});
	});
}
var fw = {
	message: null,
	open: function (dialog) {
		$("#fw_overlay").css({'opacity': 0.7});
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
				});
			});
		});
	},

	close: function (dialog) {
		cerrarModal(dialog)
	},
	error: function (xhr) {
		alert(xhr.statusText);
	}
};

function paginar(accion) {

	switch (accion) {
	case 'prev':
		$("#search_form input[name=search_pagina]").val(parseInt($("#search_form input[name=search_pagina]").val())-1);
		$("#search_form").submit();
		break;
	case 'next':
		$("#search_form input[name=search_pagina]").val(parseInt($("#search_form input[name=search_pagina]").val())+1);
		$("#search_form").submit();
		break;
	default:
		$("#search_form input[name=search_pagina]").val(accion);
		$("#search_form").submit();
		break;
	}

}

function volver_atras(ref) {
	$("#search_form").attr("action", ref);
	$("#search_form").submit();
}




function alertar (mensaje, funcion) {

	var dialog = $("<div id='confirmar' title='Informacion'>"+mensaje+"</div>").insertAfter('body');
	$(dialog).dialog({
		resizable: false,
		modal: true,
		overlay: {
				opacity: 0.5,
				background: "black"
		},
		width: 400,
		buttons: {
				 "Continuar": function() {
					if ((typeof(funcion)=="undefined") || (funcion=="")) {
						$("#confirmar").dialog('destroy').remove();
					} else {
						eval(funcion);
					}
				}
		}
	});

	$('.ui-dialog-titlebar-close').click(function() {
		$("#confirmar").dialog('destroy').remove();
	})

}
