
var current_slide = -1;
var current_blog = 0;
var blog_titles = Array();
var blog_links = Array();
var slidetimer;
var loading=0;
var next_slide=-1;

$(function() {
	
	if ($("#content").height() > $(".sidebar").height()) {
		$(".sidebar").css('height',$("#content").height());
	}
	
	$("#blog_feed").hide();
	
	$.get("/rss", function(rss){
		$(rss).find('item').each(function() {
			blog_titles.push($(this).find('title').text());
			blog_links.push($(this).find('link').text());
		});
		setInterval ( "swapRSS()", 5000 );
		
		$("#blog_feed").html("<a href=\""+blog_links[current_blog]+"\">"+blog_titles[current_blog]+"</a>");
		$("#blog_feed").fadeIn('normal');
	});
	
	$(".slide_thumb").click(function() {
		var slide_id = parseInt($(this).attr('slide_id'));
		select_slide(slide_id);
	});
	slidetimer=setTimeout( "swapSlide()", 9000 );
	select_slide(0);
	
});

function swapSlide() {
	slide_id=parseInt(current_slide)+1;

	if (slide_id >= slides.length) {
		slide_id=0;
	}
	
	select_slide(slide_id);
}

function select_slide(slide_id) {
	
	if (loading==1) {
		// If a new slide is currently fading in, set it to switch to this slide after it completes
		next_slide=slide_id;
		return false;
	}
	else if (slide_id==current_slide) {
		// If current slide is selected do nothing
		return false;
	}
	
	next_slide=-1;
	
	clearTimeout(slidetimer);
	
	$(".slide_thumb_image[slide_id='"+slide_id+"']").attr('src',slide_thumb_path+slides[slide_id]+"_on.png");
	
	$("#splash_image_back").css("background-image","url("+slide_path+slides[current_slide]+".jpg)");
	
	$("#splash_text").hide();
	

	for (i=0;i<slides.length;i++) {
		if (i != slide_id)
			$(".slide_thumb_image[slide_id='"+i+"']").attr('src',slide_thumb_path+slides[i]+".png");
	}
	
	
	$("#splash_image").hide();
	$("#splash_image").css("background-image","url("+slide_path+slides[slide_id]+".jpg)");
	
	loading=1;
	
	$("#splash_image").fadeIn('slow',function() {
		loading=0;
		slidetimer=setTimeout( "swapSlide()", 9000 );
		current_slide=parseInt(slide_id);
		
		
		$("#splash_text").html(slide_text[slide_id]);
		$("#splash_text").show();
		
		
		sIFR.replace(helveticaneue_bold, {
	      selector: 'h1'
	      ,css: {
	        '.sIFR-root': { 'color': '#8F0025' }
	      },
	      wmode:'transparent',
	      ratios:[9, 1.16, 17, 1.09, 18, 1.08, 24, 1.05, 25, 1.06, 30, 1.04, 32, 1.05, 37, 1.03, 39, 1.04, 40, 1.02, 41, 1.04, 58, 1.03, 97, 1.02, 1.01],
	      offsetTop:3

	    });
	  
	   sIFR.replace(helveticaneue_bold, {
	      selector: 'h2'
	      ,css: {
	        '.sIFR-root': { 'color': '#585856' }
	      },
	      wmode:'transparent',
	      ratios:[9, 1.16, 17, 1.09, 18, 1.08, 24, 1.05, 25, 1.06, 30, 1.04, 32, 1.05, 37, 1.03, 39, 1.04, 40, 1.02, 41, 1.04, 58, 1.03, 97, 1.02, 1.01],
	      offsetTop:3

	    });
	  
	    sIFR.replace(helveticaneue_bold, {
	      selector: 'p'
	      ,css: {
	        '.sIFR-root': { 'color': '#585856' },
	        'a:link' : { 'color': '#8F0025','text-decoration':'none','font-size':'12px'},
	        'a:visited' : { 'color': '#8F0025','text-decoration':'none','font-size':'12px'},
	        'a:hover' : { 'color': '#8F0025','text-decoration':'underline','font-size':'12px'}
	      },
	      wmode:'transparent',
	      thickness:-70,
	      ratios:[9, 1.16, 17, 1.09, 18, 1.08, 24, 1.05, 25, 1.06, 30, 1.04, 32, 1.05, 37, 1.03, 39, 1.04, 40, 1.02, 41, 1.04, 58, 1.03, 97, 1.02, 1.01]
	     
	      
	    });
		
		
	
		if (next_slide >= 0) {
			select_slide(next_slide);
		}
		
	});
	
}

function swapRSS() {
	
	if (blog_titles.length > 0) {
		
		current_blog++;
		
		if (current_blog >= blog_titles.length) {
			current_blog=0;
		}
		
		$("#blog_feed").fadeOut('normal',function() {
			$("#blog_feed").html("<a href=\""+blog_links[current_blog]+"\">"+blog_titles[current_blog]+"</a>");
			$("#blog_feed").fadeIn('normal');
		});
		
	}
	
}