// JavaScript Document

var inter_centre;
var inter_offres;
var off = 0;
var i = 0;
var defil = false;

function vcenter(anim)
{
	var height = window.getHeight();
	var main_size = $("main").getSize();
	
	var top = (height - main_size['size']['y'])/2;
	
	if( top < 0 )
		top = 0;
		
	if( anim )
	{
		var center = new Fx.Style('main', 'top').start($('main').getTop(), top);
		clearTimeout(inter_centre);
		inter_centre = undefined;
	}
	else
	{
		$("main").style.top = top+"px";
	}
}

function livraison()
{
	if( !$('ckx_livraison').checked )
		$('tab_facturation').style.display = "block";
	else
		$('tab_facturation').style.display = "none";
}

function inc_offres()
{
	if( off > 0 )
	{
		defile_offre('o'+(off-1), 0, -220);
	}
	else if ( defil )
	{
		defile_offre('o2', 0, -210);
	}
	else
	{
		defil = true;
	}
	defile_offre('o'+off, 170, 0);
	off++;
	if( off == 3 )
		off = 0;
}

function defile_offre(clip, from, goto)
{
	var eff = new Fx.Style(clip, 'top', {duration:2000}).start(from, goto);
	eff = null;
	clip = null;
}

window.addEvent('load', function()
{
	inc_offres();
	
	if(typeof sIFR == "function")
	{
		sIFR.replaceElement("div#right-col h1", named({sFlashSrc:"./medias/agencyfb.swf", sColor:"#719000", sFlashVars:"textalign=right"}));
		sIFR.replaceElement("h1", named({sFlashSrc: "./medias/agencyfb.swf", sColor: "#719000"}));
	};
	
	inter_offres = setInterval("inc_offres();", 5000);
});

window.addEvent('resize', function()
{
	if(typeof(inter_centre)=="undefined")
		inter_centre = setTimeout("vcenter(true);", 500);
});

/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}

/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        //c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}
