Panagora.Site = new (Panagora.Class.create(
/** @lends Panagora.Site */
function Site() {

	/* Private variables
	 ********************/

	var self = this;
	var validator;
	var submitting = false;
	
	this.mouseX = 0;
	this.mouseY = 0;
	
	function init() {
		$j(document).mousedown(getMouseCoords);

		$j(document).ajaxStart(function () { 
			$j('body').addClass('waiting'); 
			$j('#ajax-loader').css('left', (document.body.offsetWidth - $j('#ajax-loader').width()) / 2);
		}).ajaxStop(function () { 
			$j('body').removeClass('waiting'); 
		});

		$j("#cs-country-modal").fancybox({
			hideOnContentClick: false,
			hideOnOverlayClick: true,
			overlayShow: true,
			centerOnScroll: true,
			padding: 20,
			autoDimensions: false,
			width: 400,
			height: 100
		});
		$j("#newsletter-signup-href").fancybox({
			hideOnContentClick: false,
			hideOnOverlayClick: true,
			overlayShow: true,
			centerOnScroll: true,
			autoDimensions: true,
			padding: 20,
			href: document.getElementById('newsletter-signup-href').href + '?skip_layout=1'
		});

		$j('#search-input').focus(function(){
			if (this.value == this.defaultValue || this.value == '')
				this.value = '';
		});
		$j('#search-input').blur(function(){
			if (this.value == this.defaultValue || this.value == '')
				this.value = this.defaultValue;
		});
	
	}
	
	function getMouseCoords(e) {
		self.mouseX = e.pageX;
		self.mouseY = e.pageY;
	}

	this.updateCartSubmitButton = function _updateCartSubmitButton(willRedirect) {
		if (willRedirect)
			$j('#process-order').addClass('redirect').removeClass('process');
		else 
			$j('#process-order').addClass('process').removeClass('redirect');
	}

	Panagora.ready(init);

}))();

Panagora.errorAlert = function _errorAlert(message) {
	Panagora.alert(message, true);
}

Panagora.alert = function _alert(message, error) {
	var str = Panagora.applyConstants(message);
	
	var noticeTimeout;
	
	var className = error ? "popup-notice error" : "popup-notice";
	
	var notice = $j('<div class="' + className + '"></div>')
		.text(str)
		.css({position: 'absolute', left: Panagora.Site.mouseX + 'px', top: Panagora.Site.mouseY + 'px'})
		.appendTo($j(document.body));

	function startHideNotice() {
		noticeTimeout = setTimeout(hideNotice, 1500);
		$j(document).unbind('mousemove', startHideNotice);
	}
	
	function hideNotice() {
		notice.fadeOut('fast', onNoticeHidden);
	}
	
	function onNoticeHidden() {
		notice.remove();
	}
		
	$j(document).mousemove(startHideNotice);
}