var req;  // XMLHTTPRequest

// x and y position where mousedown has been made, to avoid displaying details of picture while dragging.
var dnx;
var dny;

//Search ajax control
var InQuery = false;
var LastQueryN = -1;

//Search Globals:
var ResArrayPages = new Array; //Results array.
var PagingSearchString = ""
var PagingType = ""
var PagingCurrentPage = 0;

var PagingArrayIsComplete = false;
var PagingItemsPerPage = 5; //changed when info comes from the server

var PagingTotalResults = 0;
var PagingLastPageInCache = 1;

var PagingLinkRadius = 5; //changed when info comes from the server

//For prev & next links
var CurrentDisplayingPage = 0; 
var CurrentDisplayingRes = 0;  

var ShowAfterLoadingNext = false;

function btnSearch_Click()
{

  if(!InQuery)
  {
  DisableSplashMode();
  HidePagingControls();
  //Store search string and type
  PagingSearchString = document.getElementById('searchtext').value;
  PagingType = document.getElementById('searchassettype').options[document.getElementById('searchassettype').selectedIndex].value;

  ResArrayPages = new Array; // Clear results cache;
  ResArrayPages[0] = new Array; //Set new page[0]

  PagingCurrentPage = 1;
  
  GetResults(PagingSearchString, 1 , PagingType, 0);
  }
  return false;
}

function DoAssetTypeSearch(AssetType) {
	
	document.getElementById('searchtext').value = "All";
	var elDropDown =document.getElementById('searchassettype');
	 
	var i;
	for (i=0; i< elDropDown.options.length; i++) {
		if (elDropDown.options[i].value == AssetType) {
			elDropDown.selectedIndex = i;
			break;
		}
	}
	
	btnSearch_Click();
}

function GetResults(searchString, pageN, dsType, lastPage)
{
  if(!InQuery)
  {
    InQuery = true;

    document.getElementById('searchindicator').style.visibility = "visible";

    LastQueryN = Math.round(Math.random()* 10000);

    strUrl  = "ajax/home_search_button.php";
    strUrl += "?unid=" + LastQueryN;
    strUrl += "&q=" + escape(searchString) ;     /* Search textbox content */
    strUrl += "&assetType=" + escape(dsType)  ;     /* AssetType */
    strUrl += "&page=" + pageN;
    strUrl += "&lastSentPage=" + lastPage;

    ajaxag(strUrl, GetResultsCB);


  }


}

function GetResultsCB()
{
if (xmlData.readyState==4)
{ if (xmlData.status==200)
{

  resultString = xmlData.responseText;

  var resItems = resultString.split("\n");

  var resHead = resItems[0].split("|");

  if(resHead[0]=="RESULTS_OK" )   /* In case results were found */
  {

    for (i=1,imax=resItems.length ; i<imax ; i++)
    {


      var resInfo = resItems[i].split("|");

      switch(resInfo[0])
      {
        case "R":
          //Fill array result
                                            //dsID      dsType      dsTitle     dsThumbFileName
          var tSearchInfo = new dsSearchInfo(resInfo[1],resInfo[2], resInfo[3], resInfo[4]);

          if(ResArrayPages[ResArrayPages.length - 1].length >= PagingItemsPerPage)
          {
            ResArrayPages[ResArrayPages.length] = new Array;
            PagingLastPageInCache = ResArrayPages.length;
          }

          ResArrayPages[ResArrayPages.length-1][ResArrayPages[ResArrayPages.length-1].length] = tSearchInfo;


        break;

        case "MORE_RESULTS":
          PagingArrayIsComplete = false;
        break;

        case "NO_MORE_RESULTS":
          PagingArrayIsComplete = true;
        break;

        case "ITEMS_PER_PAGE":
          PagingItemsPerPage = resInfo[1];
        break;

        case "TOTAL_RESULTS":
          PagingTotalResults = resInfo[1];
        break;
        
        case "PAGE_LINK_RADIUS":
          PagingLinkRadius = resInfo[1];
        break;

        case "SEARCH_TIP":
          document.getElementById("searchsuggestkeywords").childNodes[0].nodeValue = resInfo[1];
        break;

      }
    }

    if(PagingTotalResults==0)
    {
      HidePagingControls();
      EmptyDiv(document.getElementById('searchresults'))
      ShowNoResults();
      InQuery = false;
    }
    else
    {
      HideNoResults();
      ShowPagingControls()
      if(PagingCurrentPage==1)
      { SetPageNLinks(); }
      DisplayResults();
    }
    
    if(ShowAfterLoadingNext)
    { //When clicking next
        ShowAfterLoadingNext = false;
        ReOpenAssetDetail(PagingCurrentPage, 0);
    }
    
  }
  else
  { //no results or error
    HidePagingControls();
    EmptyDiv(document.getElementById('searchresults'))
    ShowNoResults();
    InQuery = false;
  }

 document.getElementById('searchindicator').style.visibility = "hidden";
 document.getElementById('searchstringshown').innerHTML = document.getElementById('searchtext').value;

}
}

  if (isSafari()) { // Fix peekabo bug in Safari
    ReRender();
  }
}



