var current="cp_tab_1";
function show(A){$("#"+current).css("display","none");$("#"+A).css("display","block");current=A};



function cp_init_sIFR(){
	if(typeof sIFR != 'undefined'){

	sIFR.replace(header, {
		selector: '#p-rcb h2'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#6ebb1f;font-size:22px}'
		,wmode: 'transparent'
	});
	
	sIFR.replace(header, {
		selector: '#p-rcb h3'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#252f47;font-size:22px;}'
		,wmode: 'transparent'
	});

	sIFR.replace(header, {
		selector: '#p-rcb h4'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#6ebb1f;font-size:18px;}'
		,wmode: 'transparent'
	});

	sIFR.replace(header, {
		selector: '#p-rcb h5'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#41131D;font-size:22px;}'
		,wmode: 'transparent'
	});

	sIFR.replace(header, {
		selector: '#p-rcb h6'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#FFFFFF;font-size:22px;}'
		,wmode: 'transparent'
	});


	}
	
	// get variable from location
	
    var userRequestedTab = $.jget['tab'];

    // find index from universal tab names
    for (var i = 0; i < universalTabNames.length; i++) {
        if (universalTabNames[i] == userRequestedTab)
            userRequestedTab = i;
    }

	// needs to wait to make sure sifr has kicked in.
	setTimeout("cp_setTab('"+userRequestedTab+"')", "10");
}

/* setup other swf files */
function cp_init_swfobject(){

}

// <TABS LOGIC>
var __currentTabIndex;
/*
 * show a tab and hides others
 *
 * @var integer || string that can be parsed into a integer
 */
function cp_setTab(value) {
    if (typeof value == 'undefined')
        value = 0;
    if (!parseInt(value))
        value = 0;

    if (value >= $('#p-rcb #cp_wrap_tab_productdetails li').length)
        value = 0;

    if (__currentTabIndex == value)
        return;

    // hide all
    for (var i = 0; i < $('#p-rcb #cp_wrap_tab_productdetails li').length; i++) {
        if (i == value) {
            $('#cp_tab_'+(i+1)).addClass('cp_active');
            $('#cp_tab_'+(i+1)).removeClass('cp_inactive');
            $('#cp_tab_content_'+(i+1)).show();
        } else {
            $('#cp_tab_'+(i+1)).addClass('cp_inactive');
            $('#cp_tab_'+(i+1)).removeClass('cp_active');
            $('#cp_tab_content_'+(i+1)).hide();
        }
    }

    // remember last set index
    __currentTabIndex = value;
    
    // change the header
    cp_setHeader(value);

    // ping statistics
    cp_sendStatistics(value);
}

var __currentHeaderSRC;
var __currentHeaderXML;
/*
 * changes the header swf
 *
 * @var integer, the index of the availableHeadersSRC global
 */
function cp_setHeader(value) {
	if (typeof availableHeadersSRC[value] == undefined)
		return false;

	if (typeof availableHeadersXML[value] == undefined)
		return false;

	var src = availableHeadersSRC[value];
	if (src == __currentHeaderSRC)
		return false;

	var src_xml = availableHeadersXML[value];
	if (src_xml == __currentHeaderXML)
		return false;

	__currentHeaderSRC = src;
	__currentHeaderXML = src_xml;
	var cp_header_animation = new SWFObject(src, "Header Animation", "960", "275", "8");
	cp_header_animation.addVariable("xmlfile", src_xml);
	cp_header_animation.addParam("wmode","transparent");
	cp_header_animation.write('flash-inner-wrapper'); 
}

/*
 * Send statictics when the user interacts with the tabs.
 */
var __statsHaveNotBeenSendViaTabInteraction = true;
function cp_sendStatistics(value) {
    if (typeof s != 'object')
        return;

    // normalize tab values;
    if (typeof universalTabNames[value] != 'undefined')
        value = universalTabNames[value];
    else
        value = "TAB" + value;
        
    if (!__statsHaveNotBeenSendViaTabInteraction) {
	    var PRODUCTSUBCATEGORY = cp_getMetrics('PRODUCTSUBCATEGORY');
	    var DIVISION = cp_getMetrics('DIVISION');
	    var SECTION = cp_getMetrics('SECTION');
	    var CATALOGTYPE = cp_getMetrics('CATALOGTYPE');
	    var PRODUCTGROUP = cp_getMetrics('PRODUCTGROUP');
	    var PRODUCTCATEGORY = cp_getMetrics('PRODUCTCATEGORY');
	    
        if (PRODUCTSUBCATEGORY != "") {
            var TABSECTION = PRODUCTSUBCATEGORY + '_' + value;
            s.pageName = DIVISION + ":" + SECTION + ":" + TABSECTION + ":" + CATALOGTYPE;
        } else if (PRODUCTCATEGORY != "") {
            var TABSECTION = PRODUCTCATEGORY + '_' + value;
            s.pageName = DIVISION + ":" + SECTION + ":" + TABSECTION + ":" + CATALOGTYPE;
        }
        s.t();
    }
	__statsHaveNotBeenSendViaTabInteraction = false;
}

function cp_getMetrics(metric) {
    var content = $("meta[name='PHILIPS.METRICS."+metric+"']").attr("content");
    if (typeof content == 'undefined' || content == null)
        return '';
    else
        return content;
}

// </TABS LOGIC>

$(document).ready(function() {
	//sIFR needs a timeout for safari or sometimes sIFR won't behave correctly
	setTimeout("cp_init_sIFR()", "1000");
	cp_init_swfobject();
	
});


/**
 * jget plugin
 * @author Alexandre Magno
 * @desc get a query string to be accessible for javascript
 * @version 1.0
 * @example
 *
 * http://www.foo.com/test.php?var1=test1
 * var outputQuery = $.jget['var1'];
 * $.debug(outputQuery);
 * //Will show 'test1'
 *
 *
 * @license free
 * @param bool vertical, bool horizontal
 * @site http://blog.alexandremagno.net
 *
 */

jQuery.extend({

	//starting the jget object
	jget: {},
	//get the url
	url: window.location.href.replace(/^[^\?]+\??/,''),
	//get the queryString
	parseQuery: function ( query ) {
	   var Params = {};
	   if ( ! query ) {return Params;}// return empty object
	   var Pairs = query.split(/[;&]/);
	   for ( var i = 0; i < Pairs.length; i++ ) {
	      var KeyVal = Pairs[i].split('=');
	      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
	      var key = unescape( KeyVal[0] );
	      var val = unescape( KeyVal[1] );
	      val = val.replace(/\+/g, ' ');
	      Params[key] = val;
	   }
	   return Params;
	},
	//Make the jget object available to jQuery.extend
	getQueryString: function() {
		this.jget = this.parseQuery(this.url);
	},
	//debugging
	debug: function(message) {

		if(!$.browser.msie) {

			console.info(message);

		} else if($.browser.safari) {

			window.console.log(message);

		} else {

			alert(message);
		}

	}

});

//start the plugin
$.getQueryString();


