﻿jQuery.noConflict();

//(function(jQuery){

var fixinputs = function() {
    jQuery('input,textarea,select').each(function(){
        var self = jQuery(this);
        if (self.parents('.input-hold').length != 0)
            return;

        var parents = self.parents('div.input,div.for-select,div.for-select2,div.textarea,div.textarea2,div.textarea1');
        if (parents.length) {
            parents.wrap(jQuery('<div class="input-hold generated"></div>'));
        }
    })
};


jQuery(document).ready(function(){
    fixinputs();

	jQuery('input.check').customCheckbox();
	jQuery('input.radio').customRadio();
	jQuery('select.select').customSelect();
	jQuery('select.select1').customSelect1();

    // additional selectors
    jQuery('#shipping-zip-form #country').customSelect();

	initFooter();
	jQuery('div.slider3').biggallery({
		duration: 500,
		autoRotation: 5000,
		listOfSlides: 'div.hold > ul > li',
		switcher: 'ul.dots > li'
	});
	jQuery('div.sliders4 div.slider div.wrap').each(function(){
		jQuery(this).gallery({
            disableBtn: 'disabled',
			duration: 500,
			listOfSlides: 'div.hold > ul > li',
			effect: true
		});
	});

	jQuery('div.item div.photos').each(function(){
		jQuery(this).gallery({
			duration: 500,
			listOfSlides: 'div.hold > ul > li',
			disableBtn: 'disabled',
			effect: true
		});
	});
	jQuery('div.slider5').each(function(){
		jQuery(this).gallery({
			duration: 500,
			disableBtn: 'disabled',
			listOfSlides: 'div.hold > ul > li',
			ajax: true
		});
	});
	jQuery('div.tab-gall').each(function(){
		jQuery(this).gallery({
			duration: 400,
			listOfSlides: 'div.wrap > div',
			switcher: 'ul.tab-menu2 > li > a',
			effect:true,
			autoHeight: true
		});
	});

	initSearch();
	initList();
	initLogo();
	initInfo();

	if(jQuery('a.lightbox').length > 0){
		jQuery("a.lightbox").fancybox({
			transitionIn		: 'none',
			transitionOut		: 'none',
			padding				: 0,
			overlayColor		: '#000',
			titlePosition 		: 'over',
			showCloseButton		: false,
			onStart				: function(){
				jQuery('iframe').css({display: 'none'});
			},
			onClosed			: function(){
				jQuery('iframe').css({display: 'block'});
			},
			titleFormat			: function(title, currentArray, currentIndex, currentOpts) {
				return '<a class="close" href="#">Закрыть</a> <h3>'+(title.length ? ' &nbsp; ' + title : '')+'</h3> Фото '+(currentIndex + 1)+
				' из '+currentArray.length+' <div class="info">Для просмотра можно использовать стрелки <span class="green">&larr; &rarr;</span>'+
				' и клавишу <span class="green">ESC</span> на клавиатуре</div>'
			},
			onComplete			: function(){
				jQuery('#fancybox-title a.close').click(function(){
					jQuery.fancybox.close();
					return false;
				});
				jQuery('#fancybox-title').css({height:'auto'});
				var h = jQuery('#fancybox-title').outerHeight();
				jQuery('#fancybox-title').css({height:0});
				jQuery('#fancybox-title').animate({height: h},{queue:false, duration: 200});
			}
		});
	}
	initSet();
    initPay();
	initNewComment();
	//initAmount();
	jQuery('a.link-popup').simplebox({
		linkClose: 'span.close2'
	});
	initRowWrap();
	initCheck();
	initNewAddress();
	initInfo2();
    initMenu();
    initLastBox();
});


function initMenu(){
	jQuery('div.menu').each(function(){
		var hold = jQuery(this);
		var link = hold.find('tr > td');
		var box = jQuery('div.menu2');
		var active = link.index(link.filter('.active:eq(0)'));
		var _time;
		if(active != -1){
			jQuery(link.eq(active).find('> a').attr('rel')).css({position: 'relative', left:0, top:0});
			box.css({height: 32});
		}

		link.hover(function(){
			var _this = jQuery(this);
			if(_this.find('a').attr('rel') && !_this.find('a').hasClass('open')){
				_time = setTimeout(function(){
					if(active == -1){
						box.animate({height: 32}, 200);
					}
					box.children().css({
						position: 'absolute',
						left: -9999,
						top:  -9999
					});
					link.find('a').removeClass('open');
					jQuery(_this.find('a').attr('rel')).css({position: 'relative', left:0, top:0, display: 'none'}).fadeIn(300);
					_this.find('a').addClass('open');
				}, 500);
			}
		}, function(){
			if(_time) clearTimeout(_time);
		});
	});
}

function initNewAddress(){
	jQuery('div.checkout div.left, div.in div.girl').each(function(){
		var hold = jQuery(this);
		var link = jQuery('#billing_address_id_new');
		var box = hold.find("ul#billing_address_id_new_form");
		
		box.css({display: 'none', height: 'auto'});
		
		if(link.is(':checked')) {
			box.css({display: 'block'});
		}
		else{
			box.css({display: 'none'});
		}
		
		link.bind('initChange', function(){
			if(link.is(':checked')) {
				box.slideDown(300);
                jQuery('.select').customSelect();
			}
			else{
				box.slideUp(300);
			}
		});
	});
    
	jQuery('div.checkout div.left, div.in div.girl').each(function(){
		var hold = jQuery(this);
		var link = jQuery('#shipping_address_id_new');
		var box = hold.find("ul#shipping_address_id_new_form");

		box.css({display: 'none', height: 'auto'});

		if(link.is(':checked')) {
			box.css({display: 'block'});
		}
		else{
			box.css({display: 'none'});
		}

		link.bind('initChange', function(){
			if(link.is(':checked')) {
				box.slideDown(300);
			}
			else{
				box.slideUp(300);
			}
		});
	});
}

function initCheck(){
	jQuery('ul.check-list3 > li:first, div.right > div.congrat2, div.congrat > div.grey').each(function(){
		var hold = jQuery(this);
		var link = hold.find('input:checkbox');
		var box = hold.find('div.message');
		
		if(link.is(':checked')) {
			box.css({display: 'block'});
		}
		else{
			box.css({display: 'none'});
		}
		
		link.bind('initChange', function(){
			if(link.is(':checked')) {
				box.slideDown(300);
			}
			else{
				box.slideUp(300);
			}
		});
	});
}

