﻿// Google Analytics
try {
	var pageTracker = _gat._getTracker("UA-12031599-1");
	pageTracker._trackPageview();
} catch(err) {};


Cufon.replace('#nav a, .tabs a, .tabs2 a, .aside h3, .top-links');


	
jQuery.fn.ytplaylist = function (options) {

    // default settings
    var options = jQuery.extend({
        holderId: 'video_holder',
        playerHeight: '385',
        playerWidth: '480',
        thumbSize: 'small',
        autoPlay: true,
        showRelated: true
    }, options);
	
	var selector = $(this);
	var autoPlay = "";
	var showRelated = "&rel=0";
	if (options.autoPlay) autoPlay = "&autoplay=1";
	if (options.showRelated) showRelated = "&rel=1";
	
	//throw a youtube player in
	function play(id) {
		var html = '';

		html += '<object height="' + options.playerHeight + '" width="' + options.playerWidth + '">';
		html += '<param name="movie" value="http://www.youtube.com/v/' + id + autoPlay + showRelated + '"></param>';
		html += '<param name="wmode" value="transparent"></param>';
		html += '<embed src="http://www.youtube.com/v/' + id + autoPlay + showRelated + '" type="application/x-shockwave-flash" wmode="transparent"  height="' + options.playerHeight + '" width="' + options.playerWidth + '"></embed>';
		html += '</object>';

		return html;
	};
		
	function videoId(url) {
		var id = url.match("[\\?&]v=([^&#]*)");
		return id[1];
	};
	
	var firstVideo = selector.children("a:first-child").addClass("current_video").attr("href");
	
	//load inital video
	$("#" + options.holderId + "").html(play(videoId(firstVideo)));
	 			
	//load video on request
	$(".video").bind('click', function () {
		
		$('.current_video').removeClass("current_video");
		
		var $this = $(this);
		
		$('#' + options.holderId).fadeTo("fast", 0, function(){
										 
			$(this).html(play(videoId($this.attr("href")))).fadeTo("slow", 0, function(){ 
				$(this).fadeTo("fast", 1);
			});
			
		});
				
		$(this).addClass("current_video");

		return false;
	}); 

};



// create custom tooltip effect for jQuery Tooltip
$.tools.tooltip.addEffect("bouncy",

	// opening animation
	function(done) {
		this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show();
	},

	// closing animation
	function(done) {
		this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  {
			$(this).hide();
			done.call();
		});
	}
);

// custom easing called "custom" 
$.easing.custom = function (x, t, b, c, d) { 
    var s = 1.70158;  
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
}

// custom easing called "bouncy"
$.easing.bouncy = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}









if (site.page == 'media') {
	
var api2 = $("#scroll").scrollable({
	items: '#gallery',
	size: 1,
	clickable: false

// use the navigator plugin
}).navigator({api2: true});


// a dedicated click event for the intro thumbnail
/**/
$("#g1").click(function() {

	// seek to the beginning (the hidden first item)
	$("#scroll").scrollable().begin();

});


var flashvars = {
    feed: site.base_url+'/med/imgs/photos.rss',
	style: 'light'
},

params = {
    allowscriptaccess: "always"
};

swfobject.embedSWF("http://apps.cooliris.com/embed/cooliris.swf",
                   "wall", "650", "450", "9.0.0", "", 
                   flashvars, params);
}



$(function() {
	
	var tabsNav = $(".tabs2 a");
	
	$(".tabs").tabs('.article > div', { 
		onBeforeClick: function(e, i) {
			tabsNav.removeClass('current');
			tabsNav.eq(i).addClass('current');
		}											   
	}).history();	
	
	var api = $(".tabs").tabs();		
    tabsNav.eq(0).click(function() { api.prev(); }); 
    tabsNav.eq(1).click(function() { api.next(); });
		
	if (site.page == 'media') {
		$("#infinite").scrollable({size: 3, easing: 'custom', speed: 700}).mousewheel();	
		
		$("#videos").ytplaylist({autoPlay: false});
		
		$("#videos img[title]").tooltip({tip: '#video_tool_tip', effect: 'bouncy', predelay: 500});	
		
		$(".galleries").scrollable({size: 3, easing: 'custom', speed: 700}).mousewheel();
		
		
		var api2 = $("#scroll").scrollable({
			items: '#gallery',
			size: 1,
			clickable: false
	
		}).navigator({api2: true});	
		
		$("#g1").click(function() {
		
			$("#scroll").scrollable().begin();	
		});
	}
});


$(".tweet").tweet({
  join_text: "auto",
  username: "jahucr",
  count: 8,
  auto_join_text_default: "dijimos,", 
  auto_join_text_ed: "nosotros",
  auto_join_text_ing: "estabamos",
  auto_join_text_reply: "respondimos",
  auto_join_text_url: "estamos revisando",
  loading_text: "cargando tweets..."
});
