//Function to load the collections for a given artist.  The artist id and the html element id are passed
var currentArtist=-1;
function loadCollections(artistId, page)
{ 
    if(currentArtist!=artistId || page!=0)
    { //Open the selected artist if not already open
        currentArtist=artistId;  //Store which artist is in the open state
        var urlget = "collections.ajax.php"; 
        if(page==0) closeArtists();  //Close any open artists
        $('loading'+artistId).style.visibility='visible';
        var t2 = Math.random(); //Fixes an IE caching issue
    	new Ajax.Updater("art"+artistId, urlget, { method: 'get', asynchronous: false , parameters: { a: artistId, p: page, r: t2 } });
        $('loading'+artistId).style.visibility='hidden';
        if(page==0) setTimeout('Effect.SlideDown("art'+artistId+'",{ queue: "end", duration: 1.0 })',50);
        $('artist'+artistId).style.color='#ff0099';
        //Embed the movie if it exists (If it does the div tag will exist)
        if($("Movie"+artistId)!=null) embedFlv('Movie'+artistId,'http://'+location.hostname+'/images/'+$("Movie"+artistId).getAttribute('movie'),468,369, false,'flowplayerMovie'+artistId);;
    } else {
     //Close the open artist
        //$('artist'+artistId).style.color='';
        currentArtist=-1;  //Store that no artists are open
        if(page==0) closeArtists();  //Close any open artists
    }
}

//Function to load the images in a particular collection
function loadCollectionImages(artistId, page, collectionId, overviewId, biog, news, website)
{ 
    var urlget = "collectionimages.ajax.php"; 
    if(page==0)
    {   //If on the collection view do a slide up and then down
        Effect.SlideUp("art"+artistId,{ duration: 1.0, queue: 'end',
        afterFinish: function()
            {
                $('loading'+artistId).style.visibility='visible';
                var t2 = Math.random(); //Fixes an IE caching issue
            	new Ajax.Updater("art"+artistId, urlget, { method: 'get', asynchronous: false , parameters: { a: artistId, p: page, g: collectionId, o: overviewId, b: biog, n: news, w: website, r: t2 } });
                $('loading'+artistId).style.visibility='hidden';
            }
        
         });
    } else {
        //If on the collection images view just change with no slide animation
        var t2 = Math.random(); //Fixes an IE caching issue
    	new Ajax.Updater("art"+artistId, urlget, { method: 'get', asynchronous: false , parameters: { a: artistId, p: page, g: collectionId, o: overviewId, b: biog, n: news, w: website, r: t2 } });
    }    
    if(page==0) Effect.SlideDown("art"+artistId,{ duration: 2.0, queue: 'end' });
}

//function to close the open artist elements.
function closeArtists()
{
    var numElements=document.getElementsByTagName('div').length;
    var eIndex, fElement;
    //Enumerate form elements and check required elements are filled in and display message if not
    for(eIndex=0; eIndex < numElements ; eIndex++)
    {
        fElement=document.getElementsByTagName('div')[eIndex];
        if(fElement.id.substring(0,3)=='art')
        {
            if (document.getElementById(fElement.id).style.display != "none")
            {  // DOM3 = IE5, NS6
                if($("artistMovie"+fElement.id.substring(3,fElement.id.length))!=null && $("artistMovie"+fElement.id.substring(3,fElement.id.length)).style.display!='none') $('flowplayerMovie'+fElement.id.substring(3,fElement.id.length)).DoStop();
                Effect.SlideUp(fElement, { duration: 1.0 });
            }
        }
        
    }
    
    //Remove the pink colour from the active artist
    numElements=document.getElementsByTagName('span').length;
    for(eIndex=0; eIndex < numElements ; eIndex++)
    {
        fElement=document.getElementsByTagName('span')[eIndex];
        if(fElement.id.substring(0,3)=='art')
        {
            document.getElementById(fElement.id).style.color = "";
        }
        
    }
}