function initPay(){
	jQuery('div.pay-methods3').each(function(){
        if (jQuery(this).hasClass('x-processed'))
            return;

        jQuery(this).addClass('x-processed');

		var hold = jQuery(this);
		var link = hold.find('h4 a');
		var box = hold.find('div.pay-wrap');
		var item = box.find('div.item');
		var row = box.find('div.row');
		var close = hold.find('span.close');

		link.click(function(){
			if(!link.parent().hasClass('open')){
				box.slideDown(300);
				link.parent().addClass('open');
                jQuery('.radio', hold).customRadio();
			}
			else
            {
				box.slideUp(300);
				link.parent().removeClass('open');
			}
			return false;
		});
		
		row.each(function(i){
			row.eq(i).find('> div.item').each(function(k){
				jQuery(this).find('> div.selected').css({left: -71*k});
			});
		});

        item.find('.check-it').click(function(){
            setTimeout(function(){
             //   close.trigger('click');
            }, 500)
        });
		item.find('div.bg1').click(function(){
			var _this = jQuery(this).parent();
			if(!_this.hasClass('active')){
				if(box.find('div.active').length > 0){
					box.find('div.active').find('> div.selected').slideUp(300, function(){
						box.find('div.active').removeClass('active');
						_this.addClass('active');
						_this.find('> div.selected').slideDown(300);
					});
				}
				else{
					_this.addClass('active');
					_this.find('> div.selected').slideDown(300);
				}
			}
			else{
				_this.removeClass('active');
				_this.find('> div.selected').slideUp(300);
			}
			return false;
		});
		close.click(function(){
			item.removeClass('active');
			item.find('> div.selected').slideUp(300);
			return false;
		});
	});
}

function initRowWrap(){
	jQuery('div.row-wrap').each(function(){
		var hold = jQuery(this);
		var link = hold.find('input.check');
		var box = hold.find('.half-wrap');
		var h = box.outerHeight() ;
		box.css({height:'0px', overflow: 'hidden', position: 'relative'});
		
		if(link.is(':checked')){
			box.css({height: h});
        }
        else{
            box.css({height: 0});
        }
		
		link.bind('change', function(){
			if(link.is(':checked')) {
                box.animate({height: h}, { duration: 1000, queue: false});
			} else{
				box.animate({height: 0}, { duration: 1000, queue: false});
			}
            return true;
		});
	});
}

function initAmount(){
	jQuery('div.amount').each(function(){
		var hold = jQuery(this);
		var input = hold.find('input');
		var minus = hold.find('a.minus');
		var plus = hold.find('a.plus');
		
		minus.click(function(){
			if(input.val()/1 != NaN && input.val()/1 != 0){
				input.val(input.val()/1-1);
			}
			return false;
		});
		plus.click(function(){
			if(input.val()/1 != NaN){
				input.val(input.val()/1+1);
			}
			return false;
		});
	});
}

function initNewComment(){
	jQuery('div.tab-slide').each(function(){
		var hold = jQuery(this);
		var link = hold.find('ul.tab-menu2 a.add');
		var box = hold.find('div.new-comment');
		var h = box.outerHeight();
		var tab = hold.find('ul.tab-menu2 > li > a.tab:last');
		var block = hold.find('div.tab-hold');
		var cancel = hold.find('.close-comment-form');
		
		box.css({height: 0});
		
		link.click(function(){
			tab.trigger('click');
			setTimeout(function(){
				box.animate({height: h}, {queue:false, duration: 400});
				block.animate({height: (block.height() + h)}, {queue:false, duration: 300});
				link.fadeOut(300);
			}, 450);
			return false;
		});
		cancel.click(function(){
			box.animate({height: 0}, {queue:false, duration: 400});
			link.fadeIn(300);
			block.animate({height: (block.height() - h)}, {queue:false, duration: 300});
			return false;
		});
	});
}

function initSet(){
	jQuery('div.set-wrap').each(function(){
		var hold = jQuery(this);
		var link = hold.find('ul.names input');
		var photos = hold.find('ul.photos li');
		var result = hold.find('div.result div.price strong span');
		var active;
		var temp;
		
		link.bind('initChange', function(){
			active = link.index(jQuery(this));
			disPic();
			reCalc();
		});
		function reCalc(){
			temp = 0;
			link.each(function(i){
				if(jQuery(this).attr('checked')) temp += jQuery(this).attr('value')/1;
			});
			result.text(temp);
		}
		
		function disPic(){
			link.each(function(i){
				if(!jQuery(this).attr('checked')){
					photos.eq(i).fadeOut(250);
					if(active+1 == link.length){
						photos.eq(active-1).find('div.plus').fadeOut(250);
					}
				}
				else{
					photos.eq(i).fadeIn(250);
					if(active+1 == link.length){
						photos.eq(active-1).find('div.plus').fadeIn(250);
					}
				}
			});
		}
		
		reCalc();
	});
}

function initInfo2(){
	jQuery('div.info2').each(function(){
		var hold = jQuery(this);
		var link = hold.find('span.icon');
		var sub = hold.find('div.sub');
		var h = sub.outerHeight();
		var tooltip;
		//sub.css({top: 16, height:0, overflow: 'hidden'});
		var _time;

		link.click(function(){
			if(!hold.hasClass('open')){
				hold.addClass('open');
				jQuery('body').append(jQuery('<div class="tooltip-sub"></div>'));
				tooltip = jQuery('div.tooltip-sub');
				tooltip.css({top: link.offset().top+17, left: link.offset().left-184});
				tooltip.append(sub.clone());
				tooltip.animate({height:h}, {queue:false, duration: 300});
				tooltip.hover(function(){
					hold.addClass('hovering');
					if(_time) clearTimeout(_time);
				}, function(){
					hold.removeClass('hovering');
					_time = setTimeout(function(){
						if(hold.hasClass('open')){
							hold.removeClass('open');
							tooltip.animate({height:0}, {queue:false, duration: 300, complete: function(){
								jQuery(this).remove();
							}});
						}
					}, 500);
				});
			}
			else{
				if(_time) clearTimeout(_time);
				hold.removeClass('open');
				tooltip.animate({height:0}, {queue:false, duration: 300, complete: function(){
					jQuery(this).remove();
				}});
			}
			return false;
		});
		hold.hover(function(){
			if(_time) clearTimeout(_time);
			hold.addClass('hovering');
			_time = setTimeout(function(){
				if(!hold.hasClass('open')){
					hold.addClass('open');
					tooltip = jQuery('<div class="tooltip-sub"></div>');
                    tooltip.appendTo(jQuery('body'));
					tooltip.css({top: link.offset().top+17, left: link.offset().left-184});
					tooltip.append(sub.clone());
                    sub.css({display:'none'});
					tooltip.animate({height:h}, {queue:false, duration: 300});
					tooltip.hover(function(){
						hold.addClass('hovering');
						if(_time) clearTimeout(_time);
					}, function(){
						hold.removeClass('hovering');
						_time = setTimeout(function(){
							if(hold.hasClass('open')){
								hold.removeClass('open');
								tooltip.animate({height:0}, {queue:false, duration: 300, complete: function(){
                                    tooltip.remove();
                                    sub.css({display:'block'});
								}});
							}
						}, 500);
					});
				}
			}, 500);


            return false;
		}, function(){
			if(_time) clearTimeout(_time);
			hold.removeClass('hovering');
			_time = setTimeout(function(){
				if(hold.hasClass('open')){
					hold.removeClass('open');
					tooltip.animate({height:0}, {queue:false, duration: 300, complete: function(){
                        tooltip.remove();
                        sub.css({display:'block'});
					}});
				}
			}, 500);

            return false;
		});
	});
}



