function growmap() {
	$('#smaller').animate( { height:'400px' }, 1000 );
}

function shrinkmap() {
	$('#smaller').animate( { height:'280px' }, 1000 );
}

$(function() {


	$('ul.home-latest .story').equalHeights();
	$('ul.pictures li strong').equalHeights(); 	
	$('#header label').hide();
	$('input#header-search, #group-search-input').focus( function() { if( this.value == 'Enter keywords' || this.value == 'Search group' ) this.value = ''; });
	$('#breadcrumb ul li:last, ul.lang li:last, .footer-nav li:last, .vcard:last').addClass('last');
	if($('.message').length ){
		$('.message:last, .comment:last').css({ 'background':'none', 'margin': 0} );
	}
	if($('.documents').length ){
		$('.item:last').css({ 'background':'none', 'margin': 0} );
	}
	
	if ( $('#members-list') ) $('#members-list').listnav({includeNums: false});

	
	if ( $('.pullout').length > 0 ) { 
		$('.pullout').click(function() {
		url = $(this).find('a').attr('href'); 
		window.location = url;
		});
	}
	
	$('.iboxhide').wrapAll('<div style="display: none;"></div>');
	$('a[rel~="video"]').colorbox({width:"550px", inline:true, href: '#video' });
	
	$('ul.country-select li a.faux-check').live('click', function() { 
		$(this).find('span').toggleClass('checked');
		return false; 
	});
	
	$('ul.country-select li a.clear').live('click', function() {
		$('ul.country-select li a span').removeClass('checked');
		return false;
	});
	$('ul.region-select li a').live('click', function() {
		var region = $(this).attr('rel');
		var data = 'filter=true';
		data = data + '&region=' + region;
		$('ul.region-select').after('<span style="display: none;" id="current-region">'+region+'</span>');
		$('#loader').load('inc-content.html',data,function() {
				$('#members-list').listnav({includeNums: false});
				return false;
			} );
		$('#filter p, .filter p, .param').slideUp();
		return false;
	});
	$('ul.country-select li a.go').live('click', function() {
		var countriesSelected = $('ul.country-select li a span.checked');
		var data = '?filter=true&region='+$('#current-region').text();
		for( i = 0; i < countriesSelected.length; i++ ) {
			data = data + '&country=' + $(countriesSelected[i]).attr('rel');
		}
		$('#loader').load('inc-content.html'+data);
		$('#filter p, .filter p, .param').slideUp();
		return false;
	});
	$('ul.issue-select li a').live('click', function() {
		var issue = $(this).attr('rel');
		var data = '?filter=true';
		data = data + '&issue=' + issue;
		$('#loader').load('inc-content.html'+data);
		$('#filter p, .filter p, .param').slideUp();
		return false;
	});
	
	$('.pullout').hover(function() { $(this).addClass('pullout-over'); }, function() { $(this).removeClass('pullout-over'); });
	
	$('img.video').after('<div class="icon video-icon">Video File</div>');
	//$('img.audio').after('<div class="icon audio-icon">Audio File</div>');
	$('img.photo').after('<div class="icon photo-icon">Photo</div>');
	
	filterHead = $('#section .filter h3');
	widthHead = filterHead.find('a').width();
	filterHead.css('width', widthHead+10);
	
	//story parameters
	if ( $('.aside .anythingSlider').length ) {
		var slideshowParams = {easing: "easeInOutExpo", autoPlay: false, delay: 4500, startStopped: false, animationTime: 600,hashTags: false, buildNavigation: false, pauseOnHover: true };
	} else {
		var slideshowParams = {easing: "easeInOutExpo", autoPlay: false, delay: 4500, startStopped: false, animationTime: 600,hashTags: true, buildNavigation: true };
	}
	
	$('.anythingSlider').anythingSlider( slideshowParams );
	
	$('.aside .anythingSlider li').hover(function() {
		link = $(this).find('a').attr('href');
		text = $(this).find('img').attr('alt');
		if( text.length > 1 ) {
		message = '<a href="'+ link +'" class="titleLink"><div class="title">' + text + '</div></a>';
		// show message 
		$(this).append(message);
		}
	},function() {
		$(this).find('.title, a.titleLink').remove();
	});
	
	if( $('.groups ul.categories').length ) {
		var trigger  = $('.category-select');
		
		pos = trigger.position();
		$('.groups ul.categories').hide().css({ 'left': pos.left, 'top': pos.top + trigger.height() });
		
		trigger.click(function() { 
			$(this).toggleClass('selected');
			$('.groups ul.categories').slideToggle();
			return false;
		});
	}
	

	/* MEDIA CONTACTS SHOW/HIDE ON HOT TOPIC */
	var mediaContacts = $('.media-contact-show');
	var vcards = mediaContacts.siblings('.contacts');
	vcards.hide();
	mediaContacts.click(function() {
		vcards.slideToggle();
		return false;
	});
	/* end media show/hide */
	
		
	if( $('.filter').length ) {
		var filterBox = $('.filter');
		filterBox.find('p').hide().css('position', 'absolute');
		
		filterBox.find('h3').click(function() {
			$(this).next().slideToggle();
			$('.param').hide();
			return false;
		});
		
		filterBox.append('<div class="param target"></div><div class="param target2"></div><div class="param target3"></div><div class="param target4"></div>');
		$('.target3, .target, .target2, .target4').hide();
		filterBox.find('.region').click(function(){
			$(this).toggleClass('selected').siblings().removeClass('selected');
			pos = $(this).position();
			$('.target').load('inc-regions.html').css('left', pos.left);
			$('.target2, .target3, .target4').hide();
			$('.target').slideToggle();
			return false;
		});
		filterBox.find('.countries').click(function(){
			$(this).toggleClass('selected').siblings().removeClass('selected');
			$('.target2').load('inc-countries.html');
			$('.target, .target3, .target4').hide();
			$('.target2').slideToggle();
			$('.target2 ul li:nth-child(4n+1)').css('clear', 'left');
			return false;
		});
		filterBox.find('.members').click(function(){
			$(this).toggleClass('selected').siblings().removeClass('selected');
			$('.target3').load('inc-members.html');
			$('.target, .target2, .target4').hide();
			$('.target3').slideToggle();
			$('.target3 ul li:nth-child(4n+1)').css('clear', 'left');
			return false;
			
		});filterBox.find('.issues').click(function(){
			$(this).toggleClass('selected').siblings().removeClass('selected');
			pos = $(this).position();
			$('.target4').load('inc-issues.html').css('left', pos.left);
			$('.target, .target3, .target2').hide();
			$('.target4').slideToggle();
			return false;
		});
	}
	



	if( $("#leadblock").length > 0 ){
		$("#leadblock").find("div.lead:first").addClass("ontop");  
		$("#leadblock").find("ul").find("li:first").addClass("active");
		
		$("#leadblock").find("ul").find("li").hoverIntent({
					sensitivity: 2, 
					interval: 200, 
					over: hovon, 
					timeout: 200, 
					out: hovoff
		});

	}
	
	/** pause the on mouse over the image **/
	$("#leadblock").find("div.lead").hover(function() {
			pauseindex = pauseTimer(); 
		},function(){ 
			setRotationwhat( pauseindex+1, $("#leadblock").find("ul").find("li").length ); 
	});
	
	/** pause on mouse over the menu  **/
	$("#leadblock").find("ul").hover(function() {
			pauseindex = pauseTimer(); 
		},function(){
			setRotationwhat( pauseindex+1, $("#leadblock").find("ul").find("li").length ); 
	});
	
			/** where menu onclick event **/
			$("#wheremenu").find("ul:first").find("li").click(function(event) {
				event.preventDefault(); 
				var thisindex = $("#wheremenu").find("ul:first").find("li").index(this); 
				runTransition( thisindex+1, thisindex+2, "wheremenu" );  
			});

			/** trigger what and where menu rotaion events **/
			setRotationwhat(1, $("#leadblock").find("ul").find("li").length );
	
			// handle tabs...
			$('div#right').find('div.tabs').find('ul:first').find('li').click(function(event) {
				event.preventDefault(); 																   
				thisindex = $(this).parent().find('li').index(this); 															
				$(this).parent().find('li').removeClass('active'); 
				$(this).addClass('active'); 
				$(this).parent().parent().find('div').removeClass('active'); 
				$(this).parent().parent().find('div:nth-child('+( thisindex+2 )+')').addClass('active'); 	
			})

			
		
			setRotationwhat_uk(1, $("div#uk").find("ul").find("li").length ); 	


});

 

