﻿// events (live) 
// live events need only be declared here once. 
// all future instances (ajaxed) of the element will also be 'bound'   
   
  function BindLiveEvents() {
  
  

  
    // CULTURE SELECT
    $(".cultureClick").live("click", function(){
      GoCulture($(this).attr('id').replace('____',''));
      return false;
    });
  
    // form block accordian persists
    $("h3.modHeader:not(#loginDlgHeader)").live("click", function(){
    if ($(this).is('.isDiag')) {
      BindAccordian(this);
    }
    else {
    try {
      var state = "closed";
      if ($(this).attr('id').indexOf("open",0) > -1) {
        state = "open"
      }

      var idString;
      if (state == "open") {
        idString = $(this).attr('id').replace("open_", "");
      }
      else {
        idString = $(this).attr('id').replace("closed_", "");
      }

      var targetBlockID;
      targetBlockID = idString.replace("h3_", "");
      
      var targetFormBlockPointerID;
      targetFormBlockPointerID = idString.replace("h3_blockAjaxID_", "");

      AjaxLoad("#" + targetBlockID,"/Parts/ajaxBlock.aspx?inPid=" + targetFormBlockPointerID,"","loading form block","loaded form block","");
      
      if (state == "open") {

        $("#" + targetBlockID).empty();
      }
      
      BindAccordian(this);
      
      //return false, to stop event bubbling
      return false;
      
      }
        catch (err) {
        BindAccordian(this);
        }
      }
      //fixGrids();
    });

    // drop down group headers accordian
    $("div.grouptext").live("click", function(){
      doDropDownGroupClick(this);
      //return false, to stop event bubbling
      return false;
    });
 
    // force dialog to cles and navigate to
     $(".diagClose").live("click", function(){
      CancelDialog($(this).attr('id').replace('____',''));
      //return false, to stop event bubbling
      return false;
    });   
    

    // actions
    // based on class of clicked list item, call CntrlAction(id, type, '', '')
    // block binding on dialog actions :not(.dlglistitem)
    $("ul.listitem li:not(.dlglistitem)").live("click", function(){
      whichListItemClicked(this);
      //return false, to stop event bubbling
      return false;
    });
    
    $("ul li.rootGroup").live("click", function(){
      whichListItemClicked(this);
      //return false, to stop event bubbling
      return false;
    });    
    
    // tabs
    $("li.root").live("mouseover", function(){
      if (!$(this).is('.inactive')) {
         dropDownHover(this);
      }
      return false;
    });   
    
     $("li.root").live("mouseout", function(){
      if (!$(this).is('.inactive')) {
        dropDownOut(this);
      }
      return false;
    });
    
     $("li.more").live("mouseover", function(){
      if (!$(this).is('.inactive')) {
         dropDownHoverMore(this);
      }
      return false;
    });   
    
     $("li.more").live("mouseout", function(){
      if (!$(this).is('.inactive')) {
        dropDownOutMore(this);
      }
      return false;
    });

    // checkbox lists
    $("div#workAreaUpdate ul.checkboxList li input").live("click", function(){
      CheckboxListBind(this);
     // return false;
    });
        
    // NAV LINK
    $("div.navLink").live("click", function(){
      Go($(this).attr('id').replace('____',''));
      return false;
    });
    
    // GRID version ROW
    $(".gridVersionRow").live("click", function(){
      versionRowClick(this);
      return false;
    });   
    
    // GRID ROW
    $(".gridRow").live("click", function(){
      Go($(this).attr('id').replace('____',''));
      return false;
    });   

    //ACTIONS - outside of actions dropdown
    $(".controlClick").live("click", function(){
      var passID = $(this).attr('id').replace('____','');
      myString = passID.split("_")
      var controlID = myString[0];
      var pointerID = myString[1];
      CntrlAction(controlID,'',pointerID,'');
      return false;
    });
    
    //break inheritance
    $("li.breakInherit").live("click", function(){
        CntrlAction('','break','','');
        return false;
    });
    
    //screen toggle
//    $("li.breakInherit").live("click", function(){
//        CntrlAction('','break','','');
//        return false;
//    });
    
    //export users
    $("li.exportUsers").live("click", function(){
        CntrlAction('','exportUsers',$(this).attr('id'),'');
        return false;
    });
    
            
       // INNER MODULE CLICK
        $("div.inModule").live("click", function(){
        Modu($(this).attr('id').replace('i___',''));
        return false;
    });
    
    //grid toggler
    $("div.panelControls div").live("click", function(){
        if (isToggled) {
          isToggled = false;
        }
        else {
          isToggled = true;
        }
        return false;
    });
    
  //grid toggler
    $("tr.gridRowToggler").live("click", function(){
        $(this).next("tr").toggle();
        if ($(this).is('.toggleOpen')) {
          $(this).removeClass('toggleOpen');
        }
        else {
          $(this).addClass('toggleOpen');
        }
        return false;
    });
    
    $(".opendrop").live("click", function(){
        var pid = ($(this).attr("id")).split('_')[0];
        var vid = ($(this).attr("id")).split('_')[1];
        windowOpener('/assets/bulk/fileManager_SingleDrop.aspx?versionid=' + vid + '&pointerid=' + pid,480,170);
        //window.open("/bulk/fileManager_SingleDrop.aspx?versionid=" + vid + "&pointerid=" + pid, null, "height=190,width=120,status=yes,toolbar=no,menubar=no,location=no")
        return false;
    });  
    
    //grid click
//    $("tr.gridRow").live("click", function(){
//        $(this).addClass('selected');
//        return false;
//    });   
    
    $("div.quickTaggingAvailable .availabletags").live("click", function(){
        var tag = $(this).attr('name');
        if ($(this).attr('checked')) {
          tagAsset(tag, 'add');
        }
        else {
         // tagAsset(tag, 'remove');
        }
        //return false;
    }); 
    
    
    $("div.quickTaggingTaggedWith .taggedWith").live("click", function(){
        var tag = $(this).attr('name');
        if ($(this).attr('checked')) {
          //tagAsset(tag, 'add');
        }
        else {
          tagAsset(tag, 'remove');
        }
        //return false;
    });     
    
    return false;
  }
  


  
    function whichListItemClicked(Object) {
    
      // ACTIONS
    
        // action link (standard)
        if ($(Object).is('.actionLink')) {
          CntrlAction($(Object).attr('id').replace('____',''), '', '', '');
          return false;
        }
        // action link (save)
        if ($(Object).is('.actionLink_save')) {
          CntrlAction($(Object).attr('id').replace('____',''), 'save', '', '');
          return false;
        }     
        // action link (save permissions)
        if ($(Object).is('.actionLink_updatepermissions')) {
          CntrlAction($(Object).attr('id').replace('____',''), 'updatePermissions', '', '');
          return false;
        }
        
          // action link (save draft translation editor)
        if ($(Object).is('.actionLink_saveDraftTranslation')) {
          CntrlAction($(Object).attr('id').replace('____',''), 'saveDraftTranslation', '', '');
          return false;
        }      
        
        
      // MODULE CLICK
        if ($(Object).is('.moduleLink')) {
          Modu($(Object).attr('id').replace('____',''));
          return false;
        }         
        
      // TABS
        if ($(Object).is('.tabLink')) {
          tabClick($(Object).attr('id').replace('____',''));
          return false;
        }       
        
       // HISTORY
        if ($(Object).is('.historyLink')) {
          Go($(Object).attr('id').replace('____',''));
          return false;
        }              
          

      // undefined click
      return false;
    }

