﻿//////////////
var dox;
var oGly;
var oScrollLeft=null;
var oScrollRight=null;
var delayTimer=null;
var BROWSER='IE';
var LastInt=0;
 var LastSide='L';
 var LStep=1;
 var RStep=1;
 var cc=0;
//var FF=

function GalleryGeneral(document)
{
    this.doc=document;
    dox=document;
    
	this.init=GalleryInitialization;
	
	set_BROWSER();

	//Captions
	this.BigDivCaption='divBig';
	this.BigDivABSCaption='divBigImageABS';
	
	this.LeftGalleryImgCaption='imgGalleryLeft';
	this.RightGalleryImgCaption ='imgGalleryRight';
	this.LeftGalleryDivCaption='divGalleryLeft';
	this.RightGalleryDivCaption ='divGalleryRight';
	/////
	this.LeftGalleryOuterDivCaption ='divOuterLeft';
	this.LeftGalleryInnerDivCaption='divInnerLeft';
	
	this.RightGalleryOuterDivCaption ='divOuterRight';
	this.RightGalleryInnerDivCaption ='divInnerRight';
	/////
	this.LeftGalleryArrowUpImgCaption='imgArrowLeftUp';
	this.LeftGalleryArrowDownImgCaption='imgArrowLeftDown';
	//
	this.RightGalleryArrowUpImgCaption ='imgArrowRightUp';
	this.RightGalleryArrowDownImgCaption ='imgArrowRightDown';
	
	//Divs
	this.BigDiv;
	this.BigDivABS;
	this.ToggleSlideShow=true;
	
	this.LeftGalleryOuterDiv;
	this.LeftGalleryInnerDiv;
	this.RightGalleryOuterDiv;
	this.RightGalleryInnerDiv;
	
	//
	this.LeftGalleryArrowUp;
	this.LeftGalleryArrowDown;
	
	this.RightGalleryArrowUp;
	this.RightGalleryArrowDown;
	//
	
	this.ImagesInAColumn=3;
    //Variables	
	this.LtImgArr;
	this.RtImgArr;	
	this.LtCurIdx=0;
	this.RtCurIdx=0;
	this.LtTotCount=0;
	this.RtTotCount=0;
	
	this.BigImg;
	this.BigTotCount=0;
	this.BigCurIdx=0;
	this.LtBigTextArr;
	this.RtBigTextArr;	
	
	this.LtScrollCurIdx=0;
	this.RtScrollCurIdx=0;
	
	this.CommonBigTextArr;

	//Other Functions
	oGly = this;
	this.StartSlideShow = startSlideShow; 
	 
}
////////////////
    
