var videoFixedWidth = 320;
var imageOnPage;

window.onload = function(){

    $('textGuidelineWelcome').hide();
    $('imageContainer').hide();
    $('videoContainer').hide();
    $('soundContainer').hide();


    if(textGuidelineWelcome){
        $('textGuidelineWelcome').show();
        $('textGuidelineWelcome').update(textGuidelineWelcome);
    }

    if(imagePath){
        imageOnPage = document.createElement('img');
        imageOnPage.src = mediasFolder + "/" + imagePath;
        imageOnPage.id = 'imageOnPageId';
        imageOnPage.onload = findHHandWW;
    }

    //video
    if(videoPath){
        videoPath = mediasFolder + "/" + videoPath;

        var ajustedHeight = ((videoFixedWidth / videoWidth) * videoHeight) + 16;
        var ajustedWidth = videoFixedWidth;
        
        htmlVideo = "<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width=\"" + ajustedWidth + "\" height=\"" + ajustedHeight + "\" codebase='http://www.apple.com/qtactivex/qtplugin.cab'>";
        htmlVideo += "<param name='src' value=\"" + videoPath + "\">";
        htmlVideo += "<param name='autoplay' value=\"" + autoplayVideo + "\">";
        htmlVideo += "<param name='controller' value=\"" + showVideoController + "\">";
        htmlVideo += "<param name='loop' value=\"false\">";
        htmlVideo += "<param name='scale' value=\"TOFIT\">";
        htmlVideo += "<EMBED src=\"" + videoPath + "\" width=\"" + ajustedWidth + "\" height=\"" + ajustedHeight + "\" autoplay=\"" + autoplayVideo + "\" controller=\"" + showVideoController + "\" loop=\"false\" scale=\"TOFIT\" pluginspage='http://www.apple.com/quicktime/download/'>";
        htmlVideo += "</EMBED>";
        htmlVideo += "</OBJECT>";

        $('videoContainer').update(htmlVideo);
        $('videoContainer').show();
    }

    //sound
    if(soundPath){
        soundPath = mediasFolder + "/" + soundPath;

        var sWidth = 1;
        var sHeight = 1;

        if (showSoundController == true){
            var sWidth = 240;
            var sHeight = 16;
        }

        htmlSound = "";
        htmlSound = "<OBJECT classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' id=\"theSound\" width=\"" + sWidth  + "\" height=\"" + sHeight + "\" codebase='http://www.apple.com/qtactivex/qtplugin.cab'>";
        htmlSound = htmlSound + "<param name='src' value=\"" + soundPath + "\">";
        htmlSound = htmlSound + "<param name='autoplay' value=\"" + autoplaySound + "\">";
        htmlSound = htmlSound + "<param name='controller' value=true>";
        htmlSound = htmlSound + "<param name='loop' value=\"false\">";
        htmlSound = htmlSound + "<EMBED src=\"" + soundPath + "\" name=\"theSound\" enablejavascript=\"true\" width=\"" + sWidth  + "\" height=\"" + sHeight + "\" autoplay=\"" + autoplaySound + "\" controller=\"" + showSoundController + "\" loop=\"false\" pluginspage='http://www.apple.com/quicktime/download/'>";
        htmlSound = htmlSound + "</EMBED>";
        htmlSound = htmlSound + "</OBJECT>";
        
        //SI PAS DE SHOW, LE SON JOUE PAS...
        $('soundContainer').update(htmlSound);
        $('soundContainer').show();

        //htmlSound = "<br /><br /><img src=\"images/btn_back_disabled.jpg\" onClick=\"javascript:volumeControl(0,document.theSound);\">&nbsp;&nbsp;&nbsp;<img src=\"images/btn_next_disabled.jpg\" onClick=\"javascript:volumeControl(1,document.theSound);\">";
        //$('soundContainer').update(htmlSound);
        //$('soundContainer').show();

        //htmlSound = "<img src=\"images/icn_sonvolume.jpg\" />&nbsp;<img src=\"images/vol_plus_norm.jpg\" onClick=\"javascript:volumeControl(1,document.theSound);\" onmouseover=\"this.src='images/vol_plus_roll.jpg'\" onmouseout=\"this.src='images/vol_plus_norm.jpg'\" /><img src=\"images/vol_moins_norm.jpg\" onClick=\"javascript:volumeControl(0,document.theSound);\" onmouseover=\"this.src='images/vol_moins_roll.jpg'\" onmouseout=\"this.src='images/vol_moins_norm.jpg'\"/>";
        //$('soundControls').show();
    }

    document.body.style.backgroundColor = '#' + bgSkinColor;
}

function findHHandWW(){
    var srcImage = mediasFolder + "/" + imagePath;

    var imgW = this.width;
    var imgH = this.height;
    var imgProp = imgW / imgH;

    $('imageContainer').update(imageOnPage);

    if (imgW > 680){
        var newWidth = 680;
        var newHeight = parseInt(newWidth / imgProp);

        document.getElementById('imageOnPageId').style.width = newWidth + 'px';
        document.getElementById('imageOnPageId').style.height = newHeight + 'px';

        var innerHTMLImg = document.getElementById('imageContainer').innerHTML;
        var newInnerHTMLImg = "<a href=" + srcImage + " class=\"highslide\" onclick=\"return hs.expand(this)\">" + innerHTMLImg + "</a>";
        $('imageContainer').innerHTML = newInnerHTMLImg;
    }

    $('imageContainer').show();

    return true;
}

function imgover(){
    document.getElementById('imgGo').src = 'images/skin/btn_go_roll.png';
    document.getElementById('tdGo').style.textDecoration = 'underline';
}

function imgout(){
    document.getElementById('imgGo').src = 'images/skin/btn_go_norm.png';
    document.getElementById('tdGo').style.textDecoration = 'none';
}


