//Cufon.replace('.main_image h2'); // replace as necessary
//Cufon.replace('h1'); // replace as necessary
//Cufon.replace('.bannerBorder a span'); // replace as necessary



$(document).ready(function(){

equalHeight($(".maincolumn"));

label2value();

$('#slideshow').cycle({
	slideExpr: '.slider',
	fx: 'fade',
	timeout: 8000
});

$('#contacts').cycle({
	slideExpr: '.contact',
	fx: 'fade',
	speed: 'fast',
	timeout: 4000,
    next:   '#c-next', 
    prev:   '#c-prev'
});

$("#playerTabs").idTabs();
$('#scroller').jScrollPane({wheelSpeed: 35});

$('.tipsy').tipsy({gravity: 'e'}); // n | s | e | w
$('.tipsy-share').tipsy({gravity: 'n'}); // n | s | e | w
$('.tipsy-rss').tipsy({gravity: 's'}); // n | s | e | w
$('.tipsy').click(function () {
	return false;
});
$('.share-icons').hide();
$(".share-it").live("click", share);


	//grab all the anchor tag with rel set to shareit
	function share(event) {
		event.preventDefault();
		
		//display the box
		$(this).parent().next('.share-icons').toggle();
		return false;
	}

	//hightlight the textfield on click event
	$('.share-icons').find('input').click(function () {
		$(this).select();
	});;



/*
	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 1 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	//$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
	
		//Set Variables
		var imgAlt = $(this).find('h2').text(); //Get Alt Tag of Image
		var imgTitle = $(this).find('input').val(); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 1,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
*/

});

this.label2value = function(){	

	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	$("label").each(function(){		
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			$(obj).addClass(inactive);			
			var text = $(this).text();
			$(this).css("display","none");			
			$(obj).val(text);
			$(obj).focus(function(){	
				$(this).addClass(focused);
				$(this).removeClass(inactive);
				$(this).removeClass(active);								  
				if($(this).val() == text) $(this).val("");
			});	
			$(obj).blur(function(){	
				$(this).removeClass(focused);													 
				if($(this).val() == "") {
					$(this).val(text);
					$(this).addClass(inactive);
				} else {
					$(this).addClass(active);		
				};				
			});				
		};	
	});		
};

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}


// ******************************************* Date in words

Date.prototype.time_ago_in_words = function() {
    var words;
    distance_in_milliseconds = new Date() - this;
    distance_in_minutes = Math.round(  Math.abs(distance_in_milliseconds / 60000)  );

    if (distance_in_minutes == 0) {
      words = "mindre än en minut";
    } else if (distance_in_minutes == 1) {
      words = "1 minut";
    } else if (distance_in_minutes < 45) {
      words = distance_in_minutes + " minuter";
    } else if (distance_in_minutes < 90) {
      words = "1 timme";
    } else if (distance_in_minutes < 1440) {
      words = "" + Math.round(distance_in_minutes / 60) + " timmar";
    } else if (distance_in_minutes < 2160) {
      words = "1 dag";
    } else if (distance_in_minutes < 43200) {
      words = Math.round(distance_in_minutes / 1440) + " dagar";
    } else if (distance_in_minutes < 86400) {
      words = "1 månad";
    } else if (distance_in_minutes < 525600) {
      words = Math.round(distance_in_minutes / 43200) + " månader";
    } else if (distance_in_minutes < 1051200) {
      words = "1 år";
    } else {
      words = "över " + Math.round(distance_in_minutes / 525600) + " år";
    }

    return words;
};
