/* Marc Boronat                                                               */

var slide_arr;
var slide_curr;
var slide_go;
var silde_millis
var slide_time;
var appear_int;

var slide_lmnt;
var slide_img;
var controller;
var play_pause;

function slide_set(id,arr,millis) {
    if(document.getElementById(id)) {
        slide_arr = arr;
        slide_curr = -1;
        slide_millis = millis;

        slide_lmnt = document.getElementById(id);
        slide_lmnt.style.width = "960px";
        slide_lmnt.style.height = "539px";
        slide_lmnt.style.marginBottom = "30px";

        slide_img = slide_lmnt.getElementsByTagName('img').item(0);
        slide_img.style.width = "960px";
        slide_img.style.height = "539px";

        controller = document.createElement("div");
        controller.style.position = "absolute";
        controller.style.top = "0px";
        controller.style.left = "0px";
        controller.style.height = "30px";
        controller.style.width = "100%";
        controller.style.background = "url("+server_url+"wp-content/themes/son-gener/media/web-stock/controller.png)";

        play_pause = document.createElement("span");
        play_pause.setAttribute('class', 'play-pause');
        play_pause.setAttribute('className','play-pause');
        play_pause.setAttribute('onclick','slide_pauseplay()');
        play_pause.innerHTML = "play-pause";

        controller.appendChild(play_pause);

        for (i=0;i<arr.length;i++) {
            var bulb = document.createElement("img");
            bulb.setAttribute('alt',arr[i]);
            bulb.setAttribute('src',server_url+"wp-content/themes/son-gener/media/web-stock/bulb.png");
            bulb.setAttribute('onclick','slide_to('+i+')');
            bulb.style.styleFloat = "right";
            bulb.style.cssFloat = "right";
            bulb.style.marginLeft = "5px";
            bulb.style.marginTop = "10px";
            bulb.style.cursor = "pointer";
            controller.appendChild(bulb);
        }

        slide_lmnt.appendChild(controller);

        slide_play();
    }
}

function slide_play() {
    if(slide_curr == (slide_arr.length - 1)) {
        slide_curr = 0;
    } else {
        slide_curr ++;
    }
    slide_img.setAttribute('src', slide_arr[slide_curr]);
    slide_img.style.opacity = .1;
    appear_int = setInterval("appear(slide_img)", 10);
    slide_time = setTimeout("slide_play()", slide_millis);
    slide_go = true;
}

function slide_pauseplay() {
    if (slide_go == false) {
        slide_go = true;
        slide_time = setTimeout("slide_play()", slide_millis);
        play_pause.style.background = "url("+server_url+"wp-content/themes/son-gener/media/web-stock/pause.png)";
        play_pause.style.backgroundPosition = "bottom center";
    } else if (slide_go == true) {
        slide_go = false;
        clearTimeout(slide_time);
        play_pause.style.background = "url("+server_url+"wp-content/themes/son-gener/media/web-stock/play.png)";
        play_pause.style.backgroundPosition = "bottom center";
    }
}

function slide_to(count) {
    clearTimeout(slide_time);
    slide_curr = count;
    slide_play()
}

function appear(lmnt) {
    if(lmnt.style.opacity >= 1){
        clearInterval(appear_int);
        slide_lmnt.style.backgroundPosition = "top left";
        slide_lmnt.style.backgroundRepeat = "no-repeat";
        slide_lmnt.style.background = "url("+slide_arr[slide_curr]+")";
    } else {
        lmnt.style.opacity *= 1.03;
        lmnt.style.filter = "alpha(opacity="+(lmnt.style.opacity*100)+")";
    }
}

/* -------------------------------------------------------------------------- */

function toggle_lmnt(id) {
    if(document.getElementById(id).style.display != "none") {
        document.getElementById(id).style.display = "none";
    }
    else {
        document.getElementById(id).style.display = "inherit";
    }
}

function printit(){
    if (window.print) {
        window.print();
    } else {
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6,2);
    }
}