function hovon_uk(){
	
    pauseindex = pauseTimer_uk(); 
	oldindex_uk=100; 
	juk=0;
    clearTimeout(juk);
	thisindex_uk = $("div#uk").find("ul").find("li").index(this); 
	
	if( thisindex_uk!=oldindex_uk ) { 
		runTransition2_uk( thisindex_uk+1, thisindex_uk+2, "uk" );  
		clearTimeout(t);
	}
}


function hovoff_uk(){
	if( $("div#uk").find("div.nrlead").mouseover() )
		clearTimeout(tuk);
	else if( $("div#uk").find("ul").find("li").mouseover() )
		clearTimeout(tuk);
	else 
	  	setRotationwhat_uk( thisindex_uk+1, $("div#uk").find("ul").find("li").length ); 
}


/******* OF UK *********/
/** what menu rotation function - timing is set in here **/
function setRotationwhat_uk( index, length ) {
	tuk = setTimeout( "changeStylewhat_uk("+ index +", "+ length +" )", 12000 );
}

/** what change function... triggered by rotation function **/
function changeStylewhat_uk( index, length ) {
	
	next_uk = index+1; 
	if( next_uk > length)
		next_uk = 1; 
	runTransition_uk( next_uk, next_uk+1, "uk" );  
	clearTimeout(tuk);
	setRotationwhat_uk( next_uk, length ); 
}	 


