/// <reference name="MicrosoftAjax.js"/>

// I've made this pageLoad unique for all pages so I can have all pages initialized from this method so 
// I don't have to implement different client page initialization in every ascx. Although
// it is not best practice appears as ok in this way of organizing page (set of ascx files).
function pageLoad()
{
    var allDivs = document.getElementsByTagName("div");
    Array.forEach(allDivs, CreateGalleries , null);
    
    // this is for GalleryManager.aspx page
    if (location.pathname.lastIndexOf('GalleryManager.aspx') > -1)
    {
		$create(MyAjaxControls.GallerySelector, { imagesContainerElement : $get('currentImagesDiv'), linkDisplayElement : $get('linkToGallery') }, null, null, $get('filesAndFolders'));
		assignCheckGallerySelected(); // this function is defined (located) in
		// BusinessControls/Common/admin/contentEdit/GalleryManager.ascx
    }
}

function CreateGalleries(arrayItem, index, array)
{
    if (arrayItem.className == 'ImageGallery')
    {
        $create(MyAjaxControls.ImageGallery, null, null, null, arrayItem);
    }
    else if (arrayItem.className == 'ImageGalleryViaHandler')
    {
		$create(MyAjaxControls.ImageGallery, { generationMode : 'viaHandler' }, null, null, arrayItem);
    }
}
