﻿var data;
var images;
window.addEvent('domready', function() {

    if (document.getElementById("tipobook").innerHTML == "compcard") {
        $("show").setStyle("display", "none");
        var comp = $('hiddenpics').getElement(".caption_comp").get("html");
        var im = $('hiddenpics').getElement('.mo').getElement('.main').getProperty('src');
        var imhr = $('hiddenpics').getElement('.mo').getElement('.hir').get("html");
        new Element('a', { href: imhr, target: "_blank", id: "hireslink" }).inject($("c_pic"))
        new Element('img', { src: im }).inject($("hireslink"));

        $("c_feat_cont").innerHTML = comp;
        $("comp").setStyle("display", "block");
        $("next").setStyle("display", "none");
        $("prev").setStyle("display", "none");
        $$("div.slideshow-thumbnails").setStyle("display", "none")
    } else if (document.getElementById("tipobook").innerHTML == "video") {
        $("div_feat_cont").innerHTML = $('videostring').getElement(".caption").get("html"); ;
        var myHTMLRequest = new Request.HTML({
            url: '/getplaylisthtml.aspx',
            method: 'GET',
            update: 'playlist',
            onSuccess: function() {
                createVideo(document.getElementById("firstvideo").innerHTML);
            }
        });
        myHTMLRequest.get({ 'b': idbook });
    } else {
        var strjson = "";
        $$('.mo').each(function(el) {
            var capt = el.getElement("div.caption").get("html");
            var urlimg = el.getElement("img.main").getProperty("src");
            strjson += "'" + urlimg + "': {href: '#',caption: '" + capt + "'},";
        });
        strjson = "{" + strjson.substring(0, strjson.length - 1) + "}";
        var data2 = eval('(' + strjson + ')');
        document.getElementById("progress-bar").style.visibility = "hidden";
        var myShow = new Slideshow('show', data2, { paused: true, random: false });
        $("next").addEvent("click", function() {
            myShow.next();
        });
        $("prev").addEvent("click", function() {
            myShow.prev();
        });
        if ($$('.mo').length == 1) {
            $("next").setStyle("display", "none");
            $("prev").setStyle("display", "none");
            $$("div.slideshow-thumbnails").setStyle("display", "none")
        }
    }
});


function createVideo(pv) {
    var flashvars = {
        videoFilename: pv,
        autoPlay: 0,
        skinUrl: "/flvplayer/skin.swf"
    };
    var params = {
        //menu: "false"
        allowFullScreen: true

    };
    var attributes = {
        id: "lettore",
        wmode: "Transparent",
        allowFullScreen: true,
        name: "lettore"
    };

    swfobject.embedSWF("/flvplayer/lettore.swf", "videoplaceholder", 440, 440, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

// This is a javascript handler for the player and is always needed.
var currPos = 0;
function thisMovie(movieName) {
    //if(navigator.appName.indexOf("Microsoft") != -1) {
    //    return window[movieName];
    //} else {
    //    return document[movieName];
    //}
    return document.getElementById(movieName);
};
function pdf(singlepage) {
    if (document.getElementById("tipobook").innerHTML == "compcard") {
        window.open('/generatePdf.aspx?b=' + window.idbook + '&m=' + window.idmodel + '&p=0&c=1', 'pdf');
    } else {
        window.open('/generatePdf.aspx?b=' + window.idbook + '&m=' + window.idmodel + '&p=0&c=0', 'pdf');
    }
}
function sendEvent(typ, prm) {
    thisMovie("player").sendEvent(typ, prm);
    currPos = prm;
};