$(document).ready(function () {
    var stopEvent = false;
	//Красивые Alert'ы
	window._alert = window.alert;
	window.alert = function(message) {
		$.pnotify({
			pnotify_title: '',
			pnotify_text: message,
			pnotify_delay: 5000
		});
	};
	Cart.afterFunc();
	
	$('#clearcart').click(function() {
		$.cookie('cart', JSON.stringify(Array()), {path: '/', expires: 14});
		if (window.location.pathname == '/cart/') {
			window.location.reload();
		} else {
			$('#cart-table').html('<tr><td colspan="2"><div style="text-align: center; color: #636363;"><br>Перетащите сюда<br>понравившуюся вам<br>плитку.<br><br></div></td></tr>');
			$('#cart-total').html(0);
		}
		this.style.display = 'none';
		return false;
	});


	$('#close-element').click(function() {
		$('#contaner').hide();
        $('#order_form_table').hide();
		return false;
	});
	$('#contaner').click(function(e){
		if (e.target.id.indexOf('contaner') != -1 || e.target.className == 'weleimg') {
			$(this).hide();
            $('#order_form_table').hide();
		}
	});
	$('#order_form_table').click(function(){
        $('#contaner').hide();
        $('#thanks_table').hide();
        $('#order_form_div').show();
        $('#order_form_table').hide();
	});
	$('#order_form_outer').click(function(e){
        if(e.target.id == 'order_form_submit'){
            return true;
        } else {
            return false;
        }
	});
	$('#main-fw .order a').click(function(e){
		if(!stopEvent) {
            $('#contaner').show();
            $('#order_form_table').show();
            $('form[name=order_projects] input[name=project]').val($('#'+$(this).attr('rel')).find('td:first').find('strong').html());
		}
		stopEvent = false;
		return false;
	});

});
