﻿

var lightboxOpen = false;
var scrolling = false;
var lightBoxHeigth = 425;
var lightBoxWidth = 766;
var alpha = 0;


function _$(id) {
    return document.getElementById(id);
}


$(document).ready(function () {
    $(window).resize(function () {
        WindonResized();
    });

     $(window).scroll(function() {
       WindonScrolled();
    });

});


function WindonResized() {

    if (lightboxOpen == true) {

        if ($('.closebarplayer').is(':visible')) {

            lightBoxWidth = $(window).width()
            lightBoxHeigth = $(window).height() 

            $('#videoIframe').attr('width', lightBoxWidth);
            $('#videoIframe').attr('height', lightBoxHeigth);
            ShowOpacity();

        }else{
            ShowOpacity();
        }
    }

}

function WindonScrolled() {

    if (lightboxOpen == true) {
        //scrolling = true;
       // setTimeout('', 500);
        ShowOpacity();
       // scrolling = false;
    }

}
var SelectedVideo = "";

function OpenImage(src,  w, h) {
    lightBoxHeigth = h;
    lightBoxWidth = w;

    $(function() {
    
        $('.lightbox-container').css('width', lightBoxWidth);
        $('.lightbox-container').css('height', lightBoxHeigth);
        _$('Lightbox-Homemade-Div').style.display = "block";

        ShowOpacity();
        FadeIn();

        $('#video_content').css('width', w);
        $('#video_content').css('height', h);
        
        $('#LightBox-Div').hide();
        $('#LightBox-Div').fadeIn(500);

        lightboxOpen = true;
    });
    

}


function FadeIn() {
    var object = document.getElementById('Opacity-Div').style;
    var increment = alpha + 15;

    object.opacity = '.' + increment;
    object.MozOpacity = '.' + increment;
    object.KhtmlOpacity = '.' + increment;
    object.filter = "alpha(opacity=" + increment + ")"

    if (alpha < 50) {
        setTimeout('FadeIn();', 10);
        alpha = alpha + 10;
    } else if (alpha == 50) {
        alpha = 0;
    }
}

function ShowLightBox() {
    _$('LightBox-Div').style.display = "block";
}

function ShowOpacity() {


 
    var height = parseInt($('body').height()) + 'px';
    var width = parseInt($('body').width()) + 'px';

    if (  parseInt( $(window).height()) >  parseInt($('body').height())){
        height = parseInt($(window).height()) + 'px';
    }

    


    var size = Size();
    var scroll = getScrollXY();
    var marginTop = 0;
    var marginLeft = 0;
   

    if (size[0] < $('body').outerWidth()) {
        _$('Lightbox-Homemade-Div').style.width = width;
        _$('Opacity-Div').style.width = width;
    } else {
        _$('Lightbox-Homemade-Div').style.width = '100%';
        _$('Opacity-Div').style.width = '100%';
    }

    _$('Lightbox-Homemade-Div').style.height = height;
    _$('Opacity-Div').style.height = height;
    _$('Opacity-Div').style.display = "block";

    border = parseInt($('#LightBox-Div').css("borderLeftWidth").replace("px", ""))

    marginTop = parseInt((size[1] - lightBoxHeigth) / 2 - border);
    marginLeft = parseInt((size[0] - lightBoxWidth) / 2 - border);

    //alert(marginTop + " " + marginLeft)

    if (marginTop > 0) {
        _$('LightBox-Div').style.top = parseInt(marginTop + scroll[1]) + 'px';
    } else {
        _$('LightBox-Div').style.top = parseInt(0 + scroll[1]) + 'px';
    }

    if (marginLeft > 0) {
        _$('LightBox-Div').style.left = parseInt(marginLeft + scroll[0]) + 'px';
    } else {
        _$('LightBox-Div').style.left = parseInt(0 + scroll[0]) + 'px';
    }

}