function GalleryInitialization()
{
   //alert(dox);
    var d=this.doc;
   
    if (d!=null){
    //alert(d);
        /////
        if(d.getElementById(this.BigDivCaption)!=null){
            this.BigDiv = d.getElementById(this.BigDivCaption);
        }
        if(d.getElementById(this.BigDivABSCaption)!=null){
            this.BigDivABS = d.getElementById(this.BigDivABSCaption);
        }
        if(d.getElementById(this.BigImgCaption)!=null){
            this.BigImg = d.getElementById(this.BigImgCaption);
        }

		////
		//alert("fdfsf");
//		setOnClickOnBigImage(this.BigDivABS);
		//setOnClickOnBigImage(this.BigDiv);
		
		////
        //ARROW///
                  
        if(d.getElementById(this.LeftGalleryArrowUpImgCaption)!=null){
            this.LeftGalleryArrowUp = d.getElementById(this.LeftGalleryArrowUpImgCaption);
            if (this.LeftGalleryArrowUp.parentNode!=null){
                this.LeftGalleryArrowUp.parentNode.onClick = callLeftUpClick;
            }
            this.LeftGalleryArrowUp.onclick = callLeftUpClick;
        }
        if(d.getElementById(this.LeftGalleryArrowDownImgCaption)!=null){
            this.LeftGalleryArrowDown = d.getElementById(this.LeftGalleryArrowDownImgCaption);
            if (this.LeftGalleryArrowDown.parentNode!=null){ 
                this.LeftGalleryArrowDown.parentNode.onClick = callLeftDownClick;
            }
            this.LeftGalleryArrowDown.onclick = callLeftDownClick;
        }
        /////
         //alert("dfdf");
        if(d.getElementById(this.RightGalleryArrowUpImgCaption)!=null){
            this.RightGalleryArrowUp = d.getElementById(this.RightGalleryArrowUpImgCaption);
            if (this.RightGalleryArrowUp.parentNode!=null){
                this.RightGalleryArrowUp.parentNode.onclick = callRightUpClick;
            }
            this.RightGalleryArrowUp.onClick = callRightUpClick;
        }
        //alert(this.RightGalleryArrowUp);
        if(d.getElementById(this.RightGalleryArrowDownImgCaption)!=null){
            this.RightGalleryArrowDown = d.getElementById(this.RightGalleryArrowDownImgCaption);
            if (this.RightGalleryArrowDown.parentNode!=null){
                this.RightGalleryArrowDown.parentNode.onclick = callRightDownClick;
            }
            //alert(this.RightGalleryArrowDown);
            this.RightGalleryArrowDown.onClick = callRightDownClick;
        }
        ////////
        
        if(d.getElementById(this.LeftGalleryOuterDivCaption)!=null){
            this.LeftGalleryOuterDiv= d.getElementById(this.LeftGalleryOuterDivCaption);
        }
        
        if(d.getElementById(this.RightGalleryOuterDivCaption)!=null){
            this.RightGalleryOuterDiv = d.getElementById(this.RightGalleryOuterDivCaption);
        }
        
        if(d.getElementById(this.LeftGalleryInnerDivCaption)!=null){
        //alert("a");
            this.LeftGalleryInnerDiv= d.getElementById(this.LeftGalleryInnerDivCaption);
        }
        
        if(d.getElementById(this.RightGalleryInnerDivCaption)!=null){
            this.RightGalleryInnerDiv = d.getElementById(this.RightGalleryInnerDivCaption);
        }
      //alert('gg');  
        //
        if (this.LeftGalleryInnerDiv!=null){
            var ltImgArr = this.LeftGalleryInnerDiv.getElementsByTagName('img');
            //alert(ltImgArr.length );
            var ltImgArr1= new Array();
            var imgCount=0;
            for(var i=0;i<ltImgArr.length;i++){//alert("ss : "+ltImgArr.length);alert(getEID(ltImgArr[i]));alert("eee")
                if (getEID(ltImgArr[i])!=''){
                    if (ltImgArr[i].id.indexOf(this.LeftGalleryImgCaption)>-1){
                        var oIm =setBigImageOnClick(ltImgArr[i],'left');
                        ltImgArr1.push(oIm);    
                        imgCount++;
                    }
                }
            }
            this.LtImgArr = ltImgArr1;
            this.LtTotCount = imgCount;
        }
        //alert('gg1');
        if (this.RightGalleryInnerDiv!=null){
            var rtImgArr = this.RightGalleryInnerDiv.getElementsByTagName('img');
            var rtImgArr1= new Array();
            var imgCount =0;
            for(var i=0;i<rtImgArr.length;i++){
                if (rtImgArr[i].id!='undefined' && rtImgArr[i].id!=''){
                    if (rtImgArr[i].id.indexOf(this.RightGalleryImgCaption)>-1){
                        var oIm =setBigImageOnClick(rtImgArr[i],'right');
                        rtImgArr1.push(oIm);    
                        imgCount++;
                    }
                }
            }
            //alert('ghr');
            this.RtImgArr = rtImgArr1;
            this.RtTotCount = imgCount;
        }
        //alert('ghr');
        if (this.LeftGalleryInnerDiv!=null){
            var ltArr = this.LeftGalleryInnerDiv.getElementsByTagName('div');
            //alert(ltArr.length);
            var ltArr1= new Array();
             
            var imgCount =0;
            for(var i=0;i<ltArr.length;i++){
                if (ltArr[i].id!='undefined' && ltArr[i].id!=''){
                    if (ltArr[i].id.indexOf('divGalleryLeft')>-1){
                        ltArr1.push(ltArr[i].innerHTML);    
                        imgCount++;
                    }
                }
            }
            //alert(ltArr1);
            this.LtBigTextArr = ltArr1;
            //alert(this.LtBigTextArr);
        }
        //alert('ghr');
        if (this.RightGalleryInnerDiv!=null){//alert("dd1");
            var rtArr = this.RightGalleryInnerDiv.getElementsByTagName('div');
            var rtArr1= new Array();
            var imgCount =0;
            //alert("dd1");
            
            for(var i=0;i<rtArr.length;i++){ 
                //if (rtArr[i].attribute('id')=='undefined'){alert('dsfasd55');}
                if (getEID(rtArr[i])!=''){
                    if (rtArr[i].id.indexOf('divGalleryRight')>-1){
                        rtArr1.push(rtArr[i].innerHTML);    
                        imgCount++;
                    }
                }
            }
            //alert("dd1");
            this.RtBigTextArr = rtArr1;
            //alert(this.RtBigTextArr);
        }
        //alert(this.LtBigTextArr.length);
        //alert("dderw");
        var iCount = this.LtBigTextArr.length;
        if (iCount<this.RtBigTextArr.length){
            iCount = this.RtBigTextArr.length;
        }
        this.BigTotCount = iCount;
        //alert(iCount);
       for (var i=0; i<iCount; i++){
            if (this.CommonBigTextArr==null){
                this.CommonBigTextArr = new Array();
            }
            
            if (i<this.LtBigTextArr.length){
                this.CommonBigTextArr.push(this.LtBigTextArr[i])
            }
            if (i<this.RtBigTextArr.length){
                this.CommonBigTextArr.push(this.RtBigTextArr[i])
            }
       }
       //alert(this.CommonBigTextArr);
       
       ////////////
       oScrollLeft=initHScroll('left');//alert("45454");
       //alert(oScrollLeft.type);
       oScrollRight=initHScroll('right');
       //alert(oScrollRight.type);
       ////////////
        //alert(this.CommonBigTextArr);
       
        var sHTMLBig = new Array();
        //alert(this.LtTotCount );
        //elemId, elemIdABS, elemIdPrefix, count, startIndex, delay, fromOpacity, toOpacity, time, fps
         if (this.ToggleSlideShow){
            this.StartSlideShow(this.BigDivCaption,'divBigImageABS',this.LeftGalleryDivCaption,this.BigTotCount);  
         }
        //alert("ff"); 
        //this.StartSlideShow();    
    }
}

