﻿var m_AllIsLoaded = false;
var oImagePopup = null;

var oCloseZoomPopup = true;

function DoNotCloseZoom() {
    oCloseZoomPopup = false;
}

function DoCloseZoom() {
    oCloseZoomPopup = true;
    setTimeout('CloseImageZoom();', 10);
}

function OpenImageZoom1(sImg, isMovie, sAlt) {

    var oImg = oImagePopup;
    if (oImg == null)
        return;
    var oMiddleDiv = document.getElementById("divZoomContainer");
    if (oMiddleDiv != null) {
        if (isMovie=="true")
            loadMovieFullDetails("divZoomContainer", sImg);
        else {
            var oZoomImg = document.getElementById("ImgImageViewerWrap");
            if (oZoomImg != null) {
                
                var oNewImage = new Image();
                oNewImage.src = sImg;
                
                if (oNewImage.width > oNewImage.height){
                    
                    var iRatio = oNewImage.width / oNewImage.height;
                    
                    var thumbWidth = 214 * iRatio;
                    if (thumbWidth < 285)
                    {
                        oZoomImg.style.height = "214px";
                    }
                    else{
                        oZoomImg.style.width = "285px";
                    }

                }
                else{
                    oZoomImg.style.height = "214px";
                }
                //resize image
                /*if (oNewImage.height < 214 || oNewImage.width < 285) {
                    //get ratio
                    var iRatio = oNewImage.height / oNewImage.width;
                    
                    //adjust width
                    if (iRatio >= 1)
                        oZoomImg.style.width = "285px";
                    else
                    //adjust height
                        oZoomImg.style.height = "214px";

                }*/
                
                oZoomImg.src = sImg;
                oZoomImg.alt = sAlt;
                
            }
        }
        
        var oImgDiv = document.getElementById("DivImageViewerWrap");
        
        if (oImgDiv != null) {
            if (oImg != null) {
                var size = BodySize();
                var scroll = getScrollXY();
                var ImageLeft = getLeft(oImg);
                var ImageTop = getTop(oImg);
                var iLeft = (parseInt(ImageLeft) + 85);
                var iTop = (parseInt(ImageTop) - 210);
                var iTempLeft = (ImageLeft + 414 - scroll[0]);
                var iTempTop = (ImageTop - scroll[1]);
                if(iTempTop < 210){
                    iTop += 260;
                }
                if(iTempLeft > size[0]){
                    iLeft -= 358;
                }
                oImgDiv.style.left = iLeft + "px";
                oImgDiv.style.top = iTop + "px";
            }
            oImgDiv.style.display = 'inline';
        }
    }
}

function OpenImageZoom(oImg, sImg, isMovie, sAlt) {
 
    oImagePopup = oImg;
    setTimeout("OpenImageZoom1('"+sImg+"','"+isMovie+"','"+sAlt+"');",500);
}

function BodySize() {
  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];
}
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 ];
}
function getLeft(element)
{
    var left = element.offsetLeft;
    while(element=element.offsetParent)
    {
        if (element.className != "CenterWrap")
            left += element.offsetLeft;
    }
    return left;
}


function getTop(element)
{
    var top  = element.offsetTop;
    while(element=element.offsetParent)
    {
        top  += element.offsetTop;
    }
    
    return top;
    
}


function CloseImageZoom() {
    if (oCloseZoomPopup == null || oCloseZoomPopup == true) {
        oImagePopup = null;
        var oMiddleDiv = document.getElementById("divZoomContainer");
        if (oMiddleDiv != null) {
            //debugger;
            oMiddleDiv.innerHTML = '<img style="" src="../Images/pic.jpg" id="ImgImageViewerWrap" />';
        }

        var oImgDiv = document.getElementById("DivImageViewerWrap");
        if (oImgDiv != null) {
            oImgDiv.style.display = 'none';
        }
    }
}

function loadMovieFullDetails(sIntoDiv, sFileLink) {
    var s1 = new SWFObject("mediaplayer.swf", "mediaplayerfulldetails", "285", "214", "8");
    s1.addParam("allowfullscreen", "false");
    s1.addVariable("shownavigation", "false");
    s1.addVariable("width", "285");
    s1.addVariable("height", "214");
    s1.addVariable("file", sFileLink + ".flv");
    s1.addVariable("image", sFileLink + ".jpg");
    s1.addVariable('javascriptid', 'mediaplayerfulldetails');
    s1.addVariable('enablejs', 'true');
    s1.addVariable('autostart', 'true');
    s1.addParam('allowscriptaccess', 'always');
    s1.addParam('wmode', 'window');
    s1.write(sIntoDiv);
}
function GoToContent(iContentID){
    var sReturnUrl = "../pages/ContentDetails.aspx?ContentID=" + iContentID;
    window.open("../direct/LoginForm.aspx?IsAuth=1&ReturnUrl="+ sReturnUrl,"ContentWin" + iContentID);
    //escape()
}
m_AllIsLoaded = true;
