

$(document).ready(function() 
{
    $("#sm").click(function () { SetPageSize(768); });
    $("#me").click(function () { SetPageSize(972); });
})

function SetPageSize(size)
{ 
    var iBannerWidth  = size==768 ? 737 : 941;
    var iBannerHeight = size==768 ? 232 : 296;
    var iInfoWidth    = size==768 ? 212 : 275;
    var iInfoHeight   = size==768 ?  60 :  70;
    var iFontSize     = size==768 ?  10 :  11;
    
    $("#page"                ).animate( { width:size+"px" }, 1000 );
    $("#homepage_flash"      ).animate( { width:iBannerWidth+"px", height:iBannerHeight+"px" }, 1000 );
    $("#homepage_NoFlashImg" ).animate( { width:iBannerWidth+"px", height:iBannerHeight+"px" }, 1000 );
    $("#homepage_NoFlashInfo").animate( { width:iInfoHeight+"px", height:iInfoWidth+"px", fontSize:iFontSize+"px" }, 1000 );
    
    // Update cookie
    document.getElementById('imgCookieSetter').src = "/styles/ui/templates/setwidth.aspx?width="+size+"&cb=" + Date();
    
    if(size>768)
        jQuery(".languageBar"    ).fadeOut(500, function() {jQuery(".languageBarFull").fadeIn(500);});
    else
        jQuery(".languageBarFull").fadeOut(500, function() {jQuery(".languageBar"    ).fadeIn(500);});
}

var IsFlashInit = false;

//======================================
//
//
//======================================
    function Banner_Flash_Init()
    {
		var HasFlash = DetectFlashVer(8,0,0);
    
        if(!HasFlash)    return;
        if( IsFlashInit) return;
        
        IsFlashInit = true;
    
        if(AC_FL_RunContent == 0) 
        {
            alert("This page requires AC_RunActiveContent.js");
        }
        else 
        {   
            // IMPORTANT: phrases.swf must be located in /flash => it is in the CBD project
            AC_FL_RunContent(
                'codebase','https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab',
                'width','100%',
                'height','100%',
                'src','styles/ui/templates/cbd/flash/home', 
                'flashvars','xml=styles/ui/templates/cbd/flash/phrases-'+lang+'.xml',
                'quality','high',
                'scale','exactfit',
                'wmode','transparent',
                'pluginspage','http://www.macromedia.com/go/getflashplayer',
                'movie','styles/ui/templates/cbd/flash/home'); 
        }
    }

//======================================
//
//
//======================================
function Banner_NoFlash_Init()
{
	var HasFlash = DetectFlashVer(8,0,0);

    var oFlash   = document.getElementById('homepage_flash');
    var oNoFlash = document.getElementById('homepage_NoFlash');
    
    if(oFlash   != null) oFlash  .style.display = HasFlash ? ""     : "none";
    if(oNoFlash != null) oNoFlash.style.display = HasFlash ? "none" : "";
    
    if(HasFlash) 
        return;
        
    Banner_NoFlash_StartRollText();           
    
}


//No Flash Text rolling

var Banner_NoFlash_RollingTextTimer = null;
var Banner_NoFlash_RollingTextLinks = null;
var Banner_NoFlash_RollingTextIndex = 0;

//======================================
//
//
//======================================
function Banner_NoFlash_StartRollText()
{
    if(Banner_NoFlash_RollingTextLinks!=null)
        return;
        
    Banner_NoFlash_RollingTextLinks = [];
    
    jQuery.get( "/styles/ui/templates/cbd/flash/phrases-"+lang+".xml", null, function(data, status)
    {
        if(status!="success") 
            return;
        
            
        var xStrings = data.documentElement.getElementsByTagName("phrase");
        
        for(var i=0; i<xStrings.length; ++i)
        {
            var oLink = { Text: "", Href: ""};
            
            for(var c=0; c<xStrings[i].childNodes.length; ++c)
            {
                var xChild =  xStrings[i].childNodes[c];
                
                if(xChild.nodeType == 1)// not an Element
                {
                    if(xChild.nodeName == "texte") oLink.Text = xChild.childNodes[0].nodeValue;
                    if(xChild.nodeName == "lien")  oLink.Href = xChild.childNodes[0].nodeValue;
                }                        
            }
            
            if(oLink.Text == null) oLink.Text = "";
            if(oLink.Href == null) oLink.Href = "";
            
            Banner_NoFlash_RollingTextLinks.push(oLink);
            
        }       
        
        
        Banner_NoFlash_RollingTextIndex = Banner_NoFlash_RollingTextLinks.length - 1;
        
        Banner_NoFlash_RollText();
        
    });
}

//======================================
//
//
//======================================
function Banner_NoFlash_RollText()
{
    if(Banner_NoFlash_RollingTextTimer!=null)
    {
        clearTimeout(Banner_NoFlash_RollingTextTimer);
        Banner_NoFlash_RollingTextTimer = null;
    }

    if(Banner_NoFlash_RollingTextLinks==null || Banner_NoFlash_RollingTextLinks.length==0) 
        return;
    
    Banner_NoFlash_RollingTextIndex = (Banner_NoFlash_RollingTextIndex+1) 
                                    %  Banner_NoFlash_RollingTextLinks.length;
    
    var oLink = Banner_NoFlash_RollingTextLinks[Banner_NoFlash_RollingTextIndex];
   
    document.getElementById("homepage_NoFlashInfo_Href").innerHTML     = oLink.Text+" ";
    document.getElementById("homepage_NoFlashInfo_Href").href          = oLink.Href;
    document.getElementById("homepage_NoFlashInfo"     ).style.display = "";
    
    Banner_NoFlash_RollingTextTimer = setTimeout(Banner_NoFlash_RollText, 10000); 
}