function callLeftUpClick()
{ 
   var idx = oGly.LtCurIdx;
    if (idx>0){
        if (oGly.LeftGalleryArrowDown.parentNode!=null){
            scrollRow(oScrollLeft,'up');
            setButtons(oScrollLeft);
        }
    }
}
function callLeftDownClick()
{ 
    var idx = oGly.LtCurIdx;
    if ((idx + oGly.ImagesInAColumn)<oGly.LtTotCount){
        if (oGly.LeftGalleryArrowDown.parentNode!=null){
            scrollRow(oScrollLeft,'down');
            setButtons(oScrollLeft);
        }
    }
}
function callRightUpClick()
{ 
    var idx = oGly.RtCurIdx;
    if (idx>0){
        if (oGly.RightGalleryArrowUp.parentNode!=null){
            scrollRow(oScrollRight,'up');
            setButtons(oScrollRight);
        }
    }
}
function callRightDownClick()
{
    var idx = oGly.RtCurIdx;
    if ((idx + oGly.ImagesInAColumn)<oGly.RtTotCount){
        if (oGly.RightGalleryArrowDown.parentNode!=null){
            scrollRow(oScrollRight,'down');
            setButtons(oScrollRight);
        }
    }
}

//////////////////////////////////////////////////////
////////////////////////scroll////////////////////////
//////////////////////////////////////////////////////
function initHScroll(type)
{ 
    var oHScroll = new Object();
    
    oHScroll.stepUp = 40;
    oHScroll.smoothStepUp = 0;
    oHScroll.stepDown = 40;
    oHScroll.smoothStepDown = 0;
    oHScroll.timerUp = 0;
    oHScroll.timerDown = 0;
    oHScroll.speed = 10;
    oHScroll.smoothFirstValue = 0;//around 40 % of offset width of elemIdRowsOuter(510)
    
    oHScroll.type = type;
    
    oHScroll.currentRow = oGly.LtCurIdx;
    oHScroll.currentRowNo = oGly.LtCurIdx;
    oHScroll.totalRows = oGly.LtTotCount;
    oHScroll.bScroll=true;
    oHScroll.OuterDiv = dox.getElementById('divOuterLeft');
    oHScroll.InnerDiv = dox.getElementById('divInnerLeft');
    
    if (type!=null && type!=''){
        if (type=='right'){
            oHScroll.currentRow = oGly.RtImgArr[oGly.RtCurIdx];
            oHScroll.currentRowNo = oGly.RtCurIdx;
            oHScroll.totalRows = oGly.RtTotCount;
            oHScroll.bScroll=true;
            //alert("divOuterRight");
            oHScroll.OuterDiv = dox.getElementById('divOuterRight');
            oHScroll.InnerDiv = dox.getElementById('divInnerRight');
        }
        else{
            oHScroll.currentRow = oGly.LtImgArr[oGly.LtCurIdx];
            oHScroll.currentRowNo = oGly.LtCurIdx;
            oHScroll.totalRows = oGly.LtTotCount;
            oHScroll.bScroll=true;
            oHScroll.OuterDiv = dox.getElementById('divOuterLeft');
            oHScroll.InnerDiv = dox.getElementById('divInnerLeft');
        }
    }
    return oHScroll;
}

