$(document).ready(function(){

	// Fancybox
	$("#movie").fancybox();

	// Language-selector
	$(".languages a").fadeTo(0, 0.3);
	$(".languages a").hover(function(){
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	}, function() {
		$(this).stop().animate({opacity:0.3},{queue:false,duration:300});
	});
	
	$("a.dansk.da").fadeTo(0, 1.0);
	$("a.dansk.da").hover(function(){
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	}, function() {
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	});

	$("a.deutsch.de").fadeTo(0, 1.0);
	$("a.deutsch.de").hover(function(){
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	}, function() {
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	});

	$("a.english.en").fadeTo(0, 1.0);
	$("a.english.en").hover(function(){
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	}, function() {
		$(this).stop().animate({opacity:1.0},{queue:false,duration:300});
	});

	// Dropdown Menu
	$('.dropdown').each(function () {
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
				var current = $('.dropdown:eq(0)', this);
				current.slideDown(500);
			},
			out: function () {
				var current = $('.dropdown:eq(0)', this);
				current.fadeOut(500);
			}
		});
	});
	
	$('.dropdown a').hover(function () {
		$(this).stop(true).animate({paddingLeft: '35px'}, {speed: 100, easing: 'easeOutBack'});
	}, function () {
		$(this).stop(true).animate({paddingLeft: '15px'}, {speed: 100, easing: 'easeOutBounce'});
	});
	$('.dropdown li.button1 a').hover(function () {
		$(this).stop(true).animate({paddingLeft: '35px'}, {speed: 100, easing: 'easeOutBack'});
	}, function () {
		$(this).stop(true).animate({paddingLeft: '35px'}, {speed: 100, easing: 'easeOutBounce'});
	});
	
	$('#menu').find('ul').each(function (){
		if ($.trim($(this).text()) == ""){
			$(this).remove();
		}
	});

	// Banner Rotator
	$('.commercial').appendTo('#bannerad');
	$('#slides').appendTo('#topbanner');
	$('#slides').slides({
		preload: true,
		preloadImage: '../img/loading.gif',
		play: 7500,
		pause: 2500,
		hoverPause: true,
		effect: 'fade'
	});
	
	// Galleri
	$('div.navigation').css({'width' : '320px', 'float' : 'left'});
	$('div.content').css('display', 'block');

	// Initially set opacity on thumbs and add
	// additional styling for hover effect on thumbs
	var onMouseOutOpacity = 0.67;
	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
				
	// Initialize Advanced Galleriffic Gallery
	var gallery = $('#thumbs').galleriffic({
		delay:                     2500,
		numThumbs:                 15,
		preloadAhead:              10,
		enableTopPager:            true,
		enableBottomPager:         true,
		maxPagesToShow:            7,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '#controls',
		captionContainerSel:       '#caption',
		loadingContainerSel:       '#loading',
		renderSSControls:          true,
		renderNavControls:         true,
		playLinkText:              'Play Slideshow',
		pauseLinkText:             'Pause Slideshow',
		prevLinkText:              '&lsaquo; Forrige Billede',
		nextLinkText:              'Nęste Billede &rsaquo;',
		nextPageLinkText:          'Nęste &rsaquo;',
		prevPageLinkText:          '&lsaquo; Forrige',
		enableHistory:             false,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			this.find('ul.thumbs').children()
			.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});
	
});
