﻿$(document).ready(function () {

	$(".cms-popup").fancybox({
		'speedIn': 600,
		'speedOut': 200,
		'type': 'ajax',
		'centerOnScroll': true
	});

	$(".cms-popup").click(function(){
			_gaq.push(['_trackPageview', $(this).attr('href')]);
	});
});

//$(document).ready(function () {
//	var lastHash = null;
//	$('.cms-popup').click(function () {
//		$this = $(this);
//		var targetSelector = $this.attr('rel');
//		var $target = $(targetSelector);

//		$this.effect("transfer", { to: $target, className: "ui-effects-transfer" }, 500);

//		$.ajax({
//			url: $this.attr('href'),
//			dataType: 'html',
//			error: function (data, textStatus, jqXHR) {
//			},
//			success: function (data, textStatus, jqXHR) {
//				$target.html(data);
//			}
//		});

//		lastHash = new Date().getTime();
//		jQuery.history.load(lastHash);

//		return false;
//	});

//	$.history.init(function (hash) {
//		if (lashHash != null && hash < lastHash) {
//			window.location = window.location.href.replace(/#.*/, "");
//			//window.location.reload();
//		}
//	},
//    { unescape: ",/" });
//});



/*$(document).ready(function () {
	var cms_last = null;

	function loadCMS(id) {
		var cms = cms_last; //cms_data[id];

		//back / retrieve from history
		if (cms_last == null) {
			var $div = $('div[id=cms-' + id + ']');
			if ($div.length == 0)
				return;

			$($div.data('target')).append($div.children());
			$div.remove();

			return;
		}

		$.ajax({
			url: cms.url,
			dataType: 'html',
			error: function (data, textStatus, jqXHR) {
				cms_last = null;
			},
			success: function (data, textStatus, jqXHR) {
				//Backup
				$target = $(cms_last.target);
				var id = 'cms-' + $('div[id^=cms-]').length;
				$('<div/>')
					.attr('id', id)
					.css('display', 'none')
					.append($target.children())
					.appendTo($('body'));

				$target.html(data);
				cms_last = null;
				//$(cms.data('source')).effect("transfer", { to: $target, className: "ui-effects-transfer" }, 500);
			}
		});
	}

	$.history.init(function (hash) {
		if (hash == "") {
			loadCMS(hash);
		} else {
			loadCMS(hash);
		}
	},
    { unescape: ",/" });

	$('.cms-popup').click(function () {
		$this = $(this);
		var targetSelector = $this.attr('rel');
		var $target = $(targetSelector);

		cms_last = {
			target: targetSelector,
			url: $this.attr('href')
		};

		$this.effect("transfer", { to: $target, className: "ui-effects-transfer" }, 500);

		jQuery.history.load($('div[id^=cms-]').length);

		return false;
	});
});*/
