$(document).ready(function() {

	// open external links in a new window. These links must be marked with the rel attribute.

	$("a[rel=external]").click(function() {
		window.open(this.href);
		return false;
	});
	
	$("#featured .next, #featured .prev").delay(499).fadeTo(1000, 0.4).hover(function() {
		$(this).stop().fadeTo(300, 0.67);
	}, function() {
		$(this).stop().fadeTo(800, 0.4);
	});
	
	$("#featured .slideshow").cycle({
		fx: "scrollHorz",
		timeout: 10000,
		next: ".next",
		prev: ".prev"
	});
	
	var grid = $("<div />").addClass("grid");
	$(document).bind("keyup", function(e) {
		//console.log(e.keyCode);
		if(e.keyCode==71 && e.metaKey) {
			if($(".grid").length) {
				$(".grid").remove();
			}
			else {
				$("body").prepend(grid);
			}
		}
	});

	// dibs payment page:
		
	$(".popup-terms").click(function(){
		var newwin=window.open(this.href,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=450');
		newwin.focus();
		return false;
	});

});
		
function paymentPopup(frm) {
	if(frm.orderid.value.length < 2) {
		alert('Du måste ange ett fakturanummer.');
		frm.orderid.focus();
		return false;
	} else if(frm.amount.value.length < 2) {
		alert('Du måste ange ett belopp.');
		frm.amount.focus();
		return false;
	} else if(frm.terms.checked == false) {
		alert('Du måste godkänna villkoren.');
		frm.terms.focus();
		return false;
	} else {
		var newwin = window.open('', 'paywin', 'status=yes,menubar=no,scrollbars=yes,resizable=yes,width=550,height=600');
		newwin.focus();
		return true;
	}
}

