/*----------------------------------------------------------
  
  After loading the page, 
    
  @package 
  @author Dario Cavada, cavada@ectrlsolutions.com
  @version v 1.03 2010/07/05

  $previewImage = 'http://video.visittrentino.it/img/prima1.jpg';
  $movieName = 'ws-trentino/Trentino%20neve%20-%20ita.flv';

VideoTag sample...

<div title="videobanner" class="videotag">
  <abbr title="http://video.visittrentino.it/img/prima1.jpg" class="previewImage"/>
  <abbr title="ws-trentino/Trentino%20neve%20-%20ita.flv" class="movieName"/>
  <abbr title="/servizi_multimedia/video" class="videoGalleryLink"/>
  <abbr title="/servizi_multimedia/video" class="photoGalleryLink"/>
  <abbr title="/servizi_multimedia/video" class="webCamGalleryLink"/>
</div>
  
  ---------------------------------------------------------*/

var videobannerOverlay = "";
var videobannerOverlay2 = "";
var videoBannerOverWidth = 800;
var videoBannerOverHeight = 600;
var videoVolume = "0";
var videoAutostart = "true";
var videoMinimized = "true";
var bHeaderVideoBtn = false; // Toggle between open and close (minimized state)

jQuery.noConflict();

jQuery(document).ready(function($){
    //alert(">> ready" + $(".videotag")); // *** DEBUG
    var videotags = $(".videotag");
    var videotag = null;

    if (videotags.length > 0) {

        videotag = videotags[0];
        var width = 282;
        var height = 168;
        var bOverlay = false;

        var previewImageElem = $(".previewImage", videotag)[0];
        var movieNameElem = $(".movieName", videotag)[0];

        var videoGalleryElem = $(".videoGalleryLink", videotag)[0];
        var photoGalleryElem = $(".photoGalleryLink", videotag)[0];
        var webCamGalleryElem = $(".webCamGalleryLink", videotag)[0];
        
        var videoInOverlayEnabledElem = $(".videoInOverlayEnabled", videotag)[0];

        if (videoInOverlayEnabledElem != null) {
            var videoInOverlayEnabled = $(".videoInOverlayEnabled").attr("title");
            if (videoInOverlayEnabled == "true") {
                bOverlay = true;
            }
            
            var videoInOverlayWidth = $(".videoInOverlayWidth").attr("title");
            videoBannerOverWidth = parseInt(videoInOverlayWidth);

            var videoInOverlayHeight = $(".videoInOverlayHeight").attr("title");
            videoBannerOverHeight = parseInt(videoInOverlayHeight);

            videoVolume = $(".videoVolume").attr("title");
            videoAutostart = $(".videoAutoStart").attr("title");
            

        }

        if (previewImageElem && movieNameElem) {
            var previewImage = '';
            var movieName = '';

            var videoGalleryLink = '';
            var photoGalleryLink = '';
            var webCamGalleryLink = '';

            var videoGalleryLabel ='Video';
            var photoGalleryLabel ='Photo';
            var webCamGalleryLabel ='Webcam';

            if (previewImageElem) {
                previewImage = $(previewImageElem).attr("title");

            }
            if (movieNameElem) {
                movieName = $(movieNameElem).attr("title");
            }

            if (videoGalleryElem) {
                videoGalleryLink = $(videoGalleryElem).attr("title");
            }
            if (photoGalleryElem) {
                photoGalleryLink = $(photoGalleryElem).attr("title");
            }
            if (webCamGalleryElem) {
                webCamGalleryLink = $(webCamGalleryElem).attr("title");
            }

            var videobanner = "";
            if (bOverlay) {
                videobanner = '<a id="videobannerinline" href="#videobannerover" style="padding-left: 0px; border-left-width: 0px; padding-right: 0px;"><img width="'+width+'"height="'+height+'" src="'+previewImage+'" alt=""></a>' +
                '<br />' +
                '<div class="icon_container"><a href="'+ webCamGalleryLink +'" rel="nofollow">'+webCamGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_webcam_ico.png" width="24" height="19" class="last_item" /></div>'+
                '<div class="icon_container"><a href="'+ photoGalleryLink +'" rel="nofollow" >'+photoGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_foto_ico.png" width="24" height="19" /></div>'+
                '<div class="icon_container"><a href="'+ videoGalleryLink +'" class="firstItem" rel="nofollow">'+videoGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_video_ico.png" width="24" height="20" /></div>';

                videobannerOverlay = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '</object>';

                videobannerOverlay2 = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '</object>';
               

            } else {
                videobanner = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+width+'" height="'+height+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+width+'&amp;height='+height+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+width+'&amp;height='+height+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+width+'" height="'+height+'">' +
                '</object>' +
                '<br />' +
                '<div class="icon_container"><a href="'+ webCamGalleryLink +'" rel="nofollow">'+webCamGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_webcam_ico.png" width="24" height="19" class="last_item" /></div>'+
                '<div class="icon_container"><a href="'+ photoGalleryLink +'" rel="nofollow" >'+photoGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_foto_ico.png" width="24" height="19" /></div>'+
                '<div class="icon_container"><a href="'+ videoGalleryLink +'" class="firstItem" rel="nofollow">'+videoGalleryLabel+'</a><img src="/ptt-portal-theme/images/ptt/css/box_video_video_ico.png" width="24" height="20" /></div>';
            }

            jQuery("#top-foto_video_webcam").empty();
            jQuery("#top-foto_video_webcam").css("padding","3px 8px 10px");
            jQuery("#top-foto_video_webcam").css("background","transparent url(/ptt-portal-theme/images/ptt/css/video_background.png) no-repeat scroll 0% 0%");
            jQuery("#top-foto_video_webcam").css("right","15px");
            jQuery("#top-foto_video_webcam").css("text-align","right");
            jQuery("#top-foto_video_webcam").css("-moz-background-clip","-moz-initial");
            jQuery("#top-foto_video_webcam").css("-moz-background-origin","-moz-initial");
            jQuery("#top-foto_video_webcam").css("-moz-background-inline-policy","-moz-initial");

            jQuery("#top-foto_video_webcam").append(videobanner);

            if (bOverlay) {
                initializeVideoBannerOverlay();
            }

        }
    }

    // Nuovo tema

    var videotags2010 = $(".videotag2010");
    if (videotags2010.length > 0) {

        videotag = videotags[0];
        var width = 282;
        var height = 168;
        var bOverlay = false;
        var videoGalleryLabel ='Video';

        var previewImageElem = $(".previewImage", videotag)[0];
        var movieNameElem = $(".movieName", videotag)[0];

        var videoInOverlayEnabledElem = $(".videoInOverlayEnabled", videotag)[0];

        if (videoInOverlayEnabledElem != null) {
            var videoInOverlayEnabled = $(".videoInOverlayEnabled").attr("title");
            if (videoInOverlayEnabled == "true") {
                bOverlay = true;
            }

            var videoInOverlayWidth = $(".videoInOverlayWidth").attr("title");
            videoBannerOverWidth = parseInt(videoInOverlayWidth);

            var videoInOverlayHeight = $(".videoInOverlayHeight").attr("title");
            videoBannerOverHeight = parseInt(videoInOverlayHeight);

            videoVolume = $(".videoVolume").attr("title");
            videoAutostart = $(".videoAutoStart").attr("title");
            videoMinimized = $(".videoMinimized").attr("title");


        }

        if (previewImageElem && movieNameElem) {
            var previewImage = '';
            var movieName = '';

            if (previewImageElem) {
                previewImage = $(previewImageElem).attr("title");
            }
            if (movieNameElem) {
                movieName = $(movieNameElem).attr("title");
            }

            var videobanner = "";
            if (bOverlay) {
                videobanner = '<a id="videobannerinline" href="#videobannerover" style="padding-left: 0px; border-left-width: 0px; padding-right: 0px;"><img width="'+width+'"height="'+height+'" src="'+previewImage+'" alt=""></a>' +
                '<div class="icon_container" id="headerVideoBtn"><a href="#video" rel="nofollow">'+videoGalleryLabel+'</a><img id="videoGalleryArrowImg" src="/ptt2010-portal-theme/images/ptt/css/video-close-arrow.png" width="15" height="8" class="last_item" /></div>';

                videobannerOverlay = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '</object>';

                videobannerOverlay2 = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+videoBannerOverWidth+'&amp;height='+videoBannerOverHeight+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+videoBannerOverWidth+'" height="'+videoBannerOverHeight+'">' +
                '</object>';


            } else {
                videobanner = '<div id="videobannerinline"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="StreamZillaPlayer" width="'+width+'" height="'+height+'">' +
                '<param name="movie" value="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+width+'&amp;height='+height+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'">' +
                '<param name="quality" value="high">' +
                '<param name="settings" value="hide">' +
                '<param name="allowFullScreen" value="true">' +
                '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" name="StreamZillaPlayer" src="http://st1.streamzilla.jet-stream.nl/ws-trentino/StreamZillaLoader.php?rtmpURL=rtmp://fl1.streamzilla.jet-stream.nl:80/VOD&amp;movieName='+movieName+'&amp;width='+width+'&amp;height='+height+'&amp;autoStart='+videoAutostart+'&amp;initVolume='+videoVolume+'&amp;autoHide=1&amp;playerType=4&amp;previewImage='+previewImage+'" quality="high" settings="hide" allowfullscreen="true" width="'+width+'" height="'+height+'">' +
                '</object></div>' +
                '<div class="icon_container" id="headerVideoBtn"><a href="#video" class="firstItem" rel="nofollow">'+videoGalleryLabel+'</a><img id="videoGalleryArrowImg" src="/ptt2010-portal-theme/images/ptt/css/video-close-arrow.png" width="15" height="8" /></div>';
            }

            jQuery("#top-foto_video_webcam").empty();
            jQuery("#top-foto_video_webcam").css("padding","5px 20px 0px");
            jQuery("#top-foto_video_webcam").css("background","transparent url(/ptt2010-portal-theme/images/ptt/css/video-bg.png) no-repeat scroll 0% 0%");
            jQuery("#top-foto_video_webcam").css("text-align","right");
            jQuery("#top-foto_video_webcam").css("margin-top","-2px");
            jQuery("#top-foto_video_webcam").css("-moz-background-clip","-moz-initial");
            jQuery("#top-foto_video_webcam").css("-moz-background-origin","-moz-initial");
            jQuery("#top-foto_video_webcam").css("-moz-background-inline-policy","-moz-initial");
            jQuery("#top-foto_video_webcam").css("background-repeat","no-repeat");

            jQuery("#top-foto_video_webcam").append(videobanner);

            if (bOverlay) {
                initializeVideoBannerOverlay();
            }

            // Open it
            if (videoMinimized == 'true') {
                closeHeaderVideoBtn();
            } else {
                openHeaderVideoBtn();
            }

            jQuery('#headerVideoBtn').click(function() {
                toggleHeaderVideoBtn();
            });

        }
    }
});

