$(document).ready(function() {
	
	



	
////////////////////////
//Featured Posts Slide//
////////////////////////

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageHeight = $(".window").height();
	var imageSum = $(".image_reel img").size();
	var imageReelHeight = imageHeight * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'height' : imageReelHeight});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageHeight; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			top: -image_reelPosition
		}, 1500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 10000); //Timer speed in milliseconds (5 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});
	
	
//////////////////////
//Newsletter Flipper//
//////////////////////

$("#pageflip").hover(function() { //On hover...
	$("#pageflip img, .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '90px',
			height: '94px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '90px',
			height: '90px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});

/////////////////
//Child Borders//
/////////////////




$('ul.childnav-content li:first').addClass('first-menu-item');
$('ul.childnav-content li:last').addClass('last-menu-item');
$('ul.childnav-content li:odd').addClass('odd-menu-item');
$('ul.childnav-content li:even').addClass('even-menu-item');


/////////////////////////////////
//Opacity on different elements//
/////////////////////////////////





$('.paging').fadeTo('slow', 0.5);

$('#s, #searchsubmit, #facebooklink, .qtrans_flag_no, .qtrans_flag_en, .mp3').fadeTo('slow', 0.5);
$('#s, #searchsubmit, #facebooklink, .qtrans_flag_no, .qtrans_flag_en, .mp3').hover(function(){
	$(this).stop().fadeTo('slow', 1);
	},function(){
	$(this).stop().fadeTo('slow', 0.5);
});





//Dato knapp til skjema på norsk//
$('.dato_knapp').datepicker({ 
	showOn: 'both',
	monthNames: ['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'],
	monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'],
	dayNames: ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag'],
	dayNamesMin: ['Søn','Man','Tirs','Ons','Tors','Fre','Lør'],
	dayNamesSort: ['Søn','Man','Tirs','Ons','Tors','Fre','Lør'],
	firstDay: '1',
	buttonText: 'Velg en dato', 
	buttonImage: 'http://www.spahotellvelvare.no/wp-content/themes/spa2/js/jquery_ui_images/calendar.png', 
	buttonImageOnly: true, 
	navigationAsDateFormat: true,
	prevText: 'forrige',
	nextText: 'neste',
	dateFormat: 'dd.mm.yy',
	goToCurrent: 'true',
	weekHeader: 'Uke',
	showWeek: 'true'
});




//Dato knapp til skjema på engelsk//
$('.date_button').datepicker({ 
	showOn: 'both',
	firstDay: '1',
	buttonText: 'Pick a date', 
	buttonImage: 'http://www.spahotellvelvare.no/wp-content/themes/spa2/js/jquery_ui_images/calendar.png', 
	buttonImageOnly: true, 
	navigationAsDateFormat: true,
	dateFormat: 'dd.mm.yy',
	goToCurrent: 'true',
	weekHeader: 'Week',
	showWeek: 'true'
});





$('#frontslide').cycle({ 
    fx: 'fade', 
    speed: 2000, 
    timeout: 5000, 
    delay: 1000
});





$('#footerbilder').cycle({ 
    fx: 'fade', 
    speed: 2000, 
    timeout: 10000
});




$(".mp3").jmp3();





});