// JavaScript Document

/*
@description DevOff homepage JS

@author	Bryan Gullan
@created 2007-10
*/

$(document).ready(function() {
	if( $('#news-ticker').length ) {
	var options = {
		newsList: "#news-ticker",
		startDelay: 100,
		tickerRate: 60
	}
	$().newsTicker(options);
	}
	/*$('#thinkers a span').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    opacity: 0.85,
		showBody: " - ",
		top: -48, 
    	left: -10 
	});
	$('div#thinkers li a span').bind('mouseover', function(event) {
		$(this).addClass('over');//Oxford thinkers - fix cursor in IE6
	});
	$('div#thinkers li a span').bind('mouseout', function(event) {
		$(this).removeClass('over');//Oxford thinkers - fix cursor in IE6
	});*/
	
	
	// feature switching
	var pagingItems = $('<ul class="switching"><li><a href="#previous" class="previous">Previous</a></li><li><a href="#next" class="next">Next</a></li></ul>');
	/*$('div#opportunities').prepend(pagingItems);
	var currentFeatures = parseInt($('div#opportunities ul#giving-options').attr('class').split(' ')[0].split('-')[1]);
	var featuresLimit = parseInt($('div#opportunities ul#giving-options').attr('class').split(' ')[1].split('-')[1]);
	
	$('div#opportunities ul.switching a.previous').click(function() {
		var previousFeatures = currentFeatures - 1;
		
		if(previousFeatures < 1) {
			previousFeatures = featuresLimit;
		}
		$('li.feature1-'+currentFeatures).hide();
		$('li.feature1-'+previousFeatures).show();
		$('li.feature2-'+currentFeatures).hide();
		$('li.feature2-'+previousFeatures).show();
		$('li.feature3-'+currentFeatures).hide();
		$('li.feature3-'+previousFeatures).show();
		currentFeatures = previousFeatures;
	});
	$('div#opportunities ul.switching a.next').click(function() {
		var nextFeatures = currentFeatures + 1;
		
		if(nextFeatures > featuresLimit) {
			nextFeatures = 1;
		}
		$('li.feature1-'+currentFeatures).hide();
		$('li.feature1-'+nextFeatures).show();
		$('li.feature2-'+currentFeatures).hide();
		$('li.feature2-'+nextFeatures).show();
		$('li.feature3-'+currentFeatures).hide();
		$('li.feature3-'+nextFeatures).show();
		currentFeatures = nextFeatures;
		
	});*/
	
	$("img.preloader").each(function () {
			this.src = this.title;
		});
	
	$('#feature ul.menu li a').each(function(list) {
		var anchorID = $(this).parent().attr('id');
		$(this).attr('href','#j' + anchorID);
	});
	
	//ensure any element specified by an anchor in the URL is shown
	var url = document.location.href;
	var url_array = url.split('#j');
	var $bookmark = url_array[1];
	if($bookmark) {
		$('#feature ul.menu li').removeClass('active');
		$('li#' + $bookmark).addClass('active');
		$('#feature div.feature-content').hide();
		var $backgroundImage = $('#feature div.' + $bookmark + ' img.background').attr('src');
		$('#feature').css("background-image", "url("+$backgroundImage+")");
		$('#feature div.' + $bookmark).show();
		window.scrollTo(0,0);
	}
	$('#feature ul.menu li').click(function(){
		switchFeatures($(this));
	});
	$('#feature ul.menu li a').click(function(){
		switchFeatures($(this).parent());
	});
});

function switchFeatures(element) {
	var $item = $(element).attr('id');
		$('#feature div.feature-content').hide();
		$('#feature ul.menu li').removeClass('active');
		$('li#' + $item).addClass('active');
		var $backgroundImage = $('#feature div.' + $item + ' img.background').attr('src');
		$('#feature').css("background-image", "url("+$backgroundImage+")");
		$('#feature div.' + $item).show();
		window.scrollTo(0,0);
}