function scrollRow(oHScroll, dir)
{

    var oOuter = oHScroll.OuterDiv;
    var oInner = oHScroll.InnerDiv;
    var oCurrentRow =null;
    
    if (oHScroll.type=='right'){
        oHScroll.currentRowNo = oGly.RtCurIdx;
        oCurrentRow=oGly.RtImgArr[oGly.RtCurIdx];
    }
    else{
        oHScroll.currentRowNo = oGly.LtCurIdx;
        oCurrentRow=oGly.LtImgArr[oGly.LtCurIdx];
    }
        
    //alert(oOuter + ':' + oHScroll.totalRows + ':' + oCurrentRow.id + ':' + oHScroll.currentRowNo);
    //alert("fd");
    
    var offsetH = 109;
    if (oCurrentRow.height!=null && oCurrentRow.height!='undefined' && oCurrentRow.height!=''){
        offsetH=oCurrentRow.height;
    }
    else if (oCurrentRow.scrollHeight!=null && oCurrentRow.scrollHeight!='undefined' && oCurrentRow.scrollHeight!=''){
        offsetH=oCurrentRow.scrollHeight;
    }
    else if (oCurrentRow.clientHeight!=null && oCurrentRow.clientHeight!='undefined' && oCurrentRow.clientHeight!=''){
        offsetH=oCurrentRow.clientHeight;
    }
    //alert(oHScroll.totalRows);
    if (oOuter!=null && oHScroll.totalRows!=null && oHScroll.bScroll == true && oHScroll.totalRows>oGly.ImagesInAColumn){ 
        if (dir == 'down') {  
            //alert("parseInt(oInner.style.top.replace('px','')):" + parseInt(oInner.style.top.replace('px','')));
            if(oInner.style.top == null || oInner.style.top == ''){
                oInner.style.top = '0px';
            }
            //alert(oHScroll.currentRowNo);
            var iLastValue = parseInt(oInner.style.top.replace('px',''))  - parseInt(oCurrentRow.offsetHeight)-8;
            //iLastValue =  - (113)*oHScroll.currentRowNo;
            var iSmoothFirstValue = iLastValue + oHScroll.smoothFirstValue;
            //alert('iLastValue::' + iLastValue);
            //alert('iSmoothFirstValue::' + iSmoothFirstValue);
            scrollUp(oHScroll, iLastValue,iSmoothFirstValue,oHScroll.timerDown,oHScroll.speed);
            //alert(oInner.style.top);
            
        }
        else// for up/next
        { 
            //alert(oHScroll.currentRowNo + ':' + oHScroll.totalRows);
            if (oHScroll.currentRowNo<oHScroll.totalRows){
                if(oInner.style.top == null || oInner.style.top == ''){
                    oInner.style.top = '0px';
                }
                var iLastValue = parseInt(oInner.style.top.replace('px',''))  + parseInt(oCurrentRow.offsetHeight)+8;                 
                var iSmoothFirstValue = iLastValue - oHScroll.smoothFirstValue;
                //alert(oInner.style.top + ':' + oCurrentRow.offsetHeight + ':' + iLastValue);
                //alert('iLastValue::' + iLastValue);
                //alert( 'iSmoothFirstValue ::' + iSmoothFirstValue);
                scrollDown(oHScroll,iLastValue,iSmoothFirstValue,oHScroll.timerUp,oHScroll.speed);
                //alert(oInner.style.top);
            }
        }
        if (oHScroll.type=='right'){
            if (dir=='down'){
                oGly.RtCurIdx = oGly.RtCurIdx + 1;
                if (oGly.RtCurIdx>=oGly.RtTotCount){
                    oGly.RtCurIdx=oGly.RtTotCount-1;
                }
            }
            else{
                oGly.RtCurIdx = oGly.RtCurIdx - 1;
                if (oGly.RtCurIdx<0){
                    oGly.RtCurIdx=0;
                }
            }
        }
        else{
            if (dir=='down'){
                oGly.LtCurIdx = oGly.LtCurIdx + 1;
                if (oGly.LtCurIdx>=oGly.LtTotCount){
                    oGly.LtCurIdx=oGly.LtTotCount-1;
                }
             }
             else{
                oGly.LtCurIdx = oGly.LtCurIdx - 1;
                if (oGly.LtCurIdx<0){
                    oGly.LtCurIdx=0;
                }
             }
        }
    }   
    //alert(oGly.LtCurIdx);
}

function scrollDown(oHScroll,lastValue, smoothFirstValue, timerUp, speed)
{    
    var oDivInner = oHScroll.InnerDiv;
    if(oDivInner != null){        
        var iTop = parseInt(oDivInner.style.top.replace('px',''));
        //alert(iTop + ':' + lastValue);
        //alert(lastValue);
        if(iTop < parseInt(lastValue)){
            var iNextValue = 0;
            if(iTop < smoothFirstValue){//alert(iTop + ':' + smoothFirstValue + ':' + lastValue);
                if(iTop + oHScroll.stepUp < smoothFirstValue){
                    iNextValue = iTop + parseInt(oHScroll.stepUp);
                }
                else{
                    iNextValue = smoothFirstValue;
                } 
            }
            else{
                if(iTop + oHScroll.smoothStepUp < lastValue){
                    iNextValue = iTop + parseInt(oHScroll.smoothStepUp);
                }
                else{
                    iNextValue = lastValue;
                }
            }
           //alert('smoothFirstValue:' +smoothFirstValue + ' oDivInner.style.top:' + oDivInner.style.top + '::lastValue:' + lastValue + '::iNextValue:' + iNextValue + '::' + oHScroll.stepUp + '::' + timerUp);            
           //exit(0);
            oDivInner.style.top = iNextValue + 'px'; //alert(oHScroll); 
            //alert(smoothFirstValue);          
            timerUp=setTimeout(function(){scrollDown(oHScroll,lastValue,smoothFirstValue,timerUp,speed)},speed);
        }
        else{
            clearTimeout(timerUp);
           //setButtons(oHScroll);        
        }  
    }
}

