
(function($){
	$.fn.simpleButton = function(){
		this.mousedown(function(){
			$(this).addClass('mousedown');
		}).mouseup(function(){
			$(this).removeClass('mousedown');
		}).mouseleave(function(){
			$(this).removeClass('mousedown');
		});
	};
})(jQuery);


$(function(){


		$('.button-game').click(function(event){
			yaCounter3630886.reachGoal('home');
			yaCounter3630886.notBounce();
			return true;
		});
		$('.innerclick').click(function(event){
			yaCounter3630886.reachGoal('inner');
			yaCounter3630886.notBounce();
			return true;
		});
		


	$(".content tr:nth-child(even)").addClass("even");
	$('.simple-button').simpleButton();
	
	$('a#click-box-one').click(function (event) {
		event.preventDefault();
		$("#box-two").hide();
		$("#box-one").show();
    });
	
	$('a#click-box-two').click(function (event) {
		event.preventDefault();
		$("#box-one").hide();
		$("#box-two").show();
    });
    
	$('input.placeholder')
		.val($('input.placeholder').attr('title'))
		.blur(function(event){
			var $this = $(this);
			if(!$this.val()){
				$this.val($this.attr('title'));
			}
		})
		.focus(function(event){
			var $this = $(this);
			if($this.val() == $this.attr('title')){
				$this.val('');
			}
		});
	
	$('#subscriptionForm')
		.submit(function(event){
			event.preventDefault();
			var $this = $(this);
			var fields = $this.serialize();
			$.get($this.attr('action'), fields, function(data){
				var $message = $this.find('div.message');
				console.log($message);
				$message.removeClass('error success').addClass(data.result);
				switch(data.result){
					case 'success':
						$message.text('Все ок.');
						break;
						
					default:
						$message.text('Произошла ошибка.');
						break;
				}
				$message.show();
			}, 'json');
		})
		
		.find('input[type="text"]')
			.keypress(function(event){
				if (event.which == 13) {
					event.preventDefault();
					$(this).parents('form').submit();
		      	}
			})
			.end()
			
		.find('a')
			.click(function(event){
				event.preventDefault();
				$(this).parents('form').submit();
			});
			
	$('.elink').click(function (event) {
			event.preventDefault();
			sHref = $(this).attr('id');
			window.location.href = 'http://www.casino-player.ru' + sHref;
	    });
	$('.nlink').click(function (event) {
			event.preventDefault();
			sHref = $(this).attr('rel');
			window.location.href = sHref;
	    });
			
});
