﻿// JScript File
/// Start Upload Image //////
function ShowUploadImages()
{
    ShowUploadImages.NumberOfImages = 0;
    ShowUploadImages.UploadedImages = 0;
    
    PopDialogObject.Title = "رفع ملفات";
    var _html ="";
    var _selectedPath = window.tree?tree.selected.folderPath:"";
    _html += "<table border='0' width='100%'>";
    _html += "<tr><td width='30%'>موقع رفع الملفات:</td><td>"+_selectedPath+"</td></tr>";
    _html += "<tr><td colspan='2'><input type='button' value='Add Image' onclick='GetNewImageHTML()'/></td></tr>"+
             "<tr><td colspan='2' id='UploadImagesImagesArea'><span id='UploadImagesImagesArea_0'></span></td></tr>";
    _html += "</table>";
    PopDialogObject.InnerHTML =  _html;   
    PopDialogObject.Buttons.length = 0;
    PopDialogObject.Buttons[0] = new CMSButton("Upload Images","Upload Images","upload",90,23,'CreateUploadImagesClicked();');
    PopDialogObject.Buttons[1] = new CMSButton("HideUploadImages","HideUploadImages","cancel",60,23,'PopDialogObject.Close();');
    PopDialogObject.Show();
    GetNewImageHTML();
    PopDialogObject.AdjustDimensions();
}//ShowUploadImages

/*function GetNewImageHTML()
{
    ret('UploadImagesImagesArea_'+ShowUploadImages.NumberOfImages).innerHTML +="<iframe style='width:100%;height:26;' style='border:solid 1px #808080;' frameborder='0' id='UploadIF_"+ShowUploadImages.NumberOfImages+"'></iframe><span id='UploadImagesImagesArea_"+(ShowUploadImages.NumberOfImages+1)+"'></span>";
    var _document = window.frames["UploadIF_"+ShowUploadImages.NumberOfImages].window.document;
    _document.open();
    _document.write('<html><head><link rel="stylesheet" type="text/css" href="'+CMSPath+'/CSS/ar/default.css" /></head>'+
                "<body dir='rtl' topmargin='0' leftmargin='0' rightmargin='0' bottommargin='0'>"+
                "<table cellpadding='2' cellspacing='0' id='UploadTable' border='0' width='100%'><form id='UploadForm' action='UploadImage.aspx' enctype='multipart/form-data' method='post'><tr><td width='80' nowrap class='popup_body_bg'>- ملف رقم <b>"+(ShowUploadImages.NumberOfImages+1)+
                "</b> : </td><td nowrap><input type='hidden' name='album' value='"+AlbumFolder+"'/><input type='hidden' name='maxWidth' value='"+CAlbum.ThumbnailMaxWidth+"'/>"+
                "<input type='hidden' name='maxHeight' value='"+CAlbum.ThumbnailMaxHeight+"'/>"+
                "<input style='width:95%' type='file' name='uFile'><!--<input onclick='RenameFileChanged(this,\"UploadFilesFile_Name_"+ShowUploadFiles.NumberOfFiles+
                "\")' type='checkbox'> Upload with Different Name --><input disabled type='hidden' style='background-color:#C0C0C0' id='UploadImagesImage_Name_"+ShowUploadImages.NumberOfImages+
                "'/></td></tr></form></table><div align='center' id='LoadingDiv' style='display:none' class='popup_body_bg'>Uploading Image Number "+(ShowUploadImages.NumberOfImages+1)+", please wait...</div></body></html>");
    _document.close();   
    
    ShowUploadImages.NumberOfImages++;
}//GetNewImageHTML*/

function GetNewImageHTML()
{
    ret('UploadImagesImagesArea_'+ShowUploadImages.NumberOfImages).innerHTML +="<iframe style='width:100%;height:62;' style='border:solid 1px #808080;' frameborder='0' id='UploadIF_"+ShowUploadImages.NumberOfImages+"'></iframe><span id='UploadImagesImagesArea_"+(ShowUploadImages.NumberOfImages+1)+"'></span>";
    var _document = window.frames["UploadIF_"+ShowUploadImages.NumberOfImages].window.document;
    _document.open();
    _document.write('<html><head><link rel="stylesheet" type="text/css" href="'+CMSPath+'/CSS/ar/default.css" /></head>'+
                "<body dir='rtl' topmargin='0' leftmargin='0' rightmargin='0' bottommargin='0'>"+
                "<table cellpadding='1' cellspacing='0' id='UploadTable' border='0' width='100%'><form id='UploadForm' action='UploadImage.aspx' enctype='multipart/form-data' method='post'><tr><td colspan='2' width='80' nowrap class='popup_body_bg'>- ملف رقم <b>"+(ShowUploadImages.NumberOfImages+1)+
                "</b> : </td></tr><tr><td nowrap class='popup_body_bg'>ملف الصورة:</td><td><input type='hidden' name='album' value='"+AlbumFolder+"'/><input type='hidden' name='maxWidth' value='"+CAlbum.ThumbnailMaxWidth+"'/>"+
                "<input type='hidden' name='maxHeight' value='"+CAlbum.ThumbnailMaxHeight+"'/>"+
                "<input style='width:95%' type='file' name='uFile'></td></tr><tr><td width='20%' nowrap class='popup_body_bg'>ملف الصورة الصغيرة:</td><td>"+
                "<input style='width:95%' type='file' name='uiFile'><input disabled type='hidden' style='background-color:#C0C0C0' id='UploadImagesImage_Name_"+ShowUploadImages.NumberOfImages+
                "'/></td></tr></form></table><div align='center' id='LoadingDiv' style='display:none' class='popup_body_bg'>Uploading Image Number "+(ShowUploadImages.NumberOfImages+1)+", please wait...</div></body></html>");
    _document.close();   
    
    ShowUploadImages.NumberOfImages++;
}//GetNewVideoHTML