function scrollUp(oHScroll,lastValue,smoothFirstValue, timerDown, speed)
{    
    var oDivInner = oHScroll.InnerDiv;
    if(oDivInner != null){
        var iTop = parseInt(oDivInner.style.top.replace('px',''));
        //alert("iTop:" + iTop + " lastValue: " + lastValue + " smoothFirstValue: " + smoothFirstValue);
        if(iTop > parseInt(lastValue)){
            var iNextValue = 0;
            if(iTop > smoothFirstValue){
                if(iTop - oHScroll.stepDown > smoothFirstValue){
                    iNextValue = iTop - parseInt(oHScroll.stepDown);
                }
                else{
                    iNextValue = smoothFirstValue;
                } 
            }
            else{
                if(iTop - oHScroll.smoothStepDown > lastValue){
                    iNextValue = iTop - parseInt(oHScroll.smoothStepDown);
                }
                else{
                    iNextValue = lastValue;
                }
            }
            //alert( 'oDivInner.style.top:' + oDivInner.style.top + '::lastValue:' + lastValue + '::iNextValue:' + iNextValue + '::' + oHScroll.stepDown + '::' + timerDown);
            oDivInner.style.top =iNextValue + 'px';
            //alert(oDivInner.style.top);
            timerDown=setTimeout(function(){scrollUp(oHScroll,lastValue,smoothFirstValue,timerDown,speed)},speed);                    
        }
        else{
            clearTimeout(timerDown);
            //setButtons(oHScroll);        
        }  
    }
}

function setButtons(oHScroll)
{ 
    if (oHScroll.type=='right'){
        var idx = oGly.RtCurIdx;
        var count = oGly.RtTotCount;
        oGly.RightGalleryArrowUp.src="images/gallery_top_arrow_normal.jpg";
        if (oGly.RightGalleryArrowUp.parentNode!=null){
            oGly.RightGalleryArrowUp.parentNode.onClick ="#";    
        }
        oGly.RightGalleryArrowDown.src="images/gallery_bottom_arrow_normal.jpg";
        if (oGly.RightGalleryArrowDown.parentNode!=null){
            oGly.RightGalleryArrowDown.parentNode.onClick ="#";    
        }
        /////////
        if (idx>0){
            oGly.RightGalleryArrowUp.src="images/gallery_top_arrow_hover.jpg";
            if (oGly.RightGalleryArrowUp.parentNode!=null){
                oGly.RightGalleryArrowUp.parentNode.onClick = callRightUpClick;
            }
        }
        if ((idx + oGly.ImagesInAColumn)<count){
            oGly.RightGalleryArrowDown.src="images/gallery_bottom_arrow_hover.jpg";
            if (oGly.RightGalleryArrowDown.parentNode!=null){
                oGly.RightGalleryArrowDown.parentNode.onClick = callRightDownClick;
            }
        }
    }
    else{
        var idx = oGly.LtCurIdx;
        var count = oGly.LtTotCount;
        oGly.LeftGalleryArrowUp.src="images/gallery_top_arrow_normal.jpg";
        if (oGly.LeftGalleryArrowUp.parentNode!=null){
            oGly.LeftGalleryArrowUp.parentNode.onClick ="#";    
        }
        oGly.LeftGalleryArrowDown.src="images/gallery_bottom_arrow_normal.jpg";
        if (oGly.LeftGalleryArrowDown.parentNode!=null){
            oGly.LeftGalleryArrowDown.parentNode.onClick ="#";    
        }
        //
        if (idx>0){
            oGly.LeftGalleryArrowUp.src="images/gallery_top_arrow_hover.jpg";
            if (oGly.LeftGalleryArrowUp.parentNode!=null){
                oGly.LeftGalleryArrowUp.parentNode.onClick = callLeftUpClick;
            }
        }
        if ((idx + oGly.ImagesInAColumn)<count){
            oGly.LeftGalleryArrowDown.src="images/gallery_bottom_arrow_hover.jpg";
            if (oGly.LeftGalleryArrowDown.parentNode!=null){
                oGly.LeftGalleryArrowDown.parentNode.onClick = callLeftDownClick;
            }
        }
    }
}

function disabledButton(oHScroll)
{
    oHScroll.bScroll = false;
}

////////////////////////////////////////


