$(document).ready(function() {
	$('a.currentLanguage').toggle(function() {
		$('div.localized').css('display', 'block');
		return false;
	}, function() {
		$('div.localized').css('display', 'none');
		return false;
	});
});


// if not yet set - get the current locale and path
if (typeof(scriptVars['locale']) == 'undefined') {
	scriptVars['urlSplit'] = window.location.href.split(/(http|https):\/\/(\w+:{0,1})?([^\/]+)\/([^\/]+)(\/.+|.*)/);
	scriptVars['locale'] = scriptVars['urlSplit'][4].split('#')[0];
	scriptVars['path'] = scriptVars['urlSplit'][5];
	if (!scriptVars['locale']) scriptVars['locale'] = 'en';
}

function replaceText() {
	if ($.fn.flash.hasFlash('7')) {
	    $('#suggestedContent h3').flash(
	        {
	            src: '/media/rockwell.swf', 
	            flashvars: { 
	                css: [
	                    //'* { color: #666666; }',
	                    'a { color: #0099CC; text-decoration: none; }',
	                    'a:hover { text-decoration: underline; }'
	                ].join(' ')
				},
				wmode: 'transparent'
	        },
	        { version: 7 },
	        function(htmlOptions) {
	            htmlOptions.flashvars.txt = this.innerHTML;
	            this.innerHTML = '<div>'+this.innerHTML+'</div>';
	            var $alt = $(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            $(this)
	                .addClass('flash-replaced')
	                .prepend($.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
	    $('.section h1').flash(
	        {
	            src: '/media/rockwell.swf', 
	            flashvars: { 
	                css: [
	                    '* { color: #a94618; }',
	                    'a { color: #0099CC; text-decoration: none; }',
	                    'a:hover { text-decoration: underline; }'
	                ].join(' ')
				},
				wmode: 'transparent'
	        },
	        { version: 7 },
	        function(htmlOptions) {
	            htmlOptions.flashvars.txt = this.innerHTML;
	            this.innerHTML = '<div>'+this.innerHTML+'</div>';
	            var $alt = $(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            $(this)
	                .addClass('flash-replaced')
	                .prepend($.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
		/*$('.first .newsItem h3, .second .newsItem h3').flash(
	        {
	            src: '/media/rockwell.swf', 
	            flashvars: { 
	                css: [
	                    '* { color: #a94618; }',
	                    'a { color: #a94618; text-decoration: none; }',
	                    'a:hover { text-decoration: none; }'
	                ].join(' ')
				},
				wmode: 'transparent'
	        },
	        { version: 7 },
	        function(htmlOptions) {
	            htmlOptions.flashvars.txt = this.innerHTML;
	            this.innerHTML = '<div>'+this.innerHTML+'</div>';
	            var $alt = $(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            $(this)
	                .addClass('flash-replaced')
	                .prepend($.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );*/
	    $('h3.quote').flash(
	        {
	            src: '/media/segoe_script.swf', 
	            flashvars: { 
	                css: [
	                    '* { color: #73062E; text-align: center; }',
	                    'a { color: #0099CC; text-decoration: none; }',
	                    'a:hover { text-decoration: underline; }'
	                ].join(' ')
				},
				wmode: 'transparent'
	        },
	        { version: 7 },
	        function(htmlOptions) {
	            htmlOptions.flashvars.txt = this.innerHTML.replace('%', '&#37;');
	            this.innerHTML = '<div>'+this.innerHTML+'</div>';
	            var $alt = $(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            $(this)
	                .addClass('flash-replaced')
	                .prepend($.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
	}
}

$(document).ready(function() {
	$('table tr:nth-child(odd)').addClass('odd');
	$('table tr:nth-child(even)').addClass('even');
	
	$('a[rel=external]').attr('target', '_blank');
});


function crossFade($container, classElement, classActive, fadeTime, delay) {
	var $cur = $container.find("." + classActive);
	var $next = $container.find("." + classActive).next("." + classElement);
	if ($next.length !== 1) {
		$next = $container.find("." + classElement + ":first");
	}
	$cur.css('z-index', 1).removeClass(classActive);
	$next.stop().css('z-index', 2).animate({'opacity': 1}, fadeTime, null, function(){
		$next.addClass(classActive);
		$cur.css('opacity', 0);
		if (typeof(delay) != 'undefined') {
			setTimeout(function(){
				crossFade($container, classElement, classActive, fadeTime, delay);
			}, delay);
		}
	});
}
