// Jquery scripts

//Binds the referenced functions to be executed whenever the DOM is ready to be traversed and manipulated.
$(document).ready(function() {
showHideRows1();
showHideRows2();
showHideRows3();
showHideRows4();
 showHide();
 stripeTable();
 //tableSorter();
 });
 
 //to do: abstract class so only one function needed for 4 classes
  function showHideRows1() {
    $('tr.ACCEPTED').show();
  $('tr.catRowACCEPTED td').click(function(event) {
	$('tr.ACCEPTED').toggle();
  });
  };

  function showHideRows2() {
    $('tr.REJECTED').show();
  $('tr.catRowREJECTED td').click(function(event) {
	$('tr.REJECTED').toggle();
  });
  };

  function showHideRows3() {
    $('tr.SUBMITTED_FOR_REVIEW').show();
  $('tr.catRowSUBMITTED_FOR_REVIEW td').click(function(event) {
	$('tr.SUBMITTED_FOR_REVIEW').toggle();
  });
  };
 
   function showHideRows4() {
    $('tr.SAVED').show();
  $('tr.catRowSAVED td').click(function(event) {
	$('tr.SAVED').toggle();
  });
  };
 
// Show/hide a div
function showHide() {
  $('div.showhide> div').hide();
  $('div.showhide> a').click(function() {
	$(this).next().slideToggle('slow');
  });
};


/*for striping tables other than tablesort*/
function stripeTable() {
  $('table.striped tbody tr:odd').addClass('odd');
  $('table.striped tbody tr:even').addClass('even');
   $('table.striped tr').mouseover(
    function () {
 $('table.striped tr').removeClass('highlight');
 $(this).addClass('highlight');
 });
};

//sortable table columns using jquery.tablesorter.js. Added highlight function from stripeTable.COMMENTED OUT - IT BREAKS XGDB SHOWHIDE
//function tableSorter() {
//$("#myTable").tablesorter( { widgets: ['zebra']} ); /*sortList: [[0,0], [1,0]],*/
//$('#myTable tr').mouseover(
//    function () {
// $('#myTable tr').removeClass('highlight');
// $(this).addClass('highlight');
// });
//};



// #### JQuery ui based function to support video launch in a dialog window. Launches a modal window using jquery ui dialog. At onclick, the tag id of the video-buttom image  (set to the name of the movie file or its id if hosted) is passed as a cgi variable to the driver script (e.g. movie.php), accessible via php $_GET  There are two scripts, one for quicktime and one for flash (hosted).

//NOTE: the scripts below should be synchronized with /Product/javascript/default.js

$(function() {
        $('.video-button').css('cursor','pointer');
        $('.video-button').attr('src', '/images/qtvideo.png');
        $('.video-button').mouseover(function(){ this.src =  '/images/qtvideo_hover.png'; });
        $('.video-button').mouseout(function(){ this.src = '/images/qtvideo.png'; });
        $('.video-button').click(function(event) {
                $.get('/help/av/movie.php',
                        { 'movieid[]': [this.id, this.title] },
                        function(html) {
                                $('#video_dialog').html(html);
                        }
                );
                $('#video_dialog').dialog('open');
        });
        $('#video_dialog').dialog({bgiframe:true,autoOpen:false,height:560,width:622,modal:true});
});

$(function() {
        $('.flvideo-button').css('cursor','pointer');
        $('.flvideo-button').attr('src', '/images/flvideo.png');
        $('.flvideo-button').mouseover(function(){ this.src =  '/images/flvideo_hover.png'; });
        $('.flvideo-button').mouseout(function(){ this.src = '/images/flvideo.png'; });
        $('.flvideo-button').click(function(event) {
                $.get('/help/av/flmovie.php',
                        { 'movieid[]': [this.id, this.title] },
                        function(html) {
                                $('#video_dialog').html(html);
                        }
                );
                $('#video_dialog').dialog('open');
        });
        $('#video_dialog').dialog({bgiframe:true,autoOpen:false,height:560,width:622,modal:true});
});

//Opens an image specified by the enclosing tag id and launched by /Product/help/image.php. Image must have the same name as the id, plus the '.png' suffix, and must be stored in /Product/help/
$(function() {
        $('.image-button').css('cursor','pointer');
        $('.image-button').click(function(event) {
                $.get('/XGDB/help/image.php',
                        { 'imageid[]': [this.id, this.title] },
                        function(html) {
                                $('#image_dialog').html(html);
                        }
                );
                $('#image_dialog').dialog('open');
        });
        $('#image_dialog').dialog({bgiframe:true,autoOpen:false,height:640,width:480,modal:true});
});

// #### JQuery based function to support a context-sensitive help system where context provides the filename and title for an include file.
$(function() {
        $('.xgdb-help-button').css('cursor','help');
        $('.xgdb-help-button').attr('src', '/XGDB/images/help-icon.png');
        $('.xgdb-help-button').mouseover(function(){ this.src = '/XGDB/images/help-icon_hover.png'; });
        $('.xgdb-help-button').mouseout(function(){ this.src = '/XGDB/images/help-icon.png'; });
        $('.xgdb-help-button').click(function(event) {
                $.get('/XGDB/xGDB_help.php',
                        { 'context[]': [this.id, this.title] },
                        function(html) {
                                $('#help_dialog').html(html);
                        }
                );
                $('#help_dialog').dialog('open');
        });
        $('#help_dialog').dialog({bgiframe:true,autoOpen:false,height:640,width:480,modal:true});
});