function initInfo(){
	jQuery('div.item div.info').each(function(){
		var hold = jQuery(this);
		var link = hold.find('div.icon');
		var sub = hold.find('div.sub');
		var h = sub.outerHeight();
		sub.css({top: 16, height:0, overflow: 'hidden'});
		var _time;
		
		link.click(function(){
			if(!hold.hasClass('open')){
				hold.addClass('open');
				sub.animate({height:h}, {queue:false, duration: 300});
			}
			else{
				hold.removeClass('open');
				sub.animate({height:0}, {queue:false, duration: 300});
			}
			return false;
		});
		hold.hover(function(){
			if(_time) clearTimeout(_time);
			hold.addClass('hovering');
			_time = setTimeout(function(){
				if(!hold.hasClass('open')){
					hold.addClass('open');
					sub.animate({height:h}, {queue:false, duration: 300});
				}
			}, 500);
		}, function(){
			if(_time) clearTimeout(_time);
			hold.removeClass('hovering');
			_time = setTimeout(function(){
				if(hold.hasClass('open')){
					hold.removeClass('open');
					sub.animate({height:0}, {queue:false, duration: 300});
				}
			}, 500);
		});
	});
}

function initLogo(){
//	jQuery('div.menu1 li.green:eq(0)').each(function(){
//		var hold = jQuery(this);
//		var link = hold.find('a.link');
//		var close = hold.find('span.close');
//		var sub = hold.find('div.sub');
//		var h = sub.outerHeight();
//		sub.css({top: 19, height:0, overflow: 'hidden'});
//
//		link.click(function(){
//			if(!hold.hasClass('active')){
//				hold.addClass('active');
//				sub.animate({height:h}, {queue:false, duration: 300});
//			}
//			else{
//				hold.removeClass('active');
//				sub.animate({height:0}, {queue:false, duration: 300});
//			}
//			return false;
//		});
//		close.click(function(){
//			hold.removeClass('active');
//			sub.animate({height:0}, {queue:false, duration: 300});
//		});
//	});
}

function initLastBox(){
	jQuery('div.menu2 li:has(div.sub)').each(function(){
		var hold = jQuery(this);
		var link = hold.find('> a');
		if(link.find('> span.arr2').length > 0) link = link.find('> span.arr2');
		var sub = hold.find('> div.sub');
		var _time;

		if(sub.hasClass('sort')) {
			sub.each(function(){
				var hold2 = jQuery(this);
				var block = hold2.find('div.block');
				var link2 = block.find('ul > li');
				var k = (block.outerHeight(true)/2 > 210) ? block.outerHeight(true)/2 : 210;
				var temp = false;

				link2.each(function(i){
					if (k < jQuery(this).position().top && !temp) {
						temp = i;
						if(!(link2.eq(i-1).position().top < k && k > link2.eq(i-1).position().top + link2.eq(i-1).outerHeight(true))) temp--;
					}
				});
				if(temp > 1){
					block.parent().prepend(block.clone());
					block = hold2.find('div.block');
					block.each(function(k){
						if(k == 0) jQuery(this).find('ul > li').each(function(i){
							if(temp <= i) jQuery(this).remove();
						});
						if(k == 1) jQuery(this).find('ul > li').each(function(i){
							if(temp > i) jQuery(this).remove();
						});
					});
					block.find('> ul').each(function(){
						if(jQuery(this).children().length == 0) jQuery(this).remove();
					});
				}
			});


			sub.gallery({
				duration: 400,
				listOfSlides: 'div.item ul > li',
				switcher: 'div.sort ul > li',
				effect:true,
				event: 'mouseover',
				autoHeight: true
			});


//            jQuery('div.item ul > li', sub).css('opacity', '0');
//            jQuery('div.sort ul > li', sub).bind('mouseover', function(){
//                var id = jQuery(this).attr('id');
//                var dataHolder = jQuery('#' + id + '-data');
//
//                jQuery('div.item ul > li', sub).css('opacity','0');
//
//                dataHolder.css('opacity','1');
//            });
//            sub.bind('mouseout', function(){
//                jQuery('div.item ul > li', sub)
//                    .css('opacity','0')
//                    .removeClass('active');
//            });
//
		}


		var h = sub.outerHeight();

		sub.css({top: 34, height:0, overflow: 'hidden'});

		if(jQuery('#container').offset().left > sub.offset().left + 8 + 9999){
			sub.css({right: -(jQuery('#container').offset().left - sub.offset().left + 8 + 9999)});
		}

		link.click(function(){
			if(!hold.hasClass('active')){
				hold.addClass('active');
				sub.animate({height:h}, {queue:false, duration: 300});
			}
			else{
				hold.removeClass('active');
				sub.animate({height:0}, {queue:false, duration: 300});
			}
			return false;
		});
		hold.hover(function(){
			if(_time) clearTimeout(_time);
			_time = setTimeout(function(){
				hold.addClass('active');
				sub.animate({height:h}, {queue:false, duration: 300});
			}, 500);
			hold.addClass('hovering');
		}, function(){
			hold.removeClass('hovering');
			_time = setTimeout(function(){
				hold.removeClass('active');
				sub.animate({height:0}, {queue:false, duration: 300});
			}, 500);
		});

	});
}