function HideUploadImages()
{
    PopDialogObject.Close();
}//HideUploadFilesDiv

function CreateUploadImagesClicked(imageName,orgWidth,orgHeight,thumbWidth,thumbHeight)
{
    if(imageName)
    {
        var image = new AlbumImage();
        image.Name = imageName;
        image.Caption = imageName;
        image.ThumbWidth = CAlbum.ThumbnailMaxWidth;//thumbWidth;
        image.ThumbHeight = CAlbum.ThumbnailMaxHeight//thumbHeight;
        image.OrgWidth = orgWidth;
        image.OrgHeight = orgHeight;
        image.Position = CAlbum.Images.length;
        CAlbum.AddImage(image);
        //alert(imageName)
    }//if
    if(!window.frames["UploadIF_"+ShowUploadImages.UploadedImages])
    {
        PopDialogObject.Close();
        CAlbum.RenderImages();
        return;
    }//if
    var _document = window.frames["UploadIF_"+ShowUploadImages.UploadedImages].document;
    if(_document.getElementById("uFile").value == "")
        return;
    _document.getElementById("LoadingDiv").style.display = 'inline';
    _document.getElementById("UploadTable").style.display = 'none';
    _document.getElementById("UploadForm").submit();
    ShowUploadImages.UploadedImages++;
}//CreateNewFolderClicked
/// End Upload Image //////

/// Start Edit Image Properties //////
function ShowEditImage()
{
    PopDialogObject.Title = "خصائص الصورة";
    var _html ="";
    _html += "<table border='0' width='100%'>";
    _html += "<tr><td width='30%'>اسم الصورة:</td><td>"+CAlbum.SelectedImage.Name+"</td></tr>";
    _html += "<tr><td width='30%'>عنوان الصورة:</td><td><input style='width:250px;' id='EditImageLabel' value='"+
        CAlbum.SelectedImage.Caption+"' /></td></tr>";
    _html += "</table>";
    PopDialogObject.InnerHTML =  _html;   
    PopDialogObject.Buttons.length = 0;
    PopDialogObject.Buttons[0] = new CMSButton("Save Caption","Save Caption","accept",60,23,'CreateEditImageClicked();');
    PopDialogObject.Buttons[1] = new CMSButton("HideEditImage","HideEditImage","cancel",60,23,'PopDialogObject.Close();');
    PopDialogObject.Show();
    PopDialogObject.AdjustDimensions();
}//ShowEditImage

function HideEditImage()
{
    PopDialogObject.Close();
}//HideUploadFilesDiv

function CreateEditImageClicked()
{
    CAlbum.SelectedImage.Caption = ret('EditImageLabel').value;
    HideEditImage();
}//CreateNewFolderClicked
/// End Edit Image Properties //////

//////////////////////////////////////////////////////////////////
//////////// Images Handling /////////////////////////////////////
//////////////////////////////////////////////////////////////////
//Global Variables
//var ImagesRepository = new Array();

//Global Objects
function AlbumImage(name,caption,position,orgWidth,orgHeight,thumbWidth,thumbHeight)
{
    this.Name = name;
    this.Visible = true;
    this.Caption = caption;
    this.Position = position;
    this.OrgWidth = orgWidth;
    this.OrgHeight = orgHeight;
    this.ThumbWidth = thumbWidth;
    this.ThumbHeight = thumbHeight;
}//AlbumImage

