jQuery(document).ready(function(){
	initPopup("a[rel=popup]");
	initAjaxVideo();
});
function initAjaxVideo(){
	jQuery('a.video-btn').each(function(){
		var _btn = jQuery(this);
		if(_btn.attr('rel') && jQuery(_btn.attr('rel').length)){
			var video_hold = jQuery(_btn.attr('rel'));
			if(!video_hold.data('load')){
				video_hold.data('load', true);
				jQuery.ajax({
					url: _btn.attr('href'),
					data: 'get_video=1',
					type: 'POST',
					success: function(_html){
						video_hold.html(_html);
					}
				});
			}
			_btn.click(function(){
				jQuery.ajax({
					url: _btn.attr('href'),
					data: 'get_video=1',
					type: 'POST',
					success: function(_html){
						video_hold.html(_html);
					}
				});
				return false;
			});
		}
	});
}
function initPopup(_target) {
	_popup = jQuery(_target).fancybox({
		'width': 625,
		'padding': 35,
		'scrolling': 'auto',
		'autoDimensions': true,
		'autoScale': false,
		'showCloseButton': false,
		'showNavArrows': false,
		'margin': 0,
		ajax : {
            type    : "POST",
			data    : 'ajax=1'
        },
		onComplete: function() {
			jQuery("#popup a.popup-close").each(function(i, el){
				el.href = "#";
			});
			jQuery("#popup a.popup-close").bind('click', function(){
				jQuery.fancybox.close();
				return false;
			});
			initPopup("#popup .popup-link a");
		}
	});

}
