 /**
 * AUDI JavaScript library: flash
 * 
 * @projectDescription	functions for interactions with flash
 * @namespace			flash.*
 *
 * @author 				$Author: hhoettecke $
 * @version				$Revision: 173 $
 * @copyright			NEUE DIGITALE GmbH, Berlin
 * 
 * @jslint: 2008-10-31
 * 
 * @file:				audi_ngw.flash.js
 * $URL: https://svn.pvtool.org/svn/day_audi_ngw/trunk/ngw_base/frontend/js/audi/audi_ngw.api.js $
 */

/* create namespace */
audi_ngw.namespace(audi_ngw,'flash');
audi_ngw.flash.hasFlash = false;
audi_ngw.flash.disableFlash = false;
audi_ngw.flash.hasSIFR = false;
audi_ngw.flash.sNeededFlashVersion = null;




audi_ngw.flash.overlayHide = function(){
//console.log('audi_ngw.flash.overlayHide');
	jQuery('#audi_gallery_fullscreen').hide();
};

audi_ngw.flash.overlayShow = function(){
//console.log('audi_ngw.flash.overlayShow');
	jQuery('#audi_gallery_fullscreen').show();
};



audi_ngw.flash.setWidth = function(id, width){
	var $element = jQuery('#' + id);
	if( 1 == $element.size() ) {
		$element.css('overflow','hidden');
		$element.width(width);
		return true;
	}
	return false;	
};


audi_ngw.flash.setHeight = function(id, height){
	var $element = jQuery('#' + id);
	if( 1 == $element.size() ) {
		$element.height(height).attr('height', height);
		return true;
	}
	return false;
};


/**
 * Replaces breadcrumb, acts as api to audi_ngw.flash.replace
 * @method replaceBreadcrumb
 * @return {Void}
 */
audi_ngw.flash.replaceBreadcrumb = function () {
	
	if( false === audi_ngw.sIFRenabled ) {
		return false;
	}
	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_navigation_breadcrumb',sSelectorElement: '*', sFontSize: ''});		
};

/**
 * Replaces headlines, acts as api to audi_ngw.flash.replace
 * @method adviceLayerHeadlines
 * @return {Void}
 */
audi_ngw.flash.adviceLayerHeadlines = function(){
	audi_ngw.flash.replace({sSelectorWrapper: '.audi_template_d',sSelectorElement: 'h4.sIFR', sFontSize: '14px'});	
};
/**
 * Replaces headlines, acts as api to audi_ngw.flash.replace
 * @method replaceHeadlines
 * @return {Void}
 */
audi_ngw.flash.replaceLayerHeadlines = function(){
	
	if( 'undefined' !== typeof(audi_ngw.sIFRenabled) && false === audi_ngw.sIFRenabled ) {
		return false;
	}
	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_container',sSelectorElement: 'h1.sIFR', sFontSize: '18px'});		
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_container',sSelectorElement: 'h2.sIFR', sFontSize: '13px' });	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_container',sSelectorElement: 'h3.sIFR', sFontSize: '13px' });	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_container',sSelectorElement: 'h4.sIFR', sFontSize: '11px'});	
 

//	audi_ngw.flash.replace({
//		sSelectorWrapper: '#audi_modal_container',
//		sSelectorElement: 'h1.sIFR',
//		sFontSize: '18px'
//	});
};

/**
 * Replaces headlines, acts as api to audi_ngw.flash.replace
 * @method replaceHeadlines
 * @return {Void}
 */
audi_ngw.flash.replaceHeadlines = function () {
	
	if( 'undefined' !== typeof(audi_ngw.sIFRenabled) && false === audi_ngw.sIFRenabled ) {
		return false;
	}
	
	// content left
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_nav_distributor',sSelectorElement: 'h2.sIFR', sFontSize: '13px'});	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_teaser_content',sSelectorElement: 'h3.sIFR', sFontSize: '11px'});	

	// main content
	audi_ngw.flash.replace({sSelectorWrapper: '#con_news_pageheadline',sSelectorElement: 'h1.sIFR', sFontSize: '13px'});		
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_content_wrapper',sSelectorElement: 'h1.sIFR', sFontSize: '18px'});		
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_header',sSelectorElement: 'h1.sIFR', sFontSize: '18px'});		
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_teaser_area',sSelectorElement: 'h2.sIFR', sFontSize: '11px' });	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_content_wrapper',sSelectorElement: 'h3.sIFR', sFontSize: '13px' });	
	audi_ngw.flash.replace({sSelectorWrapper: '.audi_template_d',sSelectorElement: 'h4.sIFR', sFontSize: '14px'});	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_content_wrapper',sSelectorElement: 'h2.sIFR', sFontSize: '13px'});	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_modal_body',sSelectorElement: 'h2.sIFR', sFontSize: '13px'});	
	
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_content_wrapper',sSelectorElement: 'legend.sIFR', sFontSize: '13px'});	

	// content right 
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_marginalia',sSelectorElement: 'h3.sIFR', sFontSize: '13px'});	
	
	// footer
	audi_ngw.flash.replace({sSelectorWrapper: '#audi_navigation_footer',sSelectorElement: 'h4.sIFR', sFontSize: '11px'});	
};


