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:#f6a0a5;font-size:24px;}'
		,wmode: 'transparent'
	});
	
	
	sIFR.replace(header, {
		selector: '#p-rcb h3'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#4c8bff;font-size:24px;}'
		,wmode: 'transparent'
	});

	sIFR.replace(header, {
		selector: '#p-rcb h4'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#013e82;font-size:24px;}'
		,wmode: 'transparent'
	});
	
	sIFR.replace(header, {
		selector: '#p-rcb h5'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#6ebb1f;font-size:24px;}'
		,wmode: 'transparent'
	});

	sIFR.replace(header, {
		selector: '#p-rcb h6'
		,css: '.sIFR-root {background-color:#FFFFFF;color:#992c96;font-size:24px;}'
		,wmode: 'transparent'
	});

	}
	
	// get variable from location
    var userRequestedTab = $.jget['tab'];

    // find index from universal tab names only when global js var exists
    if (typeof universalTabNames != 'undefined')
        for (var i = 0; i < universalTabNames.length; i++) {
            if (universalTabNames[i] == userRequestedTab)
                userRequestedTab = i;
        }

    // magic to the url of the default image to get the image directory
    var match = /url\(([\"]{0,1})(.*)([\"]{0,1})\)/i.exec($('#cp_wrap_tab_productdetails').css('background-image')); // match[1] contains the full url
    cp_imgDir = match[2].split("/");
    cp_imgDir.pop();
    cp_imgDir = cp_imgDir.join('/') + '/';

	// needs to wait to make sure sifr has kicked in.
	setTimeout("cp_setTab('"+userRequestedTab+"')", "10");
	
	// preload some tab images
    if (typeof tabMenuAppearance != 'undefined') {
        var allImgs = new Array();
        for (var i = 0; i < $('#p-rcb #cp_wrap_tab_productdetails li').length; i++) {
            var variant = (typeof tabMenuAppearance[i][0] == 'undefined' || tabMenuAppearance[i][0] == null || tabMenuAppearance[i][0] == '') ? '' : '-' + tabMenuAppearance[i][0];

            img = new Image();
            img.src = cp_imgDir + 'menuBg'+variant+'.gif';
            allImgs.push(img);
            img = new Image();
            img.src = cp_imgDir + 'menuBorderL'+variant+'.gif';
            allImgs.push(img);
            img = new Image();
            img.src = cp_imgDir + 'menuBorderR'+variant+'.gif';
            allImgs.push(img);
            img = new Image();
            img.src = cp_imgDir + 'menuBorderBlank'+variant+'.gif';
            allImgs.push(img);
        }
    }
}

/* setup other swf files */
function cp_init_swfobject(){

}

// <TABS LOGIC>
var __currentTabIndex;
/* the directory background images where are kept */
var cp_imgDir = null;
/*
 * 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;


    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();
        }
    }

    // now is the time to gather some defaults, but only the first time
    
    if (typeof cp_defaultTextColorActive == 'undefined' )
        cp_defaultTextColorActive = $('#p-rcb #cp_wrap_tab_productdetails .cp_active a').css('color');

    if (typeof cp_defaultTextColorInactive == 'undefined' )
        cp_defaultTextColorInactive = $('#p-rcb #cp_wrap_tab_productdetails .cp_inactive a').css('color');

 //   if (typeof cp_defaultBgColorActive == 'undefined' )
 //       cp_defaultBgColorActive = $('#p-rcb #cp_wrap_tab_productdetails .cp_inactive a').css('color');


    // change relevant background images and link colors if they are specified in a global array
    if (typeof tabMenuAppearance != 'undefined') {
        for (var i = 0; i < $('#p-rcb #cp_wrap_tab_productdetails li').length; i++)
            if (i == value) {
                var imgVariant = (typeof tabMenuAppearance[i][0] == 'undefined' || tabMenuAppearance[i][0] == null || tabMenuAppearance[i][0] == '') ? '' : '-' + tabMenuAppearance[i][0];
                var textColorActive = (typeof tabMenuAppearance[i][1] == 'undefined' || tabMenuAppearance[i][1] == null || tabMenuAppearance[i][1] == '') ? cp_defaultTextColorActive : tabMenuAppearance[i][1];
                var textColorInActive = (typeof tabMenuAppearance[i][2] == 'undefined' || tabMenuAppearance[i][2] == null || tabMenuAppearance[i][2] == '') ? cp_defaultTextColorInactive : tabMenuAppearance[i][2];
            }


        // general background
        $('#cp_wrap_tab_productdetails').css('background-image', 'url("'+cp_imgDir+'menuBg'+imgVariant+'.gif")');
        // spacers have same general background
        var elements = $('#cp_wrap_tab_productdetails span.cp_spacer, #p-rcb #cp_wrap_tab_productdetails');
        for (var si = 0; si < elements.length; si++) {
            $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBg'+imgVariant+'.gif")');
        }
        
        // left background images for active tabs. note: don't change the LEFT image for the FIRST tab
        var elements = $('#p-rcb #cp_wrap_tab_productdetails li span.cp_leftImg');
        for (var si = 0; si < elements.length; si++) {
            if (si > 0)
                $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBorderL'+imgVariant+'.gif")');
            else 
                $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBorderBlank'+imgVariant+'.gif")');
        }

        // right background images for active tabs. note: don't change the RIGHT image for the LAST tab
        var elements = $('#p-rcb #cp_wrap_tab_productdetails li span.cp_rightImg');
        for (var si = 0; si < elements.length; si++) {
            if (si < elements.length - 1)
                $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBorderR'+imgVariant+'.gif")');
            else 
                $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBorderBlank'+imgVariant+'.gif")');
        }

        var elements = $('#p-rcb #cp_wrap_tab_productdetails li.cp_active, #p-rcb #cp_wrap_tab_productdetails li.cp_active a');
        for (var si = 0; si < elements.length; si++) {
            $(elements[si]).css('background-image', 'url("'+cp_imgDir+'menuBorderBlank'+imgVariant+'.gif")');
        }
        var elements = $('#p-rcb #cp_wrap_tab_productdetails li.cp_inactive, #p-rcb #cp_wrap_tab_productdetails li.cp_inactive a');
        for (var si = 0; si < elements.length; si++) {
            $(elements[si]).css('background-image', 'none');
        }

        //link colors
        var elements = $('#p-rcb #cp_wrap_tab_productdetails .cp_inactive a');
        for (var si = 0; si < elements.length; si++) {
            $(elements[si]).css('color', textColorInActive);
        }
        
        //link colors
        var elements = $('#p-rcb #cp_wrap_tab_productdetails .cp_active a');
        for (var si = 0; si < elements.length; si++) {
            $(elements[si]).css('color', textColorActive);
        }
    }

    // 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 == 'undefined')
		return false;

	if (typeof availableHeadersSRC[value] == 'undefined')
		return false;

	if (typeof availableHeadersXML == '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>

// <FAQS LOGIC>
var cp_toggleSpeed = 500; // millisecs, the link that clicked on
var cp_closeSpeed = 400; // millisecs, any other open divs that should be closed 
function cp_initFaqs() {
    // attach an click event to all question anchors + add a method to then
    $('.question a.p-link_question').bind("click", function(e) {
        var answerDiv = $(this).parent('.question').next('.answer').children('.answer_hide');


        // close all open answers that are not the one clicked on
        /*$('.answer .answer_hide:visible').each(function(i){
            if (this != answerDiv[0])
                $(this).slideToggle(cp_closeSpeed);
        });*/
        
        // toggle the one clicked on
        answerDiv.slideToggle(cp_toggleSpeed);
    });
    // close all open answers
    $('.answer .answer_hide').each(function(i){
        $(this).hide();
    });
}


// </FAQS LOGIC>

// <PAGEREADY WHATNOW>
$(document).ready(function() {
	//sIFR needs a timeout for safari or sometimes sIFR won't behave correctly
	setTimeout("cp_init_sIFR()", "1000");

	cp_initFaqs();

	cp_init_swfobject();
});
// </PAGEREADY WHATNOW>


/**
 * 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();




// DIV POPUP



function showOverlay(element, div, left, top)//, text)
{
	var e = document.getElementById(element);
	var d = document.getElementById(div);
	//var t = document.getElementById('overlay_text');
	
	d.style.display = '';
	//t.innerHTML = text;
	
	var divheight = 0;
	if(d.offsetHeight) { divheight = d.offsetHeight; }
	else if(d.style.pixelHeight) { divheight = d.style.pixelHeight; }

	//left 18 top 50
	d.style.left = (findPosX(e) - (-left)) + "px";
	d.style.top = (findPosY(e) - (-top) - divheight) + "px";
}

function hideMe(div)
{
	var d = document.getElementById(div);
	d.style.display = 'none';
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