function initList(){
	jQuery('div.jewel-selection ul.list').each(function(){
		var hold = jQuery(this);
		var li = hold.find('> li');
		var sub = li.find('> div.sub');
		var link = li.find('> a.link');
		var ul = sub.find('> ul > li');
		var h = [];
		var active;
		
		sub.each(function(i){
			h[i] = jQuery(this).outerHeight();
		});
		sub.css({top: 32, height:0, overflow: 'hidden'});
		
		link.click(function(){
			active = link.index(jQuery(this));
			if(!li.eq(active).hasClass('active')){
				li.removeClass('active');
				sub.animate({height: 0}, {queue:false, duration: 300});
				li.eq(active).addClass('active');
				sub.eq(active).animate({height: h[active]}, {queue:false, duration: 300});
			}
			else{
				li.removeClass('active');
				sub.animate({height: 0}, {queue:false, duration: 300});
			}
			return false;
		});
		hold.hover(function(){
			hold.addClass('hovering');
		}, function(){
			hold.removeClass('hovering');
		});
		jQuery('body').click(function(){
			if (!hold.hasClass('hovering')){
				li.removeClass('active');
				sub.animate({height: 0}, {queue:false, duration: 300});
			}
		});
		ul.click(function(){
			jQuery(this).parent().find('.checkboxAreaChecked').removeClass('checkboxAreaChecked').parent().removeClass('checkboxAreaCheckedBox').find('input').attr('checked', false);
			jQuery(this).parent().find('.radioAreaChecked').removeClass('radioAreaChecked').parent().find('input').attr('checked', false);
			jQuery(this).find('span.checkboxArea').addClass('checkboxAreaChecked').parent().addClass('checkboxAreaCheckedBox')
			jQuery(this).find('span.radio').addClass('radioAreaChecked');
			jQuery(this).find('input').attr('checked', true);
			if(!jQuery(this).find('label').attr('title')){
				link.eq(active).find('span').text(jQuery(this).find('label').text());
			}
			else{
				link.eq(active).find('span').text(jQuery(this).find('label').attr('title'));
			}
			li.removeClass('active');
			sub.animate({height: 0}, {queue:false, duration: 300});
		});

	});
}

function initSearch(){


	jQuery('div.search').each(function(){
		var hold = jQuery(this);
		var input = hold.find('div.input input');
		var form = hold.find('form');
		var results = hold.find('div.results');
		var items = results.find('div.items');
		var num = results.find('div.bottom > strong');
		var w1 = hold.outerWidth();
		hold.addClass('open');
		var w2 = hold.outerWidth();
		hold.removeClass('open');
		hold.css({width:w1});
		var _time;
		
		var val = input.val();
		input.bind('focus', function(){
			if(!hold.hasClass('open')){
				if(this.value == val) this.value = '';
				hold.addClass('open');
				hold.animate({width:w2},{queue:false, duration: 300, complete: function(){
					hold.css({overflow: 'visible'});
				}});
			}
		}).bind('blur', function(){
			if (!hold.hasClass('hovering')){
				if(this.value == '') this.value = val;
				hold.animate({width:w1},{queue:false, duration: 300, complete: function(){
					hold.removeClass('open');
					hold.css({overflow: 'visible'});
				}});
			}
		});
        /*
		input.keyup(function(){
			if(_time) clearTimeout(_time);
			_time = setTimeout(function(){
				if (input.val().length > 1) {
					jQuery.ajax({
						type: "GET",
						data: { 'q' :  input.val() },
						dataType: "html",
						url: AUTOCOMPLETE_ACTION || form.attr('action'),
						success: function(msg){
                            results.css({left:-1});
                            items.find('div.item').remove();
                            jQuery(msg).find('.item').each(function(index, elem) {
                                jQuery('<div class="item"></div>')
                                    .html(jQuery(elem).html())
                                    .appendTo(items);
                            });

							//items.html(result);
							//num.empty().append(jQuery(msg).find('ul > li').length);
						},
						error: function(){
							alert('Ошибка на сервере! Перегрузите страницу!')
						}
					});
				}
				else{
					results.css({left:-9999});
				}
			}, 700);
		});
		*/
		
		hold.hover(function(){
			hold.addClass('hovering');
		}, function(){
			hold.removeClass('hovering');
		});
		jQuery('body').click(function(){
			if (!hold.hasClass('hovering')){
				if(this.value == '') this.value = val;
				hold.animate({width:w1},{queue:false, duration: 300, complete: function(){
					hold.removeClass('open');
				}});
			}
		});
	});
}

jQuery.fn.biggallery = function(options) { return new bigGallery(this.get(0), options); };

function bigGallery(context, options) { this.init(context, options); };

bigGallery.prototype = {
	options:{},
	init: function (context, options){
		this.options = jQuery.extend({
			duration: 700,									
			slideElement: 1,								
			autoRotation: false,							
			listOfSlides: 'ul > li',						
			switcher: false,								
			disableBtn: false,								
			nextBtn: 'a.link-next, a.btn-next, div.next',		
			prevBtn: 'a.link-prev, a.btn-prev, div.prev',		
			circle: true,									
			event: 'click'									
		}, options || {});
		var _el = jQuery(context).find(this.options.listOfSlides);
		this.list = _el.parent();
		this.switcher = jQuery(context).find(this.options.switcher);
		this.nextBtn = jQuery(context).find(this.options.nextBtn);
		this.prevBtn = jQuery(context).find(this.options.prevBtn);
		this.count = _el.index(_el.filter(':last'));
		
		this.active = Math.round(Math.random()*(this.count-2));
		if (this.active < 0) this.active = 0;
		this.last = this.active;
		
		this.woh = _el.outerWidth(true);
		this.installDirections(this.list.parent().width());
		
		this.rew = this.count - this.wrapHolderW + 1;
		this.anim = '{marginLeft: -(this.woh * this.active)}';
		eval('this.list.css('+this.anim+')');
		if (this.options.switcher) {
			this.switcher.removeClass('active').eq(this.active).addClass('active');
			this.switcher.eq(this.active+1).addClass('active');
			this.switcher.eq(this.active+2).addClass('active');
		}
		
		this.flag = true;
		
		this.initEvent(this, this.nextBtn, true);
		this.initEvent(this, this.prevBtn, false);
		if (this.options.disableBtn) this.initDisableBtn();
		if (this.options.autoRotation) this.runTimer(this);
		if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
	},
	initDisableBtn: function(){
		this.prevBtn.removeClass('prev-'+this.options.disableBtn);
		this.nextBtn.removeClass('next-'+this.options.disableBtn);
		if (this.active == 0 || this.count+1 == this.wrapHolderW) this.prevBtn.addClass('prev-'+this.options.disableBtn);
		if (this.active == 0 && this.count == 1 || this.count+1 <= this.wrapHolderW) this.nextBtn.addClass('next-'+this.options.disableBtn);
		if (this.active == this.rew) this.nextBtn.addClass('next-'+this.options.disableBtn);
	},
	installDirections: function(temp){
		this.wrapHolderW = Math.ceil(temp / this.woh);
		if (((this.wrapHolderW - 1) * this.woh + this.woh / 2) > temp) this.wrapHolderW--;
	},
	scrollElement: function(self){
		if (!self.options.infinite) eval('self.list.animate('+self.anim+', {queue:false, duration: self.options.duration});');
		else eval('self.list.animate('+self.anim+', self.options.duration, function(){ self.flag = true });');
		if (self.options.switcher) {
			self.switcher.removeClass('active').eq(self.active).addClass('active');
			self.switcher.eq(self.active+1).addClass('active');
			self.switcher.eq(self.active+2).addClass('active');
		}
	},
	runTimer: function(self){
		if(self._t) clearTimeout(self._t);
		self._t = setInterval(function(){
			if (self.options.infinite) self.flag = false;
			self.toPrepare(self, true);
		}, this.options.autoRotation);
	},
	initEventSwitcher: function(self, el){
		el.bind(self.options.event, function(){
			self.active = self.switcher.index(jQuery(this)) * self.options.slideElement-1;
			if (self.active == -1) self.active = 0;
			if (self.active == self.count-1) self.active--;
			if(self._t) clearTimeout(self._t);
			if (self.options.disableBtn) self.initDisableBtn();
			if (!self.options.effect) self.scrollElement(self);
			else self.fadeElement();
			if (self.options.autoRotation) self.runTimer(self);
			return false;
		});
	},
	initEvent: function(self, addEventEl, dir){
		addEventEl.bind(self.options.event, function(){
			if (self.flag){
				if (self.options.infinite) self.flag = false;
				if(self._t) clearTimeout(self._t);
				self.toPrepare(self, dir);
				if (self.options.autoRotation) self.runTimer(self);
			}
			return false;
		});
	},
	toPrepare: function(self, side){
		if ((self.active == self.rew) && self.options.circle && side) self.active = -self.options.slideElement;
		if ((self.active == 0) && self.options.circle && !side) self.active = self.rew + self.options.slideElement;
		for (var i = 0; i < self.options.slideElement; i++){
			if (side) { if (self.active + 1 <= self.rew) self.active++; }
			else { if (self.active - 1 >= 0) self.active--; }
		};
		
		if (this.options.disableBtn) this.initDisableBtn();
		self.scrollElement(self);
	}
};