function loadSchedule(scheduleId, page)
{ 
    if(currentArtist!=scheduleId || page!=0)
    { //Open the selected schedule if not already open
        currentArtist=scheduleId;  //Store which artist is in the open state
        if(page==0) closeArtists();  //Close any open artists
        Effect.SlideDown('art'+scheduleId,{ queue: "end", duration: 1.0,
                                                afterFinish: function()
                                                { 
                                                    //Changed their minds again! Uncomment below to play movie when div is expanded
                                                    //setTimeout("$('flowplayerMovie"+scheduleId+"').DoPlay();",1500);
                                                }
                                          });
        //$('artist'+scheduleId).style.color='#ff0099';
    } else {
     //Close the open artist
        //$('artist'+artistId).style.color='';
        if($("flowplayerMovie"+scheduleId)!=null) $("flowplayerMovie"+scheduleId).DoStop();  //Stop the Movie when item closed
        currentArtist=-1;  //Store that no artists are open
        if(page==0) closeArtists();  //Close any open artists
    }
}

function loadMovie(artistId)
{ 
    Effect.SlideDown('artistMovie'+artistId,{ queue: "end", duration: 1.0,
                                            afterFinish: function()
                                            { 
                                                setTimeout("$('flowplayerMovie"+artistId+"').DoPlay();",1500);
                                            }
                                      });
}

// image changing function 
function loadCollectionImage(id, image, movie)
{  //Note the singular.  Loads one large image into the display area
    elem="bigImageDiv"+id;
    //if($("zoom").style.display!="block") $(elem).style.visibility="hidden";

    elemImage="bigImage"+id;
    if(movie=="images/")
    {  //No Movie, so an image
        var theImage = new Image();
        //theImage.onLoad=function(elem){ $(elem).style.visibility="visible";};
        theImage.src=image;  //Preload Image
        //alert(tmp.height);
        $(elem).setAttribute('src',image)
        if($(elem).innerHTML.substring(0,4)=='<img')
        { //Contains an image so simply change the source
            $(elemImage).src=image;
        } else {
            //Replacing a movie so need complete image tag
            $(elem).innerHTML="<img id='"+elemImage+"' src='"+image+"' style='height: 436px;' />"; // style='height: "+theImage.height+"px;' />";
        }
    } else {
        embedFlv(elem,'http://'+ document.domain+'/'+movie);
    }
    $("zoom").style.display="block";
    //$("zoom").style.top=Math.round(posTop()+((pageHeight()-436)/2))+"px";
    $("zoom").style.top="180px";
    $("zoom").style.left="0px";
    $("zoombacker").style.display="block";  //50% background
}

//Function to switch the image text when it is clicked on.
function textSwap(id,imagenum, totalImgs)
{ 
    var nextLinks;
    //Work out the previous/next stuff
    nextLinks="<br />";
    if(imagenum>1) { nextLinks=nextLinks+"<a href='javascript: void(0);' onclick='imageLoop(\""+id+"\", \""+id+"\", "+totalImgs+",-1)'><b>Previous</b></a>&nbsp;&nbsp;"; } else {nextLinks=nextLinks+"<b>Previous</b>&nbsp;&nbsp;";}
    if(imagenum<totalImgs) 
    { 
        nextLinks=nextLinks+"<a href='javascript: void(0);' onclick='imageLoop(\""+id+"\", \""+id+"\", "+totalImgs+",1)'><b>Next</b></a>"; 
    } else {
        nextLinks=nextLinks+"<b>Next</b>";
    }
    nextLinks=nextLinks+"<br /><a href='javascript: void(0);' onclick='zoomClose();'><b>Close</b></a><br />";

    theText=$('bigImageDiv'+id).getAttribute('text'+imagenum);
    theText=theText.replace("<!-- next -->", nextLinks);
    $('imagetext'+id).innerHTML=theText;
}

function zoomClose()
{  //Note the singular.  Loads one large image into the display area
    $("zoom").style.display="none";
    $("zoombacker").style.display="none";  //50% background
}

function imgNav(elem,newSrc,imgNum)
{
    
}
