(function($) {
	
	function openBox(url) {
		var container = $('.overlay')
			, params = {
				'ajax': 'true'
			};
		closeOverlay();
		$.get(url, params, function(response) {
			container
				.html(closeButton() + response)
				.center();
			container.find('.close').click(function() {
				closeOverlay();
			});
			openOverlay(function() {
				$(window).trigger('ajaxed');
			});
		});
		
		function openOverlay(callback) {
			container.slideDown('fast', callback);
		}
		
		function closeOverlay() {
			container.slideUp('slow');
		}
		
		function closeButton() {
			return '<div class="close"></div>';
		}
	}
	
	$(document).ready(function() {
		$('body').placeholding();
		
		$('a[rel=overlay]').click(function(event) {
			openBox($(this).attr('href'));
			event.preventDefault();
			return false;
		});
		
		$('.paging').center(false, 'x', {'x': 50})
			.css('visibility', 'visible');
		
		$('.facebook').click(function(event) {
			window.open($(this).attr('href'));
			event.preventDefault();
			return false;
		});
		
		/**
			Detect IE 6
		*/
		if($.browser.msie && $.browser.version.substr(0, 1) < 7) {
			alert("This site is not supported by the Explorer 6 version."
				+ "\nIt is advisable to upgrade your Explorer version to edition 7 and above."
				+ "\nאתר זה אינו נתמך על ידי גרסה של אקפלורר."
				+ "\nמומלץ לשדרג לגרסה 7 ומעלה."
			)
		}
		
	});
})(jQuery);
