﻿//*********************************
// © Copyright Hamed J.I 2008
// Hamed.JI@gmail.com
//*********************************

var LastSelectedIndex = 'null';
var CanShow = true; // indicate if picture box is in effect time
// this variables must fill in XSL
var FileNames = new Array();
var Descriptions = new Array();
var URLs = new Array();
var Dates = new Array();
var TotalNumberOfPicture;
//*****************************
var ShowDelayTime = 10000;
var CancelOne = false; // cancel on show if user clicked on any picture to view
            
// Show specific image from list
// index: index of image to show
function ShowPic(index,userClicked)
{
    if(CanShow == false)
      return;
      
    if(userClicked == true)
      CancelOne = true;
    else if(CancelOne == true)
    {
        CancelOne = false;
        return;
    }
    
    ShowPicture(index);
    if(TotalNumberOfPicture == 1)
      return;
      
    if(index == TotalNumberOfPicture)
        setTimeout('ShowPic(1,false);', ShowDelayTime);
    else
    {
        index++;
        setTimeout('ShowPic(' + index + ',false);', ShowDelayTime);
    }
}      
            
// Description: Show specific image path in specific image tag with fade effect
// img: image tag
// filename: path of image to show
function ShowPicture(SelectedIndex)
{
    var SelectedPic = document.getElementById('PicView' + SelectedIndex);
    var SelectedNum = document.getElementById('picItem' + SelectedIndex);
    
    var PrePic;
    var PreNum;
    if(LastSelectedIndex!= 'null')
    {
      PrePic = document.getElementById('PicView' + LastSelectedIndex);
      PreNum = document.getElementById('picItem' + LastSelectedIndex);
    }
    if(CanShow == false || SelectedNum.className == 'PictureItemSelected')
        return;

    if(LastSelectedIndex!= 'null')
        PreNum.className = 'PictureItemNormal';
    SelectedNum.className = "PictureItemSelected";    

    CanShow = false; // effect time started
    FadeEffect('PicView' + SelectedIndex, 'PicView' + LastSelectedIndex);
    //FadeOut(SelectedPicture);
    setTimeout('CanShow = true',1000); // Effect time finished
      
    //SelectedTag.className = 'PictureItemSelected';
    LastSelectedIndex = SelectedIndex;   
}

function FadeEffect(In,Out)
{
    var timer = 0;
    for(i = 0; i <= 100; i+=25) 
    { 
        setTimeout("SetOpacity(" + i + ",'" + In + "')",(timer * 100));
        if(Out != 'PicViewnull' && Out != 'Rolenull')
          setTimeout("SetOpacity(" + (100-i) + ",'" + Out + "')",(timer * 100));
        timer++; 
    } 
}

// Set opacity of specific tag to specific value
// opacity: value of opacity (0-100)
// id: id of tag to set opacity
function SetOpacity(opacity, id)
{ 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
    if(opacity == 0)
       object.display= "none";
    else
       object.display = "";
} 