//   Антиспам
//==============
String.prototype.printAddr = function ($hamper,$prefix,$postfix,$face) {
	$hamper=$prefix+"@"+this+	($postfix || '')
	document.write(($face||$hamper));
}


String.prototype.printAddrName = function ($hamper,$prefix,$postfix,$face, $name) {
	$hamper="<a href='mailto:"+$prefix+"@"+this+	($postfix || '')+"'>"+$hamper+"</a>"
	document.write(($face||$hamper));
}


//   Таймер закрытия окна
//==============
function close_timer() {
	var $timeID = "close_time";
	var $e = document.getElementById($timeID);
	var $cTicks = parseInt($e.innerHTML);
	var $timer = setInterval(function() {
		if ( $cTicks ) {$e.innerHTML = --$cTicks;}
		else { clearInterval($timer); window.close(); }
		}, 1000);
}


var C = {
	//Вопросы-ответы
	faq: {
		init: function() {
			$('dd.answer').css('display', 'none');
			if (window.location.toString().indexOf('#') != -1) {
					key = window.location.toString().slice(window.location.toString().indexOf('#')+1).split('_')[1]/1;
					C.faq.showHide(key);
				};
			$('.faq_link').click(function() {
				item_id=$(this).attr('id').split('_')[1]/1;
				C.faq.showHide(item_id);
				return false;
				});
			$('.expand').click(function() {
				var link = $(this).find('span');
				link.toggleClass('inited');
				if(link.is('.inited')){
					link.html('Скрыть все ответы');
					$('.faq').not('.pane').find('.faq_link').addClass('active');
					$('.faq').not('.pane').find('dd.answer').slideDown('fast');
				}else{
					link.html('Показать все ответы');
					$('.faq').not('.pane').find('.faq_link').removeClass("active");
					$('.faq').not('.pane').find('dd.answer').slideUp('fast');
					//$('dd.answer').not('.addform').slideUp('fast');
				}
				return false;
				});
			},
		showHide: function(item_id) {
			var answ = '#answ_' + item_id;
			var q = "#q_" + item_id;
			if ($(answ).css('display') == 'none') {
				$(answ).slideDown('fast',function(){$(this).css("border-bottom", ".3em #E6E7DA solid")});
				$(q).addClass("active");
			} else {
				$(answ).slideUp('fast');
				$(q).removeClass("active");
				}
			}
	}
}




/*after all*/
$.fn.hint = function (blurClass) {
	if (!blurClass) { blurClass = 'blur'; }
	return this.each(function () {
	// get jQuery version of 'this'
	var $input = $(this),

	// capture the rest of the variable to allow for reuse
	title = $input.attr('title'),
	$form = $(this.form),
	$win = $(window);

	function remove() {
		if ($input.val() === title && $input.hasClass(blurClass)) {
			$input.val('').removeClass(blurClass);
		}
	}

	// only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
}


jQuery(document).ready(function(){
	if ($(window).width()<1100) {
		$('#header').css('margin', '5px 0 0');
		$('.mlddm ul li a').css('padding', '2px 10px');
		}
	//IE сцуко
	$('img[@src$=.png]').ifixpng();
	$('.png').ifixpng();
	$('input[title!=""],textarea[title!=""]').hint();
})