///////////////////////////slide//////////////////////////
function startSlideShow(elemId, elemIdABS, elemIdPrefix, count,elemIdTitle, elemIdTitlePrefix, startIndex, delay, fromOpacity, toOpacity, time, fps)
{  
//alert("ff");
    var oSlideShow = new Object();
    oSlideShow.elemId = 'divBig';
    oSlideShow.el = oGly.BigDiv;
    oSlideShow.elemIdABS = 'divBigImageABS';
    oSlideShow.collection = oGly.CommonBigTextArr;
    oSlideShow.elemIdPrefix = elemIdPrefix;
    oSlideShow.count = oSlideShow.collection.length;// count;
    oSlideShow.elemIdTitle = typeof(elemIdTitle) != 'undefined' ? elemIdTitle : '';
    oSlideShow.elemIdTitlePrefix = typeof(elemIdTitlePrefix) != 'undefined' ? elemIdTitlePrefix : '';
    oSlideShow.startIndex = oGly.BigCurIdx;// typeof(startIndex) != 'undefined' ? startIndex : 0;
    oSlideShow.delay = typeof(delay) != 'undefined' ? delay : 5000;//5.5 seconds
    oSlideShow.fromOpacity = typeof(fromOpacity) != 'undefined' ? fromOpacity : 100;
    oSlideShow.toOpacity = typeof(toOpacity) != 'undefined' ? toOpacity : 0;
    oSlideShow.time = typeof(time) != 'undefined' ? time : 500;
    oSlideShow.fps = typeof(fps) != 'undefined' ? fps : 10;
     
//alert(oGly.BigCurIdx);
    //startIndex = oGly.BigCurIdx;

    if(count >= 1)
    {
        if(oSlideShow.startIndex >= oSlideShow.count)
            oSlideShow.startIndex = oSlideShow.count -1;
            
        if((dox.getElementById(oSlideShow.elemId) != null) && (dox.getElementById(oSlideShow.elemIdPrefix + oSlideShow.startIndex) != null)) 
            dox.getElementById(oSlideShow.elemId).innerHTML = dox.getElementById(oSlideShow.elemIdPrefix + oSlideShow.startIndex).innerHTML;
            //alert("ff");
            //if((dox.getElementById(oSlideShow.elemIdTitle) != null) && (dox.getElementById(oSlideShow.elemIdTitlePrefix + oSlideShow.startIndex) != null))  
            //  dox.getElementById(oSlideShow.elemIdTitle).innerHTML = dox.getElementById(oSlideShow.elemIdTitlePrefix + oSlideShow.startIndex).innerHTML;        
        
        var step = 0;//count ==1
        if(oSlideShow.count > 1)
        {
            startIndexABS = oSlideShow.startIndex + 1;
            //
            //step = oSlideShow.startIndex + 1;
            //
            //alert("ghghgh")
            //dox.getElementById(elemIdABS).innerHTML = dox.getElementById(oSlideShow.elemIdPrefix + startIndexABS).innerHTML;
            //alert(oSlideShow.collection[step]);
            dox.getElementById(elemIdABS).innerHTML = oSlideShow.collection[step];
            dox.getElementById(elemId).style.opacity = 1.0;
            
            //slideImages(elemId, elemIdABS, elemIdPrefix, count, delay, fromOpacity, toOpacity, time, fps, step);
            /////////delayed sometime (make the 1st image still for some time) b4 calling slideImages 
            setTimeout(function(){slideImages(oSlideShow,step)},oSlideShow.delay);
        }    
    }
    //alert("hdfd");
}
///////////

function slideImages(oSlideShow, step)
{

                var bDiv = dox.getElementById('divBig');
                bDiv.style.zIndex=150;
                
              
                
           
    if (oGly.ToggleSlideShow){
        if(oSlideShow.count > 0)
        {
         //alert(step + ':' + oSlideShow.count);
            FadeOpacity_DownThenUp(oSlideShow,step);
            
            if(step < (oSlideShow.count-1))
            {
                step++;
                oSlideShow.startIndex = step;
                oGly.BigCurIdx = step;
            }
            else
            {
                step = 0;
                oSlideShow.startIndex = step;
                oGly.BigCurIdx = step;
            }   
            step = oGly.BigCurIdx;
            
            
            
            
             //Auto fill caption when timer slides images - G
                var cDiv;
                
                if( LastSide=='L' ) 
                {
                cDiv = dox.getElementById('CaptionGalleryLeft' + (LStep) );
                LStep=LStep+1;
                //alert(cDiv.id);
                LastSide='R';
                }
                else 
                {
                 
                 cDiv = dox.getElementById('CaptionGalleryRight' + (RStep) );
                 RStep=RStep+1;
                 //alert(cDiv.id);
                 LastSide='L';
                }
                
                              
                
                //alert(cID);
                if (cDiv != null)
                {
                dox.getElementById('hp_gallery_transparent_inner').innerHTML=cDiv.innerHTML;
                }
                
            
            
            
            setTimeout(function(){slideImages(oSlideShow,step)},oSlideShow.delay); 
        }
        
    }
}   
    
//////////////
function FadeOpacity_DownThenUp(oSlideShow, stepImageNum)
{
    var steps = Math.ceil(oSlideShow.fps * (oSlideShow.time / 1000));
    var delta = (oSlideShow.toOpacity - oSlideShow.fromOpacity) / steps;
	//alert("ggg");
    FadeOpacityStep_DownThenUp(oSlideShow, 0, steps, delta, (oSlideShow.time / steps), stepImageNum);
}

