﻿$(function() {
	
	$("a.external").bind("click", function() {
		
		window.open($(this).attr('href'));
		return false;
		
	});
	
	$("div.pop")
	.css('cursor','pointer')
	.bind('click', function() {
		location.href = $(this).find('a.popLink').attr('href');	
	});
	
	
	
	// jQuery.each($(".pop"), function() {
		
		// var scHeight = $(this).find('div p').height();
		// var marginTop = $(this).find('div p').css('marginTop');
		// var marginBottom = $(this).find('div p').css('marginBottom');
		// marginTop = parseInt(marginTop.replace('px',''));
		// marginBottom = parseInt(marginBottom.replace('px',''));
		// scHeight += marginTop + marginBottom;
		// $(this).find('img').hover(
			
			// function(){
				// $(this).parent().find('div.bgTxt').animate(
					// { 'top' : '-' + scHeight + 'px'},
					// { duration: 500 }
				// );
			// },
			// function(){
				// $(this).parent().find('div.bgTxt').animate(
					// { 'top' : '-7px'},
					// { duration: 500 }
				// );
			// }
		
		// );
	// });	
	
	if($("form.dynForm").length>0) {
		init_dynForms();
	}
	
	
	//traverse active
	jQuery.each($(".menu .active"), function() {
		$($(this).parent("ul").parents("li:eq(0)")).parent("ul").parents("li:eq(0)").addClass("active");
		$(this).parent("ul").parents("li:eq(0)").addClass("active");

	});
	$("ul.dropdown li").bind("click", function() {
		var linkObj = $(this).find("a");
		if($(linkObj).attr('href')!="") {
			if($(linkObj).hasClass('external')) {
				window.open($(linkObj).attr('href'));
			} else {
				document.location.href = $(linkObj).attr('href');
			}
		}
	
	});
	

	// gallery start
	if($("div.gal").length>0) {
		
		$("#gal_switch_label").html(fLang.m.gal.switchView);
		
		// gallery type 1
		$("div.gal img").css("opacity",0.8);
		$("div.gal img").hover(
			function() { $(this).stop().animate({ 'opacity' : 1}, 300); },
			function() { $(this).stop().animate({ 'opacity' : 0.8}, 300); }
		);
		
		// init images

		$.fn.colorbox.settings.transition = "fade";
		$.fn.colorbox.settings.bgOpacity = "0.8";
		$.fn.colorbox.settings.contentCurrent = fLang.m.gal.imageCurrentOutOfTotal;
		$("div.gal a").colorbox();		

		// switch view		
		$("a.switch_thumb").toggle(
			function(){
				$(this).addClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}, 
			function () {
				$(this).removeClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}
		); 
	}

	$(".lavaLamp").lavaLamp({ fx: "easeOutQuad", speed: 700 });

	
});﻿

function init_dynForms() {
	jQuery.each($("form.dynForm div.dyn"), function() {
		var parentForm = $(this).parent('form');
		
		var this_id = $(this).attr('id');
		var this_name = $(this).html();
		var this_type = $(this).attr('class').replace(/dyn /ig,"");
		
		var new_input = $("<input type=\"" + this_type + "\" name=\"" + this_name + "\" id=\"" + this_id + "\" />");

		$(parentForm).append(new_input);
		$(this).remove();
	});
	$("#fSend").bind('click', function() {
		if($("#fName").val()!=""&&$("#fPhone").val()!="") {
			$(this).parent('form').submit();
		} else {
			alert("Udfyld venligst navn og telefonnummer!");
		}
	});

}

function activate_menus() {
	// activate hover
	$("ul.menu li").hover(
		function() {
			$(this).addClass('over');
			$(this).find('a').css('color','#000');
		},
		function() {
			$(this).removeClass('over');
			$(this).find('a').css('color','#fff');
		}
	);
	$("ul.menu li").bind('click', function() {
		document.location.href = $(this).find('a').attr('href');
		return false;
	});
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

