$(document).ready(function() {
// Top Navigation
$('.topdrop').hide();
$('.drift a').click(function() {
        $('.topdrop').slideToggle('fast');
});


// Remove pipe on last link.
$('#prtf .mdl .postlinks a:last').removeClass('pipe');

// First page news animation
$('.flt3lft > .listentry:gt(0)').hide();

$('.flt3lft > .heading').click(function() {
	$(this).next('.listentry:hidden').slideDown('fast').siblings('.listentry:visible').slideUp('fast');
});


// Imagebox
$("a[rel^='fancybox']").fancybox({
	'hideOnContentClick' : true,
	'centerOnScroll' : true,
	'zoomSpeedIn' : 600,
	'zoomSpeedOut' : 600,
	'overlayShow' : true,
	'overlayOpacity' : 0.9
});

$("a.jqpost").fancybox({
	'hideOnContentClick' : false,
	'centerOnScroll' : true,
	'zoomSpeedIn' : 300,
	'zoomSpeedOut' : 300,
	'overlayShow' : true,
	'overlayOpacity' : 0.9,
	'frameWidth' : 400,
	'frameHeight' : 450
});

$("a.jqinfo").fancybox({
	'hideOnContentClick' : false,
	'centerOnScroll' : true,
	'zoomSpeedIn' : 300,
	'zoomSpeedOut' : 300,
	'overlayShow' : true,
	'overlayOpacity' : 0.9,
	'frameWidth' : 450,
	'frameHeight' : 575
});


// Portfolio shading/unshading

// Hide and show web only
$('#prtf .top .trykktext, #prtf .top .lydtext ').addClass('lightshaded');
$('#prtf .btm .trykk, #prtf .btm .lyd, #prtf .btm .trykklyd').next().addClass('darkshaded');

// Focus on web
$('#prtf .weblink').click(function() {
	$('.btm .web, .btm .webtrykk, .btm .trykkweb, .btm .weblyd, .btm .lydweb, .btm .webtrykklyd, .btm .trykkweblyd, .btm .weblydtrykk,	.btm .lydwebtrykk, .btm .trykklydweb, .btm .lydtrykkweb').next().removeClass('darkshaded');

	$('.top .webtext').removeClass('lightshaded');
	$('.top .trykktext, #prtf .top .lydtext').addClass('lightshaded');
	$('.btm .trykk, .btm .lyd, .btm .trykklyd, .btm .lydtrykk').next().addClass('darkshaded');
		});

// Focus on trykk
$('#prtf .trykklink').click(function() {
	$('.btm .trykk, .btm .trykkweb, .btm .webtrykk, .btm .trykklyd, .btm .lydtrykk, .btm .trykklydweb, .btm .trykkweblyd, .btm .webtrykklyd, .btm .lydtrykkweb, .btm .weblydtrykk, .btm .lydwebtrykk').next().removeClass('darkshaded');

	$('.top .trykktext').removeClass('lightshaded');
	$('.top .webtext, .top .lydtext').addClass('lightshaded');
	$('.btm .web, .btm .lyd, .btm .weblyd, .btm .lydweb').next().addClass('darkshaded');
		});

// Focus on lyd
$('#prtf .lydlink').click(function() {
	$('.btm .lyd, .btm .lydweb, .btm .weblyd, .btm .lydtrykk, .btm .trykklyd, .btm .lydtrykkweb, .btm .trykklydweb, .btm .trykkweblyd, .btm .webtrykklyd, .btm .lydwebtrykk, .btm .trykkweblyd').next().removeClass('darkshaded');

	$('.top .lydtext').removeClass('lightshaded');
	$('.top .webtext, .top .trykktext').addClass('lightshaded');
	$('.btm .web, .btm .trykk, .btm .webtrykk, .btm .trykkweb').next().addClass('darkshaded');
		});


// FORMS
// Show/Hide extra options
$('#antalleposter, #antallsider, #live, #studio, #webspec, #trykkspec, #lydspec').hide();

$('#epostkonto').click(function() {
	$('#antalleposter').slideToggle('fast');
		});

$('#flersidestrykk').click(function() {
	$('#antallsider').slideToggle('fast');
		});

$('#preprod').click(function() {
	$('#live, #studio').slideToggle('fast');
		});



// Add red class
//$('#webannet .box:checkbox').click(function() {
//	if ($('#webannet:checked')) {
//		$('#tilleggsinformasjon .fieldtitle').removeClass('gray');
//	} else if ($('#webannet')) {
//		$('#tileggsinformasjon .fieldtitle').addClass('gray');
//	} else {
//	}
//});

//$('#trykkannet .box:checkbox').click(function() {
//	$('#tilleggsinformasjon .fieldtitle').toggleClass('red');
//		});

//$('#lydannet .box:checkbox').click(function() {
//	$('#tilleggsinformasjon .fieldtitle').toggleClass('red');
//		});


// Form validation and submission

// Hide the errormessage
$('#formerror').hide();

// Validate form on tjenester
$("#tnstform").validate( {
	errorLabelContainer: "#formerror",
	wrapper: "p",
	rules: {
		navn: {required: true},
		firma: {rangelength:[2,50]},
		epost: {required: true, email: true},
		telefon: {number: true, minlength: 8, maxlength: 8}
	},
	messages: {
		navn: {required: "Vennligst fyll inn ditt navn."},
		epost: {required: "Vennligst fyll inn en valid e-post addresse."}

	}
});

// prepare Options Object 
var tnstform = options = {
  resetForm: true,
  success: function() { 
  alert('Takk for din forespørsel, vi vil ta kontakt med deg.'); 
  }
};

// bind to kontakt submit event 
$("#tnstform").ajaxForm(options);


// Validate form on kontakt
$("#kntktform").validate( {
    errorLabelContainer: "#formerror",
        wrapper: "p",
        rules: {
		navn: {required: true},
		firma: {rangelength: [2,50]},
		epost: {email: true},
		telefon: {number: true, minlength: 8, maxlength: 8}
	},
	messages: {
		navn: {required: "Vennligst fyll inn ditt navn."}
	}
});

// prepare Options Object 
var kntktform = options = {
  resetForm: true,
  success: function() { 
  alert('Takk for din tilbakemelding.'); 
  }
};

// bind to kontakt submit event 
$("#kntktform").ajaxForm(options);

}); // The End