/**
 * Set options to replace .sFIR tagged elements with flash movies if body.hasClass('sIFRenabled') and the required flash verion's present, bridges to _doReplace
 * @see _doReplace
 * @param {Object} Options
 */
audi_ngw.flash.replace = function(oOptions){

	// check environment
	if ( audi_ngw.flash.disableFlash === true || audi_ngw.flash.hasFlash === false || audi_ngw.flash.hasSIFR === false )  { return; }

	var $content;
	
	
	// get the path to the images
	var _sFlashSrcBreadcrumb = audi_ngw.docroot + 'img/swf/breadcrumb_jfr_audi_sans_ext.swf';
	var _sFlashSrcHeadlines = audi_ngw.docroot + 'img/swf/nd_jfr_audi_sans_ext.swf';

	var _sSelector = oOptions.sSelectorWrapper;
	_sSelector += " ";
	_sSelector += oOptions.	sSelectorElement;

	switch (_sSelector) {
	
		// breadcrumb 
		case '#audi_navigation_breadcrumb *':
			// get content wrapper
			$content = jQuery('#audi_navigation_breadcrumb');
			// prevent multiple replacements
			if ($content.hasClass('flashReplaced')) { return false; }
			// replace 
			audi_ngw.flash._doReplace($content, {
				sFlashSrc: _sFlashSrcBreadcrumb
			}, {
				sType: 'breadcrumb'
			});
			// set classes, mark as replaced
			$content.addClass('flashReplaced').removeClass('sIFR');
			break;
			
		// content h1
		case '#audi_modal_container h1.sIFR':
		case '#audi_content_wrapper h1.sIFR':
			// get content wrapper
			$content = jQuery(_sSelector.split(' ')[0]);
//			audi_ngw.log('sIFR: content h1')
			// check for multi-line headlines 
			if ($content.find('h1.sIFR span.first_half').size()) {
				// replace first line 
				audi_ngw.flash._doReplace($content.find('h1.sIFR span.first_half'), {
					sTextColor: '#ffffff',
					sFontSize: oOptions.sFontSize,
					sFlashSrc: _sFlashSrcHeadlines
				}, {
					sType: 'h1.multiline'
				});
				// replace second line 

				audi_ngw.flash._doReplace($content.find('h1.sIFR span.second_half'), {
					sTextColor: '#2b2f33',
					sFontSize: oOptions.sFontSize,
					sFlashSrc: _sFlashSrcHeadlines
				}, {
					sType: 'h1.multiline'
				});
			}
			// replace single-line headlines 
			else {
				// get elements
				var $elements = $content.find('h1.sIFR');
				// ensure replacement is necessary
				if (!$elements.size()) { return false; }
				// add span, needed for swfobject
				if (!$elements.find('span').size()) {
					$elements.wrapInner(document.createElement('span'));
				}
				// replace
				audi_ngw.flash._doReplace($content.find('h1.sIFR span'), {
					sTextColor: '#ffffff',
					sFontSize: oOptions.sFontSize,
					sFlashSrc: _sFlashSrcHeadlines
				}, {
					sType: 'h1.singleline'
				});
			}
			// set classes, mark as replaced
//			$content.find('h1.sIFR object').parent().addClass('flashReplaced').removeClass('sIFR');
			$content.find('h1.sIFR').addClass('flashReplaced').removeClass('sIFR');
			break;
			
		// content headlines
		default:
	//	audi_ngw.log('sIFR: default')
			// get content wrapper
			$content = jQuery(oOptions.sSelectorWrapper);
			// get elements
			$elements = $content.find(oOptions.sSelectorElement);
			// ensure replacement is necessary
			if (!$elements.size()) { return false; }
			// add span, needed for swfobject
			if (!$elements.find('span').size()) {
				$elements.wrapInner(document.createElement('span'));
			}
			// add span, needed for swfobject
			audi_ngw.flash._doReplace($content.find(oOptions.sSelectorElement + ' span'), {
				sTextColor: oOptions.sTextColor || '#ffffff',
				sFontSize: oOptions.sFontSize,
				sFlashSrc: _sFlashSrcHeadlines
			}, {
				sType: 'headlines'
			});
			// set classes, mark as replaced
//			$content.find(oOptions.sSelectorElement + ' object').parent().addClass('flashReplaced').removeClass(oOptions.sSelectorElement.split('.')[1]);
			$content.find(oOptions.sSelectorElement).addClass('flashReplaced').removeClass(oOptions.sSelectorElement.split('.')[1]);
			break;
	}
};


