    function advanceFrame(){
      var t = jQuery('.gallery').find('ul').find('.gallery-image:visible');
      uglyt = t;

      if(!t.next(':not(.gallery-info, .gallery-msg)')[0]){
        var elm = t.fadeOut("fast").parent().find(':first-child');
      }else{
        var elm = t.fadeOut("fast").next();
      }

      elm.fadeIn("slow");
      jQuery('.gallery-title').html(elm.find('img').attr('title'));

      current_gallery_img++;
      if(current_gallery_img>max_gallery_img){
        current_gallery_img=1;
      }

      jQuery('#currentimage').text(current_gallery_img);
      var gid = jQuery('#gallery_id').val();
      jQuery('#gallery'+gid).css('height', (parseInt(elm.find('img').css('height'))+30)+"px");
      jQuery('#galleryul'+gid).css('height', (parseInt(elm.find('img').css('height')))+"px");
      //alert(gid+"|"+jQuery('#'+gid).attr('height')+"|"+elm.find('img').attr('height'));

    }

function previousFrame(){
      var t = jQuery('.gallery').find('ul').find('.gallery-image:visible');

      if(!t.prev(':not(.gallery-info, .gallery-msg)')[0]){
        var elm = t.fadeOut("fast").parent().find(':last-child');
      }else{
        var elm = t.fadeOut("fast").prev();
      }

      elm.fadeIn("slow");
      jQuery('.gallery-title').html(elm.find('img').attr('title'));

      current_gallery_img--;
      if(current_gallery_img<1){
        current_gallery_img=max_gallery_img;
      }

      jQuery('#currentimage').text(current_gallery_img);
      var gid = jQuery('#gallery_id').val();
      jQuery('#gallery'+gid).css('height', (parseInt(elm.find('img').css('height'))+30)+"px");
      jQuery('#galleryul'+gid).css('height', (parseInt(elm.find('img').css('height')))+"px");


    }

    function toggleSlideShow(){
        if(!jQuery(".gallery").data("playing")){
           startSlideShow();
        }else{
           stopSlideShow();
        }
    }

    function nextBTN(){
        stopSlideShow();
        advanceFrame();
    }

    function prevBTN(){
        stopSlideShow();
        previousFrame();
    }

    function startSlideShow(){
        jQuery("#playpause").toggleClass('play',false).toggleClass('pause',true);
        viewing_gallery = setInterval( "advanceFrame()", 6500 );
        jQuery(".gallery").data("playing", true);
    }

    function stopSlideShow(){
        jQuery("#playpause").toggleClass('play',true).toggleClass('pause',false);
        clearInterval(viewing_gallery);
        jQuery(".gallery").data("playing", false);
    }

    function galleryInit(){
       //  actions - defined
        current_gallery_img = 1;
        max_gallery_img = jQuery('#max_gallery_img').val();
        gallery_id = jQuery('#gallery_id').val();
        jQuery('.gallery').css('background-color','#000000').css('border','3px solid #000000');
        jQuery("#gallery"+gallery_id).prepend("<div class='gallery-controls'><div class='gallerycounter' id='gallerycounter'><span id='currentimage'>1</span>/"+max_gallery_img+"</div><div class='prev' id='prevbtn'><!-- Prev button --></div><div class='pause' id='playpause'><!-- Play/Pause button --></div><div class='next' id='nextbtn'><!-- Next button --></div></div><div class='gallery-title'></div>");

        jQuery(".gallery-image").click(function(){ }).hide();
        jQuery("#first-img").show();
        jQuery("#prevbtn").click(function(){ prevBTN(); });
        jQuery("#playpause").click(function(){ toggleSlideShow(); });
        jQuery("#nextbtn").click(function(){ nextBTN(); });
        //jQuery(".gallery-btn").css('opacity',.9).hover(function(){ jQuery(this).fadeTo("fast", 1) }, function(){ jQuery(this).fadeTo("fast", .9) });

       //   actions - applied
        var elm = jQuery(".gallery").find('ul').find('li:first-child');
        elm.show();
        jQuery('.gallery-title').html(elm.find('img').attr('title'));




    }


jQuery(document).ready(function(){
    var notie6 = true;
    jQuery.each(jQuery.browser, function(i) {
        if(jQuery.browser.msie){
            notie6 = false;
        }
    });

    if(notie6 == true){
            galleryInit();
            toggleSlideShow();
    }

});