/**
 * Javascript file for default/global actions and effects
 *
 * @author Terry Duivesteijn <terry@contactivity.com>
 * @copyright Copyright (c) 2011, Contactivity bv, Leiden
 * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)
 * @version $Id: contactivity.global.js,v 0.1 13-5-2011 14:44:18
 */


/**
 * Set the initial functions and effects on pageload
 */
$(document).ready(function(){
	// check width of browser
	checkWidth();

	// on resize, check width and adjust layout
	$(window).resize(function() {
		checkWidth();
	});

	// scroll down to anchor
	if(window.location.hash) {
      $('html,body').animate({scrollTop: $("#"+window.location.hash).offset().top},'500');
	}

	// Start carousel
	startSlider();

	// tag cloud
	$(".indented_container").not('#sidebar').find(".tagcloudcontainer").tagcloud({height:200});
	$('#sidebar').find(".tagcloudcontainer").tagcloud({height:150, type: "list"});

	// display map
	if(typeof window.doMap == 'function') {
		doMap();
	}

	/* nice fonts */
	Cufon.replace('h1');
	Cufon.replace('h2');

	// correction for big font
	$("section.content article header h1").css({'line-height':'40px'});

	// prettyphoto
	$("a[rel^='prettyPhoto']").prettyPhoto({
		twitter_via: 'thebrokeronline',
		twitter_text: $("meta[name=twitter]").html(),
		theme: 'facebook'
	});

	// clickable headers
	$("header.pointer").click(function() {
		if($(this).find('a').first().length == 1) {
			window.location = $(this).find('a').first().attr('href');
		}
	});


});

/*
 *
 * @author Terry Duivesteijn <terry@duivesteijn.com>
 */
function execute(){
	// this function is empty.
	void(0);
}

/*
 * Start the slider / carousel
 * @author Terry Duivesteijn <terry@duivesteijn.com>
 */

function startSlider(){
	if($.browser.msie && parseInt($.browser.version) < 9) {
		// no fix for carousel available yet, show only first item
	} else {
		if($("section.carousel").length > 0) {
			$("section.carousel").easySlider({
				auto: true,
				continuous: true,
				numeric: true
			});
		}
	}
}

/*
 * Check for enough space to display author list
 *
 * @author Terry Duivesteijn <terry@duivesteijn.com>
 */
function checkWidth(){
	// check for enough space for margin
	var marginheight = $("#marginstretcher").height() - parseInt($("#margin").css('top'));
	$("#margin").css('height',marginheight);
	if($("body").width() > 1100) {
		$("#wrapper").removeClass("no_margin");
	} else {
		if(!$("#wrapper").hasClass("no_margin")) {
			$("#wrapper").addClass("no_margin");
		}
	}
}


/**
 * Enable debugging in Firebug for example.
 * @author Terry Duivesteijn <terry@contactivity.com>
 * @category core
 */
function log() {
	if (window.console && window.console.log)
		window.console.log('debug: ' + Array.prototype.join.call(arguments,' '));
}