/**
 * Replace headlines with custom flash font, uses swfObject plugin.
 * Keep in mind that it's impossible to grab width/height of hidden elements (e.g.:display: none).
 * Solution: copying the source element to the body and setting class "forceDisplay" (left: -9999em; display: block;).
 * To get the correct dimensions, we're adding the source's class, tagname in lowercases and text without special chars 
 * to the cloned class-attribute (e.g.: span[class="h1 audi_tab_navigation_value Audi_Sitemap___Gebrauchtwagen forceDisplay"]).
 * Please specify the dimensions for this cloned elements at your stylesheet 
 * (e.g.: span.audi_generated_corners_background { width: 166px; font-size: 13px; height: 18px;})
 * to ensure the new sIFR-element gets the correct dimensions.
 * @param {jQuery-object} $target
 * @param {String} properties
 * @return 
 */
audi_ngw.flash._doReplace = function($target, properties,options){	
	/*
		var version = deconcept.SWFObjectUtil.getPlayerVersion();
		
		// IE has problems with minor flash player versions with this functions
		if (version["major"] < audi_ngw.flashreqversion["major"] && version["rev"] < audi_ngw.flashreqversion["rev"] && $.browser.msie) {
			return false;
		};
	*/		

		// use custom properties or take the default values
		var sHoverColor = (properties && properties.hoverColor) ? properties.hoverColor : '#d5d5d5';
		var sTextColor = (properties && properties.sTextColor) ? properties.sTextColor : '#ffffff';
		var customCSS = (properties && properties.css) ? properties.css : '';

		// use $source.height() if no values is  present
		var iFontSize = (properties && properties.sFontSize) ? parseInt(properties.sFontSize.slice(0,-2)) : '';

		// use $source.height() if no values is  present
		var sFontSize = (properties && properties.sFontSize) ? 'font-size: '+properties.sFontSize+';' : '';

		var sFlashSrc = (properties && properties.sFlashSrc) ? properties.sFlashSrc : 'undefined' ;
 
		// construct css string, passed as flashvar
		var cssString = [
						'* { color: '+sTextColor+'; '+sFontSize+'}',
						'.active, a:hover{color: '+sHoverColor+';}'
		].join(' ');

//		audi_ngw.log(cssString);
 
		// replace targets with flash
		$target.each(function(id){

			// cache current element
			var $source = jQuery(this);

			var flashMargin = 0; /* Flash adds 2px padding to every flash-textfield, we compensate it now */
			
			// get text
			var sText = $source.html();
 
			// used code from prototype 1, no idea if it's still necessary
			if (jQuery.browser.msie) {
				// cleanup IE innerHTML result, maybe the solution should be submitted to jQuery
				var wrongMarkup = new RegExp('=(.[^"]*?)(?=( |>))', 'g'); // search for atributes without semicolons
				var rightMarkup = new RegExp('="$1"'); // add semicolons
				sText = sText.replace(wrongMarkup, '="$1"');
			}

			// generate attributes
			var oAttributes = {};

			// get dimensions from css definitions of replaced headline
			oAttributes.height =  (options.sType == "h1.multiline") ? parseInt($source.height()) + flashMargin : parseInt($source.parent().height()) + flashMargin;
			oAttributes.width = parseInt( $source.parent().width() ) ; //+ flashMargin;
 
			// swfobject fails if width || height equals zero (in case of $source or a parent element ain't visible) 
 			if (oAttributes.height === 0 || oAttributes.width === 0 ) { 
				// force id, store for getElementById
				var _sId = $source.audi_identify()[0].id;
				//clone element to get dimensions, use native methods 'cause jquery clone fails 
				var _parent = document.getElementById(_sId);
				var _elTmp = _parent.cloneNode(true);
				_elTmp.id = "audi_generic_copy";
				// set classname, set classname to parentNode.nodeValue + parentNode.parentNode.className to get css styles specified, sets display properly
				// e.g.span.h4.audi_generated_corners_background.Schlie_en.forceDisplay or span.h1.audi_tab_navigation_value.forceDisplay
				_elTmp.className = _parent.parentNode.tagName.toLowerCase()+" "+ _parent.parentNode.parentNode.className +" "+sText.replace(/[^a-zA-Z]/g,"_")+" forceDisplay";
				// append on body
				document.body.appendChild(_elTmp);
				// get dimensions 
				oAttributes.height = jQuery('#audi_generic_copy').outerHeight();
				oAttributes.width = jQuery('#audi_generic_copy').width();

				// delete element
				_elTmp.parentNode.removeChild(_elTmp);
				_elTmp=null;
			}
			
			// margin-left for H1 second_half can be set in CMS
			// we make sure it´s still there after flash replacement
			if ($source.attr('class').indexOf('second_half') !== -1) {
				var _cssMarginLeft = jQuery('.second_half').css('marginLeft');
			}

			// generate param-element
			var oParams = {};
			oParams.wmode = 'transparent';
			
			// generate flashvars
			var oFlashVars = {};
			oFlashVars.css = escape(cssString);
			oFlashVars.shadow = ($source.parent().hasClass('hasShadow'));
			oFlashVars.txt = encodeURI(sText.toString().replace(/&gt;/g,''));

			// prevent calulation errors, "fake scalable"
			oAttributes.width = "100%";
			
			// replace breadcrumb
			 if (options.sType === 'breadcrumb') {
				var id = 'audi_navigation_breadcrumb';
				oAttributes.src = sFlashSrc;
				// create replacement container
				if (jQuery('#'+id+'_replaced').length === 0)  {
//					jQuery('<div id="">').appentTo(jQuery('#'+id));
					jQuery('<div>').attr('id',(id+'_replaced')).prependTo(jQuery('#' + id).parent());
				}
				// fix ie 
				if (jQuery.browser.msie) {
					// add missing </li> elements
					var string = decodeURI(oFlashVars.txt);
					oFlashVars.txt = encodeURI(string.replace(/(<(.*?)><a.*?>.*?<\/a>\s([^<\/$2]))/gi, '$1</$2>'));
				}
				
				// replace
				swfobject.embedSWF(oAttributes.src, id+'_replaced', oAttributes.width, oAttributes.height, audi_ngw.flash.sNeededFlashVersion, "expressInstall.swf", oFlashVars, oParams);

				// hide HTML breadcrumb - will be updated via js
				jQuery('#' + id).addClass('flashReplaced').css({
					'visibility': 'hidden',
					'height': '1px',
					'line-height': '1px',
					'font-size' : '1px',
					'width' : '1px',
					'text-indent': '-999em',
					'position': 'absolute',
					'left':'0',
					'top': '0'
				});
			}
			// replace headlines 
			else {
				var id = audi_ngw.dom.identify($source);
				oAttributes.src = sFlashSrc;

				// store replaced text at span.aural 
				var $spanAuraul = $source.parent().find('span.aural');
				if (!$source.parent().find('span.aural').size()) {
					jQuery('<span class=""></span>').addClass('aural').text(sText).insertAfter($source);
				} else {
					$spanAuraul= $spanAuraul.eq(0);
					$spanAuraul.text($spanAuraul.text()+" "+sText);
				}

				// replace
				swfobject.embedSWF(oAttributes.src, id, oAttributes.width, oAttributes.height,audi_ngw.flash.sNeededFlashVersion, "expressInstall.swf", oFlashVars, oParams);

				// keep classnames 
				jQuery("#" + id).addClass($source.attr("class"));
				if ($source.attr('class').indexOf('second_half') !== -1) {
					
					jQuery("#" + id).wrap('<span class="second_headline"></span>').parent().css('marginLeft', _cssMarginLeft);
					
				
				}
					

			}
			
			// clear visibility hidden, if needed
//			$source.css('visibility','');
		});
};

