// JavaScript Document

$(document).ready(function()
{

            var host='http://' + self.location.host + '/htm/';

        
	//Examples of how to assign the ColorBox event to elements
	// colorbox solo una sin grupo
	$("a[rel='colorbox_ns']").colorbox({rel:"nofollow"});
	//colorbox para grupo
	$("a[rel='colorbox']").colorbox({transition:"fade",current:"Imagen {current} de {total}"});
	$("a[rel='equipamiento']").colorbox({transition:"elastic",title:false,opacity:0.60});
        //$(".hayreportes").colorbox();
	//$(".hayreportes").colorbox({transition:"elastic",title:false,opacity:0.60,href:host +"equipamiento.html"});
/*		$("a[rel='example1']").colorbox();
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".hayreportes").colorbox();
	/*$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});*/
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function()
	{ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
});
	



$(function(){

	 // Accordion
	 $("#accordion").accordion({clearStyle: true}, { header: "h3"}, {autoHeight: false},{navigation: true});
	 $('#dialog_link, ul#icons li').hover(
	 function() { $(this).addClass('ui-state-hover'); },
	 function() { $(this).removeClass('ui-state-hover'); }
	 );
}); 

$(function(){

	 // Accordion
	 $("#accordionmain").accordion({clearStyle: true}, { header: "h3"}, {autoHeight: false},{navigation: true});
	 $('#dialog_link, ul#icons li').hover(
	 function() { $(this).addClass('ui-state-hover'); },
	 function() { $(this).removeClass('ui-state-hover'); }
	 );
}); 
$(function(){
	
	 // Accordion
   $("#accordion2").accordion({clearStyle: true}, { header: "h3"}, {autoHeight: false},{navigation: true});

/*	 $('#dialog_link, ul#icons li').hover(
	 function() { $(this).addClass('ui-state-hover'); },
	 function() { $(this).removeClass('ui-state-hover'); }
	 );*/
 }); 
//Boton a:link de accordion2 y otros
$(function() {
	$("button, input:submit, a", ".menu").button();
	
	$("a", ".menu").click(function() { return true; });
});
$(function() {
	$("button", ".ayuda").button();
});
$(function() {
	$("button", ".formulario").button();
});
jQuery(document).ready(function(){
	$("#iconbar span").hover(
		function(){
			var iconName = $(this).find("img").attr("src");
			var origen = iconName.split("x.")[0];
			$(this).find("img").attr({src: "" + origen + "o.png"});
						
		}, 
		function(){
			var iconName = $(this).find("img").attr("src");
			var origen = iconName.split("o.")[0];
			$(this).find("img").attr({src: "" + origen + "x.png"});
			$(this).find("span").animate({opacity: 0, top: "-50"}, {queue:false, duration:400}, "linear",
				function(){
					$(this).find("span").attr({"style": 'display:none'});			
				}
			);
		});
});

//$(function() {	
//		$("#tablaflota").tablesorter({sortList:[[0,0]], widgets: ['zebra'],headers: { 3:{sorter: false}}});
//});

$(function() {
		$("#tablaconceptos").tablesorter({sortList:[[0,0]], widgets: ['zebra'],headers: { 2:{sorter: false},3:{sorter: false},4:{sorter: false},5:{sorter: false},6:{sorter: false}}});
		
});
$(function() {
		$("#tablaasientos").tablesorter({sortList:[[0,0]], widgets: ['zebra'],headers: {1:{sorter: false},2:{sorter: false},3:{sorter: false},4:{sorter: false}}});

});
$(function() {
		$("#tablaaux").tablesorter({widgets: ['zebra'],headers: {0:{sorter: false},1:{sorter: false},2:{sorter: false},3:{sorter: false},4:{sorter: false}}});

});
// Comprueba reservas
//si hay que depurar DOM cambiar funcion load por ready
//
//QUITADO TODO HASTA QUE SE HAGA
//*****************************************
//jQuery(document).ready(function(){
//
//var host='http://' + self.location.host + '/action.php/';
//  var id_alea = setInterval(function()
//   {
//     $.ajax({url: host + "mvs_eventos_alea/compruebaFechaReservas", dataType: "json", context: document.body, success:display
//			
//	});
//   }, 5000);
// setTimeout("clearInterval("+id_alea+")",5000);   
//});
//******************************************

// Se activa Ajax para ejecutar eventos cada 5 segundos
//si hay que depurar DOM cambiar funcion load por ready
jQuery(document).ready(function(){

    var host='http://' + self.location.host + '/action.php/';


  var id_eventos = setInterval(function()
   {
     $.ajax({ url: host + "mvs_eventos_finanzas", context: document.body, success: function(){
        $(this).addClass("alea");
      }});
   }, 5000);
 setTimeout("clearInterval("+id_eventos+")",5000);     
 });
 
//si hay que depurar DOM cambiar funcion load por ready 
//QUITADO TODO HASTA QUE SE HAGA
//***************************************** 
//jQuery(document).ready(function(){
//var host='http://' + self.location.host + '/action.php/';
//  var id_alea = setInterval(function()
//   {
//       
//     $.ajax({url: host + "mvs_eventos_alea", dataType: "json", context: document.body, success:display
//			
//	});
//   }, 5000);
// setTimeout("clearInterval("+id_alea+")",5000);  
// });
// ******************************************

jQuery(document).ready(function(){

if (self.location.pathname == '/index.php/' || self.location.pathname == '/'){
    var host='http://' + self.location.host + '/action.php/';
    $.ajax({url: host + "mvs_toptwo/compruebaPireps", dataType: "json", context: document.body, success:display});
}
});

function display(data,text,respuesta)
	{
		var json=respuesta.responseText; //in my case response text form server is "{sc:true,msg:''}"
		
		var result=eval("("+json+")"); //create js object from server reponse
		//alert(result.sc);
		if (result.sc)
		{
		alert(result.msg);
		return [result.sc,result.msg,null];
		}
	
	}
// Abre dialogo movible-resizable para ayuda y demas a partir de button
$(document).ready(function() {

        var host='http://' + self.location.host + '/lib/images/';

        
	var $loading = $('<img src="'+host+'loading.gif" alt="loading" class="loading">');

	$('#ayuda').each(function() {
		var $dialog = $('<div></div>')
			.append($loading.clone());
			
		var $link = $(this).one('click', function() {
			$dialog
				.load($link.attr('value')) // en el atributo value de button está la url de lo que hay que ver
				.dialog({
					title: $link.attr('title'), // en atributo title esta el titulo del dialogo
					width: 840,
					height: 600
				});

			$link.click(function() {
				$dialog.dialog('open');

				return false;
			});

			return false;
		});
	});
});

$(document).ready(function() {

    $('#tooltitle *').tooltip({
    track: true,
    delay: 300,
    showURL: false,
    extraClass: "right",
    showBody: " - ",
    fade: 250

    });
$("#fancy, #fancy2").tooltip({
	track: true,
	delay: 0,
	showURL: false,
	fixPNG: true,
	showBody: " - ",
	extraClass: "pretty fancy",
	top: -15,
	left: 5
});

$('#pretty').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	showBody: " - ",
	extraClass: "pretty",
	fixPNG: true,
	left: -120
});

});


