// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function () {

	//SuperBanner
	$('#superbanner').flash({
		swf: 'flash/superbanner/superbanner.swf',	width: '900',	height: '200',	hasVersion: 9,
		flashvars: { rutaXML: path+'xml/', rutaArchivos: path+'flash/superbanner/banners/' },
		params: { menu: 'false', wmode: 'transparent', scale: 'noscale'}
	});
	
	//History
	
	//$('#history').flash({
	//	swf: '../../flash/history.swf',	width: '420',	height: '300',	hasVersion: 9,
	//	params: { menu: 'false', wmode: 'solid', scale: 'noscale'}
	//});
	
	//Publi
	$('#fotos').flash({
		swf: 'flash/fotos.swf',	width: '290',	height: '240',	hasVersion: 9,
		params: { menu: 'false', wmode: 'transparent', scale: 'noscale'}
	});


	//Video
	/*
	var youtube_id = $('#videoplayer').attr('rel');
	var imagen = encodeURIComponent($('#videoplayer img').attr('src'));
	$('#videoplayer').flash({
		swf: path+'flash/if/video.swf',	width: '420',	height: '300',	hasVersion: 9,
		flashvars: { skin: path+'flash/if/videoskin_modieus.swf', autostart: false, type: 'video', stretching: 'fill', displayclick:'none', 
		icons: true, overstretch: false, file: encodeURIComponent(path+'videos/yt/'+youtube_id)
		,image: imagen
		},
		params: { menu: 'false', wmode: 'transparent', scale: 'noscale', allowfullscreen: true,	allowscriptaccess: 'always' }
	});

*/
	
    //Shop
    $('#shop').serialScroll({
		target:'#scrollshop',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'.nav.iz',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'.nav.de',// Selector to the 'next' button (absolute too)
		axis:'x',// The default is 'y' scroll on both ways
		duration:500,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
		//stop:false,// Each click will stop any previous animations of the target. (false by default)
		//lock:true, // Ignore events if already animating (true by default)		
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		interval:6000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		easing:'easeOutQuart',
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});	
	
	//Pasafotos Noticias
	var current = 1;
	var total = $('.flash_noticia').length;
	var ancho = 420;

	$('.next').click(function(e){
		var ir_a = current>=total ? 1 : current+1;
		go(ir_a,e);
	});
	$('.prev').click(function(e){
		var ir_a = current<=1 ? total : current-1;
		go(ir_a,e);
	});
	
	$('.go').click(function(e){
		var ir_a = parseInt(this.id.substr(1,1));
		go(ir_a,e);
	});
	
	function go(ir_a,e){
		if(ir_a < 1 || ir_a > total || ir_a == current) { return; }
		e.preventDefault();
		var step = ancho*(ir_a-1);
		//alert('current: '+current+', ir_a: '+ir_a+', scroll: '+step);
		$('#box').animate({scrollLeft: step}, 'fast');
		$('.go').removeClass('actual');
		$('#b'+ir_a+'.go').addClass('actual');
		current = ir_a;
	}
	$('.flash_navega #b1').addClass('actual');
	$('.flash_navega .go').addClass('oculta');
	for(var i=1;i<=total;i++){
		$('#b'+i+'.go').removeClass('oculta');
	}
    });	
		
	//CUENTA ATRAS
	var fecha = new Date();
	fecha = new Date(fecha.getFullYear() , 2, 18, 0); //Parametros: (año, mes restando 1, dia, hora)
	$('#countdown').countdown({
		until: fecha,
		compact: true, 
	    layout: '<div class="i{d10}"></div><div class="i{d1}"></div>' +
	        //'<div class="iDay"></div>' + 
	        '<div class="iSpace"></div>' + 
	        '<div class="i{h10}"></div><div class="i{h1}"></div>' + 
	        '<div class="iSep"></div>' + 
	        '<div class="i{m10}"></div><div class="i{m1}"></div>' + 
	        '<div class="iSep"></div>' + 
	        '<div class="i{s10}"></div><div class="i{s1}"></div>'
	});