function Close() {



    $("#videoIframe").attr("src", "/common/db_blank.htm");
    $("#videoIframe").hide();
    _$('Lightbox-Homemade-Div').style.display = "none";
    _$('LightBox-Div').style.top = '180px';
    _$('Lightbox-Homemade-Div').style.width = '100%';
    _$('Opacity-Div').style.width = '100%';
    $(".close").removeClass("fullscreenClose");
    $('.closebarplayer').hide();

    $(".lightbox-container").css('border', "");
    HideLightBox();
    HideOpacity();
    lightboxOpen = false

    var object = document.getElementById('Opacity-Div').style;
    var increment = 0;

    object.opacity = '.' + increment;
    object.MozOpacity = '.' + increment;
    object.KhtmlOpacity = '.' + increment;
    object.filter = "alpha(opacity=" + increment + ")"

    $('#video_content').hide();
    $("#videoContent").hide();

    $('#videoIframe').attr('width', "800");
    $('#videoIframe').attr('height', "446");

   // $("body").css("overflow", "auto");
    return false;

}

function HideLightBox() {
    _$('LightBox-Div').style.display = "none";

}

function HideOpacity() {
    _$('Opacity-Div').style.display = "none";
    _$('Opacity-Div').style.height = "0px";

}

function Size() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    return [myWidth, myHeight];
    //window.alert('Width = ' + myWidth);
    //window.alert('Height = ' + myHeight);
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];

}

var SelectedVideoID = 0
var hasCopy = false

function OpenReportageVideo(src, w, h, id, copy) {

    lightBoxHeigth = h;
    lightBoxWidth = w;
    SelectedVideo = src;
    SelectedVideoID = id
    hasCopy = copy

    $("#" + selectedVideoID).attr("value", id);


    //alert($("#" + selectedVideoID).attr("value"));

    //alert(src);

   



    $('.lightbox-container').css('width', lightBoxWidth);
    $('.lightbox-container').css('height', lightBoxHeigth);
    _$('Lightbox-Homemade-Div').style.display = "block";

    ShowOpacity();
    FadeIn();

    $('#main_image').hide();
    $('#video_content').show();
    $('#iframeID').attr('src', src);
    $('#iframeID').attr('width', lightBoxWidth);
    $('#iframeID').attr('height', lightBoxHeigth);

    $('#LightBox-Div').hide();
    //$('#LightBox-Div').fadeIn();
    $('#LightBox-Div').fadeIn(700, "quartEaseInOut", function () {});

    lightboxOpen = true;
    setTimeout("LoadReportageMovie();", 500)

    // });
}


function LoadReportageMovie() {
//height:446px; width:800px;
    $('#videoIframe').attr('width', "800");
    $('#videoIframe').attr('height', "446");
    $('#videoIframe').attr('scrolling', 'no');
    $("#videoIframe").attr("src", "/common/reportage/playvideo.aspx?url= " + SelectedVideo);
    $("#videoIframe").show();
    LoadHtml();
}




var _EditURL = "";
function OpenEditArchive(src, w, h) {

    lightBoxHeigth = h;
    lightBoxWidth = w;

    _EditURL = "http://www.gettyimages.co.uk/Search/Search.aspx?family=editorial&contractUrl=1&ep=Edit&p=";
    _EditURL = _EditURL + (src.replace(" ", "+"));

    $('.lightbox-container').css('width', lightBoxWidth);
    $('.lightbox-container').css('height', lightBoxHeigth);
    _$('Lightbox-Homemade-Div').style.display = "block";

    ShowOpacity();
    FadeIn();

    $('#main_image').hide();
    $('#video_content').show();
    $('#iframeID').attr('src', src);
    $('#iframeID').attr('width', lightBoxWidth);
    $('#iframeID').attr('height', lightBoxHeigth);

    $('#LightBox-Div').hide();
    //$('#LightBox-Div').fadeIn();
    $('#LightBox-Div').fadeIn(700, "quartEaseInOut", function () { });

    lightboxOpen = true;
    setTimeout("LoadReportageEditArchive();", 500)
}


function LoadReportageEditArchive() {
   // alert(_EditURL)

    $("#videoIframe").attr("src", _EditURL);
    $('#videoIframe').attr('width', lightBoxWidth);
    $('#videoIframe').attr('height', lightBoxHeigth);
    $('#videoIframe').attr('scrolling', 'yes');
    //scrolling = "no"
    $("#videoIframe").show();
    $("#videoContent").hide();
}

