(function($) {

	function open_in_popup_window(url, name, width, height) {
		window.open(url.href, name,'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
		return false;
	}
	
	function open_in_new_window(url) {
		window.open(url.href, 'external_link', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
		return false;
	}
	
	function pop(url, target, width, height, scrollbars, top, left) {
		var props = '',
		win;
		if (target == null) {
			target = '_blank';
		}
		if (width != null) {
			props += ',width=' + width;
		}
		if (height != null) {
			props += ',height=' + height;
		}
		if (scrollbars != null) {
			props += ',scrollbars=' + scrollbars;
		}
		if (top != null) {
			props += ',top=' + top + ',screenY=' + top;
		}
		if (left != null) {
			props += ',left=' + left + ',screenX=' + left;
		}
		if (props.length) {
			props = 'resizable=1' + props;
		}
		win = window.open(url, target, props);
		win.focus();
		return false;
	}
	
	function goto(loc) {
		window.location.href = '/' + loc;
	}
	
	function emailForm(emailadd, sub) {
		var email = emailadd;
		var subject = sub;
		var mailto_link = 'mailto:' + email + '?subject=' + subject;
	
		var win = window.open(mailto_link, 'emailWindow');
		if (win && win.open && !win.closed) {
			win.close();
		}
	}
	
	function timeCheck(userid, cid, time, duration, start, rowid, self) {
		//"userid=" + userid + "&cid=" + cid + "&time=" + time + "&duration=" + duration + "&start=" + start + "&rowid=" + rowid,
		$.ajax({
			type: 'POST',
			url: '/checkTime.php',
			data: {
				userid: userid,
				cid: cid,
				time: time,
				duration: duration,
				start: start,
				rowid: rowid
			},
			success: function(msg) {
				$(self).parents('p').siblings('.error').html(msg);
			}
		});
	}
	
	function timeCheckReset(){
		$.ajax({
			type: 'POST',
			url: '/checkTime.php',
			data: {
				reset: true
			}
		});
	}
	
	function checkCard(val) {
		var displayMess =  $('#displayMessage');
		if (val === 'Maestro') {
			displayMess.show();
		} else {
			displayMess.hide();
		}
	}
	
	function addtoextradetail(option) {
		var o = $('#workshopdetails');
		// add to textarea extra detail box
		var html = o.html();
		var r = html + '\n' + option;
		$('#workshopdetails').html(r);
	}
	
	function showMoreDetails(id) {
		var obj = $('#' + id);
		if (obj.style.display === "none") {
			obj.show();
		} else {
			obj.hide();
		}
	}
	
	function showOptions(id) {
		$('#' + id).fadeIn('slow');
		return false;
	}
	
	function hideOptions(id) {
		$('#' + id).fadeOut('slow');
		return false;
	}

	$(function () {
	
		timeCheckReset();
	
		var b = $('body, html'),
		page_container = $('.page-container'),
		w = $(window),
		d = $(document),
		popup = $('.popup-container'),
		popup_msg = $('.popup_msg');
	
		$('#cookiecheck-container').css({
			height: d.height(),
			width: d.width()
		}).bind('click', function (event) {
			$('#cookiecheck, #cookiecheck-container').fadeOut();
			event.preventDefault();
		});
	
		popup.css({
			height: d.height(),
			width: d.width()
		}).bind('click', function (event) {
			$('.popup_msg, .popup-container').fadeOut();
			event.preventDefault();
		});
	
		setTimeout(function () {
			popup.hide();
			popup_msg.hide();
		}, 1);
	
		$('.show-details').click(function (event) {
			var i = $(this).index('.show-details');
			popup.eq(i).fadeIn();
			popup_msg.eq(i).fadeIn();
			popup_msg.css({
				top: 20 + w.scrollTop()
			});
			event.preventDefault();
		});
	
		$('.hide-details').bind('click', function (event) {
			$('.popup_msg, .popup-container').fadeOut();
			event.preventDefault();
		});
	
		//Question popup
		$('.question').hover(function() {
			$(this).parents('li, .pageoverflow').find('.question-popup').show();
		}, function() {
			$(this).parents('li, .pageoverflow').find('.question-popup').hide();
		});
	
	});
}(window.jQuery));