function FadeOpacityStep_DownThenUp(oSlideShow, stepNum, steps, delta, timePerStep, stepImageNum)
{
    //alert(Math.round(parseInt(fromOpacity) + (delta * stepNum))/100 + "::" + dox.getElementById(elemId).style.opacity);
    var oGap = Math.round(parseInt(oSlideShow.fromOpacity) + (delta * stepNum)/100) - dox.getElementById(oSlideShow.elemId).style.opacity;
    //alert("gggtt");
    ////////////////////////////////////////
    //alert(oGap);
    var opacityAsInt = Math.round(parseInt(oSlideShow.fromOpacity) + (delta * stepNum));
    if (opacityAsInt > 100)
	    opacityAsInt = 100;
    
    var elemABS = dox.getElementById(oSlideShow.elemIdABS);
    var opacityAsIntABS = 0;
    if(opacityAsInt == 100)
    {
    //alert("oSlideShow.collection["+stepImageNum+"]"+oSlideShow.collection[stepImageNum]);
        //elemABS.innerHTML= dox.getElementById(oSlideShow.elemIdPrefix + stepImageNum).innerHTML;
         elemABS.innerHTML=oSlideShow.collection[stepImageNum]; //dox.getElementById(oSlideShow.elemIdPrefix + stepImageNum).innerHTML;
    }
    else
    {
        var opacityAsDoubleABS = parseFloat(dox.getElementById(oSlideShow.elemIdABS).style.opacity);
        opacityAsDoubleABS += oGap;
        opacityAsIntABS = parseFloat(opacityAsDoubleABS) * 100;
    }
    SetOpacity(dox.getElementById(oSlideShow.elemIdABS), opacityAsIntABS, 1);//up
    ////////////////////////////////////////
    
    SetOpacity(dox.getElementById(oSlideShow.elemId), opacityAsInt, 0);//down
    
    if (stepNum < steps)
    {
        ////call it (self) again and again and sets opacity from 100 to 0
        setTimeout(function(){FadeOpacityStep_DownThenUp(oSlideShow,stepNum+1,steps,delta,timePerStep,stepImageNum)},timePerStep); 
    }
    else
    {
        //alert(dox.getElementById(elemId).style.opacity + "::/n" + dox.getElementById(elemId).style.filter)
        //alert(dox.getElementById(elemIdABS).style.opacity + "::/n" + dox.getElementById(elemIdABS).style.filter)
        //dox.getElementById(oSlideShow.elemId).innerHTML = dox.getElementById(oSlideShow.elemIdPrefix + stepImageNum).innerHTML;
        dox.getElementById(oSlideShow.elemId).innerHTML = oSlideShow.collection[stepImageNum];
        
        
        if(dox.getElementById(oSlideShow.elemIdTitle) != null) 
        {
            if(dox.getElementById(oSlideShow.elemIdTitlePrefix + stepImageNum) != null)        
                dox.getElementById(oSlideShow.elemIdTitle).innerHTML= dox.getElementById(oSlideShow.elemIdTitlePrefix + stepImageNum).innerHTML;
        }
    }
}
/////////////
function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
    var steps = Math.ceil(fps * (time / 1000));
    var delta = (toOpacity - fromOpacity) / steps;
    //alert(steps + '::' + delta);
    FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(dox.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)), 1);//up

    if (stepNum < steps)
    {
        setTimeout(function(){FadeOpacityStep(elemId,(stepNum+1),steps,fromOpacity,delta,timePerStep)},timePerStep); 
    }
}
///////////////
function SetOpacity(elem, opacityAsInt, downOrUp)//0->down//1->up
{
    var opacityAsDecimal = opacityAsInt;
	
    if (opacityAsInt > 100)
	    opacityAsInt = opacityAsDecimal = 100;
	//else if (opacityAsInt < 30)
	//    opacityAsInt = opacityAsDecimal = 30; 
	    
    opacityAsDecimal /= 100;
    	        
    //if (opacityAsInt < 1)
	//    opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	    
	//alert(opacityAsDecimal + '::' + opacityAsInt);
    elem.style.opacity = opacityAsDecimal;
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
    //alert(elem.style.opacity);
}




function setBigImageOnClick(oImg,type)
{
    if (oImg!=null){
   // alert(oImg);alert(oImg.id);
        //oImg.onclick = setBigImage(oImg.parentNode,type);
        if (oImg.parentNode!=null){ //alert(oImg.parentNode.id);
            //oImg.parentNode.onclick = setBigImage(oImg.parentNode,type);
             if (window.attachEvent) {//alert("fddfdf");
                //oImg.parentNode.attachEvent("onclick","return setBigImage(this,'"+type+"');");alert("fddfdf7777");
                oImg.parentNode.attachEvent("onclick",function(event){setBigImage(oImg.parentNode,type)}); 
                //oImg.parentNode.onclick =setBigImage(oImg.parentNode,type);alert("fddfdf7777");
            } else if (window.addEventListener) {
                oImg.parentNode.setAttribute("onclick","return setBigImage(this,'" + type + "')");
            }
            
            oImg.parentNode.href="#";
           
        }
    }  
    return oImg;
}