//Object that handles Album rendering
function Album(objectName)
{
    //Member Variables
    this.ObjectName = objectName;
    this.ImagesDiv = "AlbumImagesDiv";
    this.Images = new Array();
    this.Title = "";
    this.Description = "";
    this.ImagesPerPage = -1;//-1 means all in one page
    this.ThumbnailMaxHeight = 100;
    this.ThumbnailMaxWidth = 100;
    this.ImagesPerRow = 4;
    this.SelectedImage = null;
    this.DisplayMode = "Design";
    
    //Member Functions
    this.RenderImages = RenderImages;
    this.AddImage = AddImage;
    this.GenerateXML = GenerateXML;
    this.ShowContext = ShowContext;
    this.RemoveImage = RemoveImage;
    this.ViewImage = ViewImage;    
    
    function RenderImages()
    {
        var _baseAlbumURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/"+this.Name+"/";
        var _html = "";
        
        _html += "<center><table border='0'>"
        
        var _counter = 0;
        for(i=0;i<this.Images.length;i++)
        {
            if(this.Images[i])
            {
                if(_counter==0)
                    _html += "<tr>";
                
                var _onContext = this.DisplayMode=="Design"?this.ObjectName+".ShowContext(this.id);return false;":"";
                var _onClick = this.DisplayMode=="Design"?"return "+this.ObjectName+".ViewImage(\""+this.Images[i].Name+"\");":"";
                
                _html += "<td id='imgTD_"+i+"' oncontextmenu='"+_onContext+"' position='"+i+"' width='"+this.ThumbnailMaxWidth+"' nowrap>"+
                        "<table title='"+this.Images[i].Caption+"' id='tablemg_"+i+"' width='"+(this.ThumbnailMaxWidth+20)+"' style='cursor:hand;' "+
                            " onmouseover='this.style.backgroundColor=\"#eef3fa\";' onmouseout='this.style.backgroundColor=\"\";' cellpadding='0' cellspacing='0'>"+
                            "<tr><td><img src='"+CMSPath+"Img/imagegal/upperright.gif' width='6' height='3'></td>"+
                            "<td height='3' background='"+CMSPath+"Img/imagegal/uppermid.gif'></td>"+
                            "<td><img src='"+CMSPath+"Img/imagegal/upperleft.gif' width='4' height='3'></td></tr>"+
                            "<tr><td width='6' background='"+CMSPath+"Img/imagegal/right.gif'></td>"+
                            "<td style='padding:5px;' height='"+(this.ThumbnailMaxHeight+90)+
                            "'><a onclick='"+_onClick+"' href='"+CMSPath+_baseAlbumURL+"org/"+
                            this.Images[i].Name+"' rel=\"["+this.Title+"]\" class='lightwindow' title='"+this.Images[i].Caption+"' caption='"+this.Images[i].Caption+"'><img src='"+CMSPath+_baseAlbumURL+"thumb/"+
                            this.Images[i].Name+"' width='"+this.Images[i].ThumbWidth+"' height='"+
                            this.Images[i].ThumbHeight+"' border='0'/></a>";
                  if(this.DisplayMode=="Design")
                    _html += "<br/>"+this.Images[i].Name+
                            " <br/>("+this.Images[i].OrgWidth+"*"+this.Images[i].OrgHeight+")";
                  _html += "</td>"+
                            "<td width='4' background='"+CMSPath+"Img/imagegal/left.gif'></td></tr>"+
                            "<tr><td><img src='"+CMSPath+"Img/imagegal/downright.gif' width='6' height='3'></td>"+
                            "<td height='3' background='"+CMSPath+"Img/imagegal/downmid.gif'></td>"+
                            "<td><img src='"+CMSPath+"Img/imagegal/downleft.gif' width='4' height='3'></td></tr>"+
                        "</table></td>";
                
                if(_counter==this.ImagesPerRow)
                {
                    _html += "</tr>";    
                    _counter=0;
                }//if
                else
                    _counter++;
            }//if
        }//for        
        _html += "</table></center>"
        
        ret(this.ImagesDiv).innerHTML = _html;
    }//RenderImages
    
    function ShowContext(tdId)
    {
        var _tdObject = ret(tdId);
        _tdObject.click();
        this.SelectedImage = this.Images[parseInt(_tdObject.position)];
        ImageContextMenu.Show();
    }//ShowContext
    
    function AddImage(image)
    {
        this.Images[this.Images.length]=image;
    }//AddImage
    
    function GenerateXML(fieldId)
    {
        var _xml = "";
        _xml+='<?xml version="1.0" encoding="utf-8" ?>';
        _xml+='<AlbumInfo>';
        _xml+='<Album title="'+ret('AlbumName').value+'" description="'+ret('AlbumDesc').value+'" '+
            'maxHeight="'+ret('AlbumMaxHeight').value+'" maxWidth="'+ret('AlbumMaxWidth').value+'">';
        var _counter = 1;
        for(i=0;i<this.Images.length;i++)
        {
            if(this.Images[i])
            {
                _xml += '<Image name="'+this.Images[i].Name+'" caption="'+this.Images[i].Caption+'" width="'+this.Images[i].OrgWidth+
                        '" height="'+this.Images[i].OrgHeight+'" thumbWidth="'+this.Images[i].ThumbWidth+'" '+
                        'thumbHeight="'+this.Images[i].ThumbHeight+'"   position="'+_counter+'" visible="true"></Image>';
                _counter++;
            }//if
        }//for       
        _xml+='</Album></AlbumInfo>';
        
        if(ret(fieldId))
           ret(fieldId).value = _xml; 
    }//GenerateXML
    
    function RemoveImage()
    {
        this.Images[ this.SelectedImage.Position] = null;
    }//RemoveImage
    
    function ViewImage(imageName)
    {
        var _baseAlbumURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/"+
                            this.Name+"/";
        window.open(CMSPath+_baseAlbumURL+"org/"+imageName);
        return false;
    }//ViewImage
}//Album

/// ****** Start Image Context Menu Handling ******////
var ImageContextMenu = null;
function CreateImageContextMenu()
{
    ImageContextMenu = new RightMenu("ImageContextMenu","RightMenuGlobalDiv");
    
    ImageContextMenu.ImagesPath = CMSPath+"Img/rightmenu/";
    
    ImageContextMenu.AddItem(new RightMenuItem("خصائص","عرض و تعديل خواص الصورة",new RightMenuIcon("properties.gif",23,22),"ShowEditImage();"));    
    ImageContextMenu.AddItem(new RightMenuSeparator());
    ImageContextMenu.AddItem(new RightMenuItem("قص","قص الصورة لوضعها في ترتيب آخر",new RightMenuIcon("cut.gif",23,22),"CutImageClicked();"));
    ImageContextMenu.AddItem(new RightMenuItem("لصق قبل","لصق الصورة التي تم قصها قبل",new RightMenuIcon("paste.gif",23,22),"PasteImageClicked(true);",false));
    ImageContextMenu.AddItem(new RightMenuItem("لصق بعد","لصق الصورة التي تم قصها بعد",new RightMenuIcon("paste.gif",23,22),"PasteImageClicked(false);",false));
    ImageContextMenu.AddItem(new RightMenuSeparator());
    ImageContextMenu.AddItem(new RightMenuItem("حذف","حذف الصورة المختارة",new RightMenuIcon("delete.gif",16,16),"DeleteImageClicked();"));
    
    ImageContextMenu.GetMessageRightMenu();
}//CreateTreeContextMenu
/// ****** End File Context Menu Handling ******////


