﻿

var lightboxOpen = false;
var scrolling = false;
var lightBoxHeigth = 425;
var lightBoxWidth = 745;
var alpha = 0;


function _$(id) {
    return document.getElementById(id);
}

function WindonResized() {

    if (lightboxOpen == true) {
        ShowOpacity();
    }

}

function WindonScrolled() {

    if (lightboxOpen == true) {
        ShowOpacity();
    }

}
var SelectedVideo = "";

function OpenVideo(src, w, h) {

    lightBoxHeigth = h;
    lightBoxWidth = w;
    SelectedVideo = src;

    //$("body").css("overflow", "hidden");

    //$(function() {

    $('.flash-image-banner').hide();

    $('.lightbox-container').css('width', lightBoxWidth);
    $('.lightbox-container').css('height', lightBoxHeigth);
    _$('Lightbox-Homemade-Div').style.display = "block";

    ShowOpacity();
    FadeIn();
    //ShowLightBox();
    $('#main_image').hide();
    $('#video_content').show();
    $('#iframeID').attr('src', src);
    $('#iframeID').attr('width', lightBoxWidth);
    $('#iframeID').attr('height', lightBoxHeigth);

    $('#LightBox-Div').hide();
    // $('#Opacity-Div').fadeIn(500);
    $('#LightBox-Div').fadeIn(500);

    lightboxOpen = true;
    setTimeout("LoadMovie();", 500)

    // });
}

function LoadMovie() {


//    $("#videoIframe").attr("src", "/common/v2/playvideo.aspx?url= " + SelectedVideo);
    //    $("#videoIframe").show();


     $("#videoIframe").attr("src",  SelectedVideo);
    $("#videoIframe").show();
}



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';
    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";

    marginTop = parseInt((size[1] - lightBoxHeigth) / 2);
    marginLeft = parseInt((size[0] - lightBoxWidth) / 2);

    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", "");
    $("#videoIframe").hide();
    _$('Lightbox-Homemade-Div').style.display = "none";
    _$('LightBox-Div').style.top = '180px';
    _$('Lightbox-Homemade-Div').style.width = '100%';
    _$('Opacity-Div').style.width = '100%';

    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();
    $('.flash-image-banner').show();
    
    // $("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];

}