/**
 * Force document repaint to reinitialize flash films after textreplacing.
 * Necessary because some browsers (Opera 9.27, ) sometimes fail on showing the updated flash movie.
 * @method forceRepaint
 * @return {Void}
 */
audi_ngw.flash.forceRepaint = function () {
	audi_ngw.animation.forceRepaint();
};
 


audi_ngw.flash.initiate = function(scope){

	audi_ngw.flash.checkVersion();
	var _sSelector = (scope)  ? '#'+scope : '';
	_sSelector += ' .media';

	audi_ngw.flash.objects =[];

	if(  audi_ngw.flash.disableFlash === true || false === audi_ngw.flash.hasFlash ) {
		return;
	}

	// replace all dom-objects with the class 'media' with flash-films defined in the class-metadata
	// using swfobject 2.1
	// TODO update to 2.1 stable as soon as it is ready (using 2.1 rc1 now)
	jQuery(_sSelector).each(function(){

		var $image = jQuery(this);
		var data = $image.metadata();
 
		var attribute = {};
		attribute.version = ( 'undefined' == typeof(data.version) ) ? audi_ngw.flash.sNeededFlashVersion : data.version;
		attribute.width = ( 'undefined' == typeof(data.width) ) ? $image.width() : data.width;
		attribute.height = ( 'undefined' == typeof(data.height) ) ? $image.height() : data.height;
		attribute.src = ( 'undefined' == typeof(data.src) ) ? $image.attr('src').replace(/jpg/, 'swf') : data.src;


		var params = {};
		params.allowScriptAccess = ( 'undefined' == typeof(data.allowScriptAccess) ) ? 'always' : data.allowScriptAccess;
		params.allowFullScreen = ( 'undefined' == typeof(data.allowFullScreen) ) ? 'true' : data.allowFullScreen;
		params.scale = ( 'undefined' == typeof(data.scale) ) ? 'noscale' : data.scale;
		params.menu = ( 'undefined' == typeof(data.menu) ) ? 'false' : data.menu;
		params.wmode = ( 'undefined' == typeof(data.wmode) ) ? 'opaque' : data.wmode;
		
		if ('undefined' != typeof(data.ctalabel)) {
			data.ctalabel = escape(data.ctalabel);
		}
		
		if ('undefined' != typeof(data.ctalink)) {
			data.ctalink = escape(data.ctalink);
		}
		
		data.parent_id = $image.parent().audi_identify().attr('id');

		//-- handle and reorganize cta-button on non-emo-stage
		if (jQuery('#audi_container_emo').size() == 0 && jQuery('a.cta-button').size() == 1) {
			jQuery('a.cta-button').appendTo( jQuery('#' + data.parent_id).parent());
		}
		
		swfobject.embedSWF(attribute.src, data.parent_id, attribute.width, attribute.height, attribute.version, "expressInstall.swf", data, params);
		
		audi_ngw.flash.objects.push(data.parent_id);

	});
	
	
	
};


