$(document).ready(function(){
	
	var fieldquote = null;
	
	// Tab selection:
	$('div.tabs ul li', this).hover(function(){
		
	});
	
	// Contact page slideshow:
	$("div#contactTabs ul").tabs("div#contactSlider div.panel", {
		effect: 'fade',
		fadeInSpeed: "slow",
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		clickable: false
	});

	// Manual slideshow:
	$('div#ctTabs ul li', this).click(function(){
		var panelID = $(this).attr('data-id');
		if (!$(this).hasClass('current')){
			$('div.panel').each(function(){
				if ($(this).attr('data-id') == panelID){
					$(this).fadeIn('slow');
				} else {
					$(this).fadeOut('slow');
				}
			});
		$(this).addClass('current');
		$(this).siblings().removeClass('current');
		} else {
			return false;
		}
	}); //.filter(':first').trigger('click');
	
	// Create random int:
	var randInt = Math.floor(Math.random() * $('div#ctTabs ul li').length) + 1;
	
	// Click random tab at start:
	$('div#ctTabs ul li').each(function(){
		if ($(this).attr('data-id') == randInt){
			$(this).trigger('click');
		}
	});
	
	// Slideshow:
	$('#panels').nivoSlider({
		effect:'fade',
		slices:1,
		animSpeed:1000,
 		pauseTime:5000,
 		startSlide:0,
 		directionNav:false
	});
	
	// Input effect - Focus:
	$(".field", this).focus(function(){
		fieldquote = $(this).attr("data-text");
		
		if ($(this).attr("value") == fieldquote){
			$(this).attr("value", "");
		}
	});
	
	// Input effect - Blur:
	$(".field", this).blur(function(){
		if ($(this).attr("value") == "" || $(this).attr("value") == " "){
			$(this).attr("value", fieldquote);
		}
	});
	
	// Newsletter AJAX:
	/*$('.prenumeration').click(function(e){
		$.ajax({
			type: "POST",
			url: "newsletter.php",
			data: ({
				fornamn : $('input[name=fornamn]').val(),
				efternamn : $('input[name=efternamn]').val(),
				email : $('input[name=email]').val()
			}),
			success: function(msg) {
				alert(msg);
			}
		});
		
		e.preventDefault();
	});*/
	
	// Accordion:
	$(".information").accordion({
		autoHeight: false
	});
	
	// Set member display:
	var length = $("#personal div.person").length;
	
	var ran = Math.floor(Math.random()*length) + 1;
	
	//var firstContact = $('#personal div.person:first');
	var firstContact = $("#personal div.person:nth-child(" + ran + ")");
	$('h1.title').html('<img src="img/titles/personal/' + firstContact.attr('data-id') + '.png" alt="' + firstContact.attr('data-name') + '" />');
	$('img.image').attr('src', 'img/kontakt/kontakt_' + firstContact.attr('data-id') + '_big.png');
	$('p.role').html(firstContact.attr('data-role'));
	$('a.email').html(firstContact.attr('data-email'));
	$('a.email').attr('href', 'mailto:' + firstContact.attr('data-email'));
	$('input.reciever').attr('value', firstContact.attr('data-email'));
	$('div.title p.person').html('Skicka till ' + firstContact.attr('data-email'));
	
	
	// Staff members:
	$('#personal div.person', this).hover(function(){
		
		// Fade out all:
		$('div.person').css({
			opacity: 0.5
		});
			
		// Highlight current:
		$(this).css({
			opacity: 1.0
		});
		
	}, function(){
		$('div.person').css({ opacity: 1.0 });
	});
	
	// Staff members - onClick:
	$('#personal div.person', this).click(function(){
		
		// Replace info:
		$('#content div.left h1.title').html('<img src="img/titles/personal/' + $(this).attr('data-id') + '.png" alt="' + $(this).attr('data-name') + '" />');
		$('#content div.left img.image').attr('src', 'img/kontakt/kontakt_' + $(this).attr('data-id') + '_big.png');
		$('#content div.left p.role').html($(this).attr('data-role'));
		$('a.email').html($(this).attr('data-email'));
		$('a.email').attr('href', 'mailto:' + $(this).attr('data-email'));
		$('input.reciever').attr('value', $(this).attr('data-email'));
		$('div.title p').html('Skicka till ' + $(this).attr('data-email'));
		
	});
	
});
