﻿$(function(){

   // Valider betalingsmetode
   $('#payment-method input:eq(0)').attr('checked','checked');

   // Aktiver hovedmenupunktet
   var hostName = window.location.hostname;
   if (hostName=='pixelineshop.dk'||hostName=='www.pixelineshop.dk'||hostName=='pixeline.dk'||hostName=='www.pixeline.dk') {$('#global-menu ul li:eq(0)').addClass('active');};
	
	// Lav runde hjørner diverse elementer
	$("h1,h4,h3,.alert,.success").corner("5px");
	$("legend span").corner("5px tl tr");
	$("#related-column div.box").corner("5px bl br");
	$("ol li:last-child").corner("5px bl br").css('border-top','1px solid #fff');

	// Accepter betingelser 
	$('#accept-check').click(function() {
		if (this.checked) {
			$('#accept-button').removeClass('inactive').attr('href','Default.aspx?ID=606&step=5');
			$('.checkout-button-holder label').animate({ backgroundColor: "white" }, 100)
		} else {
			$('#accept-button').addClass('inactive').removeAttr('href');
		}
	});

	// Accepter betingelser, skolesite 
	$('#accept-check-skole').click(function() {
		if (this.checked) {
			$('#accept-button').removeClass('inactive').attr('href','Default.aspx?ID=762&step=5');
			$('.checkout-button-holder label').animate({ backgroundColor: "white" }, 100)
		} else {
			$('#accept-button').addClass('inactive').removeAttr('href');
		}
	});

$('.niceForm').validate({
	errorElement:'p',
	errorClass: 'fieldError'
});
	
	$('#accept-button').click(function() {
		if (!this.href) {
			$('.checkout-button-holder label').animate({ backgroundColor: "yellow" }, 150)
			.animate({ backgroundColor: "white" }, 150)
			.animate({ backgroundColor: "yellow" }, 150)
			.animate({ backgroundColor: "white" }, 150)
			.animate({ backgroundColor: "yellow" }, 150);
		};
		
	});

   // Pixeline-menu
   $('li.active ul').addClass('show');
   
   $('ul.level0 li').click(function() { 
		$('ul.level0 li').not(this).removeClass('active').children('ul').removeClass('show');
		$(this).toggleClass('active');
		$(this).children('ul').toggleClass('show');
	 });

	// Billedskifter til produktsider
	var extraImg = $(".product-thumbs li").length;
	var extraImgLink = $("#product-image img").attr("src");
	if (extraImgLink) {
		extraImgLink = extraImgLink.replace("medium","small");
	}
	if (extraImg!=0) {
		$(".product-thumbs ul").prepend("<li><img class='active' src='"+extraImgLink+"' width='47' height='47' alt='' /></li>");
	}
	$(".product-thumbs img").click(function() {
		var imgSrc = $(this).attr("src");
		mediumSrc = imgSrc.replace("small","medium");
		largeSrc = imgSrc.replace("small","large");
		$('#product-image img').attr('src',mediumSrc);
		$('#product-image a').attr('href',largeSrc);
		$(".product-thumbs img").removeClass("active");
		//$(".product-thumbs img").fadeTo("fast", 1);
		//$(this).fadeTo("fast", 0.5);
		$(this).addClass("active");
	 });

	// Fjern sektionsoverskriften, når vi er inde i shoppen
	var isShop = $(document).getUrlParam("ProductID");
	if (isShop) {$('.section-header, .column').css('display','none')};


	 $('#andenModtager2').click( 
	 	function() { 
		$('#andenModtagerFields').slideDown("fast");
	} );
	
	$('#andenModtager1').click( 
	 	function() { 
		$('#andenModtagerFields').slideUp("fast");
		$('#andenModtagerFields input').attr("value","");
	} );
	
	$('.niceForm input,.niceForm textarea')
	.focus( function() {
		$(this).parent('li').addClass('highlight');
	})
	.blur( function() {
		$(this).parent('li').removeClass('highlight');
	});



// Hover-td
	$(".cart-overview tbody tr").hover(function(){
		$(this).addClass("highlight");
	},function(){
		$(this).removeClass("highlight");
	});

// Sys-req 

   $('.req-link').click( function() {

   $('#product-requirements').slideToggle('fast');
      $(this).toggleClass('minus');
   });


$("#submitForm").click( function() { 
  $(this).parents("form").submit();
  return false;
});



$("#payment-method :checked").parent("label").parent("li").addClass("highlight2");
$("#payment-method :radio").click( function() {
   $('#payment-method :radio').not(this).parent("label").parent("li").removeClass("highlight2");
   $(this).parent("label").parent("li").addClass("highlight2");
});


});