audi_ngw.flash.checkVersion = function() {
 
	try {
		var aVersion = [audi_ngw.flashreqversion.major,audi_ngw.flashreqversion.minor,audi_ngw.flashreqversion.rev];
		audi_ngw.flash.sNeededFlashVersion = aVersion.join('.');

		audi_ngw.flash.hasFlash = swfobject.hasFlashPlayerVersion(audi_ngw.flash.sNeededFlashVersion);
 		if ( audi_ngw.flash.disableFlash === true || audi_ngw.flash.hasFlash === false  ){
			// show html text on elements that'll be sIFR-replaced because there won't be any replacement
			jQuery('html').removeClass('hide_sIFR');
 		}

	}catch (e) {}
};

audi_ngw.flash.pause = function(id){		
	try {
		jQuery('#' + id)[0].freeze();
	}catch (e) {
		//audi_ngw.log('audi_ngw.flash.pause: ' + e, 'error');
	}
};


audi_ngw.flash.resume = function(id){	
	try {
		jQuery('#' + id)[0].unfreeze();
	}catch (e) {
		//audi_ngw.log('audi_ngw.flash.resume: ' + e, 'error');
	}
};


audi_ngw.flash.pauseAll = function(){
	jQuery(audi_ngw.flash.objects).each(function(){
		audi_ngw.flash.pause(String(this));
	});
};


