var mainImage

/** @type modalContents формы подтверждения покупки */
var modalBuyRightNowContent

$(document).ready(
	function ()
	{
		mainImage = $('#mainImage')

		if ( loggedIn == 0 )
		{
			$('form.s-would-you').submit(
				function()
				{
					tb_show(null, '/?TB_inline&height=300&width=600&inlineId=modal-loginForm&modal=true&showHandler=modalLoginContent.reset()', null)

					return false
				}
			)
		}
		
		$('#mc-chooseNotLoggedIn-auth-link').click(
			function ()
			{
				modalLoginContent.select( 'mc-loginForm' )
				return false
			}
		)

		$('.watchTheme a').click(
			function ()
			{
				var self = $(this)
				$.get(
					'/choose/index.html',
					{
						id: designId,
						action: 'toggleWatch'
					},
					function ()
					{
						self.toggleClass('doNotWatch')
					}
				)
				return false
			}
		)
		
		$('#zoom-image-link, #show-images-link').click(
			function()
			{
				// есть ещё дублирующий вызов в sifr-config.js (Opera и IE не отрабатывают по клику на flash-объекте)
				tb_show(null, '/?TB_inline&height=700&width=570&inlineId=modal-choosePhotos&modal=true&showHandler=resizeModalByContent()', null)
				return false
			}
		)
		
		/* Формы подтверждения покупки */
		var contents = $('#modal-buyRightNow div.modalPadding')
		
		if( contents.length > 0 ){
			modalBuyRightNowContent = new modalContents(
				contents,
				{
					'mc-buyRightNow-success':
						function()
						{
							$('#TB_ajaxContent').height(172)
						},
					'mc-buyRightNow-fail':
						function()
						{
							$('#TB_ajaxContent').height(172)
						}
				}
			)
			
			$('.buy-right-now a').click(
				function()
				{
					tb_show(null, '/?TB_inline&height=350&width=600&inlineId=modal-buyRightNow&modal=true', null)
					modalBuyRightNowContent.select( 'mc-buyRightNow-confirm' )
					
					return false
				}
			)
			
			$('#buyRightNow-submitter', contents).click(
				function()
				{
					$.post(
						'/choose/buyRightNow.html',
						{
							designId: $('input[name=design_id]', contents).val()
						},
						function (response)
						{
							response = parseInt(response)

							switch ( response )
							{
								case 0:
									modalBuyRightNowContent.select( 'mc-buyRightNow-fail' )
								break;
								case 1:
									modalBuyRightNowContent.select( 'mc-buyRightNow-success' )
								break;
							}
						}
					)
					return false
				}
			)
		}
	}
)
