popup = {
	overlay:	undefined,
	popup:		undefined,
	close:		undefined,
	content:	undefined,
	loading:	undefined,
	init:		function(){
		this.overlay = jQuery('.overlayBg');
		this.popup = jQuery('.popupTbl');
		this.close = jQuery('.popupClose');
		this.content = jQuery('.popupContent');
		this.loading = jQuery('<div class="loading"></div>');
		this.hidden = jQuery('<div style="position:absolute;left:-1000px;top:-1000px;width:1px;height:1px;overflow:hidden;"></div>');
		this.overlay.append(this.hidden);
		var overlay = this.overlay;
		var popup = this.popup;
		var content = this.content;
		var loading = this.loading;
		if( jQuery.browser.msie ){
			this.overlay.css({opacity:0.7});
		}
		if( jQuery.browser.msie && jQuery.browser.version == 6 ){
			this.overlay.css({position:'absolute', height:jQuery(window).height()+'px'});
			this.popup.css({position:'absolute', height:jQuery(window).height()+'px'});
			jQuery(window).resize(function(){
				overlay.css({height:jQuery(window).height()+'px'});
				popup.css({height:jQuery(window).height()+'px'});
			}).scroll(function(){
				overlay.css({top:jQuery(window).scrollTop()+'px'});
				popup.css({top:jQuery(window).scrollTop()+'px'});
			});
		}
		this.close.click(function(){
			overlay.addClass('hidden');
			popup.addClass('hidden');
			content.empty().append(loading);
		});
	},
	iframe:		function(url){
		this.overlay.removeClass('hidden');
		this.popup.removeClass('hidden');
		var content = this.content;
		var iframe = (function(obj){ return obj; })( jQuery('<iframe></iframe>') );
		iframe.attr({frameborder:0, width:520, src:url}).one('load', function(){
			var height = jQuery('iframe').contents().find('body').height();
			iframe.attr({height:height});
			content.empty().append( iframe );
		});
		this.hidden.append(iframe);
	},
	ajax:		function(url){
		this.overlay.removeClass('hidden');
		this.popup.removeClass('hidden');
		var content = this.content;
		jQuery.ajax({
			url: url,
			success: function(text){
				content.empty().append( jQuery('#responceContent', text).html() );
			}
		});
	}
}

mainInitFunction = function(){
	jQuery('#mainPageMovie .slideItem').each(function(){
		var actEl = jQuery(this).find('.cw:first');
		var oHeight = jQuery(this).find('.c:first').height();
		var cHeight = 0;
		var timer = undefined;
		jQuery(this).mouseover(function(){
			jQuery(actEl).animate({height:oHeight+'px'}, {duration:200, queue:false, easing: 'linear'});
		}).mouseout(function(){
			jQuery(actEl).animate({height:cHeight+'px'}, {duration:200, queue:false, easing: 'linear'});
		});
	});
	jQuery('#headerBlock .today').each(function(){
		var d = new Date();
		var dd = ( d.getDate() < 10 )?( '0'+d.getDate() ):( d.getDate() );
		var mm = ( d.getMonth() < 9 )?( '0'+( d.getMonth() + 1 ) ):( d.getMonth() + 1 );
		var yyyy = d.getFullYear();
		jQuery(this).find('.day').text( dd );
		jQuery(this).find('.month').text( mm );
		jQuery(this).find('.year').text( yyyy );
	});
	jQuery('div.cthr .arrow').click(function(){
		var arrow = this;
		var data = jQuery(this).parents('.productDataTd:first').find('.dataTbl:first');
		if( jQuery(arrow).hasClass('show') ){
			jQuery(arrow).removeClass('show');
			jQuery(data).slideUp(300);
		}else{
			jQuery(arrow).addClass('show');
			jQuery(data).slideDown(300);
		}
	});
	
	jQuery('label.checkbox-inline, label.checkbox-block').each(function(){
		var label = jQuery(this);
		var checkbox = label.find('input:first');
		var className = label.attr('class');
		checkbox.css({'opacity':0});
		checkbox.change(function(){
			if( checkbox.attr('checked') ){
				label.attr({'class': className+'-check'});
			}else{
				label.attr({'class': className});
			}
			checkbox.blur();
		}).change();
	});
	jQuery('#allProductsCheck input').each(function(){
		var checkbox = jQuery(this);
		var allCheck = false;
		jQuery('#catalogFilterWrapper .filterCol1 input[type="checkbox"]').not(checkbox).each(function(){
			jQuery(this).change(function(){
				if( !jQuery(this).attr('checked') ) checkbox.removeAttr('checked').change();
			});
		});
		checkbox.change(function(){
			if( checkbox.attr('checked') ){
				jQuery('#catalogFilterWrapper .filterCol1 input[type="checkbox"]').not(checkbox).attr({'checked':'checked'}).change();
			}
		});
	});
	jQuery('#catalogFilterWrapper .select-style select').each(function(){
		var select = jQuery(this);
		select.css({'opacity':0});
		var option = select.parent().find('.select-option');
		select.change(function(){
			var val = select.find('option[value="'+select.val()+'"]').html();
			option.text( val );
		});
	}).change();
	
	/* Feedback form */
	jQuery('input[placeholder],textarea[placeholder]').each(function(){
		var prText = jQuery(this).attr('placeholder');
		jQuery(this).removeAttr('placeholder');
		var pr = jQuery('<span class="placeholder">'+prText+'</span>');
		var input = this;
		var checkInput = function(){
			if( jQuery(input).val() != '' ){
				pr.addClass('hidden');
			}else{
				pr.removeClass('hidden');
			}
			return true;
		}
		jQuery(input).before(pr).keyup(checkInput).blur(checkInput).blur();
	});
	jQuery('a.feedbackLink').click(function(){
		popup.iframe( jQuery(this).attr('href') );
		return false;
	});
	jQuery('#mainPageServices a').click(function(){
		popup.ajax( jQuery(this).attr('href') );
		return false;
	});
	popup.init();
	/* Feedback form */
	
}
jQuery.noConflict();
jQuery(document).ready(mainInitFunction);