jQuery.fn.customSelect = function(options) {

var _options = jQuery.extend({
	selectStructure: '<div class="select2"><div class="x-select-selected-btn x-select-selected selected"></div></div>',
	selectText: '.x-select-selected',
	selectBtn: '.x-select-selected-btn',
	selectDisabled: '.x-select-disabled',
	optStructure: '<div class="sub1 sub2"><div class="sub-tl"><div class="sub-tr"><div class="sub-tc"></div></div></div><div class="sub-cl"><div class="sub-cr"><ul></ul></div></div><div class="sub-bl"><div class="sub-br"></div></div></div>',
	optList: 'ul'
}, options);

return this.each(function() {
	var select = jQuery(this);
	if(select.is(':visible') && !select.hasClass('outtaHere'))
    {
        {
			var replaced = jQuery(_options.selectStructure);
			var selectText = replaced.find(_options.selectText);
			var selectBtn = replaced.find(_options.selectBtn);
			var selectDisabled = replaced.find(_options.selectDisabled).hide();

			if(select.attr('disabled'))
                selectDisabled.show();

            var optHolder = jQuery(_options.optStructure);
            var optList = optHolder.find(_options.optList);

            if (select.attr('title'))
                selectText.text(select.attr('title'));

			select.find('option').each(function(e) {
				var selectOption = jQuery(this);

				var optionReplacement = jQuery('<li><a href="#">' + selectOption.html() + '</a></li>');

                if(selectOption.attr('selected') == true)
                {
					selectText.text(selectOption.text());
					optionReplacement.addClass('selected');
				}

				optionReplacement.children('a')
                    .attr('href', '#')
                    .attr('option_value', selectOption.attr('value'))
                    .click(function()
                    {
                        var me = jQuery(this);

                        optList.find('li').removeClass('selected');
                        select.find('option').removeAttr('selected');
                        me.parent().addClass('selected');
                        selectOption.attr('selected', 'selected');
                        selectText.html(selectOption.html());

                        select.val(me.attr('option_value'));
                        select.change();
                        optHolder.hide();
                        return true;
                });

				optList.append(optionReplacement);
			});

			replaced.width(select.outerWidth());
			replaced.insertBefore(select);

			replaced.addClass(select.attr('class')).removeClass('product-custom-option');
            optHolder.css({
                width: parseInt(select.outerWidth()) + 4,
                position: 'absolute',
                display: 'none',
                zIndex: parseInt(select.css('z-index')) + 10
            });
			optHolder.addClass(select.attr('class')).removeClass('product-custom-option');
			jQuery(document.body).append(optHolder);

			var optTimer;
			replaced.hover(function() {
				if(optTimer)
                    clearTimeout(optTimer);
			}, function() {
				optTimer = setTimeout(function() {
					optHolder.hide();
				}, 200);
			});
			optHolder.hover(function(){
				if(optTimer)
                    clearTimeout(optTimer);
			}, function() {
				optTimer = setTimeout(function() {
					optHolder.hide();
				}, 200);
			});

			selectBtn.click(function() {
				if(optHolder.is(':visible')) {
					optHolder.hide();
				}
				else
                {
                    if (optHolder.find('ul li').length >= 10) {
                        optHolder.find('ul').css({
                            'height' : '220px',
                            'max-height' : '220px',
                            'overflow' : 'auto'
                        })
                    } else {
                        optHolder.children('ul').css({height:'auto', overflow:'hidden'});
                    }

					optHolder.css({
						top: replaced.offset().top + replaced.outerHeight() +1,
						left: replaced.offset().left -2,
						display: 'block'
					});
				}
				return false;
			});

			select.addClass('outtaHere');
		}
	}
});
};

