$(document).ready(function() {
	Cufon.replace('.HelveticaNeueLTStd-Lt');
    Cufon.replace('.HelveticaNeueLTStd-Md');
    
/*Spotbox slide start*/

$("div.spotBoxSlide").hover(
  function () {
  $(".spotBoxSlideImage",this).animate({"top": "-=28px"}, "slow");
   $("h1.spotBoxHeader",this).animate({"top": "-=28px"}, "slow");
   $(".spotBoxSlideHolder",this).animate({"top": "-=91px"}, "slow");
  },
  function () {
	$(".spotBoxSlideImage",this).animate({"top": "+=28px"}, "slow");    
    $("h1.spotBoxHeader",this).animate({"top": "+=28px"}, "slow");
     $(".spotBoxSlideHolder",this).animate({"top": "+=91px"}, "slow");
  });

/*Spotbox slide end*/    

/* Institution chooser start */
$(".chooserMenu").click(function(){

var marginCheck = $(".institutionChooser").css('margin-top');
if(marginCheck == "-120px")
{
	$(".institutionChooser").animate({"marginTop": "0px"}, {duration: 800, easing: "easeOutQuart"});
}
else
{
	 $(".institutionChooser").animate({"marginTop": "-120px"}, {duration: 800, easing: "easeOutQuart"});
}

});

$(".institutionSelecter").clone().appendTo("#SelecterBackup");

 $("select.typeSelecter").change(function()
   {
     var str ="";
 
 
		 /*CLONE*/
	    $("#institutionSelecterHolder .institutionSelecter").remove();
		$("#SelecterBackup .institutionSelecter").clone().change(function() { 
			  $("#institutionSelecterHolder select.institutionSelecter option:selected").each(function()
				 {
					 url = $(this).attr("value");
					/*location = url;*/ 
					
					window.open( url, "win");
				 });
		}).appendTo("#institutionSelecterHolder");
		

     $("select.typeSelecter option:selected").each(function()
     {
		 str = $(this).val();
		 if(str !="")
		 {
			 $("#institutionSelecterHolder select.institutionSelecter").removeAttr("disabled");
				
				/*Reset*/
				/* $("#institutionSelecterHolder select.institutionSelecter option").hide();*/
				 
				/*Selecter*/	 
				 $("#institutionSelecterHolder select.institutionSelecter option").each(function()
					 {
						 var refName = $(this).attr("ref");
						 
						 if(refName == str || refName == "selectinstitution"){ 
							 $(this).show();
							 }
						 else
						 {
							 $(this).remove();
						 }
					 });
	 	 }
	 	 else
	 	 {
			 $("#institutionSelecterHolder select.institutionSelecter").attr("disabled","disabled");
	 	 }
     });

   }); 
  	   

/* Institution chooser end */


    
	$(".tabs").tabs();
	$("div#topBanner").cycle({
		startingSlide: 0,
		timeout: 6000,
		pause: 1,
		random: 0
	});
	$("div#mostVisited").bind("mouseover", function() {
        $(this).addClass("mostVisitedCloudHover");
    }).bind("mouseout", function() {
        $(this).removeClass("mostVisitedCloudHover");
    });
    $("div#breadCrumbs").bind("mouseover", function() {
        $(this).addClass("breadCrumbsHover");
    }).bind("mouseout", function() {
        $(this).removeClass("breadCrumbsHover");
    });
	$('#eventCalendarMonth').jqueryCal({
        xmlPath: '',
		noEvents: '&nbsp;',
		noEventsToday: '&nbsp;',
		monthText: '',
		getXMLmonthly: true,
		toolTipBigPrev: "",
		toolTipSmallPrev: "Forrige m&aring;ned",
		toolTipSmallNext: "N&aelig;ste m&aring;ned",
		toolTipBigNext: ""
    });
	$("form").bind("submit", function() {
		$(".inputText input[type=text]", $(this)).focus();
	});
    $(".inputText input[type=text]").bind("focus", focusContent).bind("blur", blurContent).blur();
    function focusContent() {
        var _me = $(this);
        if (_me.attr("value") == _me.attr("title")) {
            _me.attr("value", "");
            _me.removeClass("watermark");
        }
    };
    function blurContent() {
        var _me = $(this);
        if (_me.attr("value").replace(/\s/g, "") == "") {
            _me.attr("value", _me.attr("title"));
            _me.addClass("watermark");
        }
        else {
			_me.removeClass("watermark");
        };
    };
	$("select.select").selectbox({
		inputClass: 'selectbox',
        containerClass: 'selectbox-wrapper',
        hoverClass: 'current',
        currentClass: 'selected',
        debug: false
    });
	$("div.pageIndex").accordion({
		active: ".pageIndexSelected",
		autoHeight: false,
		collapsible: true
	});
	$("ul.sitemap").treeview({
		collapsed: true,
		animated: "medium",
		prerendered: false
	});
	$("div.gallery a.thumb").each(function(index) {
		$(this).fancybox({
			frameWidth: 800,
			frameHeight: 640,
			overlayColor: "#fff",
			overlayOpacity: 0.8,
			hideOnContentClick: false,
			callbackOnShow: function() {
				//$("#fancy_close").css("display", "block");
				//$("#fancy_div div.slides").css("display", "block");
				$("#fancy_div div.slides div.controls").css("display", "block");
				$("#fancy_div div.slides div.controls div.buttons a.pause").bind("click", function(e) {
					$("#fancy_div div.slides").cycle("pause");
					$("#fancy_div div.slides div.controls div.buttons a.play").css("display", "block");
					$(this).css("display", "none");
				});
				$("#fancy_div div.slides div.controls div.buttons a.play").bind("click", function(e) {
					$("#fancy_div div.slides").cycle("resume");
					$("#fancy_div div.slides div.controls div.buttons a.pause").css("display", "block");
					$(this).css("display", "none");
				});
				$("#fancy_div div.slides div.controls div.buttons a.start").bind("click", function(e) {
					$("#fancy_div div.slides").cycle(0);
					$("#fancy_div div.slides").cycle("pause");
					$("#fancy_div div.slides div.controls div.buttons a.play").css("display", "block");
					$("#fancy_div div.slides div.controls div.buttons a.pause").css("display", "none");
				});
				$("#fancy_div div.slides div.controls div.buttons a.end").bind("click", function(e) {
					$("#fancy_div div.slides").cycle($("#fancy_div div.slides div.slide").size() - 1);
					$("#fancy_div div.slides").cycle("pause");
					$("#fancy_div div.slides div.controls div.buttons a.play").css("display", "block");
					$("#fancy_div div.slides div.controls div.buttons a.pause").css("display", "none");
				});
				$("#fancy_inner").bind("mouseenter", function(e) {
					$("#fancy_div div.slides div.controls").css("display", "block");
					$("#fancy_close").css("display", "block");
				});
				$("#fancy_inner").bind("mouseleave", function(e) {
					$("#fancy_div div.slides div.controls").css("display", "none");
					$("#fancy_close").css("display", "none");
				});
				$("#fancy_div div.slides").cycle({
					startingSlide: index,
					slideExpr: ".slide",
					next: $("#fancy_div div.slides div.controls div.buttons a.next"),
					prev: $("#fancy_div div.slides div.controls div.buttons a.prev"),
					prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement) {
						$("#fancy_div div.slides").cycle("pause");
						$("#fancy_div div.slides div.controls div.buttons a.play").css("display", "inline-block");
						$("#fancy_div div.slides div.controls div.buttons a.pause").css("display", "none");
					},
					before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
						if ($(currSlideElement).parents("body").size() == 0) {
							$(currSlideElement).parents("div.slides").cycle("stop");
						}
						else {
							$("#fancy_div div.slides div.controls div.links a.link").attr("href", $("img", nextSlideElement).attr("src"));
							$("#fancy_div div.slides div.controls div.links a.send").attr(
								"href",
								"mailto:?subject=Billede&body=" + document.location.protocol + "//" + document.location.host + $("img", nextSlideElement).attr("src")
							);
						};
					}
				});
			}
		});
	});
});