function ShowResPage()
{
  //Check if page is in caché and show the items, if not, queries.
  
  if(PagingArrayIsComplete)
  {
    DisplayResults();
  }
  else
  {
    if(PagingCurrentPage > PagingLastPageInCache)
    {
      GetResults(PagingSearchString, PagingCurrentPage , PagingType, PagingLastPageInCache);

       
    }
    else
    {
      DisplayResults();
    }
  }
}





function DisplayResults()
{
  //Loops through the array and adds the items to the results
  //Sets next and prev controls visibility

  EmptyDiv(document.getElementById('searchresults'));

  iFirstItem = 0;

  EnableNext();
  EnablePrev();

  iLastItem = PagingItemsPerPage -1;

  if(!(iLastItem<ResArrayPages[PagingCurrentPage-1].length))
  {
    iLastItem = ResArrayPages[PagingCurrentPage-1].length -1;
  }


  if(PagingCurrentPage == ResArrayPages.length )
  {
    if(PagingArrayIsComplete){ DisableNext();}  //Disable next
  }

  if(PagingCurrentPage==1)
  { DisablePrev(); }

  for(i=iFirstItem;i<=iLastItem;i++)
  {
     InsertResultAsset(ResArrayPages[PagingCurrentPage-1][i] , PagingCurrentPage-1, i );
  }


  document.getElementById('pagingtotal').innerHTML = PagingTotalResults;
  document.getElementById('pagingfrom').innerHTML = parseInt(((PagingCurrentPage-1) * PagingItemsPerPage)) + parseInt(1);
  document.getElementById('pagingto').innerHTML = parseInt(((PagingCurrentPage-1) * PagingItemsPerPage)) + parseInt(1) + parseInt(iLastItem); ;

  InQuery = false;
  
  CreateNextPrevSearchResults();
}





function InsertResultAsset(dsInfo, pageNr , resNr )
{
  //Creates the div and inserts the div in the results.

  var ResultsDiv = document.getElementById('searchresults');
  
  var nextItemNr = ResultsDiv.childNodes.length + 1;

      NewDiv = document.createElement("div");
      NewDiv.className = 'searchresult';
      NewDiv.id = 'resultItem' + nextItemNr;

      NewDiv.pageNr = pageNr;
      NewDiv.resNr = resNr;
 
      NewDivImageContainer = document.createElement("div");
      NewDivImageContainer.className = 'searchresultimagecontainer'; //Necessary to give all pictures 110px width and height


      NewImage = document.createElement("img");

      NewImage.dsInfo = dsInfo

      NewImage.className = 'searchresultimage';
      NewImage.id = 'imgResImage' + nextItemNr;
      NewImage.dsID = dsInfo.dsID;   
      NewImage.dsType = dsInfo.dsType; 
      NewImage.title = dsInfo.dsTitle;
  	  NewImage.origin = 'search';        // used for identifying where was it dragged from

      NewImage.src =  'userfiles/thumbs/' + dsInfo.dsThumbFileName;       //@@@@ path

      NewImage.onmousedown = imgMDown ;
      NewImage.onclick = function(e){imgShowDetails(e,this);};

      // Fix peekabo bug in Safari
      if (isSafari()) {
        NewImage.onload = function() { ReRender(); }
      }

      NewTypeH2 = document.createElement("H2");
      NewTypeH2.className = dsInfo.dsType;
      if (dsInfo.dsType == "3D") {  NewTypeH2.className = "DD"; }

      NewTitleLink = document.createElement('a');
      NewTitleLink.setAttribute('href', '#');
      NewTitleLink.onclick = function(e){details_click_ShowDetails(e, this); return false;};

      NewTitleData = document.createTextNode(NewImage.title);
      NewTitleLink.appendChild(NewTitleData);

      NewDivImageContainer.appendChild(NewImage);
      NewDivImageContainer.appendChild(NewTypeH2);

      NewDiv.appendChild(NewDivImageContainer);
      NewDiv.appendChild(NewTitleLink);

      ResultsDiv.appendChild(NewDiv);

      new Draggable('imgResImage' + nextItemNr , {revert:true,DragCopy: true,srcParentId:"searchresults"});

}