function setBigImage(oCtrl,type)
{   //alert("dd");
    oGly.ToggleSlideShow=false;
    //setTimeout(function(){oGly.StartSlideShow(oGly.BigDivCaption ,'divBigImageABS',oGly.LeftGalleryDivCaption,oGly.BigTotCount)}, 10);
    //setTimeout(function(){oGly.ToggleSlideShow=true;}, 10000);
    
    if (oCtrl!=null){//alert(oCtrl);
        var imgArr = oCtrl.getElementsByTagName('img');
        if (imgArr!=null && imgArr.length>0){
            var oImg = findImage(imgArr);//alert("aaa");
            if (oImg!=null){//alert("aaa111");
                var sID = getEID(oImg).replace('img','div');
                var oDiv = dox.getElementById(sID);
                if (oDiv!=null){//alert("aaa4444");
                    setBigDiv(oDiv);
                }
                var cID = getEID(oImg).replace('img','Caption');
                var cDiv = dox.getElementById(cID);
                //alert(cID);
                dox.getElementById('hp_gallery_transparent_inner').innerHTML=cDiv.innerHTML;
                
            }
        }
        if(oCtrl.nextSibling!=null){//alert(oCtrl.nextSibling.className);
        //alert(oGly.CommonBigTextArr);
             for(var i=0;i<oGly.CommonBigTextArr.length;i++){  
                if (oGly.CommonBigTextArr[i]==oCtrl.nextSibling.innerHTML){//alert("i=" + i)
                    oGly.BigCurIdx = i;
                }
             }
        }
    }
    return true;
}

function findImage(imgArr)
{

    if (imgArr!=null && imgArr.length>0){
        for(var i=0;i<imgArr.length;i++){
            if (getEID(imgArr[i]).indexOf(oGly.LeftGalleryImgCaption)>-1){
            // alert(imgArr[i].src);
                return imgArr[i];
            }
            else if (getEID(imgArr[i]).indexOf(oGly.RightGalleryImgCaption)>-1){
                return imgArr[i];
            }
        }
    }
    return null;
}

function setBigDiv(oDiv)
{
    if(oDiv!=null){
        oGly.BigDiv.innerHTML = oDiv.innerHTML;
        oGly.BigDivABS.innerHTML = oDiv.innerHTML;
		//alert("fdfdfd");
		
    }
}
function getEID(el)
{
    var id='';
    try{ id=el.id; }catch(e){ id=''; }
    return id;
}

function bigDivClick(oDiv)
{
	//alert("fwwwdf");
	//alert(oDiv.firstChild);
	oGly.ToggleSlideShow=false;
	//setTimeout(function(){oGly.StartSlideShow(oGly.BigDivCaption ,'divBigImageABS',oGly.LeftGalleryDivCaption,oGly.BigTotCount)}, 10);
	//alert("fdf");
	return true;
}

function setOnClickOnBigImage(oBigDiv)
{
	//alert("aaa");
	if (oBigDiv!=null){//alert(oBigDiv);//alert(oBigDiv.id);
        //oBigDiv.onclick = setBigImage(oImg.parentNode,type);
		// if (window.attachEvent){
        if (BROWSER == 'IE'){ //alert("bbbb:" + window.attachEvent);
            //oImg.parentNode.onclick = setBigImage(oImg.parentNode,type);
			oBigDiv.attachEvent("onclick",function(event){bigDivClick(oBigDiv);}); 
            if (oBigDiv.childNodes[0]!=null) {//alert("fddfdf");
                //oImg.parentNode.attachEvent("onclick","return setBigImage(this,'"+type+"');");alert("fddfdf7777");
				oBigDiv.childNodes[0].attachEvent("onclick",function(event){bigDivClick(oBigDiv); return true;});// alert("fdfdfdfd")
                //oImg.parentNode.onclick =setBigImage(oImg.parentNode,type);
				//alert("fddfdf7777");
            }
		}
		else { //alert("cccc:" + window.addEventListener);
			oBigDiv.setAttribute("onclick","return bigDivClick(this);");
			//alert("fdfd");
			//if (oBigDiv.childNodes[0]!=null) {
			//		oBigDiv.childNodes[0].setAttribute("onclick","return bigDivClick(oBigDiv)");
			//}
        }
        //}
    }  
}

function set_BROWSER()
{
	if (navigator.appName.indexOf("Microsoft Internet Explorer")>-1){
		BROWSER = 'IE';
	}
	else if (navigator.appName.indexOf("Netscape")>-1){
		if (navigator.userAgent.indexOf("Firefox")>-1){
			BROWSER = 'FF';
		}
		else if (navigator.userAgent.indexOf("Chrome")>-1){
			BROWSER = 'CH';
		}
	}
	
//alert("BROWSER = " + BROWSER );

}

function UpdateDIV()
{

    if (oGly.ToggleSlideShow)
    {
        oGly.ToggleSlideShow=false;
        //alert("Slideshow Stopped");
    }
}


function ShowVideo(intNum)
{
    var cID = getEID('VideoPreview' + intNum);
    var cDiv = dox.getElementById('VideoPreview' + intNum);
    var vID = getEID('VideoEmbed' + intNum);
    var vDiv = dox.getElementById('VideoEmbed' + intNum);
    cc = cc+1;

    if (intNum != LastInt) {
cc=0;
     if (oGly.ToggleSlideShow)
        {
            oGly.ToggleSlideShow=false;
            //alert("Slideshow Stopped");
        }
    //alert('VideoPreview' + intNum);
    //alert(cDiv);
    //alert(vDiv);
    //vDiv.style.visibility="visible"; 
    cDiv.innerHTML=vDiv.innerHTML;
    LastInt=intNum;
    } 
    else
        {
        if (cc % 2 ==0)
            {
            cDiv.innerHTML=vDiv.innerHTML;
            
            }
        }
       
}