/// ****** END Image Context Menu Handling ******////
function DeleteImageClicked()
{
    CAlbum.RemoveImage();
    CAlbum.RenderImages();
}//DeleteImageClicked

function CutImageClicked()
{
    CAlbum.CutImage = CAlbum.SelectedImage;
    ret('tablemg_'+CAlbum.CutImage.Position).style.filter = "alpha(opacity=50)";
    ImageContextMenu.Items[3].Enabled = true;
    ImageContextMenu.Items[4].Enabled = true;
    ImageContextMenu.GetMessageRightMenu();
}//DeleteImageClicked

function PasteImageClicked(isBefore)
{
    var _currentPosition = parseInt(CAlbum.SelectedImage.Position);
    var _sourcePosition = parseInt(CAlbum.CutImage.Position);
    if(!isBefore)
        _currentPosition++;
    if(_sourcePosition<_currentPosition)
    {
        _currentPosition--;
    }//if
    
    var _startIndex = _currentPosition>_sourcePosition?_sourcePosition:_currentPosition;
    var _endIndex = _currentPosition>_sourcePosition?_currentPosition:_sourcePosition;
    
    var _newImagesArray = new Array();
    for(i=0;i<_startIndex;i++)
    {
        _newImagesArray[i] = CAlbum.Images[i];
        _newImagesArray[i].Position = i;
    }//for
    
    
    if(_sourcePosition>_currentPosition)
    {
        _newImagesArray[_currentPosition] = CAlbum.CutImage;
        for(i=_currentPosition+1;i<_sourcePosition+1;i++)
        {
            _newImagesArray[i] = CAlbum.Images[i-1];
            _newImagesArray[i].Position = i;
        }//for
    }//if
    
    if(_sourcePosition<_currentPosition)
    {
        _newImagesArray[_currentPosition] = CAlbum.CutImage;
        //alert(_currentPosition+"="+_sourcePosition)
        for(i=_currentPosition-1;i>_sourcePosition-1;i--)
        {
            _newImagesArray[i] = CAlbum.Images[i+1];
            _newImagesArray[i].Position = i;
        }//for
    }//if
    
    for(i=_endIndex+1;i<CAlbum.Images.length;i++)
    {
        _newImagesArray[i] = CAlbum.Images[i];
        _newImagesArray[i].Position = i;
    }//for
    
    //CAlbum.CutImage = null;
    
    CAlbum.Images = _newImagesArray;
    CAlbum.RenderImages();
    
    ImageContextMenu.Items[3].Enabled = false;
    ImageContextMenu.Items[4].Enabled = false;
    ImageContextMenu.GetMessageRightMenu();
}//DeleteImageClicked


/// ****** Start Image Context Menu Handling ******////