function AssetNext()
{
 ShowOtherAsset(1);
 return false;
}

function AssetPrev()
{
 ShowOtherAsset(-1);
 return false;
}

function ShowOtherAsset(JumpNr)
{
  var NextPageToShow = 0;
  var NextResToShow= 0;
    
 if(JumpNr!=1 && JumpNr!=-1)
 {return;}

    if(JumpNr==1)
    {//Go to next
        
        if((ResArrayPages[CurrentDisplayingPage].length-1) >= (parseInt(CurrentDisplayingRes) + 1))
        { //No need to change page
            NextResToShow =  (parseInt(CurrentDisplayingRes) + 1);
            NextPageToShow = CurrentDisplayingPage;
            //Show page
            ReOpenAssetDetail(NextPageToShow, NextResToShow);
            return;    
        }
        
        //Need to change page, 
        if((ResArrayPages.length-1) >= (parseInt(CurrentDisplayingPage) + 1))
        {
            NextResToShow = 0;
            NextPageToShow = parseInt(CurrentDisplayingPage) + 1;
            aNext_click();
            ReOpenAssetDetail(NextPageToShow, NextResToShow);
            return;
        }
        
        //No more pages, get more
        if(!PagingArrayIsComplete)
        {
            NextPageToShow = parseInt(CurrentDisplayingPage) + 1;
            NextResToShow = 0;
            ShowAfterLoadingNext = true;
            aNext_click()
            
            return;
        }
        
    }
    else //(JumpNr==-1)
    {//Go to prev
        //The only thing that can happen is that when going back the page needs to be changed.
        
        // CurrentDisplayingPage
        // CurrentDisplayingRes
        
        if(CurrentDisplayingRes == 0 )
        {//Need to go to the previous page
            
            NextPageToShow = parseInt(CurrentDisplayingPage) - 1;
            NextResToShow = ResArrayPages[NextPageToShow].length - 1 ;
            
            aPrev_click();
            ReOpenAssetDetail(NextPageToShow, NextResToShow);            
            return;
        }
        
        //There is a previous to display in that page
        NextPageToShow = parseInt(CurrentDisplayingPage);
        NextResToShow = CurrentDisplayingRes - 1 ;
        ReOpenAssetDetail(NextPageToShow, NextResToShow);            
        return;
    }

}



function IsLastResult(pageNr, resNr)
{   
    if((ResArrayPages.length-1) != pageNr)
    return false; //not on last page

    if((ResArrayPages[ResArrayPages.length-1].length-1) != resNr)
    return false; //not last result

    if(PagingArrayIsComplete) 
    return true; //last loaded, no more pages
    return false; // last loaded, but there are more
}

function IsFirstResult(pageNr, resNr)
{
    if(pageNr==0 && resNr==0)
    {return true;}
    else
    {return false;}
}




function MakeNextPrevVisible(){
if(IsFirstResult(CurrentDisplayingPage, CurrentDisplayingRes))
{document.getElementById('assetPrev').style.display = "none";}
else
{document.getElementById('assetPrev').style.display = "block";}


if(IsLastResult(CurrentDisplayingPage, CurrentDisplayingRes))
{document.getElementById('assetNext').style.display = "none";}
else
{document.getElementById('assetNext').style.display = "block";}

}


function MakeNextPrevInvisible(){
document.getElementById('assetPrev').style.display = "none";
document.getElementById('assetNext').style.display = "none";
}


function ReOpenAssetDetail(pageNr, resNr)
{
    hideOverlayBox(true);
    
    // DM: If the "previous" search result is shown, resNr must be offset by 1
    if (document.getElementById('PrevPageSearchResult')) {
      resNr +=1
    }
    
    showOverlayBox(document.getElementById('searchresults').childNodes[resNr].childNodes[0].childNodes[0]);
    //alert(document.getElementById('searchresults').childNodes[resNr].childNodes[0].childNodes[0].dsInfo.dsTitle);
    //alert("ahora tengo que abrir el nro "  + resNr);
    
}


