/**
* TWSAINT - TETRAWARE S.L. 2012
* <tetraware@tetraware.net>
*/

function loading_page(){
	$('#page-loading').click(function(){ $(this).hide(); });
	$('#page-loading').center({'minY': -100});
	$('#page-loading').show(); // show animation	
}

function anythingslider_jump(idx){
	$('.anythingSlider').anythingSlider(idx);
}

//
//
//

(function($){
     $.fn.extend({
          center: function (options) {
               var options =  $.extend({ // Default values
                    inside:window, // element, center into window
                    transition: 0, // millisecond, transition time
                    minX:0, // pixel, minimum left element value
                    minY:0, // pixel, minimum top element value
                    withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
                    vertical:true, // booleen, center vertical
                    horizontal:true // booleen, center horizontal
               }, options);
               return this.each(function() {
                    var props = {position:'absolute'};
                    if (options.vertical) {
                         var top = ($(options.inside).height() - $(this).outerHeight()) / 2;
                         if (options.withScrolling) top += $(options.inside).scrollTop() || 0;
                         top = (top > options.minY ? top : options.minY);
                         $.extend(props, {top: top+'px'});
                    }
                    if (options.horizontal) {
                          var left = ($(options.inside).width() - $(this).outerWidth()) / 2;
                          if (options.withScrolling) left += $(options.inside).scrollLeft() || 0;
                          left = (left > options.minX ? left : options.minX);
                          $.extend(props, {left: left+'px'});
                    }
                    if (options.transition > 0) $(this).animate(props, options.transition);
                    else $(this).css(props);
                    return $(this);
               });
          }
     });
})(jQuery);


