<!--//--><![CDATA[//><!--
$(document).ready(function(){
	
	//GEO
	var geo_data;
	var geo_yt_block = [ "CN", "LR", "LY", "TM" ];
	if ($('#carousel').length) { //homepage only
		$.get('/geoip.php', function(data) {
			$('.result').html(data);
			geo_data = data;
	
			//Donate - country selection based on GeoIP
			$("#donation-widget select option[title='"+geo_data+"']").attr('selected', 'selected');
			var donation_action = $("#donation-widget select option[title='"+geo_data+"']").val();
			$("#donation-widget").attr("action", donation_action);
	
			//replaces YouTube for certain geo
			if ($.inArray(geo_data,geo_yt_block) > -1) {
				$('ul.ui-tabs li a.tab-link[href=\'#feat\']').siblings().find('iframe').remove();
				$('ul.ui-tabs li a.tab-link[href=\'#feat\']').siblings().find('img.yt_replacement').show();
			}
	
		});
	}
	
	//TABS (main nav / HP feature)
	
	//randomize start tab
	if ($('.feat_random').length) {
		featstart = Math.floor(Math.random()*7)+1;
	} else {
		featstart = 1;	
	}

	// default onload
	$('#mainnavitem_4 ul.ui-tabs li').first().find('a.tab-link').addClass('selected');
	$('#mainnavitem_4 ul.ui-tabs li').first().find('div').removeClass('ui-tabs-hide');
	$('#feat ul.ui-tabs li:nth-child('+featstart+')').find('a.tab-link').addClass('selected');
	$('#feat ul.ui-tabs li:nth-child('+featstart+')').find('div').removeClass('ui-tabs-hide');
	for (i=0; i<7; i++) {
		$('#feat ul.ui-tabs li:nth-child('+ eval(i+1) +')').find('div.feathighlight').css( {backgroundPosition: '0 '+ eval(i*60) +'px'} )	
	}
		
	$('ul.ui-tabs li a.tab-link').click(function(event){
		//hide all
		$(this).closest('ul').find('a.selected').removeClass('selected');
		
		//YouTube iframe
		if ($.inArray(geo_data,geo_yt_block) == -1) {
			if ($(this).attr('href') == "#feat") {
				$('iframe').remove();	
				yt_id = $(this).siblings().find('.media span.yt_id').attr('title')
				if (yt_id) {
					$(this).siblings().find('.media').append('<iframe width="375" height="237" src="http://www.youtube.com/embed/'+yt_id+'?rel=0&hd=1&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
				};
			}
		}
		
		$(this).closest('ul').find("li div").hide();
		
		//turn on active
		$(this).addClass('selected');
		$(this).parent().find("div").show();
		event.preventDefault();
	});



	//REGIONAL MAP on main nav
	var ibc_map_layers = new Array('UNICEFibc_map_outline', 'UNICEFibc_map_tacro', 'UNICEFibc_map_tacro', 'UNICEFibc_map_eapro', 'UNICEFibc_map_wcaro', 'UNICEFibc_map_saro', 'UNICEFibc_map_esaro', 'UNICEFibc_map_ceecis', 'UNICEFibc_map_mena', 'UNICEFibc_map_ind');

	$('a[rel^="UNICEFibc_map_"], area[rel^="UNICEFibc_map_"]').hover(
		// hover on
		function() {
			$("#mainnavitem_5").addClass("stayopen");
			ibc_map_layer = $(this).attr("rel");
			$('a[rel="'+ibc_map_layer+'"]').addClass('stayopen');
			for (i=ibc_map_layers.length-1; i>=0; --i) {
				$('#'+ibc_map_layers[i]).hide();
			}
			$('#'+ibc_map_layer).show();
    },
		// hover off
		function() {
			$("#mainnavitem_5").removeClass("stayopen");
			$('#mainnav nav li').removeClass('stayopen');
			$('a[rel="'+ibc_map_layer+'"]').removeClass('stayopen');
			for (i=ibc_map_layers.length-1; i>=0; --i) {
				$('#'+ibc_map_layers[i]).hide();
			}
			$('#UNICEFibc_map_outline').show();
		});


	//FEATURE TAB list trims
	$("div.listshows2 ul li:eq(3)").remove();
	$("div.listshows2 ul li:eq(2)").remove();
	$("div.listshows3 ul li:eq(3)").remove();


	//CAROUSEL
	
	//generates pagination	
	carsize = $('ul#car_groups li.car_group').size();
	for (i=2; i<=carsize; i++) {
		$('div.car_pag ul').append('<li><a href="#"><span>'+i+'</span></a></li>');
	}
	
	//randomize start tab
	carstart = Math.floor(Math.random()*carsize)+1;
	
	$('#car_groups').jcarousel({
			initCallback: UNICEF_hpcarousel_initCallback,
			itemVisibleInCallback: { onAfterAnimation: UNICEF_hpcarousel_itemVisibleInCallbackAfterAnimation },
			visible: 1,
			scroll: 1,
			start: carstart,
			wrap: 'both'
	});
	
	function UNICEF_hpcarousel_initCallback(carousel) {
		$('.jcarousel-control ul li a').bind('click', function() {
				carousel.scroll($.jcarousel.intval($(this).text()));
				return false;
		});
		
		$('.jcarousel-control .car_pag_nav_next').bind('click', function() {
		   carousel.next();
		   return false;
	    });
	 
	    $('.jcarousel-control .car_pag_nav_prev').bind('click', function() {
		   carousel.prev();
		   return false;
	    });
		
	};
	
	function UNICEF_hpcarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
		 $('.jcarousel-control ul li a').removeClass('selected');
		 $('.jcarousel-control ul li a').eq(idx-1).addClass('selected');
	}

	$(".jcarousel-prev, .jcarousel-next").disableTextSelect();

	//Donate - pull down
	$("#donation-country").change(function() {
	  	var donation_action = $(this).val();
  		$("#donation-widget").attr("action", donation_action);
	});

	 
});
//--><!]]>