function aNext_click()
{
  if(!InQuery){
    PagingCurrentPage++;
    ShowResPage();
    SetPageNLinks();
    return false;}
}


function aPrev_click()
{
  if(!InQuery){
    PagingCurrentPage--;
    ShowResPage();
    SetPageNLinks();
    return false;}
}

function EnableNext()
{
//  document.getElementById('searchnexttop').style.visibility = 'visible';
 document.getElementById('searchnexttop').style.display = 'inline';
 document.getElementById('searchnexttopdisabled').style.display = 'none';
//  document.getElementById('searchnexttop').onclick = function(){aNext_click(); return false;};
//  document.getElementById('searchnexttop').className = '';
}

function DisableNext()
{
//  document.getElementById('searchnexttop').style.visibility = 'hidden';
 document.getElementById('searchnexttop').style.display = 'none';
 document.getElementById('searchnexttopdisabled').style.display = 'inline';
//  document.getElementById('searchnexttop').onclick = function(){return false;};
//  document.getElementById('searchnexttop').className = 'disabled';
}

function EnablePrev()
{
//  document.getElementById('searchprevtop').style.visibility = 'visible';
 document.getElementById('searchprevtop').style.display = 'inline';
 document.getElementById('searchprevtopdisabled').style.display = 'none';
//  document.getElementById('searchprevtop').onclick = function(){aPrev_click(); return false;};
//  document.getElementById('searchprevtop').className = '';

  // Create the "prev" search result
  
}

function DisablePrev()
{
//  document.getElementById('searchprevtop').style.visibility = 'hidden';
 document.getElementById('searchprevtop').style.display = 'none';
 document.getElementById('searchprevtopdisabled').style.display = 'inline';
//  document.getElementById('searchprevtop').onclick = function(){return false;};
//  document.getElementById('searchprevtop').className = 'disabled';
}

//-------------------------------------------------------------------------------------------------------
function CreateNextPrevSearchResults() {

  var ShowPrev = false;
  var ShowNext = false;
  var ElemContainer = null;
  var ElemPrevDiv = null;
  var ElemNextDiv = null;
  
  // Check which divs to show
  if (document.getElementById('searchnexttop').style.display != 'none') {  ShowNext = true;  }
  if (document.getElementById('searchprevtop').style.display != 'none') {  ShowPrev = true;  }

  // Get the container Div
  ElemContainer = document.getElementById('searchresults');

  // Find the existing divs
  ElemPrevDiv = document.getElementById('PrevPageSearchResult');
  ElemNextDiv = document.getElementById('NextPageSearchResult');

  // Kill them if it's found and shouldn't be shown
  if (ElemPrevDiv && !ShowPrev) {
    ElemContainer.removeChild(ElemPrevDiv);
  }
  if (ElemNextDiv && !ShowNext) {
    ElemContainer.removeChild(ElemNextDiv);
  }

  // Add them if they are not found, and should be shown
  if (!ElemPrevDiv && ShowPrev) {
    ElemPrevDiv = CreateNextPrevSearchResultElement("Prev");
    ElemContainer.insertBefore(ElemPrevDiv, ElemContainer.firstChild);
  }
  if (!ElemNextDiv && ShowNext) {
    ElemNextDiv = CreateNextPrevSearchResultElement("Next");
    ElemContainer.appendChild(ElemNextDiv);
  }

}

function CreateNextPrevSearchResultElement(divAction) {

  var NewDiv, NewTitleLink, NewTitleData;
  var strLinkText;
  
  NewDiv = document.createElement("div");
  NewDiv.className = 'searchresult';
  NewDiv.id = divAction + 'PageSearchResult';

  if (divAction == "Prev") {
    NewDiv.onclick = function(){aPrev_click(); return false;};
  } else {
    NewDiv.onclick = function(){aNext_click(); return false;};
  }

  // Fix peekabo bug in Safari
  if (isSafari()) {
    NewImage.onload = function() { ReRender(); }
  }

  NewTitleLink = document.createElement('a');
  NewTitleLink.setAttribute('href', '#');

  //NewTitleLink.onclick = NewDiv.onclick; // Adding this onclick isn't necessary. Bubbling takes care of this, and in Safari, this made the click work twice.


  if (divAction == "Prev") {
    strLinkText = "Previous Page";
  } else {
    strLinkText = "Next Page";
  }
  NewTitleData = document.createTextNode(strLinkText);

  NewTitleLink.appendChild(NewTitleData);
  NewDiv.appendChild(NewTitleLink);

  return NewDiv;

}

