jQuery(document).ready(function($){
//GALLERY
  var $gallery = $('#gallery'); //cache
  if ($gallery.get()[0]) {
    var gallery = $gallery.galleriffic('#thumbs-adv', {
        delay:                  4000,
        numThumbs:              $(".noFolders").get()[0] ? 8 : 6,
        preloadAhead:           4,
        enableTopPager:         false,
        enableBottomPager:      true,
        imageContainerSel:      '#slideshow-adv',
        controlsContainerSel:   '#controls-adv',
        captionContainerSel:    '#caption-adv',
        loadingContainerSel:    '#loading-adv',
        renderSSControls:       true,
        renderNavControls:      true,
        playLinkText:           "Slideshow",
        pauseLinkText:          "Stopp",
        prevLinkText:           "Forrige",
        nextLinkText:           "Neste",
        nextPageLinkText:       "Neste",
        prevPageLinkText:       "Forrige",
        enableHistory:          true,
        autoStart:              false,
        onChange:               function(prevIndex, nextIndex) {
				    $('#thumbs-adv ul.thumbs').children()
				    .eq(prevIndex).fadeTo('slow', 0.5).end()
				    .eq(nextIndex).fadeTo('slow', 1.0);
                                //$(".nav-controls").hide();
                                //$("#caption-adv").show();
                                },
	onTransitionOut:        undefined/*function() {
			        $('#slideshow-adv').fadeOut('slow');
				}*/,
	onTransitionIn:         function() {       
                                //$(".nav-controls").hide();        
                                //$("#caption-adv").show();                       
	                        $('#slideshow-adv').fadeIn('slow');
				},
	onPageTransitionOut:    function(callback) {
	                        $('#thumbs-adv ul.thumbs').fadeOut('fast', callback);
				},
	onPageTransitionIn:     function() {
	                        $('#thumbs-adv ul.thumbs').fadeIn('fast');
				}
    });
    $("#galleryWrapper").hover(function(){
         $(".nav-controls,.play,#caption-adv").show();
    }, function(){
         $(".nav-controls,.play,#caption-adv").hide();
    });
    } // END IF GALLERY IS ON PAGE

  var currentfolder = ips.system.currentfolder, urlroot = ips.system.urlroot;
  // OBJECT COMMENTS

  var $comments = jQuery(".comments"); // CACHE
  if ($comments.length) {
	$comments.find(".ajax").each(function(){
	  $comments.load($(this).attr("href"), function(){
	    var $commentForm = $("#commentForm"); //CACHE
	    if($commentForm.length) {
	      $commentForm.submit(function(event){
	         var $this = $(this), //CACHE
	             $response = $("#commentResponse"),  //CACHE
	             $signature = $this.find("#signature"),  //CACHE
	             $comment = $this.find("#comment"); //CACHE
	         event.preventDefault();
	         if ($comment.val() === "") {
	           $response.text("Skriv en kommentar.");
	           $comment.addClass("error");
	         } else {
	           $.post(urlroot, $this.serialize(), function(){
                 $("<li class='comment'><p>" + $signature.val() + "</p><p><strong>" + $comment.val() + "</strong></p></li>").appendTo("ul.commentList");
	             $response.text("Kommentaren er lagt til og venter moderering.");
	             $comment.removeClass("error").val("");
	           });
	         }
	      });
	    } 
	  });
	});
  } // END COMMENTS

  });

function facebook_click() {
  u=location.href;
  t=document.title;
  window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}