audi_ngw.flash.resumeAll = function(){
	jQuery(audi_ngw.flash.objects).each(function(){
		audi_ngw.flash.resume(String(this));
	});
};


audi_ngw.flash.soundOn = function(id){		
	try {
		jQuery('#' + id)[0].soundOn();
	}catch (e) {
		//audi_ngw.log('audi_ngw.flash.soundOn: ' + e, 'error');
	}
};


audi_ngw.flash.soundOff = function(id){		
	try {
		jQuery('#' + id)[0].soundOff();
	}catch (e) {
		//audi_ngw.log('audi_ngw.flash.soundOff: ' + e, 'error');
	}
};


audi_ngw.flash.pageLoaded = function(id){
 // skip try / catch, use safe execution (@see: audi_ngw.api_helper.execute)

	window.setTimeout(function(){
			try{swfobject.getObjectById(id).onPageLoad();}catch(e){}
		}, 100);

	return;
};


audi_ngw.flash.getFlashMovie = function(sId){

	try {
		return swfobject.getObjectById(sId);
	} catch(e) { 
		//throw new Error(e); 
	}
};

/**
 * On execute check for sIFR-marker, set flag and hide sIFR text contents to prevent flickering during load
 */
// check for sifr marker
//if (jQuery('body').hasClass('sIFRenabled') === true || true == true ) {
if( 'undefined' == typeof(audi_ngw.sIFRenabled) || false !== audi_ngw.sIFRenabled ) {
	// set flag
	audi_ngw.flash.hasSIFR = true;
	// hide html text on elements that'll be sIFR-replaced
	jQuery('html').addClass('hide_sIFR');
	
// 	audi_ngw.event.ajaxModalContentReadyCount--;
//	jQuery(document).trigger("ajaxModalContentPrepared");
}



/**
 * Custom Event: wil be fired as soon as we filled the ajax-content into the modal layer, just before "xhrReallocate"
 * @param {Object} event
 * @param {Object} xhr
 */
audi_ngw.flash.onAjaxModalContentReady = function(event,xhr){
 
	// check if this xhr-response contains valid content
	if (!audi_ngw.url.hasXHRContent(xhr,event.timeStamp)) {return false;}
	//audi_ngw.log("EVENT - ajaxModalContentReady: audi_ngw.flash.onAjaxModalContentReady",arguments);
	// execute funtions on new content
	audi_ngw.flash.replaceLayerHeadlines();
	// replace DOM.media with the corresponding flash objects (.metadata())
	audi_ngw.flash.initiate(audi_ngw.url.getContentId());
	// trigger event 
	audi_ngw.event.trigger('ajaxModalContentPrepared');
 
};
 

/**
 * Custom Event: wil be fired as soon as we injected the xhr-snippet 
 * @param {Object} event
 * @param {Object} data {sId: new HTML parent Id}
 */
audi_ngw.flash.onAjaxSnippetReady = function(event,data){
 
	//audi_ngw.log("EVENT - ajaxSnippetPrepared: audi_ngw.flash.onAjaxSnippetReady ",arguments);
	// execute funtions on new content
	audi_ngw.flash.replaceHeadlines();
	audi_ngw.flash.replaceLayerHeadlines();
	// replace DOM.media with the corresponding flash objects (.metadata())
	audi_ngw.flash.initiate(data.sId.slice(1));
	
	// trigger event 
	audi_ngw.event.trigger('ajaxSnippetPrepared');
 };
 

jQuery(document).ready(function () {
		// register ajaxModalContentReady event
		audi_ngw.event.bind('ajaxModalContentReady',audi_ngw.flash.onAjaxModalContentReady);
 
	 	audi_ngw.event.bind('ajaxSnippetReady',audi_ngw.flash.onAjaxSnippetReady);

});

// called from audi_ngw.navigation.updatePage and audi_ngw.navigation(document ready)
audi_ngw.flash.initialize = function() {

	// replace headlines on window.load
	audi_ngw.flash.replaceBreadcrumb();
	audi_ngw.flash.replaceHeadlines();
	
	// start flash video only if everything on page is loaded
	jQuery(audi_ngw.flash.objects).each(function(){
		var _sId = String(this);
		audi_ngw.api.helper.execute(function(){
			audi_ngw.flash.pageLoaded(_sId);
		},("audi_ngw.flash.pageLoaded_"+_sId));
	});
};