jQuery.fn.customSelect1 = function(options) {
var _options = jQuery.extend({
	selectStructure: '<div class="select1"><div class="selected"><span></span></div></div>',
	selectText: '.selected span',
	selectBtn: '.selected',
	selectDisabled: '.disabled',
	optStructure: '<div class="sub1"><div class="arr"></div><div class="sub-tl"><div class="sub-tr"></div></div><div class="sub-cl"><div class="sub-cr"><ul></ul></div></div><div class="sub-bl"><div class="sub-br"></div></div></div>',
	optList: 'ul'
}, options);
return this.each(function() {
	var select = jQuery(this);
	if(!select.hasClass('outtaHere')) {
		if(select.is(':visible')) {
			var replaced = jQuery(_options.selectStructure);
			var selectText = replaced.find(_options.selectText);
			var selectBtn = replaced.find(_options.selectBtn);
			var selectDisabled = replaced.find(_options.selectDisabled).hide();
			var optHolder = jQuery(_options.optStructure);
			var optList = optHolder.find(_options.optList);
			if(select.attr('disabled')) selectDisabled.show();
			select.find('option').each(function() {
				var selOpt = jQuery(this);
				var _opt = jQuery('<li><a href="#">' + selOpt.html() + '</a></li>');
				if(selOpt.attr('selected')) {
					selectText.html(selOpt.html());
					_opt.addClass('selected');
				}
				_opt.children('a').click(function() {
					optList.find('li').removeClass('selected');
					select.find('option').removeAttr('selected');
					jQuery(this).parent().addClass('selected');
					selOpt.attr('selected', 'selected');
					selectText.html(selOpt.html());
					select.change();
					optHolder.hide();
					replaced.removeClass('select1-open');
					return false;
				});
				optList.append(_opt);
			});
			if (select.attr('title')) selectText.html(select.attr('title'));
			replaced.width(select.outerWidth());
			replaced.insertBefore(select);
			replaced.addClass(select.attr('class'));
				optHolder.css({
					width: select.outerWidth()+4,
					position: 'absolute',
					display: 'none',
					zIndex: 999
				});
			optHolder.addClass(select.attr('class'));
			jQuery(document.body).append(optHolder);

			var optTimer;
			replaced.hover(function() {
				if(optTimer) clearTimeout(optTimer);
			}, function() {
				optTimer = setTimeout(function() {
					optHolder.hide();
					replaced.removeClass('select1-open');
				}, 200);
			});
			optHolder.hover(function(){
				if(optTimer) clearTimeout(optTimer);
			}, function() {
				optTimer = setTimeout(function() {
					optHolder.hide();
					replaced.removeClass('select1-open');
				}, 200);
			});
			selectBtn.click(function() {
				if(optHolder.is(':visible')) {
					optHolder.hide();
					replaced.removeClass('select1-open');
				}
				else{
					replaced.addClass('select1-open');

                    if (optHolder.find('ul li').length >= 10) {
                        optHolder.find('ul').css({
                            'height' : '200px',
                            'max-height' : '200px',
                            'overflow' : 'auto'
                        });
                    } else {
                        optHolder.children('ul').css({height:'auto', overflow:'hidden'});
                    }


					optHolder.css({
						top: replaced.offset().top + replaced.outerHeight() +1,
						left: replaced.offset().left -2,
						display: 'block'
					});
					//if(optHolder.children('ul').height() > 100) optHolder.children('ul').css({height:100, overflow:'auto'});
				}
				return false;
			});
			select.addClass('outtaHere');
		}
	}
});
};

jQuery.fn.customRadio = function(options){
	var _options = jQuery.extend({
		radioStructure: '<label></label>',
		radioDisabled: 'disabled',
		radioDefault: 'radioArea',
		radioChecked: 'radioAreaChecked'
	}, options);
	return this.each(function(){
		var radio = jQuery(this);
		if(!radio.hasClass('outtaHere') && radio.is(':radio')){
            var replaced = jQuery(_options.radioStructure);

            if (radio.attr('id') != '')
            {
                replaced.attr('for', radio.attr('id'));
            }

            replaced.addClass(radio.attr('class'));

            this._replaced = replaced;
            if (radio.is(':disabled'))
            {
                replaced.addClass(_options.radioDisabled);
            } else if (radio.is(':checked'))
            {
                replaced.addClass(_options.radioChecked).parent().addClass('radioAreaCheckedBox');
            }
            else
            {
                replaced.addClass(_options.radioDefault).parent().removeClass('radioAreaCheckedBox');
            }
//
//            replaced.click(function()
//            {
//                if (jQuery(this).hasClass(_options.radioDefault))
//                {
//                    radio.trigger('change');
//                    radio.attr('checked', 'checked');
//                    changeRadio(radio.get(0));
//                }
//            });
            radio.bind('click',function()
            {
                changeRadio(this);
            });
            replaced.insertBefore(radio);
            radio.addClass('outtaHere');
            if (radio.is(':checked'))
            {
                replaced.parent().addClass('radioAreaCheckedBox');
            }
            else
            {
                replaced.parent().removeClass('radioAreaCheckedBox');
            }
		}
	});

	function changeRadio(_this){
		jQuery('input:radio[name="'+jQuery(_this).attr("name")+'"]').not(_this).each(function(){
			if(this._replaced && !jQuery(this).is(':disabled'))
                this._replaced.removeClass('radioAreaChecked').removeClass('radioArea').addClass(_options.radioDefault).parent().removeClass('radioAreaCheckedBox');
		});
		_this._replaced.removeClass('radioAreaChecked').removeClass('radioArea').addClass(_options.radioChecked).parent().addClass('radioAreaCheckedBox');
		jQuery('input:radio[name="'+jQuery(_this).attr("name")+'"]').trigger('initChange');
	}
};

jQuery.fn.customCheckbox = function(_options){
	var _options = jQuery.extend({
		checkboxStructure: '<span></span>',
		checkboxDisabled: 'disabled',
		checkboxDefault: 'checkboxArea',
		checkboxChecked: 'checkboxAreaChecked'
	}, _options);
	return this.each(function(){
		var checkbox = jQuery(this);
		if(!checkbox.hasClass('outtaHere') && checkbox.is(':checkbox')){
			var replaced = jQuery(_options.checkboxStructure);
			replaced.addClass(checkbox.attr('class'));
			this._replaced = replaced;
			if(checkbox.is(':disabled')) replaced.addClass(_options.checkboxDisabled);
			else if(checkbox.is(':checked')) replaced.addClass(_options.checkboxDefault + ' ' +_options.checkboxChecked).parent().addClass('checkboxAreaCheckedBox');
			else replaced.addClass(_options.checkboxDefault).parent().removeClass('checkboxAreaCheckedBox');

			replaced.click(function(){
				if(checkbox.is(':checked'))
                    checkbox.removeAttr('checked');
				else
                    checkbox.attr('checked', 'checked');
                changeCheckbox(checkbox);
                return true;
			});
			checkbox.click(function(){
				changeCheckbox(checkbox);
                return true;
			});
			replaced.insertBefore(checkbox);
			checkbox.addClass('outtaHere');
			changeCheckbox(checkbox);
		}
	});
	function changeCheckbox(_this){
		if (_this.is(':checked')) {
			_this.parent().addClass('checkboxAreaCheckedBox');
			_this.get(0)._replaced.removeClass('checkboxAreaChecked').addClass(_options.checkboxChecked);
		}
		else {
			_this.parent().removeClass('checkboxAreaCheckedBox');
			_this.get(0)._replaced.removeClass('checkboxAreaChecked').addClass(_options.checkboxDefault);
		}
		_this.trigger('initChange');
        return false;
	}

}