////////////////////////////////////////////////////////////////////
////////////// Start Custom Themes - HHSheikhKhalifa ///////////////
////////////////////////////////////////////////////////////////////
function HHSheikhKhalifaPhotoGallery(objectName)
{
    this.ObjectName = objectName;
    this.RenderImages = RenderImages;
    this.ViewImage = ViewImage;
    this.HideImage = HideImage;
    this.PageSize = 15;
    this.ImagesPerRow = 2; 
    this.CurrentPage = 1;
    this.MoveTo = MoveTo;
    this.ActiveImages = new Array();
    
    function RenderImages(startIndex, endIndex)
    {
        var _baseAlbumURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/"+this.Name+"/";
        var _themePath = CMSPath+"CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Themes/HHSheikhKhalifaPhotoGallery/";
        var _imgPath = _themePath+"img/";
        //loadjscssfile(_themePath+"theme.css", "css");
        var _html = "";
        
        startIndex = !startIndex?0:startIndex;
        endIndex = !endIndex?this.PageSize:endIndex;
        var _counter = 0;
        var _colspan=(this.ImagesPerRow*2)+3;
        _html += "<center><table width='453' border='0' cellspacing='0' cellpadding='0'>"+
                    "<tr>"+
                    "  <td valign='middle'><img src='"+_imgPath+"border1.gif' width='49' height='177'></td>"+
                    "  <td><table width='355' border='0' cellspacing='0' cellpadding='0'>"+
                    "    <tr>"+
                    "      <td height='5' colspan='3' background='"+_imgPath+"gallery_top_bg.gif'></td>"+
                    "    </tr>"+
                    "    <tr>"+
                    "      <td width='4' background='"+_imgPath+"gallery_left_bg.gif'></td>"+
                    "      <td height='"+parseInt(((parseInt(this.PageSize/this.ImagesPerRow)-1)*(this.ThumbnailMaxHeight-5)))+"' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
                    var _imageInPage = 0;
                    for(i=startIndex;i<endIndex;i++)
                    {
                        if(_counter==0)
                            _html += "<tr>";
                        else
                            _html += "<td width='3' background='"+_imgPath+"gallery_vertical_line.gif'></td>";
                        
                        if(this.Images[i])
                        {
                            var _onContext = this.DisplayMode=="Design"?this.ObjectName+".ShowContext(this.id);return false;":"";
                            var _onClick = "return "+this.ObjectName+".ViewImage(\""+this.Images[i].Name+"\","+this.Images[i].OrgWidth+","+this.Images[i].OrgHeight+",\""+this.Images[i].Caption+"\","+this.Images[i].Position+","+i+");";
                        
                            _html += "<td style='padding:5px;' id='imgTD_"+i+"' position='"+i+"' align='center' "+
                                    " onmouseover='this.style.backgroundColor=\"#e0cc9a\";' onmouseout='this.style.backgroundColor=\"\";'>"+
                                    "<div style='width:"+(this.ThumbnailMaxWidth)+"px;height:"+(this.ThumbnailMaxHeight)+"px;' title='"+this.Images[i].Caption+"' id='tablemg_"+i+"' width='"+(this.ThumbnailMaxWidth)+"' style='cursor:hand;' >"+
                                        "<a onclick='"+_onClick+"' href='"+CMSPath+_baseAlbumURL+"org/"+
                                        this.Images[i].Name+"' class1='lightwindow' title='"+this.Images[i].Caption+"' caption='"+this.Images[i].Caption+"'><img src='"+CMSPath+_baseAlbumURL+"thumb/"+
                                        this.Images[i].Name+"' width='"+this.ThumbnailMaxWidth+"' height='"+
                                        this.ThumbnailMaxHeight+"' border='0'/></a>"+
                                    "</div></td>";
                        }//if
                        else
                             _html += "<td style='padding:5px;' id='imgTD_"+i+"' position='"+i+"' align='center' >"+
                                    "<div style='width:"+(this.ThumbnailMaxWidth)+"px;height:"+(this.ThumbnailMaxHeight)+"px;' id='tablemg_"+i+"'>"+
                                    "&nbsp;</div></td>";
                        if(_counter==this.ImagesPerRow)
                        {
                            _html += "</tr>"; 
                            _html += "<tr>"+
                                        "<td height='4' colspan='"+_colspan+"' background='"+_imgPath+"gallery_horizontal_line.gif'></td>"+
                                     "</tr>";  
                            _counter=0;
                        }//if
                        else
                            _counter++;
                    }//for
                    _html += "</table></td>"+
                    "      <td width='4' background='"+_imgPath+"gallery_right_bg.gif'></td>"+
                    "    </tr>"+
                    "    <tr>"+
                    "      <td height='3' colspan='"+_colspan+"' background='"+_imgPath+"gallery_bottom_bg.gif'></td>"+
                    "    </tr>";
                    //Start Navigation
                    _html += "<tr><td class='style10' colspan='"+_colspan+"'>";
                    var _imagesPerPageCounter = 0;
                    var _pageCounter = 1;
                    while(_imagesPerPageCounter<this.Images.length)
                    {
                        _html += "<a class='MenuItemClass' href='#' onclick='"+this.ObjectName+".RenderImages("+
                            (_imagesPerPageCounter)+","+(_imagesPerPageCounter+this.PageSize)+
                            ")'><b>"+_pageCounter+"</b></a> &nbsp;";
                        _pageCounter++;
                        _imagesPerPageCounter = _imagesPerPageCounter+this.PageSize;
                    }//while
                    _html += "</td></tr>";
                    //End Navigation 
                    _html += "    <tr>"+
                    "      <td height='3' colspan='3'><div align='center'><img src='"+_imgPath+"gallery_no_bg.gif' width='92' height='37'></div></td>"+
                    "    </tr>"+
                    "  </table></td>"+
                    "  <td valign='middle'><img src='"+_imgPath+"border2.gif' width='49' height='177'></td>"+
                    "</tr>"+
                  "</table><div id='"+this.ObjectName+"_View' align='center' style='vertical-align:middle;position:absolute;z-index:102;top:0px;left:0px;display:none;filter:progid:DXImageTransform.Microsoft.Fade(duration=0.8,overlap=0);'></div><div id='"+this.ObjectName+"_ViewNav' align='center' style='vertical-align:middle;position:absolute;z-index:103;top:0px;left:0px;display:none;'></div>"+
                  "<div id='"+this.ObjectName+"_ViewLoading' align='center' style='vertical-align:middle;position:absolute;z-index:101;top:0px;left:0px;display:none;'><table width='100%' border='0' height='"+getHeight()+"'>"+
                  "<tr><td align='center'><div style='padding:40px;width:200px;background-color:white'><img width='16' height='16' src='"+CMSPath+"/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Themes/HHSheikhKhalifaPhotoGallery/img/indicator.gif'><br/>جاري التحميل ، انتظر من فضلك...</div></td></tr></table></div>"+
                  "<div id='"+this.ObjectName+"_ViewBG' align='center' style='width:100%;vertical-align:middle;filter:alpha(opacity=70);background-color:#281600;position:absolute;z-index:100;top:0px;left:0px;display:none;'></div></center>";
        
        ret(this.ImagesDiv).innerHTML = _html;
    }//Render
    
    function MoveTo(imageIndex,isNext)
    {
        if(imageIndex==-1)
            imageIndex = this.Images.length-1;
        if(imageIndex==this.Images.length)
            imageIndex = 0;
        var _image = this.Images[imageIndex];
        while(!_image && imageIndex<this.Images.length && imageIndex>-1)
        {
            if(isNext)
                imageIndex++;
            else
                imageIndex--;
            _image = this.Images[imageIndex];
        }//while
        this.ViewImage(this.Images[imageIndex].Name,this.Images[imageIndex].OrgWidth,
            this.Images[imageIndex].OrgHeight,this.Images[imageIndex].Caption,
            this.Images[imageIndex].Position,imageIndex);
    }//MoveTo
    
    function ViewImage(imageName,orgWidth,orgHeight,caption,position,index)
    {
        
        var _baseURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/";
        var _baseAlbumURL = _baseURL + this.Name+"/";
        
        
        var _image = this.Images[position];                 
        
        var _divBG = ret(this.ObjectName+"_ViewBG");
        var _div = ret(this.ObjectName+"_View");
        var _divNav = ret(this.ObjectName+"_ViewNav");
        var _divLoading = ret(this.ObjectName+"_ViewLoading"); 
        
        _divBG.style.width = document.body.clientWidth;
        _divBG.style.height = document.body.clientHeight;
        
        _div.style.width = document.body.clientWidth;
        _div.style.top = getScrollY();
        _div.style.height = document.body.clientHeight;
        
        _divNav.style.width = document.body.clientWidth;
        _divNav.style.top = getScrollY();
        _divNav.style.height = document.body.clientHeight;
        
        _divLoading.style.width = document.body.clientWidth;
        _divLoading.style.height = document.body.clientHeight;
        _divLoading.style.top = getScrollY();
        
        var _maxWidth = getWidth()-50;
        var _maxHeight = getHeight()-50;
        
        if(orgWidth>_maxWidth)
        {
            orgHeight = parseInt((_maxWidth*orgHeight)/orgWidth);
            orgWidth = _maxWidth;            
        }//if
        if(orgHeight>_maxHeight)
        {
            orgWidth = parseInt((_maxHeight*orgWidth)/orgHeight);
            orgHeight = _maxHeight;            
        }//if
            
        _div.innerHTML = "<table border='0' height='"+getHeight()+"'>"+
            "<tr><td>"+
            "<table cellspacing='0' border='0' width='"+orgWidth+"' bgcolor='white' ><tr><td colspan='3'><img width='"+orgWidth+"' height='"+orgHeight+"' src='"+CMSPath+_baseAlbumURL+"org/"+imageName+"'></td></tr>"+
            "<tr height='25'><td nowrap width='20'></td><td width='"+(orgWidth-20-60)+"'>"+caption+"</td><td nowrap style='font-size:12;' width='60'> "+(_image.Position+1)+" / "+this.Images.length+" &nbsp; </td></tr></table></td></tr></table>";
        _divNav.innerHTML = "<table border='0' height='"+getHeight()+"'>"+
            "<tr><td>"+
            "<table cellspacing='0' cellpadding='0' border='0' width='"+orgWidth+"'><tr height='"+orgHeight+"'><td width='23'><a href='#' onclick='"+this.ObjectName+".MoveTo("+(index+1)+",true);'><img width='23' height='139' "+
            " style='filter:alpha(opacity=80);' onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/img_next.jpg\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/img_next_alt.jpg\"' src='"+CMSPath+_baseURL+"cms_img/img_next.jpg'></a></td><td>&nbsp;</td>"+
            "<td width='23'><a href='#' onclick='"+this.ObjectName+".MoveTo("+(index-1)+",false);'><img width='23' height='139' "+
            " style='filter:alpha(opacity=80);' onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/img_previous.jpg\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/img_previous_alt.jpg\"' src='"+CMSPath+_baseURL+"cms_img/img_previous.jpg'></a></td></tr>"+
            "<tr><td colspan='3' align='right' height='25' valign='bottom' style='padding-right:2px;'><a href='#' onclick='"+this.ObjectName+".HideImage();'><img width='12' height='12' "+
            " onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/icon_close.gif\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/icon_close_alt.gif\"' src='"+CMSPath+_baseURL+"cms_img/icon_close.gif'></a></td></tr>"+
            "</table></td></tr></table>";
        
        _divBG.style.display = 'inline';
        _divLoading.style.display = 'inline';        
        _div.style.display = 'inline';
        if(IsIE())
        {
            _div.filters[0].apply();
	        _div.filters[0].play();	
	    }//if
        _divNav.style.display = 'inline';
        return false;
    }//ViewImage
    
    function HideImage()
    {
        ret(this.ObjectName+"_ViewLoading").style.display = 'none';
        ret(this.ObjectName+"_ViewBG").style.display = 'none';
        ret(this.ObjectName+"_View").style.display = 'none';
        ret(this.ObjectName+"_ViewNav").style.display = 'none';
    }//HideImage
}
HHSheikhKhalifaPhotoGallery.prototype = new Album();



