﻿

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 && scrolling == false) {
        scrolling = true;
        setTimeout('', 1000);
        ShowOpacity();
        scrolling = false;
    }

}

function OpenVideo(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();
        //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;
    });


}


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();
        //ShowLightBox();       
        
        $('#main_image').attr('src', src);
        $('#main_image').css('width', w);
        $('#main_image').css('height', h);
        
        $('#LightBox-Div').hide();
        // $('#Opacity-Div').fadeIn(500);
        $('#LightBox-Div').fadeIn(500);

        lightboxOpen = true;
    });
    

}

function Open() {

    lightBoxHeigth = 255;
    lightBoxWidth = 400;
    
    $(function() {
        // alert("OPEN");
        $('#main_image').hide();
        $('#video_content').show();

        $('.lightbox-container').css('width', lightBoxWidth);
        $('.lightbox-container').css('height', lightBoxHeigth);
        _$('Lightbox-Homemade-Div').style.display = "block";

        ShowOpacity();
        FadeIn();
        //ShowLightBox();

        $('#LightBox-Div').hide();
        // $('#Opacity-Div').fadeIn(500);
        $('#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() {
    //$({div you're looking for}).outerHeight(); 
     
     //alert($('#MainContainer-Div').outerHeight());

     var height = parseInt($('#MainContainer-Div').outerHeight()) + 'px';
     var width = parseInt($('#MainContainer-Div').outerWidth()) + 'px';
    var size = Size();
    var scroll = getScrollXY();
    var marginTop = 0;
    var marginLeft = 0;

    if (size[0] < $('#MainContainer-Div').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() {
    _$('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 + ")"

    $('#main_image').hide();
    $('#video_content').hide();
    $('#main_image').attr('src', '#');
    $('#iframeID').attr('src', '#');

}

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];

}