function initFooter(){
	var footer = jQuery('div.footer');
	var footerPlace = jQuery('div.footer-place');
	var h = footer.outerHeight();
	
	footer.css({marginTop:-h});
	footerPlace.css({height:h});
}

jQuery.fn.gallery = function(options) {
    return new Gallery(this.get(0), options);
};

function Gallery(context, options) {
//    if (context == undefined)
//        return;
    this.init(context, options); 
};

Gallery.prototype = {
	options:{},
	init: function (context, options){
		this.options = jQuery.extend({
			infinite: false,								
			duration: 700,									
			slideElement: 1,								
			autoRotation: false,							
			effect: false,									
			listOfSlides: 'ul > li',						
			switcher: false,								
			disableBtn: false,								
			nextBtn: 'a.link-next, a.btn-next, div.next',		
			prevBtn: 'a.link-prev, a.btn-prev, div.prev',		
			circle: true,									
			direction: false,								
			event: 'click',									
			IE: false,										
			autoHeight: false,
			random: false,
			ajax: false
		}, options || {});
		var _el = jQuery(context).find(this.options.listOfSlides);

        //alert('Group: ' + jQuery(context).parents('ul').attr('id') + ' items: ' + _el.length);

		if (this.options.effect) this.list = _el;
		else this.list = _el.parent();
		this.context = jQuery(context);
		this.switcher = jQuery(context).find(this.options.switcher);
		this.nextBtn = jQuery(context).find(this.options.nextBtn);
		this.prevBtn = jQuery(context).find(this.options.prevBtn);
		this.count = _el.length ; // _el.index(_el.filter(':last'));
		
		if (this.options.switcher) this.active = this.switcher.index(this.switcher.filter('.active:eq(0)'));
		else {
			if (!this.options.random) this.active = _el.index(_el.filter('.active:eq(0)'));
			else this.active = Math.round(Math.random()*(this.count));
		}
		if (this.active < 0) this.active = 0;
		this.last = this.active;
		
		this.woh = _el.outerWidth(true);
		if (!this.options.direction) this.installDirections(this.list.parent().width());
		else {
			this.woh = _el.outerHeight(true);
			this.installDirections(this.list.parent().height());
		}
		
		if (!this.options.effect) {
			this.rew = this.count - this.wrapHolderW + 1;
			if (!this.options.direction) this.anim = '{marginLeft: -(this.woh * this.active)}';
			else this.anim = '{marginTop: -(this.woh * this.active)}';
			eval('this.list.css('+this.anim+')');
		}
		else {
			this.rew = this.count;
			this.list.css({opacity: 0}).removeClass('active').eq(this.active).addClass('active').css({opacity: 1}).css('opacity', 'auto');
			this.switcher.removeClass('active').eq(this.active).addClass('active');
			if(this.options.autoHeight) this.list.parent().css({height: this.list.eq(this.active).outerHeight()});
		}
		this.flag = true;
		if (this.options.infinite){
			this.count++;
			this.active += this.count;
			this.list.append(_el.clone());
			this.list.append(_el.clone());
			eval('this.list.css('+this.anim+')');
		}
		
		this.initEvent(this, this.nextBtn, true);
		this.initEvent(this, this.prevBtn, false);
		if (this.options.disableBtn) this.initDisableBtn();
		if (this.options.autoRotation) this.runTimer(this);
		if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
	},
	initDisableBtn: function(){
		this.prevBtn.removeClass('prev-'+this.options.disableBtn);
		this.nextBtn.removeClass('next-'+this.options.disableBtn);
		if (this.active == 0 || this.count == this.wrapHolderW)
            this.prevBtn.addClass('prev-'+this.options.disableBtn);
		if (this.active == 0 && this.count == 1 || this.count < this.wrapHolderW)
            this.nextBtn.addClass('next-'+this.options.disableBtn);
		if (this.active == this.rew-1)
            this.nextBtn.addClass('next-'+this.options.disableBtn);
	},
	installDirections: function(temp){
		this.wrapHolderW = Math.ceil(temp / this.woh);
		if (((this.wrapHolderW - 1) * this.woh + this.woh / 2) > temp) this.wrapHolderW--;
	},
	fadeElement: function(){
		if (jQuery.browser.msie && this.options.IE){
			this.list.eq(this.last).css({opacity:0});
			this.list.removeClass('active').eq(this.active).addClass('active').css({opacity:'auto'});
		}
		else{
			this.list.eq(this.last).animate({opacity:0}, {queue:false, duration: this.options.duration});
			this.context.find('iframe').css({visibility: 'hidden'});
			this.list.removeClass('active').eq(this.active).addClass('active').animate({
				opacity:1
			}, {queue:false, duration: this.options.duration, complete: function(){
				jQuery(this).css('opacity','auto');
			}});
		}
		if(this.options.autoHeight) this.list.parent().animate({height: this.list.eq(this.active).outerHeight()}, {queue:false, duration: this.options.duration});
		if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
		this.last = this.active;
	},
	scrollElement: function(self){
		if (!self.options.infinite && !self.options.ajax) eval('self.list.animate('+self.anim+', {queue:false, duration: self.options.duration});');
		else eval('self.list.animate('+self.anim+', self.options.duration, function(){ self.flag = true });');
		if (self.options.switcher) self.switcher.removeClass('active').eq(self.active / self.options.slideElement).addClass('active');
	},
	runTimer: function(self){
		if(self._t) clearTimeout(self._t);
		self._t = setInterval(function(){
			if (self.options.infinite) self.flag = false;
			self.toPrepare(self, true);
		}, this.options.autoRotation);
	},
	initEventSwitcher: function(self, el){
		el.bind(self.options.event, function(){
			if(jQuery(this).hasClass('right')){
				if(!jQuery(this).is(':hidden')){
					jQuery(this).fadeOut(300);
				}
			}
			else{
				el.parent().find('a.right').fadeIn(300);
			}
			self.active = self.switcher.index(jQuery(this)) * self.options.slideElement;
			if(self._t) clearTimeout(self._t);
			if (self.options.disableBtn) self.initDisableBtn();
			if (!self.options.effect) self.scrollElement(self);
			else self.fadeElement();
			if (self.options.autoRotation) self.runTimer(self);
			return false;
		});
	},
	initEvent: function(self, addEventEl, dir){
		addEventEl.bind(self.options.event, function(){
			if (self.flag){
				if (self.options.ajax) {
					if((self.list.find('> li').eq(self.active+self.wrapHolderW).length > 0) && !self.list.find('> li').eq(self.active+self.wrapHolderW).hasClass('loaded')){
						jQuery.ajax({
							type: "GET",
							dataType: "html",
							url: self.list.find('> li').eq(self.active+self.wrapHolderW).attr('title'),
							success: function(msg){
								self.list.find('> li').eq(self.active+self.wrapHolderW).attr('title', '').addClass('loaded').append(jQuery(msg));
								self.flag = false;
								if(self._t) clearTimeout(self._t);
								self.toPrepare(self, dir);
								if (self.options.autoRotation) self.runTimer(self);
							},
							error: function(){
								alert('Ошибка на сервере! Перегрузите страницу!')
							}
						});
					}
					else{
						self.flag = false;
						if(self._t) clearTimeout(self._t);
						self.toPrepare(self, dir);
						if (self.options.autoRotation) self.runTimer(self);
					}
				}
				else{
					if (self.options.infinite) self.flag = false;
					if(self._t) clearTimeout(self._t);
					self.toPrepare(self, dir);
					if (self.options.autoRotation) self.runTimer(self);
				}
			}
			return false;
		});
	},
	toPrepare: function(self, side){
		if (!self.options.infinite){
			if ((self.active == self.rew) && self.options.circle && side) self.active = -self.options.slideElement;
			if ((self.active == 0) && self.options.circle && !side) self.active = self.rew + self.options.slideElement;
			for (var i = 0; i < self.options.slideElement; i++){
				if (side) { if (self.active + 1 <= self.rew) self.active++; }
				else { if (self.active - 1 >= 0) self.active--; }
			};
		}
		else{
			if (self.active >= self.count + self.count && side) self.active -= self.count;
			if (self.active <= self.count-1 && !side) self.active += self.count;
			eval('self.list.css('+self.anim+')');
			if (side) self.active += self.options.slideElement;
			else self.active -= self.options.slideElement;
		}
		if (this.options.disableBtn) this.initDisableBtn();
		if (!self.options.effect) self.scrollElement(self);
		else self.fadeElement();
	},
	stop: function(){
		if (this._t) clearTimeout(this._t);
	},
	play: function(){
		if (this._t) clearTimeout(this._t);
		if (this.options.autoRotation) this.runTimer(this);
	}
}