/** what menu transition function.. with a pause **/ 
function runTransition2_uk( thisindex, blockindex, block ) {
	
	
	$("#"+block).find("ul:first").find("li").removeClass("active"); 
	$("#"+block).find("ul:first").find("li:nth-child("+thisindex+")").addClass("active"); 	
	juk=setTimeout( "changeblock_uk("+ thisindex +", "+ blockindex +")", 300 ); 
}

/** image change for leadblock block **/
function changeblock_uk(thisindex, blockindex){ 
	
	//alert( blockindex); 
	$("div#uk").find("div.nrlead:nth-child("+blockindex+")" ).addClass("ontwo"); 
	$("div#uk").find("div.ontop").fadeOut("slow", function() { 
		$("div#uk").find("div").removeClass("ontop"); 
		$("div#uk").find("div").removeClass("ontwo");
		$("div#uk").find("div.nrlead:nth-child("+blockindex+")" ).addClass("ontop");
		$("div#uk").find("div").fadeIn("fast"); 
	});

	oldindex_uk = thisindex-1; 
}


/** what / where menu transition function used throughout **/ 
function runTransition_uk( thisindex, blockindex, block ) {
	
	$("div#uk").find("ul").find("li").removeClass("active"); 
	$("div#uk").find("ul").find("li:nth-child("+thisindex+")").addClass("active"); 	
	$("div#uk").find("div.nrlead:nth-child("+blockindex+")" ).addClass("ontwo"); 
	$("div#uk").find("div.ontop").fadeOut("slow", function() { 
		$("div#uk").find("div").removeClass("ontop"); 
		$("div#uk").find("div").removeClass("ontwo");
		$("div#uk").find("div.nrlead:nth-child("+blockindex+")" ).addClass("ontop");
		$("div#uk").find("div").fadeIn("fast"); 
	});  

}

