jQuery(document).ready(function() {
	initLayout();
	init_coupon();
	initSubscribes();

	jQuery('.grey_pic').live('mouseover', function() {
		jQuery('.fullcolor_pic[relid='+jQuery(this).attr('relid')+']').show();
		jQuery(this).hide();
	});

	jQuery('.fullcolor_pic').live('mouseout', function() {
		jQuery('.grey_pic[relid='+jQuery(this).attr('relid')+']').show();
		jQuery(this).hide();
	});
});

function initLayout() {
 	jQuery('#crt_supp').click(function() {
 		//return false;
 		jQuery('.credits, .black').show();
 		return false;
 	});
 	
 	jQuery('#close_credits').click(function() {
 		jQuery('.credits, .black').hide();
 		return false;
 	});
}


function init_coupon() {
	jQuery('#idle_butt img').bind('mouseover', function() {
		jQuery(this).parent().hide();
		jQuery('#active_butt').show();
	});
	
	jQuery('#active_butt img').bind('mouseout', function() {
		jQuery(this).parent().hide();
		jQuery('#idle_butt').show();
	});

}

function initSubscribes () {
	if (jQuery('.view_tpl').length) {
		jQuery('.view_tpl').click(function() {
			$.ajax({
			   type: 'POST',
			   url: '/get_subscription_tpl.php',
			   data: 'id='+jQuery(this).attr('relid')+'&forced='+jQuery(this).attr('forced'),
			   success: function(msg) {
			   		jQuery('#tpl_preview').html(msg);
			 	}
			});
			
			return false;
		});
	}
	
	if (jQuery('#check_eml').length) {
		jQuery('#check_eml').click(function() {
			if (jQuery('#eml').val().length) {			
				mails = jQuery('#eml').val().split(' ');
				
				jQuery('#eml').val('Выполняется рассылка. Подождите, пожалуйста.');

				$.ajax({
				   type: 'POST',
				   url: '/do_subscription_view.php',
				   data: 'maneml='+mails,
				   success: function(msg) {
				   		jQuery('#tpl_preview').html(msg);
				   		jQuery('#eml').val('');
				 	}
				});
			}
		});
	}
	
	if (('input#t_theme').length) {	
		jQuery('#t_theme').click(function(){
			if (jQuery(this).val()==1) {
				jQuery(this).val(0);
			} else {
				jQuery(this).val(1);
			}
		});
	}
}