////////////////////////////////////////////////////////////////////
///////////// Start Custom Themes - SharePointDefault //////////////
////////////////////////////////////////////////////////////////////
function SharePointDefaultPhotoGallery(objectName)
{
    this.ObjectName = objectName;
    this.RenderImages = RenderImages;
    this.ViewImage = ViewImage;
    this.HideImage = HideImage;
	this.BgColor = "#000000";
    this.PageSize = 15;
    this.ImagesPerRow = 2; 
    this.CurrentPage = 1;
    this.MoveTo = MoveTo;
    this.ActiveImages = new Array();
    this.HHTheMinisterHomeMode = false;
    this.HHTheMinisterMode = false;
    
    function RenderImages(startIndex, endIndex)
    {
        var _baseAlbumURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/"+this.Name+"/";
        var _themePath = CMSPath+"CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Themes/HHSheikhKhalifaPhotoGallery/";
        var _imgPath = _themePath+"img/";
        var _html = "";
        
        startIndex = !startIndex?0:startIndex;
        endIndex = !endIndex?this.PageSize:endIndex;
        var _counter = 0;
        var _colspan=(this.ImagesPerRow*2)+3;
        
        _html += "<center><table border='0' cellspacing='0' cellpadding='0'>"+
                    "<tr>"+
                    "  <td><table width='100%' border='0' cellspacing='5' cellpadding='5'>";
                    for(i=startIndex;i<endIndex;i++)
                    {
                        if(this.Images[i])
                        {
                            if(_counter==0)
                                _html += "<tr>";
                            
                            var _onContext = this.DisplayMode=="Design"?this.ObjectName+".ShowContext(this.id);return false;":"";
                            var _onClick = "return "+this.ObjectName+".ViewImage(\""+this.Images[i].Name+"\","+this.Images[i].OrgWidth+","+this.Images[i].OrgHeight+",\""+this.Images[i].Caption+"\","+this.Images[i].Position+","+i+");";
                            
                            _html += "<td align='center' style=\"filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='"+this.BgColor+"', EndColorStr='#FFFFFF');border:solid 1px "+this.BgColor+"\" id='imgTD_"+i+"' oncontextmenu='"+_onContext+"' position='"+i+"' width='"+this.ThumbnailMaxWidth+"' nowrap>"+
                                    "<table title='"+this.Images[i].Caption+"' id='tablemg_"+i+"' width='"+(this.ThumbnailMaxWidth)+"' style='cursor:hand;' "+
                                        " onmouseover='this.style.backgroundColor=\"#e0cc9a\";' onmouseout='this.style.backgroundColor=\"\";' cellpadding='0' cellspacing='0'>"+
                                        "<tr><td align='center' style='padding:0px;' height='"+(this.ThumbnailMaxHeight)+
                                        "'><a onclick='"+_onClick+"' href='"+CMSPath+_baseAlbumURL+"org/"+
                                        this.Images[i].Name+"' title='"+this.Images[i].Caption+"' caption='"+this.Images[i].Caption+"'><img src='"+CMSPath+_baseAlbumURL+"thumb/"+
                                        this.Images[i].Name+"' width='"+this.Images[i].ThumbWidth+"' height='"+
                                        this.Images[i].ThumbHeight+"' border='0'/></a></td></tr>"+
                                    "</table></td>";
                            if(_counter==this.ImagesPerRow-1)
                            {
                                _html += "</tr>";   
                                _counter=0;
                            }//if
                            else
                                _counter++;
                        }//if
                    }//for
                    _html += "</table></td>"+
                    "    </tr>";
                    //Start Navigation
                    _html += "<tr><td class='style10' align='center'>";
                    var _imagesPerPageCounter = 0;
                    var _pageCounter = 1;
                    while(_imagesPerPageCounter<this.Images.length)
                    {
                        if(!this.HHTheMinisterHomeMode)
                        {
                            _html += "<a class='MenuItemClass' href='#' onclick='"+this.ObjectName+".RenderImages("+
                                (_imagesPerPageCounter)+","+(_imagesPerPageCounter+this.PageSize)+
                                ")'><b>"+_pageCounter+"</b></a> &nbsp;";
                            _pageCounter++;
                            _imagesPerPageCounter = _imagesPerPageCounter+this.PageSize;
                        }//if
                        else
                            _imagesPerPageCounter++;
                    }//while
                    _html += "</td></tr>";
                    //End Navigation 
                  _html +="</table><div id='"+this.ObjectName+"_View' align='center' style='vertical-align:middle;position:absolute;z-index:102;top:0px;left:0px;display:none;filter:progid:DXImageTransform.Microsoft.RandomDissolve(duration:0.7);'></div><div id='"+this.ObjectName+"_ViewNav' align='center' style='vertical-align:middle;position:absolute;z-index:103;top:0px;left:0px;display:none;'></div>"+
                  "<div id='"+this.ObjectName+"_ViewLoading' align='center' style='vertical-align:middle;position:absolute;z-index:101;top:0px;left:0px;display:none;'><table width='100%' border='0' height='"+getHeight()+"'>"+
                  "<tr><td align='center'><div style='padding:40px;width:200px;background-color:#C0C0C0'><img width='16' height='16' src='"+CMSPath+"/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Themes/HHSheikhKhalifaPhotoGallery/img/indicator.gif'><br/>جاري التحميل ، انتظر من فضلك...</div></td></tr></table></div>"+
                  "<div id='"+this.ObjectName+"_ViewBG' align='center' style='width:100%;vertical-align:middle;filter:alpha(opacity=70);background-color:"+this.BgColor+";position:absolute;z-index:100;top:0px;left:0px;display:none;'></div></center>";
        
        ret(this.ImagesDiv).innerHTML = _html;
    }//Render
    
    function MoveTo(imageIndex,isNext)
    {
        if(imageIndex==-1)
            imageIndex = this.Images.length-1;
        if(imageIndex==this.Images.length)
            imageIndex = 0;
        var _image = this.Images[imageIndex];
        while(!_image && imageIndex<this.Images.length && imageIndex>-1)
        {
            if(isNext)
                imageIndex++;
            else
                imageIndex--;
            _image = this.Images[imageIndex];
        }//while
        this.ViewImage(this.Images[imageIndex].Name,this.Images[imageIndex].OrgWidth,
            this.Images[imageIndex].OrgHeight,this.Images[imageIndex].Caption,
            this.Images[imageIndex].Position,imageIndex);
    }//MoveTo
    
    function ViewImage(imageName,orgWidth,orgHeight,caption,position,index)
    {
        var _baseURL = "/CMSObjects/Photo Managers/ManualCMSPhotoGallery/Admin/Albums/";
        var _baseAlbumURL = _baseURL + this.Name+"/";
        
        
        var _image = this.Images[index];                 
        
        var _divBG = ret(this.ObjectName+"_ViewBG");
        var _div = ret(this.ObjectName+"_View");
        var _divNav = ret(this.ObjectName+"_ViewNav");
        var _divLoading = ret(this.ObjectName+"_ViewLoading"); 
        
        _divBG.style.width = document.body.clientWidth;
        _divBG.style.height = document.body.scrollHeight;
		        
        _div.style.width = document.body.clientWidth;
        _div.style.top = getScrollY();
        _div.style.height = document.body.clientHeight;
        
        _divNav.style.width = document.body.clientWidth;
        _divNav.style.top = getScrollY();
        _divNav.style.height = document.body.clientHeight;
        
        _divLoading.style.width = document.body.clientWidth;
        _divLoading.style.height = document.body.clientHeight;
        _divLoading.style.top = getScrollY();
        
        var _maxWidth = getWidth()-50;
        var _maxHeight = getHeight()-50;
        
        if(orgWidth>_maxWidth)
        {
            orgHeight = parseInt((_maxWidth*orgHeight)/orgWidth);
            orgWidth = _maxWidth;            
        }//if
        if(orgHeight>_maxHeight)
        {
            orgWidth = parseInt((_maxHeight*orgWidth)/orgHeight);
            orgHeight = _maxHeight;            
        }//if
            
        _div.innerHTML = "<table border='0' height='"+getHeight()+"'>"+
            "<tr><td>"+
            "<table cellspacing='0' border='0' width='"+orgWidth+"' bgcolor='white' ><tr><td colspan='3'><img width='"+orgWidth+"' height='"+orgHeight+"' src='"+CMSPath+_baseAlbumURL+"org/"+imageName+"'></td></tr>"+
            "<tr height='25'><td nowrap width='20'></td><td width='"+(orgWidth-20-60)+"' align='center'>"+caption+"</td><td nowrap style='font-size:12;' width='60'> "+(index+1)+" / "+this.Images.length+" &nbsp; </td></tr></table></td></tr></table>";
        _divNav.innerHTML = "<table border='0' height='"+getHeight()+"'>"+
            "<tr><td>"+
            "<table cellspacing='0' cellpadding='0' border='0' width='"+orgWidth+"'><tr height='"+orgHeight+"'><td width='23'><a href='#' onclick='"+this.ObjectName+".MoveTo("+(index+1)+",true);'><img width='23' height='139' "+
            " style='filter:alpha(opacity=80);' onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/next_sharepoint.jpg\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/next_sharepoint_alt.jpg\"' src='"+CMSPath+_baseURL+"cms_img/next_sharepoint.jpg'></a></td><td>&nbsp;</td>"+
            "<td width='23'><a href='#' onclick='"+this.ObjectName+".MoveTo("+(index-1)+",false);'><img width='23' height='139' "+
            " style='filter:alpha(opacity=80);' onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/prev_sharepoint.jpg?v=v\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/prev_sharepoint_alt.jpg\"' src='"+CMSPath+_baseURL+"cms_img/prev_sharepoint.jpg?v=v'></a></td></tr>"+
            "<tr><td colspan='3' align='right' height='25' style='padding-right:10px;'><a href='#' onclick='"+this.ObjectName+".HideImage();'><img width='9' height='9' "+
            " onmouseout='this.src=\""+CMSPath+_baseURL+"cms_img/x.gif\"' onmouseover='this.src=\""+CMSPath+_baseURL+"cms_img/x_alt.jpg\"' src='"+CMSPath+_baseURL+"cms_img/x.gif'></a></td></tr>"+
            "</table></td></tr></table>";
        
        _divBG.style.display = 'inline';
        _divLoading.style.display = 'inline';        
        _div.style.display = 'inline';
        _div.filters[0].apply();
	    _div.filters[0].play();	
        _divNav.style.display = 'inline';
        return false;
    }//ViewImage
    
    function HideImage()
    {
        ret(this.ObjectName+"_ViewLoading").style.display = 'none';
        ret(this.ObjectName+"_ViewBG").style.display = 'none';
        ret(this.ObjectName+"_View").style.display = 'none';
        ret(this.ObjectName+"_ViewNav").style.display = 'none';
    }//HideImage
}
SharePointDefaultPhotoGallery.prototype = new Album();


////////////////////////////////////////////////////////////////////
///////////////////////// End Custom Themes ////////////////////////
////////////////////////////////////////////////////////////////////

 function getHeight() {
                if(document.documentElement.clientHeight>0)
                    return document.documentElement.clientHeight;
                if (this.webkit419) return this.innerHeight;
                if (this.opera) return document.body.clientHeight;
                return (document.documentElement.clientHeight > document.body.clientHeight || document.documentElement.clientHeight == 0)
                        ? document.body.clientHeight
                        : document.documentElement.clientHeight;
        }
function getWidth(){
                if(document.documentElement.clientWidth>0)
                    return document.documentElement.clientWidth;
                if (this.webkit419) return this.innerWidth;
                if (this.opera) return document.body.clientWidth;
                return (document.documentElement.clientWidth > document.body.clientWidth || document.documentElement.clientWidth == 0)
                        ? document.body.clientWidth
                        : document.documentElement.clientWidth;
        }
function getScrollY() {
  if(document.documentElement.scrollTop>0)
	return document.documentElement.scrollTop;
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}