var IE7_PNG_SUFFIX = ".png";

(function(){
	jQuery.fn.extend({
		placehold: function(){
			var $query = this;
			var placeholdOptions = arguments[0] || {};
			var $inputs = $query.filter(":text, :password");
			$inputs
				.each(function(){
					var $this = jQuery(this);
					this.placeholdValue = placeholdOptions.placeholdValue || $.trim($this.val());
					$this.val(this.placeholdValue);
					$this.addClass(placeholdOptions.blurClass || "");
				})
				.bind("focus",function(){
					var $this = jQuery(this);
					var val = $.trim($this.val());
					if (val == this.placeholdValue || val == "") {
						$this.val("")
							.removeClass(placeholdOptions.blurClass || "")
							.addClass(placeholdOptions.focusClass || "");
					}
				})
				.bind("blur",function(){
					var $this = jQuery(this);
					var val = $.trim($this.val());
					if(val == this.placeholdValue || val == "") {
						$this.val(this.placeholdValue)
							.addClass(placeholdOptions.blurClass || "")
							.removeClass(placeholdOptions.focusClass || "")
					}
				});
			return $query;
		}
	})
})()

$(function(){

	$.fn.qtip.styles.beige = {
		background: '#F2EEE3',
		color: '#696969',
		fontSize: '13px',
		fontStyle: 'italic',
		padding: '5px 10px',
		border: { width: 0, radius: 4, color: '#F2EEE3' },
		style: {
			width: { max: 250 }
		}
	};

	/*$('#header a.tooltip').qtip({
		position: {
			corner: { target: 'rightMiddle', tooltip: 'leftMiddle' }
		},
		style: {
			name: 'beige',
			width: { max: 250 },
			tip: { corner: 'leftMiddle', size: { x: 10, y: 10 } }
		}
	});*/

	$('#content a.print-btn').click(function() {
		window.open($(this).attr('href'), 'print_wnd', 'width=800, height=600, left=0, top=0, toolbar=0, location=0, directories=0, menubar=0, scrollbars=1, resizable=1, status=0');
		return false;
	});
	$('#content a.print-img').click(function() {
		window.open($(this).attr('href'), 'print_wnd', 'width=800, height=600, left=0, top=0, toolbar=0, location=0, directories=0, menubar=0, scrollbars=1, resizable=1, status=0');
		return false;
	});

	$('#navigation li a.tooltip, #content a.tooltip').qtip({
		position: {
			corner: { target: 'topRight', tooltip: 'bottomLeft' },
			target: 'mouse',
			adjust: { mouse: true, screen: true }
		},
		style: {
			name: 'beige',
			width: { max: 200 },
			tip: { corner: 'bottomLeft', size: { x: 10, y: 10 } }
		}
	});

	$('#benefits a').qtip({
		position: {
			corner: { target: 'rightMiddle', tooltip: 'leftMiddle' }
		},
		style: {
			name: 'beige',
			width: { max: 350 },
			tip: { corner: 'leftMiddle', size: { x: 10, y: 10 } }
		}
	});

	$('#top_links a').qtip({
		position: {
			corner: { target: 'bottomRight', tooltip: 'topLeft' },
			target: 'mouse',
			adjust: { mouse: true, screen: true }
		},
		style: {
			name: 'beige',
			width: { max: 300 },
			tip: { corner: 'topLeft', size: { x: 10, y: 10 } }
		}
	});

	/*if ($('body').hasClass('main')) {
		$('#content .promotions').accordion({header: '.title'});
	}*/

	$('#about a.more')
		.click(function() {
			var $this = $(this);
			var $more_about = $('#more_about');
			if ($more_about.is(':hidden'))
				$('#about').addClass('auto_height');
			$more_about.slideToggle('slow', function() {
				$this.toggleClass('more').toggleClass('less');
				if ($more_about.is(':hidden')) {
					$this
						.html('Подробнее')
						.attr('href', '/about/');
					$('#about').removeClass('auto_height');
				}
				else {
					$this
					.html('Скрыть')
					.attr('href', 'javascript:void(0);');
				}
			});
			return false;
			
		});
	/*$('#about a.more')
		.click(function(){ return false; })
		.qtip({
			position: {
				corner: { target: 'bottomMiddle', tooltip: 'topMiddle' },
				target: $('#about')
			},
			show: 'click',
			hide: 'unfocus',
			content: { text: $('#about .tooltip') },
			style: {
				background: 'url(/assets/about-bg.gif) right -208px no-repeat #A93C25',
				padding: '0 30px 20px',
				lineHeight: '140%',
				border: { width: 0 },
				color: '#E3DBC7',
				fontSize: '13px',
				width: { max: 734 }
			},
			api: {
				onShow: function() {
					this.elements.target.hide();
				},
				onHide: function() {
					this.elements.target.show();
				}
			}
		});*/


	$('#sidebar li li:not(.current) a').hover(
		function() {
			var $this = $(this);
			$this.css('color', $this.parents('li.current').css('background-color'));
		},
		function() {
			$(this).css('color', '#000');
		}
	);
	$('input.placeholder').placehold({blurClass:'placehold', focusClass:'focus'});
	$('#content ul.clickable li').click(function(e) {
		e.preventDefault();
		window.location = $('a', this).attr('href');
	});
	
	$('table tr:nth-child(even)').addClass('even');
	
	$('#banners_cycle').cycle({ 
	    timeout:  8000, 
	    speed:  3000
	});
	
	$('.new_icon').each(function() {
		 $(this).css('top', ($(this).parent().height() - 30) / 2);
	});
	
	lightboxParams = {
		imageLoading: '/assets/lightbox/ico-loading.gif',
		imageBtnPrev: '/assets/lightbox/btn-prev.gif',
		imageBtnNext: '/assets/lightbox/btn-next.gif',
		imageBlank: '/assets/lightbox/blank.gif',
		//imageBtnClose: '/assets/lightbox/btn-close.gif',
		imageBtnClose: '/assets/lightbox/lightbox-btn-close.gif',
		txtImage: 'Фото',
		txtOf: 'Из'
		//fixedNavigation: true
	};
	
	$("#lightbox a.image").lightBox(lightboxParams);
	$("#lightbox .title a").lightBox(lightboxParams);
	
	$(".lightbox").each(function() {
		$("a.image", this).lightBox(lightboxParams);
		$(".title a", this).lightBox(lightboxParams);
	});

	$("body div.visitors").corner('tl tr 5px');

	// Пишем в Google Analytics события при заполнении посетителем формы
	var currentPage = jQuery.url.attr("path");
	$(':input').blur(function () {
		if($(this).val().length > 0){
			pageTracker._trackEvent("Form: " + currentPage, "input_exit", $(this).attr('name'));
		} 
	});

});

