/*****************************************************************************
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.
*****************************************************************************/

var stafford_xb = { src: 'http://www.netrelations.se/flash/stafford_xb.swf' };

(function() {

	sIFR.autoInitialize = false;
	sIFR.useDomLoaded = true;
	sIFR.repaintOnResize = true;
	sIFR.activate(stafford_xb);

	$(function () {
		
		// Replace blurb h2's separately to get correct justification
		$('.blurbs').each(function () {
			var self = $(this);
			var replacedCount = 0;
			var blurbs = self.children('.blurb');
		
			sIFR.replace(stafford_xb, {
				selector: '#' + self.attr('id') + ' .blurb h2',
				css:[
					'.sIFR-root a {color:#000000;text-decoration:none;}',
					'.sIFR-root a:hover {color:#000000;text-decoration:underline;}'
				],
				wmode:'transparent',
				onReplacement: function () {
					replacedCount ++; 
					if (replacedCount == blurbs.size()) {
						blurbs.justify();
					}
				}
			});
			sIFR.initialize();
		});

		sIFR.replace(stafford_xb, {
			selector:'.m:not(.blurb, #tagcloud) h2:not(.no-sifr, .structural), .contact-box h2, #featured-result h2, #current h3',
			css:[
				'.sIFR-root a {color:#000000;text-decoration:none;}',
				'.sIFR-root a:hover {color:#000000;text-decoration:underline;}'
			],
			wmode:'transparent'
		});
		
		//Headers
		sIFR.replace(stafford_xb, {
			selector: 'h1:not(.no-sifr, .structural)',
			wmode:'transparent'
		});
		
		sIFR.replace(stafford_xb, {
			selector:'#tagcloud .m-h h2',
			css:[
				'.sIFR-root {text-align:center;font-size:18px;}'
			]
		});
		
		//Blockquotes
		sIFR.replace(stafford_xb, {
			selector: 'blockquote p',
			css:[
				'.sIFR-root {display:inline;}',
				'.blue {color:#0093D1;}'
			],
			wmode: 'transparent'
		});
		
		//Front page campaign slider
		sIFR.replace(stafford_xb, {
			selector: '#campaign .bg p',
			css:[
				'.sIFR-root {display:inline;}',
				'.sIFR-root .blue {color:#0093D1;}',
				'.truth {font-family:"Staffor R";font-size:16px;}'
			],
			wmode: 'transparent',
			onReplacement: function (o) {
				// Replace Flash callback method as it breaks if instance is null, and that happens a lot in IE6
				window.__flash__removeCallback = function (instance, name) {
					try {
						if ( instance ) {
							instance[name] = null;
						}
					} catch (e) {}
				};
			}
			
		});
		
		//Campaign page top image
		sIFR.replace(stafford_xb, {
			selector: '.layout-3 #content-3 .bg p',
			css:[
				'.sIFR-root {display:inline;}',
				'.blue {color:#0093D1;}',
				'.truth {font-family:"Staffor R";font-size:16px;}'
			],
			wmode: 'transparent'
		});

		sIFR.initialize();

	});

})();