﻿

function BindEvents() {
    var defaultSize = 40;
    jQuery("#current-show-name a").each(function() {
    var h = jQuery(this).height();
    var i = defaultSize;
    while (h > defaultSize) {
        i--;
        this.style.fontSize = i + 'px';
        h = jQuery(this).height();
    }
    });

    //jQuery('#show-info-content').wrap('<div id="show-info-content-wrapper"></div>');
  //  jQuery('.scroll-pane').jScrollPane({ scrollbarWidth: 12, scrollbarMargin: 12, dragMinHeight: 24 });
    jQuery(".scroll-pane").each(function() {
        var showid = jQuery(this).attr('id');
        GetShowFolders(showid);
    });

    jQuery("ul.cart-list-active").each(function() {
       
        swapCartSearches("carts");

    });
    
    jQuery("ul.search-list-active").each(function() {
        swapCartSearches("searches");
        
    });

    jQuery("a.popupwindow").popupwindow(profiles);
    jQuery("a.dlLink").popupwindow(profiles);
    jQuery("a.detLink").popupwindow(profiles);
    jQuery("a.footer-popup").popupwindow(profiles);
    
    SyncSelected();

    jQuery(".action_button").click(function(e) {
        e.preventDefault();
        var a = jQuery("[id$='ddlActionTarget']").getValue();
        var sa = GetSelectedAssets();
        if (sa.length === 0 && a == 'selected') {
            alert("no files selected");
        }
        else {
            RemoveSelectedAssets(a, sa);
        }

    });
    jQuery("a.assetPopAnchor").click(function() {
        jQuery(this).addClass("visited");
        LaunchAsset(jQuery(this));
    });

    jQuery("a.assetPopAnchor2").click(function() {
         jQuery(this).addClass("visited");
        LaunchAsset(jQuery(this));
    });
//    jQuery("a.assetPopAnchor2").click(function() {

//        LaunchAsset(jQuery(this));
//        //        var ext = jQuery(this).attr('id').split('_')[0];
//        //        var aId = jQuery(this).attr('id').split('_')[1];
//        //        var href=LaunchAsset(aId, ext);
//    });

////    jQuery("a.assetPopAnchor").click(function() {

////        var ext = jQuery(this).attr('id').split('_')[0];
////        var aId = jQuery(this).attr('id').split('_')[1];
////        LaunchAsset(aId, 'Asset', ext);
//    });
    //add single file to cart
    jQuery('a.addLink').click(function() {

        var assetid = jQuery(this).attr('ID');
        assetid = assetid.substring(assetid.lastIndexOf('_') + 1, assetid.length);
        g_selectedAssetid = assetid;

        loadCartPopup();

    });
    //select asset row
    jQuery('.assetCheck').click(function() {

        var rowID = '#tr_' + jQuery(this).attr('id').split('_')[1];
        var thisIsChecked = jQuery(this).attr('checked');
        jQuery(rowID + ' td').toggleClass('assetColumn-active', thisIsChecked);
        jQuery(rowID + ' td:first').toggleClass('firstAssetColumn-active', thisIsChecked);
        jQuery(rowID + ' td:last').toggleClass('gridActions-active', thisIsChecked);
        SyncSelected();
    });


    jQuery('a.assetPopInactive').each(function() {
        var aID = jQuery(this).attr('id').split('_')[1];
        var href = '/browse/AssetDetails.ashx?s=2&id=' + aID;
        jQuery(this).attr("rel", href).cluetip({dropShadow:false,  cluetipClass: 'jtip'});

    });
    jQuery('a.assetPopAnchor').each(function() {
        var aID = jQuery(this).attr('id').split('_')[1];
        var href = '/browse/AssetDetails.ashx?s=2&id=' + aID;
        jQuery(this).attr("rel", href).cluetip({ dropShadow: false, cluetipClass: 'jtip' });

    });
    jQuery('a.assetPopAnchor2').each(function() {
        var aID = jQuery(this).attr('id').split('_')[1];
        var href = '/browse/AssetDetails.ashx?s=2&id=' + aID;
        jQuery(this).attr("rel", href).cluetip({ dropShadow: false, cluetipClass: 'jtip'});

    });
    
   

    jQuery('#btnUploadMeta').click(function(e) {
        DisplayUploadManagerPop('Metadata');
    });

    jQuery('#btnUploadManager').click(function(e) {
        DisplayUploadManagerPop('Filelist');


    });
//    jQuery('.dlLink').click(function(e) {
//        // var aId = element.id.substring(element.id.lastIndexOf('_') + 1, element.id.length);
//        var aId = jQuery(this).attr('id').split('_')[1];
//        // PS.Popup.open('/browse/downloadpop.aspx?id=' + aId + '&zip=0&activity=1', { width: 700, height: 200 });
//        var src = '/browse/downloadpop.aspx?id=' + aId + '&zip=0&activity=1';
//        jQuery(this).attr("href", src);
//        return false;
//    });

    jQuery(".aProfile").click(function(e) {
     
    });


    if (jQuery('#divFilters').length) {
        GetFileListFilters();
    }

    if (jQuery("#show-pager").length) {

        currentPage = jQuery.cookie('lpg');
        if (!currentPage) {
            currentPage = 0;
        }
        GetLeftNavShowPage(currentPage);
    }
    else {
        jQuery.cookie('lpg',0);
     }

    jQuery('#divEmailShowTab').click(function(e) {
        e.preventDefault();
        jQuery('#showTabEmailPopupBox').modal();

    });

    jQuery('#uber_Email').click(function() {
        jQuery('#email-links-container').slideToggle('fast');
        jQuery('#ubernav-left-div').toggleClass('email-active');
        jQuery('#ubernav-right-div').toggleClass('email-active');
    });

    jQuery('.btnSaveSearch').click(function(e) {
        e.preventDefault();
        loadSaveSearchPopup();
        jQuery('#divSaveSearch').modal({ minHeight: 300, minWidth: 300 });

    });
    jQuery('.btnShowSearchCriteria').click(function(e) {
        e.preventDefault();
        jQuery('#divSearchCriteria').modal({ minHeight: 500, minWidth: 600, persist: true });
        jQuery(".btnCancel").show();

    });

    if (jQuery('#categoriesBody').length) {
    
        GetCategorizedSearchResults();

    }





    //add selected to cart
    jQuery('#btnAddSelected').click(function() {
        g_selectedAssetid = 0;
        var sa = GetSelectedAssets();
        if (sa.length > 0) {
            loadCartPopup();

        }
        else
            alert('No files selected');
        return false;


    });

    //select or deselect all assets
    jQuery("#checkboxall").click(function() {
        g_selectedAssetid = 0;
        var checked_status = this.checked;
        jQuery(".assetCheck").each(function() {
            this.checked = checked_status;
            var rowID = '#tr_' + jQuery(this).attr('id').split('_')[1];
            var thisIsChecked = jQuery(this).attr('checked');
            jQuery(rowID + ' td').toggleClass('assetColumn-active', thisIsChecked);
            jQuery(rowID + ' td:first').toggleClass('firstAssetColumn-active', thisIsChecked);
            jQuery(rowID + ' td:last').toggleClass('gridActions-active', thisIsChecked);
        });
        SyncSelected();
    });


    
    jQuery('#aCategories').click(function() {
    jQuery('#categoriesWrapper').toggle();
        if (jQuery('#aCategories').html() == 'show') {
            jQuery('#aCategories').html('hide');
          //  jQuery("#categoriesTable").show();
            // GetCategorizedSearchResults();
        }
        else {
            jQuery('#aCategories').html('show');

        }
        return false;

    });



    // methods for the cart and search popups
    jQuery("#popupClose").click(function() {
        jQuery.modal.close();
    });


    jQuery("#backgroundPopup").click(function() {
        jQuery.modal.close();
    });


    //Press Escape event!
    jQuery(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            jQuery.modal.close();
        }
    });

    jQuery('.btnGo').click(function(e) {
        ShowPleaseWait();

    });



    jQuery('#btnRemoveSelected').click(function() {
        __doPostBack('RemoveAssetFromCart', GetSelectedAssets());
    });


    

