/*****************************************************************************
It is adviced to place the sIFR JavaScript calls in this file, keeping it
separate from the `sifr.js` file. That way, you can easily swap the `sifr.js`
file for a new version, while keeping the configuration.

You must load this file *after* loading `sifr.js`.

That said, you're of course free to merge the JavaScript files. Just make sure
the copyright statement in `sifr.js` is kept intact.
*****************************************************************************/

// Make an object pointing to the location of the Flash movie on your web server.
// Try using the font name as the variable name, makes it easy to remember which
// object you're using. As an example in this file, we'll use Futura.
var neosans = { src: '/swf/sifr/neosans.swf' };
var neosanslight = { src: '/swf/sifr/neosanslight.swf' };

// Now you can set some configuration settings.
// See also <http://wiki.novemberborn.net/sifr3/JavaScript+Configuration>.
// One setting you probably want to use is `sIFR.useStyleCheck`. Before you do that,
// read <http://wiki.novemberborn.net/sifr3/DetectingCSSLoad>.

sIFR.useStyleCheck = true;

// Next, activate sIFR:
sIFR.activate(neosans);
sIFR.activate(neosanslight);

// Function to do sIFR replacement in a JQueryish manner
jQuery.fn.sifrReplace = function(opts, addopts) {
	sIFR.replace( jQuery.extend({elements: this.get()}, opts, addopts) );
}
// Syntactic sugar for our styles
jQuery.fn.sifrReplaceNeoSans = function(extraCss) {
	this.sifrReplace(neosans, {wmode: 'transparent', css: '.sIFR-root {' + extraCss + '}'})
}
jQuery.fn.sifrReplaceNeoSansLight = function(extraCss) {
	this.sifrReplace(neosanslight, {wmode: 'transparent', css: '.sIFR-root {' + extraCss + '}'})
}

// If you want, you can use multiple movies, like so:
//
//    var futura = { src: '/path/to/futura.swf' };
//    var garamond = { src '/path/to/garamond.swf' };
//    var rockwell = { src: '/path/to/rockwell.swf' };
//    
//    sIFR.activate(futura, garamond, rockwell);
//
// Remember, there must be *only one* `sIFR.activate()`!

// Now we can do the replacements. You can do as many as you like, but just
// as an example, we'll replace all `<h1>` elements with the Futura movie.
// 
// The first argument to `sIFR.replace` is the `futura` object we created earlier.
// The second argument is another object, on which you can specify a number of
// parameters or "keyword arguemnts". For the full list, see "Keyword arguments"
// under `replace(kwargs, mergeKwargs)` at 
// <http://wiki.novemberborn.net/sifr3/JavaScript+Methods>.
// 
// The first argument you see here is `selector`, which is a normal CSS selector.
// That means you can also do things like '#content h1' or 'h1.title'.
//
// The second argument determines what the Flash text looks like. The main text
// is styled via the `.sIFR-root` class. Here we've specified `background-color`
// of the entire Flash movie to be a light grey, and the `color` of the text to
// be red. Read more about styling at <http://wiki.novemberborn.net/sifr3/Styling>.

//themes for KF 

var siteThemes = {
	'root': { color: '#91A426', bgcolor: '#91A426' },
	'about': { color: '#91A426', bgcolor: '#91A426' },
	'connect': { color: '#266E7F', bgcolor: '#266E7F' },
	'discuss': { color: '#2C7FC0', bgcolor: '#2C7FC0' },
	'learn': { color: '#E34E1A', bgcolor: '#E34E1A' },
	'research': { color: '#804A96', bgcolor: '#360E46' },
	'visit': { color: '#E31A61', bgcolor: '#E31A61' },
	'blog': { color: '#222222', bgcolor: '#A2B024' }
}

function getBodyThemeInfo() {
	/* determine theme from body class */
	var theme = {};
	var themeName = null;
	var body = $('body');
	for (var themeNameToCheck in siteThemes) {
		if (body.hasClass(themeNameToCheck)) {
			themeName = themeNameToCheck;
			theme = siteThemes[themeNameToCheck];
			break;
		}
	}
	return {themeName: themeName, theme: theme};
}