$(function(){
	// toggle
	$("dl.toggle").each(function(){
		var $toogle_dt = $(this).children("dt");
		$toogle_dt.click(function(){
			$(this).toggleClass("current");
			$(this).next("dd").toggleClass("current");
			$(this).next("dd").toggle();
		});
		// crear otro boton para desplegar el toggle
		var rel_id	= $(this).attr('rel');
		var $rel	= $("#"+rel_id);
		if($rel){
			$rel.click(function(){
				$toogle_dt.click();
			});
		}
		
	});
	// colorbox
	$("a[rel*='colorbox'],a[rel*='lightbox']").colorbox({transition:'elastic', speed:500, current: '{current}/{total}'});
	$("a[rel*='colorbox-inline']").colorbox({inline:true, transition:'elastic', speed:500, current: '{current}/{total}', width: 660, height:400});
	$("a.iframe[rel*='colorbox']").colorbox({width:'60%', height:'60%', iframe:true});
	$("a.enviara-iframe[rel*='colorbox']").colorbox({width:'400px', height:'470px', iframe:true});
	
	// tabs
	/*
	$("ul.tabs").tabs("div.tabs-panes > .pane", {
		api: true,
		effect: 'fade',
		history: true
	});
	*/
	$("#tabs[class!='notab']").tabs({
		history: true
	});
	
	// accord
	/*
	$("dl.acor").tabs("dl.acor dd", {
		tabs: 'dt',
		effect: 'slide',
		history: false,
		initialIndex: 0,
	});
	*/
 	$(".accordion").accordion({
 		header: 'div.acc-header' , 
 		autoHeight: false 
 	});
 	$(".nofirst-accordion").accordion({
 		header: 'div.acc-header' , 
 		autoHeight: false ,
 		active: -1
 	});	
 	
	// anything alider
	$(".anythingSlider").anythingSlider({
		easing: "swing",			// Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,				// This turns off the entire FUNCTIONALY, not just if it starts running or not
        startStopped: false,		// If autoPlay is on, this can force it to start stopped
        delay: 6000,				// How long between slide transitions in AutoPlay mode
        animationTime: 1000,		// How long the slide transition takes
        hashTags: false,			// Should links change the hashtag in the URL?
        buildNavigation: false,		// If true, builds and list of anchor links to link to each slide
        pauseOnHover: false,			// If true, and autoPlay is enabled, the show will pause on hover
        startText: "Iniciar",		// Start text
        stopText: "Parar",			// Stop text
        navigationFormatter: null	// Details at the top of the file on this use (advanced use)
	});
	// simple over
	$(".showhide").mouseenter(function(){
			//$(this).find("div").show("slow");
			$(this).find("span").toggleClass("current");
			$(this).find("div").show();
		}
		).mouseleave(function(){
			//$(this).find("div").hide("slow");
			$(this).find("span").toggleClass("current");
			$(this).find("div").hide();
		});
	// cycle para home
	$("#blqCategoriasHome div ul.shuffle").each(function(){
		// asignar la animacion
		//cy  = new Object();
		new $(this).cycle({ 
			fx: 'shuffle',
			shuffle:{ top: 145, left:5},
			speed:500
		});
		$(this).cycle('pause');
		// control de la animacion
		$(this).parent('div').mouseenter(function(){
			$(this).children('ul.shuffle').cycle('resume');
			$(this).children('ul.shuffle').cycle('next');
		}).mousemove(function(){
			$(this).children('ul.shuffle').cycle('resume');
		}).mouseleave(function(){
			$(this).children('ul.shuffle').cycle('pause');
		});
	});
	
	// simple over mor images
	$(".more-images").mouseenter(function(){
			$(this).find("div.more-images-info").show("slow");
		}
		).mouseleave(function(){
			$(this).find("div.more-images-info").hide();
		});	
	
	// datepicker
	$(".datepicker").each(function(){
		at_mindate = $(this).attr('mindate'); 
		at_maxdate = $(this).attr('maxdate'); 
		at_dateformat = $(this).attr('dateformat');
		//
		new $(this).datepicker({
			minDate: at_mindate,
			maxDate: at_maxdate,
			dateFormat: at_dateformat
		});
	});
	
	// tooltip
	$(".tooltip").tooltip();	
	
	// fancy thumb
	/*
	$("ul.thumb li").hover(
		function(){
			$(this).css({'z-index' : '10'});
			$(this).find('img').addClass("hover").stop().animate(
				{
					marginTop: '-25px',
					marginLeft: '-25px',
					top: '50%',
					left: '50%',
					width: '100px',
					height: '100px'
				},
				200
			);
		},
		function(){
			$(this).css({'z-index' : '0'});
			$(this).find('img').removeClass("hover").stop().animate(
				{
					marginTop: '0',
					marginLeft: '0',
					top: '0',
					left: '0',
					width: '50px',
					height: '40px'
				},
				400
			);
		}
	);	
	*/
	// funcion generica para imprimir por id
	$(".print-id").click(function(){
			var rel = $(this).attr('href');
			rel_html = "" 
				+"<html>"
				+"<head>"
				+"<style>.noforprint, img {display:none;} dt {font-size:18pt;} .titulo {font-size:20pt;} li {list-style:none;}</style>"
				+"</head>"
				+"<body>" 
				+$(rel).html()
				+ "</body>"
				+"</html>";
			//
			var ventimp = window.open(' ','popimpr');
			ventimp.document.write(rel_html);
			ventimp.document.close();
			//ventimp.print();
			//ventimp.close();
			//
			return false;
	});	
	
	
 	// mostrar imagen de loading
	$("#frm_pack").submit(function(){
		loading_page();
	});
	$("#travel-custom").submit(function(){
		loading_page();
	});	
	
	//$("a:not([href*='#'])").click(function() {
	//	$('#page-loading').center();
	//	$('#page-loading').show(); // show animation
	//});		
	
	//
	// Control del boton de pago
	//
	$("#pay-action-button").click(function(event){
		//
		if ( $("input:checkbox[name='accept_conditions']:checked").val() != undefined ){
			//
			event.preventDefault();
			//
			loading_page();
			//
			var ref = $("input#pay-ref").val();
			//
			$.ajax({
				url: "index.php?mod=travel&mode=server&op=pay-log&ref="+ref,
				success: function(){
					$('#page-loading').hide();
					$("form#travel-pay").submit();
				}
			});
			//
			return false;
		}
		//
	});	
	
});

/*
// cycle para feedbacks
$('ul.feedbacks-anim').cycle({ 
	fx: 'scrollUp',
	pause: 1
});
// slideshow
$('.slideshow').cycle({
	fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
$('.slideshow2').cycle({
	fx: 'fade',
	next: '#next', 
	prev: '#prev' 		
});
*/

