// JavaScript Document

var urlroot = window.location.host.indexOf('idium.n') !== -1 ? window.location.pathname.substring(0,window.location.pathname.indexOf('/',2)) + "/" : "/";

$(document).ready(function () {

// Searchform interaction
   var $searchForm = $("#searchForm"), //CACHE
       $query = $searchForm.find(".query"),
       $label = $searchForm.find("label");
   if ($query.val() !== "") {$label.hide()}
   $searchForm.submit(function(){
   if ($query.val() === "") {return false}
   });
   $query.focus(function(){$label.hide()}).blur(function(){
     if ($(this).val() === "") {$label.show()}
   });
   $searchForm.find("label").click(function(){
    $query.focus();
   }); 
// END SEARCHFORM


  if($("#SlideShowContainer").length){

    $("ul.tabs").tabs(".images > div.slide", { 
        effect: 'default', 
        fadeOutSpeed: "slow", 
        rotate: true,
        event: 'mouseover'
    }).slideshow({autoplay: true, interval:5000, clickable: false});

  }

 // OBJECT COMMENTS



  var $comments = jQuery(".comments"); // CACHE
  if ($comments.length) {
	$comments.find(".ajax").each(function(){
	  $comments.load($(this).attr("href"), function(){
            var writeACommentText = jQuery("#writeACommentText") ? jQuery("#writeACommentText").text() : "Skriv en kommentar." ;
            var commentPostedText = jQuery("#commentPostedText") ? jQuery("#commentPostedText").text() : "Kommentaren er lagt til og venter moderering." ;
            var $commentForm = $("#commentForm"); //CACHE
	    if($commentForm.length) {
	      $commentForm.submit(function(event){
	         var $this = $(this), //CACHE
	             $response = $("#objectResponse"),  //CACHE
	             $signature = $this.find("#signature"),  //CACHE
	             $comment = $this.find("#comment"); //CACHE
	         event.preventDefault();
	         if ($comment.val() === "") {
	           $response.text(writeACommentText);
	           $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(commentPostedText);
                     $(".noComments").hide();
	             $comment.removeClass("error").val("");
	           });
	         }
	      });
	    } 
	  });
	});
  } // END COMMENTS


$queryLeft = $(".topLeft input"),
$labelLeft = $queryLeft.prev("label");
if ($queryLeft.val() !== "") {$labelLeft.hide()}
$queryLeft.focus(function(){$labelLeft.hide()}).blur(function(){
  if ($(this).val() === "") {$labelLeft.show()}
});
$labelLeft.click(function(){
 $queryLeft.focus();
}); 
// END topleft 

$queryTextarea = $("textarea"),
$labelTextarea = $queryTextarea.prev("label");
if ($queryTextarea.val() !== "") {$labelTextarea.hide()}
$queryTextarea.focus(function(){$labelTextarea.hide()}).blur(function(){
  if ($(this).val() === "") {$labelTextarea.show()}
});
$labelTextarea.click(function(){
 $queryTextarea.focus();
}); 
// END textarea 

$queryRight = $(".topRight input"),
$labelRight = $queryRight.prev("label");
if ($queryRight.val() !== "") {$labelRight.hide()}
$queryRight.focus(function(){$labelRight.hide()}).blur(function(){
  if ($(this).val() === "") {$labelRight.show()}
});
$labelRight.click(function(){
 $queryRight.focus();
}); 
// END topright 

jQuery("label:contains(comment)").add("label[for=comment]").css({display:'block',clear:'left'});



});
