$(document).ready(function() {
    
    //Newsletter text show/hide
	$('input#s').focus(function(){$(this).val('');$(this).removeClass('pre');});
	$('input#s').blur(function(){if($(this).val()==''){$(this).val('Search');$(this).addClass('pre');}});
	
	$("div#slideshow ul").fuFade({speed: 700,timeout: 3000});
    
	slideshowTabFirst();
    $("div#slideshowHome ul").fuFade({speed: 700,timeout: 5000,runningclass: 'fufadeON',callbackAfter: 'slideshowTabOn',callbackBefore: 'slideshowTabOff'});
    
    $("a.readMore").bind('click', preventDefault).click(function(){
    	var id = ($(this).attr('id')).replace('readA-','');
    	$('#post-'+id+' .entryShort').removeClass('displayBlock').addClass('displayNone');
    	$('#post-'+id+' .entryFull').removeClass('displayNone').addClass('displayBlock');
	});
	
	$("a.readLess").bind('click', preventDefault).click(function(){
    	var id = ($(this).attr('id')).replace('readL-','');
    	$('#post-'+id+' .entryFull').removeClass('displayBlock').addClass('displayNone');
    	$('#post-'+id+' .entryShort').removeClass('displayNone').addClass('displayBlock');
	});
	
	$('a.videoLink').bind('click', preventDefault).click(function(){
		var $url = $(this).attr('href')+'&lightbox';
		$.nyroModalManual({url:$url,forceType:'iframe',minWidth:640,minHeight:520});
	});

	
	//$("div#slideshow ul").fuFade({speed: 700,timeout: 6000});
	//$.nyroModalSettings({debug:false,type:'iframe',width:735,height:506,resizable:false,autoSizable:false});
	//initSlideshow("div#slideshowHome ul");
});

function preventDefault(evt){if(evt.preventDefault){evt.preventDefault();}return false;}

function slideshowTabFirst(){
	slideshowTabOff();
	$('div#slideshowHome ul li:first-child span.slider').css('z-index','300');
	$('div#slideshowHome ul li:first-child span.slider').animate({
		right: 0
		,bottom: 0
	  }, 700, 'linear', function() {
		 //alert('done');
	  });
}
function slideshowTabOn(){
	//alert($('div#slideshowHome ul li[style*=block]').html());
//	$('div#slideshowHome ul li[style*=block] span.slider').

	//$('div#slideshowHome ul li[style*=block] span.slider').css('z-index','300');
	$('div#slideshowHome ul li span.slider').animate({
		right: 0
		,bottom: 0
	  }, 700, 'linear', function() {
		 //alert('done');
	  });
}
function slideshowTabOff(){
	$('div#slideshowHome ul li span.slider').css('opacity','.7');
	$('div#slideshowHome ul li span.slider').css('right','-220px');
	//$('div#slideshowHome ul li span.slider').css('top','35px');
	$('div#slideshowHome ul li span.slider').css('bottom','-34px');
}

function initSlideshow(){
	$('div#slideshowHome ul li').each(function(idx){
		if(idx==0)	{ $(this).css('z-index',2); }
		else		{ $(this).css('z-index',1); }
	});
	
	$('div#slideshowHome ul li').each(function(idx){
		alert(idx + ': ' + $(this).html());
	});
	
//	window.setInterval(doSlideshow,5000);
}
function doSlideshow(theID) {
	//alert($('div#slideshowHome ul li').first().html());
	alert('in');
	var theID="div#slideshowHome ul";
	
	if($(theID + ' li').length>1) {
		//alert('length');
		var nextSlide = slideshowIDX*1+1;
		if(!$(theID + ' li:nth-child('+nextSlide+')').length) {
			nextSlide = 0;
		}
			//$(this).removeClass('displayNone');
			$(theID + ' li:nth-child('+nextSlide+')').fadeIn('slow');
			$(theID + ' li:nth-child('+slideshowIDX+')').fadeOut('slow', function() {
				// Animation complete.
				//alert('done');
				slideshowIDX = nextSlide;
			});
		
		//$('div#slideshowHome ul li').each(function(idx){
			//alert(idx + ': ' + $(this).html());
		//});
	}
}
