jQuery.flipper = function ($activator, $transformable, $highlighter, eventFlip, eventResume) {
	this.slideshow; 
	this.flipAnimation; 
	this.currentMouseover = false;
	this.autoDelay = 3000;
	this.flipDelay = 400;
	var curObj = this;
	$activator.each(function(index){
		jQuery(this).attr('flipperId', index);
		$transformable.eq(index).attr('flipperId', index);
	});
	$activator.filter(':first').addClass('active');
	$transformable.css('opacity', '0');
	$transformable.filter(':first').css({'z-index': 2, 'opacity': 1});
	
	if (eventFlip && eventResume) {
		$activator.bind(eventFlip,(function(){
			if (!jQuery(this).hasClass('active')) {
				curObj.currentMouseover = jQuery(this);
				curObj.flipTo(jQuery(this));
			}
		}));
		$activator.bind(eventResume,(function(){
			curObj.currentMouseover = false;
			if (curObj.slideshow) {
				curObj.flipAll();
			}
		}));
	}
	
	this.flipTo = function($item, delay) {
		var curObj = this;
		if (!delay) {
			delay = this.flipDelay;
		}
		clearTimeout(curObj.flipAnimation);
		curObj.flipAnimation = setTimeout(function(){ // this will add a delay before animating
			var $currentActive = $activator.filter('.active');
			$currentActive.removeClass('active');
			
			if ($highlighter) {
				$highlighter.stop().animate({
					'marginTop' : $item.css('margin-top')
				}, 300, null, function(){
					curObj.transform($item, $currentActive, $transformable, delay)
				});				
			} else {
				curObj.transform($item, $currentActive, $transformable, delay);
			}
		}, delay);
	}
	
	this.transform = function($item, $currentActive, $transformable, delay) {
			$item.addClass('active');
			var idCurrent = $currentActive.attr('flipperId');
			var idNext = $item.attr('flipperId');
			
			$transformable.filter('[flipperId=' + idCurrent + ']').
				css('z-index', 1);
			$transformable.filter('[flipperId=' + idNext + ']').
				stop().
				css('z-index', 2).
				animate({'opacity': 1}, 400, null, function(){
					$transformable.filter('[flipperId=' + idCurrent + ']').css('opacity', 0);
					if (curObj.slideshow === true && !curObj.currentMouseover) {
						curObj.flipTo(curObj.getNextItem(), curObj.autoDelay);
					} else {
						curObj.flipAnimation = false;				
					}
				});
	}

	this.flipAll = function() {
		this.slideshow = true;
		this.flipTo(this.getNextItem(), this.autoDelay);
	}

	this.getNextItem = function() {
		var $nextActive = $activator.filter('.active').next();
		if ($nextActive.length !== 1) {
			$nextActive = $activator.filter(':first');
		}
		return $nextActive;
	}
}
;

// 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'] = 'de';
}

function replaceText() {
	if (jQuery.fn.flash.hasFlash('7')) {
	    jQuery('#suggestedContent h3').flash(
	        {
	            src: Drupal.settings.themeUrl+'/swf/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 = jQuery(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            jQuery(this)
	                .addClass('flash-replaced')
	                .prepend(jQuery.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
	    jQuery('.section h1').flash(
	        {
	            src: Drupal.settings.themeUrl+'/swf/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 = jQuery(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            jQuery(this)
	                .addClass('flash-replaced')
	                .prepend(jQuery.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
		/*jQuery('.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 = jQuery(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            jQuery(this)
	                .addClass('flash-replaced')
	                .prepend(jQuery.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );*/
	    jQuery('h3.quote').flash(
	        {
	            src: Drupal.settings.themeUrl+'/swf/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 = jQuery(this.firstChild);
	            htmlOptions.height = $alt.height();
	            htmlOptions.width = $alt.width();
	            $alt.addClass('alt');
	            jQuery(this)
	                .addClass('flash-replaced')
	                .prepend(jQuery.fn.flash.transform(htmlOptions));
	        }, 
			{ update: false }
	    );
	}
}


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);
		}
	});
}


jQuery(document).ready(function() {

    jQuery('a.currentLanguage').toggle(function() {
        jQuery('div.localized').css('display', 'block');
        return false;
    }, function() {
        jQuery('div.localized').css('display', 'none');
        return false;
    });
    
    jQuery('table tr:nth-child(odd)').addClass('odd');
    jQuery('table tr:nth-child(even)').addClass('even');
    
    jQuery('a[rel=external]').attr('target', '_blank');
});
;

