

$(document).ready(function(){

///Country Selection Slider Panel	
	$(".select_country").click(function(e){	
		 e.preventDefault();
		 
		$('#country_selection').slideDown("slow").click(function(){		
			$("#country_selection").slideUp("slow");			
		});
		
		$('#country_selection a').click(function(){
			$("#country_selection").hide();
			$("#loader").fadeIn('fast');			
		});
		
				
	});
	
	
///Tabs
	
	$(function() {
		$( "#tabs" ).tabs();
	});
	
	
/// wobbly logo	
	$('#logo').hover(function() {
        $(this).stop().animate({ marginTop: '6px' }, 150).css('cursor','pointer');
    },function(){
        $(this).stop().animate({ marginTop: '0px' }, 85).animate({ marginTop: '3px' }, 150);
    });
	
	
/// prettyPhoto lightbox	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		default_width: 640,
		default_height: 480
	});
		
	/****
	 * Homepage Tweeting Mini Carousel
	 * 
	 *****/
	
	$.getJSON('http://twitter.com/status/user_timeline/krolamarin.json?count=25&callback=?', function(data){
		$.each(data, function(index, item){
			$('#twitter_feed_list').append('<li><div class="twitter_feed_tweet"><p>' + item.text.linkify() + '</p><p>' + relative_time(item.created_at) + '</p></div></li>');
		});
		
		
		$(function() {
		    $(".twitter_feed_slides").jCarouselLite({
		        btnNext: " .next_tweet",
		        btnPrev: " .prev_tweet",
		        visible: 1,
		        vertical: true,
		        auto: 6500,
		        speed: 1000
		    });
		});
	});	
	
	
	function relative_time(time_value) {
		  var values = time_value.split(" ");
		  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
		  var parsed_date = Date.parse(time_value);
		  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
		  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
		  delta = delta + (relative_to.getTimezoneOffset() * 60);
		  
		  var r = '';
		  if (delta <= 60) {
			r = 'hace 1 minuto';
		  } else if(delta < 120) {
			r = 'minutos atrás';
		  } else if(delta < (45*60)) {
			r = (parseInt(delta / 60)).toString() + ' minutos atrás';
		  } else if(delta < (90*60)) {
			r = '1 hora atrás';
		  } else if(delta < (24*60*60)) {
			r = '' + (parseInt(delta / 3600)).toString() + ' horas atrás';
		  } else if(delta < (48*60*60)) {
			r = '1 día atrás';
		  } else {
			r = (parseInt(delta / 86400)).toString() + ' días atrás';
		  }
		  
		  return r;
		}
		
		String.prototype.linkify = function() {
			return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
				return m.link(m);
			});
		};
	
/// cufon text enhancement
//	Cufon.replace('h1');
//	Cufon.replace('h2');
	
	
	$('#slider').nivoSlider({
		effect:'fade',
		//controlNavThumbs:true,
	    //controlNavThumbsFromRel:true,
		controlNavThumbs:false,
	    animSpeed:500,
	    pauseTime:8000,
	    controlNavThumbsSearch: '_large.jpg', 
        controlNavThumbsReplace: '_thumb.jpg'
	});
	
	$('.slider2').nivoSlider({
		effect:'fade',
		//controlNavThumbs:true,
	    //controlNavThumbsFromRel:true,
		controlNavThumbs:false,
	    animSpeed:500,
	    pauseTime:8000,
	    controlNavThumbsSearch: '_large.jpg', 
        controlNavThumbsReplace: '_thumb.jpg'
	});

	
	

	
	
	


		
});


function gotoLink (htmlElement) {
	
	var destinationURL = "";
	var target = "";
	
	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}
	
	if(target == "_blank") {
		window.open(destinationURL);
	}
	else {
		location.href = destinationURL;
	}
}




/**
 * HomePage Action slider
 * 
 */


jQuery.fn.center = function () {
    this.css("position","absolute");
    var left = ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px";
    this.animate({left: left}, function(){
        $(this).css({position: 'static', margin: '35px auto'});
    });
    return this;
}

$(document).ready(function() {
	$('.info_band_box').click(function(){
		   
			$('#info_band_slide_box').show().center();
	
	});
});





/****
 * Homepage Showcase Mini Carousel
 * 
 *****/


$(function() {
    $(".showcase_mini_slide_container").jCarouselLite({
        btnNext: " .next",
        btnPrev: " .prev",
        visible: 2

    });
});


$(document).ready(function() {
$('.showcase_mini_slide_container img').tipsy({fade: true,gravity: 's'});


	$('.showcase_image').hover(
		function(){
			$(this).stop().animate({opacity: "0.5"});		
		},
		function(){
			$(this).stop().animate({opacity: "1"});
		
		});
	});




/****
 * Homepage info_buttons
 * 
 *****/



$(document).ready(function() {
	$('#sld').fadeIn();
	
	$('.info_band_box').click(function(){
		var btn = $(this).attr("rel");
		$('#homepage_intro').children('.slide').hide();
		$('#homepage_intro').children('#sld_'+btn).fadeIn();
		$('.info_band_box').removeClass('selected');
		$(this).addClass('selected');
	});
	
	$('.info_band_box').hover(
			function(){
				//$(this).addClass('current');
				$(this).children('h3').stop().animate({fontSize: "15px", top: "7px", color: "#177DD1"});
				$(this).children('p').stop().fadeTo("slow", 1);
			},
			function(){				
				$(this).children('h3').stop().animate({fontSize: "18px", top: "10px", color: "#555"});
				$(this).children('p').stop().fadeTo("slow", 0);
			});
	
});


/****
 * Showcase Hover Images - list page
 * 
 *****/


$(document).ready(function() {
	
	$('.thumb_img').hover(
		function(){
			$(this).stop().animate({opacity: '0.5' });
		},
		function(){
			$(this).stop().animate({opacity: '1'});
			
	});
	
});


/****
 * Showcase Hover Images - list page
 * 
 *****/


$(document).ready(function() {
	
	$('.show_dates').click(function(e){
		e.preventDefault();
		
		var uc_date = $(this).attr("rel");		
		$('#ud_'+uc_date).toggle("slow");
	});
	
	$('.close').click(function(e){
		e.preventDefault();
		$(this).parent().slideUp("slow");
	
	});
	
});





