// Start FeatureBox script
Spry.Widget.TabbedPanels.prototype.getTabGroup = function()
{
	if (this.element)
	{
		var children = this.getElementChildren(this.element);
		if (children.length)
			return children[this.tabsAtBottom ? 1 : 0];
	}
	return null;
};

Spry.Widget.TabbedPanels.prototype.getContentPanelGroup = function()
{
	if (this.element)
	{
		var children = this.getElementChildren(this.element);
		if (children.length)
			return children[this.tabsAtBottom ? 0 : 1];
	}
	return null;
};

// Override the default version of onTabClick so that it calls
// stop(), just in case the tabbed panels is cyclying through
// all of its tabs.

Spry.Widget.TabbedPanels.prototype._onTabClick = Spry.Widget.TabbedPanels.prototype.onTabClick;
Spry.Widget.TabbedPanels.prototype.onTabClick = function(e, tab)
{
	this.stop();
	var self = this;
	if (!this.interval)
	this.interval = 2000;
	this.timerID = setTimeout(function() { self.fadeInNextPanel(); }, this.interval);
	return this._onTabClick(e, tab);
};

// Add the ability to step through the panels at a given interval.

Spry.Widget.TabbedPanels.prototype.showPreviousPanel = function()
{
	var curIndex = this.getCurrentTabIndex();
	this.showPanel(((curIndex < 1) ? this.getTabbedPanelCount() : curIndex) - 1);
};

Spry.Widget.TabbedPanels.prototype.showNextPanel = function()
{
	this.showPanel((this.getCurrentTabIndex()+1) % this.getTabbedPanelCount());
};

Spry.Widget.TabbedPanels.prototype.showFirstPanel = function()
{
	this.showPanel(0);
};

Spry.Widget.TabbedPanels.prototype.Back = function()
{
	this.stop();
	this.showPreviousPanel();
	this.startNF();
};

Spry.Widget.TabbedPanels.prototype.Next = function()
{
	this.stop();
	this.showNextPanel();
	this.startNF();
};

Spry.Widget.TabbedPanels.prototype.showLastPanel = function()
{
	var count = this.getTabbedPanelCount();
	this.showPanel(count > 0 ? count - 1 : 0);
};


Spry.Widget.TabbedPanels.prototype.start = function()
{
	this.stop();
	var self = this;
	if (!this.interval)
	this.interval = 2000;
	this.timerID = setTimeout(function() { self.fadeInNextPanel(); }, this.interval);
};
Spry.Widget.TabbedPanels.prototype.startNF = function()
{
	this.stop();
	var self = this;
	if (!this.interval)
	this.interval = 2000;
	this.timerID = setTimeout(function() { self.nofadeInNextPanel(); }, this.interval);
};

Spry.Widget.TabbedPanels.prototype.stop = function()
{
	if (this.timerID)
	clearTimeout(this.timerID);
	this.timerID = 0;
};

Spry.Widget.TabbedPanels.prototype.fadeInNextPanel = function()
{
	if (!Spry.Effect || !Spry.Effect.DoFade)
	{
		// The fade effect isn't available, so just
		// show the next panel.

		this.showNextPanel();
		if (this.timerID)
			this.start();
		return;
	}

	var curIndex = this.getCurrentTabIndex();
	var panels = this.getContentPanels();
	var currentPanel = panels[ curIndex ];
	var nextPanel = panels[ (curIndex + 1) % this.getTabbedPanelCount() ];
	var self = this;

	Spry.Effect.DoFade(currentPanel, {duration: 500, from: 100, to: 0, toggle: false, finish: function()
	{
		nextPanel.style.opacity = '0';
		nextPanel.style.filter = 'alpha(opacity=0)';

		self.showPanel(nextPanel);

		currentPanel.style.opacity = '';
		currentPanel.style.filter = '';
		Spry.Effect.DoFade(nextPanel, {duration: 500, from: 0, to: 100, toggle: false, finish: function()
		{
			if (self.timerID)
				self.start();
		}});
	}});
};
Spry.Widget.TabbedPanels.prototype.nofadeInNextPanel = function()
{
		this.showNextPanel();
		if (this.timerID)
			this.startNF();
		return;
};

// End FeatureBox script

function MM_effectAppearFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
};

function MM_effectSlideFade(targetElement, duration, from, to, toggle)
{
	Spry.Effect.DoSlide(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// Initialize XML data on the FeatureBox Home English
var dsFeatureBoxHomeEng = new Spry.Data.XMLDataSet("assets/xml/FeatureBoxHome_Data.xml", "FeatureBox/FeatureEng");
dsFeatureBoxHomeEng.setColumnType(["name","title","subtitle","photo_description"], "html");
Spry.Data.Region.addObserver("FeatureBoxHome-Eng", { onPostUpdate: function()
{
var FeatureBoxEng = new Spry.Widget.TabbedPanels("FB-948f7d", { interval: 10000 });
FeatureBoxEng.start();
}});

// Initialiser les données XML dans le FeatureBox Home Français
var dsFeatureBoxHomeFra = new Spry.Data.XMLDataSet("assets/xml/FeatureBoxHome_Data.xml", "FeatureBox/FeatureFra");
dsFeatureBoxHomeFra.setColumnType(["name","title","subtitle","photo_description"], "html");
Spry.Data.Region.addObserver("FeatureBoxHome-Fra", { onPostUpdate: function()
{
var FeatureBoxFra = new Spry.Widget.TabbedPanels("FB-948f7d", { interval: 10000 });
FeatureBoxFra.start();
}});

// Checks for the current Flash version installed on client
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
};

function updateResponseDiv(req) 
{
	Spry.Utils.setInnerHTML('RecommendSiteResult', req.xhRequest.responseText);
}

// Start slideshow on the FeatureBox
//window.onload = function(){
//}

// Toggle text size to big/normal
flip=false;off="Start";on="Stop"; // global to save state
flip=false;on="Stop";off="Start"; // global to save state
var min=0;
var max=.05;
function toggleTextSize(pn){
p=parseInt(pn,10);
var phactext = document.getElementsByTagName('body');
for (i=0;i<phactext.length;i++) {
		if(flip){
			if(phactext[i].style.fontSize) {
				var s = parseFloat(phactext[i].style.fontSize.replace("em",""));
			} else {
				var s = .8;
			}
			if (s!=min) {
			s -= .1;
			}
			phactext[i].style.fontSize = s+"em";		
   			phactext.value=on;

   		} else {
			if(phactext[i].style.fontSize) {
				var s = parseFloat(phactext[i].style.fontSize.replace("em",""));
			} else {
				var s = .8;
			}
			if (s!=max) {
			s += .1;
			}
			phactext[i].style.fontSize = s+"em";		
			phactext.value=off;		
   		}
}
flip=!flip;
};

