var cp_currentFlashHeader;
var cp_currentFlashHeaderId;

function cp_start() {
	var cp_tabs = [
   		{id:'cp_tab1',name:'overview'},
   		{id:'cp_tab2',name:'wake_up_naturally'},
   		{id:'cp_tab3',name:'boost_energy'},
   		{id:'cp_tab4',name:'relieve_pain'}
   	];
	TabManager.init('#cp_tabmenu',cp_tabs);
}
/*
 * this function will be called right after a tab has changed
 */
function cp_tabChanged(value) {
	// change the flashheader
	cp_setFlashHeader(value);
	
	if(value==0){
  		$("#container").css("display","block");
 	}else{
  		$("#container").css("display","none");
 	}
	
	// re-initialise sIFR
    //cp_init_sIFR("#"+TabManager.data[value]);
	setTimeout("cp_init_sIFR('#" + TabManager.data[value].id + "')", 10);
}

/*
 * Changes the header swf
 * @var integer, the index of the availableHeadersSRC global
 */
function cp_setFlashHeader(value) {
	
	//if(!$("#flashheader_wrapper").length) return false;
	
	var flashObject = cp_flashheaders["tabAnimation"+(value+1)];
	if (flashObject == undefined) return false;
	
	
	var src = flashObject.swf;
	if (src == cp_currentFlashHeader) return false;
		
	// Change placeholder image
	var placeholderSrc = "url("+flashObject.bg+") no-repeat";
	$("#flashheader_wrapper").css("background", placeholderSrc);
	
	if(cp_currentFlashHeaderId) removeSWFObject(cp_currentFlashHeaderId);
	
	$("#"+value).css("display", "block");
	
	cp_currentFlashHeader = src;
	
	if(flashObject.playbutton == undefined) flashObject.playbutton = "true";
	if(flashObject.replayButton == undefined) flashObject.replayButton = "true";
	if(flashObject.autoPlay == undefined) flashObject.autoPlay = "true";
	
	//create flashheader with SWFWrapper
	var flashvars = {
		swf:src,
		swfConfig:flashObject.config,
		wrapperConfig:cp_SWFWrapperConfig,
		playButton:flashObject.playbutton,
		replayButton:flashObject.replayButton,
		autoPlay:flashObject.autoPlay
	};
	var params = {
		menu: "false",
		seamlesstabbing: "false",
		wmode:"transparent",
		allowFullScreen:"true",
		allowScriptAccess :"sameDomain",
		bgColor:"0x000000"
		
	};
	tabId = "tabAnimation";
	
	var attributes = {
		id:tabId
	};
	tabId = "tabAnimation";
	
	swfobject.embedSWF(cp_SWFWrapperPath,tabId, "960", "275", "9", "/consumerfiles/pageitems/master/categorypages/template/assets/js/expressInstall.swf", flashvars, params, attributes);
	prevTab = value;
	
	cp_currentFlashHeaderId = tabId;
}

//----- sIFR
function cp_init_sIFR(tab){
	if(!tab) tab = "";
	if(typeof sIFR !='undefined'){	
	
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h2'
	  		,css: '.sIFR-root {color:#000000;font-size:20px;}'
	  		,wmode: 'transparent'	
	  	});
	
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h3'
	  		,css: '.sIFR-root {color:#000000;font-size:30px; background-color:none;}'
	  		,wmode: 'transparent'	
	  	});
	
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h4'
	  		,css: '.sIFR-root {color:#993300;font-size:20px;background-color:none;}'
	  		,wmode: 'transparent'	
	  	});
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h5'
	  		,css: '.sIFR-root {color:#ffffff;font-size:16px;background-color:none;}'
	  		,wmode: 'transparent'	
	  	});
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h6'
	  		,css: '.sIFR-root {color:#ffffff;font-size:24px;background-color:none;}'
	  		,wmode: 'transparent'	
	  	});        	  	
	}
}

function closePopup(){
	//close the popup and tell it to remove the flash content with the id flashcontent
	popupMan.close({swf:"myExperience"});
}

function openBrightcove(playerId){
	
	var params = {
	centerOnResize:true,
	centerOnScroll:false,
	background:true,
	backgroundClick:false,
	backgroundAlpha:0.5,
	hasFlash:true,
	popupWidth:506,
    popupHeight:468
	};
	
	//open the popup
	popupMan.open("#overlayDiv",params);
	
	//dynamicly create a brightcove player
	createBrightcovePlayer({    
							id:"myExperience",
							containerId:"flashcontent",
							playerId:23188062001,
							publisherID:1875254528,
							width:486,
							height:412,
							videoPlayer:27525662001,
							autoStart:"false"
							});
}

function isDefined(variable)
{
return (!(!(document.getElementById(variable))))
}

function removeSWFObject(clipName){
	var flashMovie = getFlashMovieObject(clipName);
	
	var p = flashMovie.parentNode;
	
	swfobject.removeSWF(clipName);
	var d = document.createElement("div");
	d.id = clipName;
	p.appendChild(d);
	
}

function removeFlashObject(clipName){
	var flashMovie = getFlashMovieObject(clipName);
	
	if(flashMovie){
		var p = flashMovie.parentNode;
		if(p){
		p.removeChild(flashMovie);
		}
	}
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
	  return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
	if (document.embeds && document.embeds[movieName])
	  return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
	return document.getElementById(movieName);
  } 	
}


/*
 * Bandwidth detection
 */

(function($){
  $.bandwidth = null;
  $.bandwidthTestEndpoint = 'http://test.philips.com/esi/getbw_js_tpi.esi';
  $.testBandwidth = function(cb){
    if ($.bandwidth) {
      cb($.bandwidth);
    } else {
      $.onBandwidthTested = cb;
      $.getScript($.bandwidthTestEndpoint);
    }
  }
})(jQuery);

 

