var cp_currentFlashHeader;
var cp_currentFlashHeaderId;

function cp_start() {
	var cp_tabs = [
   		{id:'cp_tab1',name:'overview'},
   		{id:'cp_tab2',name:'sound_experience'},
   		{id:'cp_tab3',name:'sound_experts'},
   		{id:'cp_tab4',name:'product_range'},
		{id:'cp_tab5',name:'songbird'}
   	];
	TabManager.init('#cp_tabmenu',cp_tabs);
}

function switchViewsTab2A(){
	$("#tab2_midboxA").toggle();
	$("#tab2_midboxB").toggle();
	window.scrollTo(0,1200);
	cp_init_sIFR();
	return false;
}

function switchViewsTab2B(){
	$("#tab2_btmboxA").toggle();
	$("#tab2_btmboxB").toggle();
	window.scrollTo(0,1500);
	cp_init_sIFR();
	return false;
}

/*
 * this function will be called right after a tab has changed
 */
function cp_tabChanged(value) {
	// change the flashheader
	cp_setFlashHeader(value);
		
	if(value == 1){
		$("#tab2_midboxA").show();
		$("#tab2_midboxB").hide();
		$("#tab2_btmboxA").show();
		$("#tab2_btmboxB").hide();
	}
	
	// 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/PortableAudio/assets_ows/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.white'
	  		,css: '.sIFR-root {color:#ffffff;font-size:30px;background-color:none;}'
	  		,wmode: 'transparent'	
	  	});
		sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h3.white'
	  		,css: '.sIFR-root {color:#ffffff;font-size:22px; background-color:none;}'
	  		,wmode: 'transparent'	
	  	});

		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h2'
	  		,css: '.sIFR-root {color:#0B5ED7;font-size:26px;}'
	  		,wmode: 'transparent'	
	  	});
		
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h3.white_title'
	  		,css: '.sIFR-root {color:#ffffff;font-size:18px; background-color:none;cursor:pointer;}'
	  		,wmode: 'transparent'	
	  	});
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h3'
	  		,css: '.sIFR-root {color:#0B5ED7;font-size:18px; background-color:none;}'
	  		,wmode: 'transparent'	
	  	});
	
		 /* sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h4'
	  		,css: '.sIFR-root {color:#0B5ED7;font-size:26px;}'
	  		,wmode: 'transparent'	
	  	});*/
		  sIFR.replace(header, {
	  		selector: '#p-rcb ' + tab + ' h5'
	  		,css: '.sIFR-root {color:#0B5ED7;font-size:20px;}'
	  		,wmode: 'transparent'	
	  	});
	}
}

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);

