﻿// JScript File
// For slide show image

function SlideImage()
{
    var obj = document.getElementById("imgDiv");
    var obj1 = document.getElementById("tmpImageDiv2");
    var objlen = obj.offsetWidth;
    if(_moveSpan > 0 && (obj1.offsetWidth - obj.scrollLeft) <= 0){
        //Post image move to right
        obj.scrollLeft = 0;
    }
    if(_moveSpan < 0 && obj.scrollLeft <= 0)
    {
        //Post image move to left
        obj.scrollLeft = obj1.offsetWidth;
    }
    obj.scrollLeft += _moveSpan;
}

function SlideToLeft(){
    if(_moveSpan < 0){
        _moveSpan *= -1;
    }
}
function SlideToRight(){
    if(_moveSpan > 0){
        _moveSpan *= -1;
    }
}

if (window.addEventListener)
{
    window.addEventListener("load", SlideShowOnLoad, false);
}
else if (window.attachEvent)
{
    window.attachEvent("onload", SlideShowOnLoad);
}
else
{
    window.onload=SlideShowOnLoad;
}
function SlideShowOnLoad(){
    var tempObj = document.getElementById("tmpImageDiv1");
    var maxObj = document.getElementById("imgDiv");
    if (tempObj && maxObj) {
        var demoWidth = tempObj.offsetWidth;
        var maxWidth = parseInt(maxObj.style.width);
        if(demoWidth <= maxWidth) {
            //set Move left btn and Move right btn visible = false
            document.getElementById("rollLeftDiv").style.display = "none";
            document.getElementById("rollRightDiv").style.display = "none";
            return;
        }
        document.getElementById("tmpImageDiv2").innerHTML = document.getElementById("tmpImageDiv1").innerHTML;
        startMove();
    }
}
function startMove(){
    if(_MoveMarquee == null)
    {
        _MoveMarquee = "move";
        _MoveMarquee = setInterval(SlideImage,_MoveSpeed);
    }
    return;
}
function stopMove(){
    window.clearInterval(_MoveMarquee);
    window.clearInterval(_MoveMarquee);
    _MoveMarquee = null;
}

 function ResizeImage(img, mWidth, mHeight){
    var image=new Image();
    image.src=img.src;
   
  var oldW = image.width;
  var oldH = image.height;
 // alert("oldwide:"+oldW+"oldHieght:"+oldH);
    
    if(image.width > 0 && image.height > 0){
        if(image.width/image.height >= mWidth/mHeight){
            if(image.width > mWidth){ 
         //   alert("1");
                img.width = mWidth;
                img.height = (image.height * mWidth)/image.width;
            }else{
         //   alert("2");
                img.width=image.width; 
                img.height=image.height;
            }
        }else{
            if(image.height>mHeight){
          //  alert("3"); 
                img.height = mHeight;
                img.width = (image.width * mHeight)/image.height; 
            }else{
          //  alert("4");
                img.width=image.width; 
                img.height = image.height;
            }
        }
    }
   
}