function applySifr(context) {
	var themeInfo = getBodyThemeInfo();
	var themeName = themeInfo.themeName;
	var theme = themeInfo.theme;
	
	$('.widget_panel_twitter h2').sifrReplaceNeoSans('letter-spacing: -0.5;color: #00BCF1;');
	
	$('body.soundboardposting h1.soundboardheader',context).sifrReplaceNeoSans('letter-spacing: -0.5;color: #ffffff; background-color: #91A426;');
	
	$('body.soundboard h1.soundboardheader',context).sifrReplaceNeoSans('letter-spacing: -0.5;color: #91A426; background-color: #ffffff;');
	
	$("h2.white").sifrReplaceNeoSans('letter-spacing: -0.5;color: #FFFFFF;');
	
	$("body.research .knowledge_database_results h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #804A96; background-color: #ffffff;');
		
	$(".knowledge_database_results h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #2C7FC0; background-color: #ffffff;');
	
	$(".site_results h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #91A426; background-color: #ffffff;');
	
	$("#quick_signup_teaser h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #FFFFFF; background-color: #000000;');
	
	$("#keeping_in_touch h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #FFFFFF; background-color: #000000;');
	
	$("body.research .project-publications-block h2").sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #804A96; background-color: #ffffff;');
		
	if (themeName == 'research') {
		$('.topic-tabbed-wrapper h1', context).sifrReplaceNeoSans(
			'letter-spacing: -2;color: #ffffff; background-color: #804A96;');
	}
	
	if (themeName == 'blog') {
		$('#primary-content h1', context).sifrReplaceNeoSans(
			'letter-spacing: -2;color: #2C7FC0; background-color: #ffffff;');

		$('.listing-blog-content h2', context).sifrReplaceNeoSans(
			['.sIFR-root { letter-spacing: -2;color: #222222; background-color: #ffffff;}'
			,'a { letter-spacing: -2;color: #222222; background-color: #ffffff; text-decoration: none;}'
			,'a:link { letter-spacing: -2;color: #222222; background-color: #ffffff; text-decoration: none;}'
			,'a:hover { letter-spacing: -2;color: #666666; background-color: #ffffff; text-decoration: none;}']
		);
			
		$('#primary-content .page-share h2',context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #A2B024; background-color: #ffffff;');
			
		$('#secondary-content h2',context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #2C7FC0; background-color: #000000;');	
	}
	
	$('#tabbed-header h1', context).sifrReplaceNeoSans(
		'letter-spacing: -2;color: #ffffff; background-color: '+ theme.bgcolor +';');
		
	$('#tabbed-header  .h1-subtitle', context).sifrReplaceNeoSansLight(
		'letter-spacing: -2;color: #ffffff; background-color: '+ theme.bgcolor +';');
	
	$('#content h1.poll-results', context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #91A426; background-color: #ffffff;');
	
	$('#content h2.poll-results', context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #91A426; background-color: #ffffff;');
	
	$('.general-election h1', context).sifrReplaceNeoSans(
		'letter-spacing: -2;color: #ffffff;');
		
	$("h1:not('.nosifr')", context).sifrReplaceNeoSans(
		'letter-spacing: -2;color: '+ theme.color +'; background-color: #ffffff;');
	
	$('.h1-subtitle', context).sifrReplaceNeoSansLight(
		'letter-spacing: -2;color: '+ theme.color +'; background-color: #ffffff;');
	
	$('#subscribe-form label').sifrReplaceNeoSans(
		'letter-spacing: -0.3;color: '+ theme.color +'; background-color: #eeeeee;');

	$('#footer h2', context).sifrReplaceNeoSans(
		['.sIFR-root {letter-spacing: -0.1;color: #ffffff; background-color: #000000;}'
			,'a { letter-spacing: -0.1;color: #ffffff; background-color: #000000; text-decoration: none;}'
			,'a:link { letter-spacing: -0.1;color: #ffffff; background-color: #000000; text-decoration: none;}'
			,'a:hover { letter-spacing: -0.1;color: #ffffff; background-color: #000000; text-decoration: none;}']
		);

	$('#secondary-content .poll-block h2', context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #ffffff; background-color: '+ theme.color +';');
	
	$("#secondary-content h2.theme-color", context).sifrReplaceNeoSans(
		['.sIFR-root {letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff;}'
			,'a { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}'
			,'a:link { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}'
			,'a:hover { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}']
		);
	
	$("#secondary-content h2:not('.nosifr')", context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #91A426; background-color: #eeeeee;');
	
	$(".standard-form h2:not('.nosifr')", context).sifrReplaceNeoSans(
			'letter-spacing: -0.5;color: '+ theme.color +'; background-color: #eeeeee;');

	$(".theme-bg h2:not('.nosifr')", context).sifrReplaceNeoSans(
		['.sIFR-root {letter-spacing: -0.5; color: #ffffff; background-color: '+ theme.color +';}'
			,'a { letter-spacing: -0.5; color: #ffffff; background-color: '+ theme.color +'; text-decoration: none;}'
			,'a:link { letter-spacing: -0.5; color: #ffffff; background-color: '+ theme.color +'; text-decoration: none;}'
			,'a:hover { letter-spacing: -0.5; color: #ffffff; background-color: '+ theme.color +'; text-decoration: none;}']
		);	
		
	
	
	//set any theme on any h2, specified by having the class "theme-[themename]"
	for (var themeNameToCheck in siteThemes) {
		$("h2:not('.nosifr')", context).each(function(){
			if ($(this).hasClass("theme-"+ themeNameToCheck)) {
				$(this, context).sifrReplaceNeoSans(
					[
						'.sIFR-root {letter-spacing: -0.5; color: '+ siteThemes[themeNameToCheck].color +'; background-color: #ffffff;}'
						,'a { letter-spacing: -0.5; color: '+ siteThemes[themeNameToCheck].color +'; background-color: #ffffff; text-decoration: none;}'
						,'a:link { letter-spacing: -0.5; color: '+ siteThemes[themeNameToCheck].color +'; background-color: #ffffff; text-decoration: none;}'
						,'a:hover { letter-spacing: -0.5; color: '+ siteThemes[themeNameToCheck].color +'; background-color: #ffffff; text-decoration: none;}'
					]
				);
			}
		});		
	}
	
	$("h2:not('.nosifr')", context).sifrReplaceNeoSans(
		['.sIFR-root {letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff;}'
			,'a { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}'
			,'a:link { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}'
			,'a:hover { letter-spacing: -0.5; color: '+ theme.color +'; background-color: #ffffff; text-decoration: none;}']
		);
	
	$('.callout blockquote p', context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: #000000; background-color: #ffffff;');

	$("h1:not('.nosifr')", context).sifrReplaceNeoSans('letter-spacing: -2;');
	
	$('#results_topsearchform label', context).sifrReplaceNeoSansLight(
		'letter-spacing: -2;color: '+ theme.color +'; background-color: #ffffff;');
	
	$('.sifrme', context).sifrReplaceNeoSans(
		'letter-spacing: -0.5;color: '+theme.color+'; background-color: #ffffff;');
}

$(function() {
	applySifr();	
});