//-------------------------------------------------------------------------------------------------------

function SetPageNLinks()
{
  var TotalPages;
  var FirstPageLink;
  var LastPageLink;
  var ExtensionToLast=0;
  var ExtensionToFirst=0;
  
  TotalPages = PagingTotalResults/PagingItemsPerPage;

  if(!(Math.floor(TotalPages)==TotalPages))
  { TotalPages = Math.floor(TotalPages) + 1; }

  if(TotalPages>0)
  {

    FirstPageLink = parseInt(PagingCurrentPage) - parseInt(PagingLinkRadius);
    if(parseInt(FirstPageLink) < 1)
      { FirstPageLink = 1;
        ExtensionToLast = 1-(parseInt(PagingCurrentPage) - parseInt(PagingLinkRadius));  }

    LastPageLink = parseInt(PagingCurrentPage) + parseInt(PagingLinkRadius);
    if(parseInt(LastPageLink) > parseInt(TotalPages))
      { LastPageLink = TotalPages;
        ExtensionToFirst = (parseInt(PagingCurrentPage) + parseInt(PagingLinkRadius)) - parseInt(TotalPages);  }

    FirstPageLink = FirstPageLink - ExtensionToFirst;
    if(parseInt(FirstPageLink) < 1) { FirstPageLink = 1; }

    LastPageLink = parseInt(LastPageLink) + parseInt(ExtensionToLast);
    if(parseInt(LastPageLink) > parseInt(TotalPages))  { LastPageLink = TotalPages; }

    pnDiv = document.getElementById('pageNLinks')    //pnDiv = PageNlinks div.
    EmptyDiv(pnDiv);

    for(i=FirstPageLink;i<=LastPageLink;i++)
    {

      if(i==PagingCurrentPage)
      {
        NewSpan = document.createElement("SPAN");
        NewSpan.className = "pageNumberCurrent";
        NewText = document.createTextNode(i);
        NewSpan.appendChild(NewText);
        pnDiv.appendChild(NewSpan);
      }
      else
      {
        NewA = document.createElement("A");
        NewA.href= "#";
        NewA.dsPage = i;
        NewA.onclick = apageN_click;
        NewA.className = "pageNumber";
        NewText = document.createTextNode(i);
        NewA.appendChild(NewText);
        pnDiv.appendChild(NewA);
      }

    }


  }
}


function apageN_click()
{
  if(!InQuery){
  PagingCurrentPage = this.dsPage;
  ShowResPage();
  SetPageNLinks();
  return false;}
}


function ShowNoResults()
{

  /*NewDiv = document.createElement("DIV");
  NewDiv.className = "noResults";

  NewText = document.createTextNode("Your query returned no results");
  NewDiv.appendChild(NewText);
  
  document.getElementById('searchresults').appendChild(NewDiv);*/
  
  document.getElementById('noresults').style.display = "block";

}

function HideNoResults()
{
  document.getElementById('noresults').style.display = "none";
}

function HidePagingControls()
{
  document.getElementById('searchpaging').style.visibility="hidden";
  DisableNext();
  DisablePrev();
}

function ShowPagingControls()
{
  document.getElementById('searchpaging').style.visibility="visible";
}





function DisableSplashMode()
{
  if ((InSplashMode) || (!ThereIsSearch))
  {
    InSplashMode = false;
    //To show
    document.getElementById('shoppingcart').style.display = "block";
    document.getElementById('lightbox').style.display = "block";
    document.getElementById('searchsuggestkeywords').style.display = "block";
    document.getElementById('searchresultscontainer').style.display = "block";

    //To hide
    document.getElementById('featuredpicture').style.display = "none";
    document.getElementById('searchbarsplash').style.display = "none";
    document.getElementById('searchsplashtoolbarmover').style.display = "none";
    document.getElementById('splashbottomcontent').style.display = "none";
  }
}


function SplashClick(dsID, dsTitle, dsType)
{
                                    //dsID      dsType      dsTitle     dsThumbFileName

  var tAssetInfo = new dsSearchInfo(dsID,dsType, dsTitle, "");
  tAssetInfo.title = dsTitle;
  showOverlayBox(tAssetInfo);
  return false;
}