//    jQuery('a.detLink').click(function() {
//        var aID = jQuery(this).attr('id').split('_')[1];
//        PS.Popup.open('/browse/detailview.aspx?id=' + aID, { width: 800, height: 700 });
//    });

    jQuery('#btnDownloadSelected').click(function(e) {
       
        var sa = GetSelectedAssets();
        if (sa.length > 0) {
            DownloadSelectedAssets(sa);           
        }
        else {
            alert('No files selected');
        }
    });
    jQuery('#aContactSheet').click(function() {
        var sa = GetSelectedAssets();
        if (sa.length > 0) {
            AjaxContactSheetStoreSelected(sa);

        }
        else
            alert('No files selected');
        return false;

    });
    jQuery(".search-toggle").click(function(node) {
        
        var img = jQuery('#' + node.id + ' img');
        var divId = node.id.replace(/a/, 'div');
        var currentDiv = jQuery('#' + divId);
        if (img.attr('src') == '/public/images/div/plus.gif') {
            img.attr('src', '/public/images/div/minus.gif');
        }

        else {
            img.attr('src', '/public/images/div/plus.gif');

        }

        jQuery(currentDiv).toggle();
    });

    jQuery("#admin-toggle-btn").click(function() {
        jQuery("#file-controls-admin").toggle();
        if (jQuery(this).html() == "show")
            jQuery(this).html("hide");
        else
            jQuery(this).html("show");

    });
      
   
    jQuery('#uber_Home').hover(function() {
        jQuery('#ubernav-left-div').addClass('ubernav-left-active');
    }, function() {
        if (!jQuery(this).hasClass('active')) {
            jQuery('#ubernav-left-div').removeClass('ubernav-left-active');
        }
    });

    jQuery('#uber_Help').hover(function() {
        jQuery('#ubernav-right-div').addClass('ubernav-right-active');
    }, function() {
        if (!jQuery(this).hasClass('active')) {
            jQuery('#ubernav-right-div').removeClass('ubernav-right-active');
        }
    }
);




};


jQuery(document).ready(function() {
    BindEvents();

});
