/*
 * setting for Countdown for jQuery v1.5.7.
 * http://keith-wood.name/countdown.html
 */
function isHere() {
	$('#countdown').empty().css({'background-image':'url(images/itsherev2011.jpg)'});
}

$(function () {
	$('#countdown').countdown({
		until: new Date(2011, 6 - 1, 21,12,00), 
		onExpiry: isHere, 
		alwaysExpire: true,
		format: 'DHMS',
		layout: '<div id="innercounter"><p>{dn}</p><p>{hnn}</p><p>{mnn}</p><p>{snn}</p></div>'		
		});
});


// tvspots
$(function(){
	var div = $('div.tvspots'),
		ul = $('ul.tvspots'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// radioclips
$(function(){
	var div = $('div.radioclips'),
		ul = $('ul.radioclips'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// videos
$(function(){
	var div = $('div.videos'),
		ul = $('ul.videos'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// slideshows
$(function(){
	var div = $('div.slideshowsb'),
		ul = $('ul.slideshowsb'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// ecards
$(function(){
	var div = $('div.ecards'),
		ul = $('ul.ecards'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// gallery
$(function(){
	var div = $('div.gallery'),
		ul = $('ul.gallery'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
// documents
$(function(){
	var div = $('div.documents'),
		ul = $('ul.documents'),
		ulPadding = 15;
	var divWidth = div.width();
	div.css({overflow: 'hidden'});
	var lastLi = ul.find('li:last-child');
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});

// fix for IE ClearType bug - http://blogs.msdn.com/ie/archive/2006/02/03/524367.aspx
// related posts: http://drupal.org/files/issues/jquerymenu-cleartype.patch
// requires to pass sped and callback parameters
(function($) {
	$.fn.fixClearTypeBug = function(speed, callback) {
		$(this).fadeIn(speed, function() {  // or may add nice effect to restore like fadeIn or fadeOut
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

// drop down menu
// http://picssel.com
$(function(){
	$('#menu li ul').hide(); //fix flickering in opera
	$('#menu li').hover(function() {
		$(this).children('a').addClass('bebe');
		$(this).children('ul').stop(true, true).delay(200).slideDown(300);}
		, 
		function() {
		$(this).children('a').removeClass('bebe');
		$(this).children('ul').stop(true, true).delay(200).slideUp(200); 
	});
});

// slide me function
// http://picssel.com 2010
$.fn.slideMe = function(){	
	$(this).hover(function(){	
//		$('.adgetty').animate({'height':'40'},{ queue:false, duration:300});
		$(this).animate({'height':'130'},{ queue:false, duration:300});
		return false;
	}, //hover
	function(){
		$(this).animate({'height':'40'},{ queue:false, duration:300});
//		$('.adgetty').animate({'height':'130'},{ queue:false, duration:300});
		return false;
	}); //out
	return false;
}; //slideme

/////////////////////////////////////////////////
//jQuery functions
//opening document ready
jQuery(document).ready(function(){
// end Oct 29, 2009 addition
// section selector
// http://picssel.com 2010
// initialize sections for projects section - show first as active
	$("div.section").hide().eq(0).fixClearTypeBug(0); 
	$("div.subnav a").eq(0).addClass("active");
// bind options to sections
	$("div.subnav a").each(function(i) {
		$(this).bind("click",function(){
			$("div.subnav a").removeClass("active").eq(i).addClass("active");
			$("div.section").hide().eq(i).fixClearTypeBug(0); 
	//		$(window).scrollTop(156);
			$(window).scrollTop(286); //
		}); //bind select
	});//each
//

	// accordion
	// jQuery UI
	// http://jqueryui.com/
	jQuery('#media').accordion({
		header: 'div.title',
		active: false,
		alwaysOpen: false,
		animated: false,
		autoheight: false
	});
	
	// stories from the field
	// http://picssel.com 2010
	// expand/collapse articles one at the time with fixClearTypeBug
	$(".articulo").hide();                       
  $(".a_open").click(function () {
		$(".articulo").hide(); 
		$(this).next(".articulo").fixClearTypeBug("fast");  	//expand this article with fixClearTypeBug Oct 29, 2009
		$(".a_open").show();												// show open option
		$(this).andSelf(".a_open").hide();					// hide open option
	});
	$(".a_close").click(function () {       	
		$(this).parents(".articulo").fadeOut("fast");	// close this article
		$(".a_open").show();												// show open option
	});
		
//fancybox custom scripts ///////////////////////////////

	$("a.fancyimage").fancybox({
	'overlayOpacity': 0.8,
	'overlayColor': '#dedede'
	});
	$("a.fancycard").fancybox({
	'overlayOpacity': 0.8,
	'overlayColor': '#dedede',
	'titleShow': false,
	'autoScale': false
	});
	$("a.fancyshoot").fancybox({
		'padding': 0,
		'width': 640,
		'height': 480,
		'autoScale': false,
		'overlayOpacity': 0.8,
		'overlayColor': '#dedede',
		'scrolling': 'no',
		'type':'iframe'
		});
	$(".fancypdf").click(function() {
	$.fancybox({
		'width': '75%',
		'height': '90%',
		'autoDimensions': false,
		'overlayOpacity': 0.8,
		'overlayColor': '#dedede',
		'content': '<embed src="'+this.href+'#nameddest=self&page=1&view=FitH,0&zoom=80,0,0" type="application/pdf" height="99%" width="100%" />',
		'onClosed': function() {
				$("#fancybox-inner").empty();
			}
		});
		return false;
	}); // pdf	
$("a.fancymodal").fancybox({
	'padding': 0,
	'modal': true,
	'width': '90%', 
	'height': '85%', 
	'overlayShow': true,
	'overlayOpacity': 0.8,
	'overlayColor': '#dedede',
	'type': 'iframe',
	'titlePosition': 'over',	
	'titleFormat': function() {
		return '<span id="fancybox-title-over"><a style="top: 0; color:#fff; text-decoration: none;" href="javascript:;" onclick="parent.$.fancybox.close();"><strong>CLOSE&nbsp;&nbsp; [ X ]</strong></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>';
	},
	'onComplete': function() {
		$("#fancybox-title").css({'top':'-35px', 'bottom':'auto', 'text-align':'right'});
	}
});// fancymodal
$("a.fancymap").fancybox({
	'padding': 0,
	'width': 640,
	'height': 360,
	'overlayOpacity': 0.8,
	'overlayColor': '#dedede',
	'type': 'iframe'
}); //fancymap

$("a.fancyvideo").fancybox({
	'padding': 0,
	'width': 500,
	'height': 399,
	'overlayOpacity': 0.8,
	'overlayColor': '#dedede',
	'type': 'swf',
	'swf': {'wmode':'transparent', 'allowfullscreen': true}
	}); //fancyvideo

$(".fancy5years").fancybox({
	'padding': 0, 
	'width': 864,  /*864*/ 
	'height': 510, /*486*/ 
	'autoScale': false, 
	'overlayOpacity': 0.8, 
	'overlayColor': '#dedede', 
	'type': 'swf', 
	'swf': {'wmode':'transparent', 'allowfullscreen': true}
	}); //fancy5years
// end fancybox

$('.advertising').slideMe();		

$("#content .subnav  #donate .donatebutton").hover(function() {
	$(this).animate({'opacity': '0.9'});
	}, function() {
	$(this).animate({'opacity': '1'});
});	
			

// fixed menu on top
// http://jqueryfordesigners.com/fixed-floating-elements

var topNv = $('#navigator').offset().top - parseFloat($('#navigator').css('marginTop').replace(/auto/,0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      if (y >= topNv) {
        // if so, ad the fixed class
				$( "#navigator" ).addClass( "navigator-fixed" );
      } else {
        // otherwise remove it
				$( "#navigator" ).removeClass( "navigator-fixed" );
      } 
			event.stopPropagation();
    });
// end fixed


}); //ready
// END jQuery plugins