jQuery.fn.simplebox = function(options) { return new Simplebox(this, options); };
	
	function Simplebox(context, options) { this.init(context, options); };
	
	Simplebox.prototype = {
		options:{},
		init: function (context, options){
			this.options = jQuery.extend({
				duration: 300,
				linkClose: 'a.close, span.close',
				divFader: 'fader',
				faderColor: 'black',
				opacity: 0.7,
				wrapper: '#container',
				linkPopap: '.link-submit'
			}, options || {});
			this.btn = jQuery(context);
			this.select = jQuery(this.options.wrapper).find('select');
			this.initFader();
			this.btnEvent(this, this.btn);
		},
		btnEvent: function(self, el){
			el.click(function(){
				if (jQuery(this).attr('href')) self.toPrepare(jQuery(this).attr('href'));
				else self.toPrepare(jQuery(this).attr('title'));
				return false;
			});
		},
		calcWinWidth: function(){
			this.winWidth = jQuery('body').width();
			if (jQuery(this.options.wrapper).width() > this.winWidth) this.winWidth = jQuery(this.options.wrapper).width();
		},
		toPrepare: function(obj){
			this.popup = jQuery(obj);
			this.btnClose = this.popup.find(this.options.linkClose);
			this.submitBtn = this.popup.find(this.options.linkPopap);
			
			if (jQuery.browser.msie) this.select.css({visibility: 'hidden'});
			this.calcWinWidth();
			this.winHeight = jQuery(window).height();
			this.winScroll = jQuery(window).scrollTop();
			
			this.popupTop = this.winScroll + (this.winHeight/2) - this.popup.outerHeight(true)/2;
			if (this.popupTop < 0) this.popupTop = 0;
			this.faderHeight = jQuery(this.options.wrapper).outerHeight();
			if (jQuery(window).height() > this.faderHeight) this.faderHeight = jQuery(window).height();
			
			this.popup.css({
				top: this.popupTop,
				left: this.winWidth/2 - this.popup.outerWidth(true)/2
			}).hide();
			this.fader.css({
				width: this.winWidth,
				height: this.faderHeight
			});
			this.initAnimate(this);
			this.initCloseEvent(this, this.btnClose, true);
			this.initCloseEvent(this, this.submitBtn, false);
			this.initCloseEvent(this, this.fader, true);
		},
		initCloseEvent: function(self, el, flag){
			el.click(function(){
				self.popup.fadeOut(self.options.duration, function(){
					self.popup.css({left: '-9999px'}).show();
					if (jQuery.browser.msie) self.select.css({visibility: 'visible'});
					self.submitBtn.unbind('click');
					self.fader.unbind('click');
					self.btnClose.unbind('click');
					jQuery(window).unbind('resize');
					if (flag) self.fader.fadeOut(self.options.duration);
					else {
						if (self.submitBtn.attr('href')) self.toPrepare(self.submitBtn.attr('href'));
						else self.toPrepare(self.submitBtn.attr('title'));
					}
				});
				return false;
			});
		},
		initAnimate:function (self){
			self.fader.fadeIn(self.options.duration, function(){
				self.popup.fadeIn(self.options.duration);
			});
			jQuery(window).resize(function(){
				self.calcWinWidth();
				self.popup.animate({
					left: self.winWidth/2 - self.popup.outerWidth(true)/2
				}, {queue:false, duration: self.options.duration});
				self.fader.css({width: self.winWidth});
			});
		},
		initFader: function(){
			if (jQuery('div.'+this.options.divFader).length > 0) this.fader = jQuery('div.'+this.options.divFader);
			else{
				this.fader = jQuery('<div class="'+this.options.divFader+'"></div>');
				jQuery('body').append(this.fader);
				this.fader.css({
					position: 'absolute',
					zIndex: 999,
					left:0,
					top:0,
					background: this.options.faderColor,
					opacity: this.options.opacity
				}).hide();
			}
		}
	};


//})(jQuery);




function decrementValue(input_name)
{
    var input = jQuery('input[name="' + input_name + '"]');

    if(input.val() / 1 != NaN && input.val()/1 != 0){
        input.val(input.val() / 1 -1);
    }

    return false;
}

function incrementValue(input_name)
{
    var input = jQuery('input[name="' + input_name + '"]');

    if(input.val() / 1 != NaN ){
        input.val( (input.val() / 1) + 1);
    }

    return false;
}