function details_click_ShowDetails(e, ref)
{
  /* the first child of the container of the div is assumed to be the image to display */
  showOverlayBox(ref.parentNode.childNodes[0].childNodes[0]);
}


function imgShowDetails(e,callerImg) /* Displays the overlayDiv with the asset's info. */
{

  /* clx, cly <- clickX, clickY positions to compare against dnx and dny to */
  /* detect if user has dragged the image                                */
  var clx;  
  var cly;

  if(!e)
  { /* Code for IE */
    clx = event.clientX;
    cly = event.clientY;
  }
  else
  { /* Code for Mozilla */
    clx = e.clientX;
    cly = e.clientY;
  }

  /* if mouse hasn't moved, show details */
  if((clx == dnx) && (cly == dny))
  {


    showOverlayBox(callerImg);
  }
}

function imgLinkMDown(e) { }

function imgMDown(e)
{

  if(!e)
  { /* Code for IE */
    dnx=event.clientX;
    dny=event.clientY;
  }
  else
  { /* Code for Mozilla */
    dnx=e.clientX;
    dny=e.clientY;
  }

}


function txtSearch_keydn(e)
{
  if(!e) { /* Code for IE */       kc = event.keyCode;  }
  else   { /* Code for Mozilla */  kc = e.keyCode;      }

  if(kc==13) {btnSearch_Click();}  /* simulate search button click */
}

function txtNewLbName_keydn(e)
{
  if(!e) { /* Code for IE */       kc = event.keyCode;  }
  else   { /* Code for Mozilla */  kc = e.keyCode;      }

  if(kc==13) {newLightboxOK_click();   return false;}  /* simulate search button click */

}

//---------------------------------------------------------------------------------



//---------------------------------------------------------------------------------

// all js initializations and event assignment goes here.
function body_load_event()
{
  /* Here goes what needs to be executed on body.onload */
  Droppables.add('lightbox', {onDrop:function(element,dropon){LightBoxDrop(element);}}) ;
  Droppables.add('shoppingcart', {onDrop:function(element,dropon){ShoppingCartDrop(element);}}) ;

  document.getElementById('btnNewLightBox').onclick = btnNewLightBox_click;
  document.getElementById('btnDeteleLightBox').onclick = btnDeleteLightBox_click;
  document.getElementById('newLightboxOK').onclick = newLightboxOK_click;
  document.getElementById('newLightboxCancel').onclick = newLightboxCancel_click;
  document.getElementById('ligthboxselect').onchange = ligthboxselect_change;

  document.getElementById('btnCheckOut').onclick = btnCheckOut_click;
  
  //Capture enter on textbox
  document.getElementById('searchtext').onkeydown = txtSearch_keydn;
  document.getElementById('newLightboxText').onkeydown = txtNewLbName_keydn;

  //Search next - prev
  document.getElementById('searchprevtop').onclick = function(){aPrev_click(); return false;};
  document.getElementById('searchnexttop').onclick = function(){aNext_click(); return false;};

  //Overlay
  document.getElementById("aDetailsAddToLB").onclick = function(e){aDetailsAddToLB_click(e); return false;};
  document.getElementById("aDetailsAddToSC").onclick = function(){aDetailsAddToSC_click(); return false;};
  document.getElementById("aDetailsZoom").onclick = function(e){aDetailsZoom_click(e); return false;};
  document.getElementById("aDetailsCloseZoom").onclick = function(e){aDetailsCloseZoom_click(e); return false;};

  document.getElementById("aDetailsAddToLBOK").onclick = function(){aDetailsAddToLBOK_click(); return false;};
  document.getElementById("aDetailsAddToLBCancel").onclick = function(){aDetailsAddToLBCancel_click(); return false;};

  document.getElementById('assetNext').onclick = AssetNext;
  document.getElementById('assetPrev').onclick = AssetPrev;



  if(LoadLightboxAtBodyLoad)
  { LoadLightBox(); }
  else
  { AddLightboxLegend("You must log in to use the Lightbox", true); }
  
//  if(ThereIsShoppingCart)
  //{
    LoadShoppingCart();
   // }
//  else
//  {document.getElementById('shoppingcartlegend').style.display = "block";}

}


addLoadEvent(body_load_event);
addLoadEvent(initOverlayBox);	// run initOverlayBox onLoad