var customULR = ""
function OpenURL(url) {

    if ($(window).width() >= 1280) {

        lightBoxWidth = 960;
        lightBoxHeigth = $(window).height() - 160

    } else {
        lightBoxWidth = 960;
        lightBoxHeigth = $(window).height() - 160
    }

    customULR = url;

    $('.lightbox-container').css('width', lightBoxWidth);
    $('.lightbox-container').css('height', lightBoxHeigth);
    _$('Lightbox-Homemade-Div').style.display = "block";

    ShowOpacity();
    FadeIn();

    $('#main_image').hide();
    $('#video_content').show();
    $('#iframeID').attr('src', url);
    $('#iframeID').attr('width', lightBoxWidth);
    $('#iframeID').attr('height', lightBoxHeigth);

    $('#LightBox-Div').hide();
    //$('#LightBox-Div').fadeIn();
    $('#LightBox-Div').fadeIn(700, "quartEaseInOut", function () { });


    lightboxOpen = true;
    setTimeout("LoadUrl();", 500)
}


function LoadUrl() {
    $('#videoIframe').attr('scrolling', 'yes');
    $("#videoIframe").attr("src", customULR);
    $('#videoIframe').attr('width', lightBoxWidth);
    $('#videoIframe').attr('height', lightBoxHeigth);
 
    $("#videoIframe").show();
    $("#videoContent").hide();
}




function LoadHtml() {
    $("#videoContent").show();
    var loadUrlc = "/common/getvideocontent.aspx";
    var ajax_load = "";
    if (hasCopy == true) {
        $("div#videoContent").html(ajax_load).load(loadUrlc, 'id=' + php_urlencode(SelectedVideoID) + '&copy=true', function (responseText) {
            $('.scroll-pane').jScrollPane({ showArrows: true });
        });
    } else {
        $("div#videoContent").html(ajax_load).load(loadUrlc, 'id=' + php_urlencode(SelectedVideoID) + '&copy=false', function (responseText) {
            //$('.scroll-pane').jScrollPane({ showArrows: true });
        });
    }
  
}


function php_urlencode(str) {
    str = escape(str);
    return str.replace(/[*+\/@]|%20/g,
                function (s) {
                    switch (s) {
                        case "*": s = "%2A"; break;
                        case "+": s = "%2B"; break;
                        case "/": s = "%2F"; break;
                        case "@": s = "%40"; break;
                        case "%20": s = "+"; break;
                    }
                    return s;
                }
           );
}



var folioURL = ""
function OpenFullScreenPlayer(url) {


    lightBoxWidth = $(window).width()
    lightBoxHeigth = $(window).height() 


    folioURL = url;
    $('.closebarplayer').show();
    //$('.closeee').width(lightBoxWidth)
    //$(".close").addClass("fullscreenClose");
    $(".lightbox-container").css('border', "none");
    $('.lightbox-container').css('width', lightBoxWidth);
    $('.lightbox-container').css('height', lightBoxHeigth);
    _$('Lightbox-Homemade-Div').style.display = "block";

    ShowOpacity();
    FadeIn();

    $('#main_image').hide();
    $('#video_content').show();
    $('#iframeID').attr('src', url);
    $('#iframeID').attr('width', lightBoxWidth);
    $('#iframeID').attr('height', lightBoxHeigth);

    $('#LightBox-Div').hide();
    //$('#LightBox-Div').fadeIn();
    $('#LightBox-Div').fadeIn(700, "quartEaseInOut", function () { });


    lightboxOpen = true;
    setTimeout("OpenFullScreenUrl();", 500)
}


function OpenFullScreenUrl() {

    $("#videoIframe").attr("src", folioURL);
    $('#videoIframe').attr('width', lightBoxWidth);
    $('#videoIframe').attr('height', lightBoxHeigth);
    $('#videoIframe').attr('scrolling', 'no');
    $('#backtext').text(backToText);


    //scrolling = "no"
    $("#videoIframe").show();
    $("#videoContent").hide();
}



