/**
* TWSAINT - TETRAWARE INFOGRAFICA S.C.A. 2010
* tetraware <tetraware@tetraware.net>
*/

$(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('normal');
		});
		// 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});
	// tabs
	$("ul.tabs").tabs("div.tabs-panes > .pane", {
		api: true,
		effect: 'fade',
		history: true
	});
	// accord
	$("dl.acor").tabs("dl.acor dd", {
		tabs: 'dt',
		effect: 'slide',
		history: false,
		initialIndex: 0
	}); 	
	// 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: 5000,				// How long between slide transitions in AutoPlay mode
        animationTime: 1500,		// 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: true,			// 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');
		});
	});
	
	
	//
	// fly to basket
	//
	$("a.cesta").click(function(event){
		event.preventDefault();
		var $self=$(this);
		var basketX = $("#blq_usuario div.cesta").offset().left;
		var basketY = $("#blq_usuario div.cesta").offset().top;
		var productX  = $(this).offset().left;
		var productY  = $(this).offset().top;
		var gotoX = basketX - productX;
		var gotoY = basketY - productY;	
		//.animate({opacity: 0.4}, 100 )
		// opacity: 0.1,
		//.clone()
		
		$(this)
		.css({'position' : 'absolute'})
		.animate({marginLeft: gotoX, marginTop: gotoY, width: 120, height: 60}, 1200, 
			function(){
				//alert('basket:'+ basketX+','+basketY+' product:'+ productX+','+productY+' goto: '+gotoX +','+ gotoY);				
				document.location = $self.attr('href');
			}
		);
	});
			
});

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

/**
* Control de los formularios de forma de pago
*/
function hydra_cfpago_check(select){
	if($(select)){
		
		value = $(select).val();
		if(!value){
			value = $("#"+select+" option:selected").attr('value');
		}
				
		switch(value){
			// tarjeta de credito - muestra los campos
			case '16':
				$("#CNTARJETA").addClass('required');
				$("#CVC").addClass('required');
				$("#CCAD_TARJETA").addClass('required');
				$("#CTTARJETA").addClass('required');
				//
				$("#grp_tarjeta").show('slow');
			break;
			// otras formas de pago - oculta los campos
			default:
				$("#CNTARJETA").removeClass('required');
				$("#CVC").removeClass('required');
				$("#CCAD_TARJETA").removeClass('required');
				$("#CTTARJETA").removeClass('required');
				//
				$("#grp_tarjeta").hide('slow');
			break;
		}
	}
}

/*
// 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' 		
});
*/

