$(document).ready(function() {   	
	$('a.calEventPreview').live('click', function() {
        var url = this.href;
		$('a.calEventPreview').removeClass('current_page_item');
		$('#eventlinks').empty();
		$('#eventlinks').load(url);
		$('html, body').animate({scrollTop: '800'}, 'slow');
		$(this).addClass('current_page_item');
		return false;
	});
	
	$('a.calEvent').live('click', function() {
        var url = this.href;
		var theTitle = this.title;
        var dialog = $('<div style="display:hidden"></div>').appendTo('body');
        // load remote content
        dialog.load(
                url, 
                {},
                function (responseText, textStatus, XMLHttpRequest) {
                        dialog.dialog({
							resizable: false,
							modal: true,
							title: theTitle,
							width: 640,
							height: 'auto',
							position: ['center',40],
							resizable: 'false',
							show: 'fade',
							buttons: {
								'Add to Calendar': function() {
									$.get('/wp-content/themes/congress2011/includes/functions_cart.php?action=addToBasket&productID='+$('#pkEvent').val());
									$('#eventview').remove()
									$(this).dialog('close');	
								},
								Close: function() {
									$('#eventview').remove()
									$(this).dialog('close');
								}
							},
							close: function() {
								$('#eventview').remove()
								//$(this).dialog('close');
							}
						});
                }
        );
        //prevent the browser to follow the link
        return false;
	});
	
	$('#formCalendarSearch').ajaxForm({
		target: '#eventlinks',
		success: function(){
			$('html, body').animate({scrollTop: '1000'}, 'slow');
		}
		
	})
	$('#cartitems').live('click', function() {
        var url = this.href;
		var theTitle = this.title;
        var dialog = $('<div style="display:hidden"></div>').appendTo('body');
        // load remote content
        dialog.load(
                url, 
                {},
                function (responseText, textStatus, XMLHttpRequest) {
                        dialog.dialog({
							resizable: false,
							width: 500,
							modal: true,
							title: theTitle,
							position: 'center',
							resizable: 'false',
							show: 'fade',
							buttons: {
								'Print': function() {
									window.print();
								},
								Close: function() {
									$(this).dialog('close');
								}
							}
						});
						$('.btnprint').button();
                }

        );
        //prevent the browser to follow the link
        return false;
	});
	$('.deleteBasketItem').live('click', function() {
		var url = this.href;
		$.get(url);
		$(this).parent().remove();
		return false;
	});
	
});