/** pause timer and return the previous element index so we can then continue ticking along **/
function pauseTimer_uk() {
	
	clearTimeout(tuk);
	$("div#uk").find("ul").find("li").each( function() {
			if( $(this).hasClass('active') )
				theindex_uk = $("div#uk").find("ul").find("li").index(this); 
	 });

	return theindex_uk
}





function hovon(){
	
		oldindex=100; 
	j=0;
	    clearTimeout(j);
	    	if ( $(this).hasClass('active')  == false ) 	{
		thisindex = $("#leadblock").find("ul").find("li").index(this);
		
		//	thisindex = $("#leadblock").find("div.view-frontpage-listing").find("view-content").find("div").find("div")
		//	alert( thisindex );
		//	console.log('this ' + thisindex);
		
		if( thisindex!=oldindex ) {
			runTransition2( thisindex+1, thisindex+2, "leadblock" );
			clearTimeout(t);
		}
		
		}
	
	
	
}



function hovoff(){
	
	
	if( $("#leadblock").find("div.lead").mouseover() )
				clearTimeout(t);
			else if( $("#leadblock").find("ul").mouseover() )
				clearTimeout(t);
			else 
			  	setRotationwhat( thisindex+1, $("#leadblock").find("ul").find("li").length ); 
	
}


/** what menu rotation function - timing is set in here **/
function setRotationwhat( index, length ) {
	t = setTimeout( "changeStylewhat("+ index +", "+ length +" )", 12000 );
}

/** what change function... triggered by rotation function **/
function changeStylewhat( index, length ) {
	
	next = index+1; 
	if( next>length)
		next=1; 
	runTransition( next, next+1, "leadblock" );  
	clearTimeout(t);
	setRotationwhat( next, length ); 
}	 


/** what menu transition function.. with a pause **/ 
function runTransition2( thisindex, blockindex, block ) {
	
	
	$("#"+block).find("ul:first").find("li").removeClass("active"); 
	$("#"+block).find("ul:first").find("li:nth-child("+thisindex+")").addClass("active"); 	
	j=setTimeout( "changeblock("+ thisindex +", "+ blockindex +")", 300 ); 
}

/** image change for leadblock block **/
function changeblock(thisindex, blockindex){ 
	
	$("#leadblock").find("div.lead:nth-child("+blockindex+")" ).addClass("ontwo"); 
	$("#leadblock").find("div.ontop").fadeOut("slow", function() { 
		$("#leadblock").find("div").removeClass("ontop"); 
		$("#leadblock").find("div").removeClass("ontwo");
		$("#leadblock").find("div.lead:nth-child("+blockindex+")" ).addClass("ontop");
		$("#leadblock").find("div").fadeIn("fast"); 
	}); 
	oldindex = thisindex-1; 
}


/** what / where menu transition function used throughout **/ 
function runTransition( thisindex, blockindex, block ) {
	
	$("#"+block).find("ul:first").find("li").removeClass("active"); 
	$("#"+block).find("ul:first").find("li:nth-child("+thisindex+")").addClass("active"); 	
	$("#"+block).find("div.lead:nth-child("+blockindex+")" ).addClass("ontwo"); 
	$("#"+block).find("div.ontop").fadeOut("slow", function() { 
		$("#"+block).find("div").removeClass("ontop"); 
		$("#"+block).find("div").removeClass("ontwo");
		$("#"+block).find("div.lead:nth-child("+blockindex+")" ).addClass("ontop");
		$("#"+block).find("div").fadeIn("fast"); 
	});  
}

/** pause timer and return the previous element index so we can then continue ticking along **/
function pauseTimer() {
	
	clearTimeout(t);
	$("#leadblock").find("ul").find("li").each( function() {
			if( $(this).hasClass('active') )
				theindex = $("#leadblock").find("ul").find("li").index(this); 
	 });

	return theindex
}