// JavaScript Document

function doPositionFixed() {
	// Checks for IE6
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	if(IE6) {
		// Fix height of semi transparent mask (leave yes/no box)
		$("div#popup_mask").css("height", $(window).height() + "px");
		// Add scroll event to make sure popup and mask stay in centre of screen
		$(window).scroll(function() {
			$("div#popup_mask").css("top", $(window).scrollTop() + "px");
			
		});
	} else {
		// Make position fixed for newer browsers
		$('.fixed').css('position','fixed');	
	}		
}


function customConfirm(yes_callback, no_callback, message) {
	var no_callback=no_callback ? no_callback : null;
	// Get target of link
	var target=$(this).attr('href');
	var message=message ? message : 'Are you sure you want to do this?';
	var popup='<div id="popup_mask" class="fixed"></div><div id="popup" class="fixed"><div id="popup_inner"><h3>'+message+'</h3><div class="popup_buttons"><a class="link_button" id="popup_yes">Yes</a> <a class="link_button" id="popup_no">No</a></div></div></div>';
	$('body').append(popup);
	// Call our function to replace headings etc with nicer font		
	
	// Call our function to emulate position fixed for any popups etc
	doPositionFixed();
	// Add href attribute to yes button
	$('#popup_yes').click(function() {
		$('#popup_mask, #popup').remove();
		if(yes_callback) {
			yes_callback();
		}
	});
	// Add href attribute to no button
	$('#popup_no').click(function() {
		$('#popup_mask, #popup').remove();
		if(no_callback) {
			no_callback();
		}
	});
}


$().ready(function() {
	// Custom warning popup box for links with class 'warn_link'
	$('.warn_link').click(function() {
		// Get target of link
		var linkTarget=$(this).attr('href');
		customConfirm(
			function() {
				window.location=linkTarget;
			},
			function() {
				return false;
			},
			'Are you sure you want to do this?'
		);
		return false;
	});
	
});