function initializeVideoBannerOverlay() {
    jQuery("#videobannerover").empty();
    jQuery("#videobannerover").append(videobannerOverlay);
    
    jQuery("#videobannerinline").fancybox({
        'hideOnContentClick': false,
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'frameWidth':videoBannerOverWidth,
        'frameHeight':videoBannerOverHeight,
        callbackOnShow: function(){
            showVideobannerOverlay();
        },
        callbackOnClose: function(){
        //bIsMinimap = true;
        }
    });

    
}

function toggleHeaderVideoBtn(){
    bHeaderVideoBtn = ! bHeaderVideoBtn;
    if (bHeaderVideoBtn) {
        openHeaderVideoBtn();
    } else {
        closeHeaderVideoBtn();
    }
}

function openHeaderVideoBtn(){
    jQuery("#top-foto_video_webcam").css("background-position","0 0");
    jQuery("#top-foto_video_webcam > #videobannerinline").show();

    // Pompare oggetto stream se overlay = false

    jQuery("#top-foto_video_webcam > .icon_container").css("height","20px");  
    jQuery("#top-foto_video_webcam > .icon_container").css("padding-top","14px");  
    jQuery("#videoGalleryArrowImg").attr("src", "/ptt2010-portal-theme/images/ptt/css/video-close-arrow.png");
}

function closeHeaderVideoBtn(){
    jQuery("#top-foto_video_webcam").css("background-position","0 -192px");
    jQuery("#top-foto_video_webcam > #videobannerinline").hide();

    // levare oggetto stream se overlay = false

    jQuery("#top-foto_video_webcam > .icon_container").css("height","auto");  //((attenzione ad obj o <a)
    jQuery("#top-foto_video_webcam > .icon_container").css("padding-top","0");  //((attenzione ad obj o <a)
    jQuery("#videoGalleryArrowImg").attr("src", "/ptt2010-portal-theme/images/ptt/css/video-open-arrow.png");
}


function showVideobannerOverlay() {
    jQuery("#videobannerover").empty();
    jQuery("#videobannerover").append(videobannerOverlay2);
}
