/*
 * SimpleModal Confirm Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: confirm.js 238 2010-03-11 05:56:57Z emartin24 $
 *
 */

jQuery(function ($) {
	$('#confirm-dialog input.confirm, #confirm-dialog a.confirm').click(function (e) {
//		e.preventDefault();

		// example of calling the confirm function
		// you must use a callback function to perform the "yes" action
		confirm2("Выберите вариант багета", function () {
			//window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';
			$('#komplektSBagetom').val('baget3' + ($('#userBagetValue').val()));
		});
	});
	
	$('input[name=userBaget]').click(function() {
		var bagetId = $('input[name=userBaget]:checked').val();
		$('#bagetBorder1').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/1.jpg\') repeat-x;');
		$('#bagetBorder11').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/11.jpg\') repeat-x;');
		$('#bagetBorder2').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/2.jpg\') repeat-x;');
		$('#bagetBorder14').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/14.jpg\') repeat-y;');
		$('#bagetBorder12').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/12.jpg\') repeat-y;');
		$('#bagetBorder4').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/4.jpg\') repeat-x;');
		$('#bagetBorder13').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/13.jpg\') repeat-x;');
		$('#bagetBorder3').attr('style', 'background: url(\'/catalog/view/theme/default/image/bagets/' + bagetId + '/3.jpg\') repeat-x;');
		
		$('#userBagetValue').val(bagetId);
	});
	
});

function showConfirm() {
	var bagetVar = $('#baget').val();
	if (bagetVar != 'baget1' && bagetVar != 'baget2') {
		confirm2("Выберите вариант багета", function () {
			//window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';
			$('#komplektSBagetom').val('baget3' + ($('#userBagetValue').val()));
		});				
	}
} 

function confirm2(message, callback) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>X</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		onShow: function (dialog) {
			$('.message', dialog.data[0]).prepend(message);
			
			var bagetVal = $('#komplektSBagetom').val();
			var temp = bagetVal.split('baget3');
			bagetVal = temp.join(''); 
			if (bagetVal == '') {
				bagetVal = 1;
			}
			$('.userBaget[value=' + bagetVal + ']').attr('checked', 'true');

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}
