//additional properties for jQuery object
$(document).ready(function()
{
   $('.l-service1').show();
   //align element in the middle of the screen
   $.fn.alignCenter = function() 
   {
      //get margin left
      var marginLeft =  - $(this).width()/2 + 'px';
      //get margin top
      var marginTop =  - $(this).height()/2 + 'px';
      //return updated element
      return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

   $.fn.togglePopup = function()
   {
       
     //detect whether popup is visible or not
     if($('#l-popup').hasClass('c-popup-hidden'))
     {
       //c-popup-hidden - then display
       //when IE - fade immediately
       if($.browser.msie)
       {
         $('#l-dark-background').height($(document).height()).toggleClass('c-popup-hidden')
                    .click(function(){$(this).togglePopup();});
       }
       else
       //in all the rest browsers - fade slowly
       {
         $('#l-dark-background').height($(document).height()).toggleClass('c-popup-hidden').fadeTo('slow', 0.7)
                    .click(function(){$(this).togglePopup();});
       }

       $('#l-popup')
         .html($(this).html())
         .alignCenter()
         .toggleClass('c-popup-hidden');
     }
     else
     {
       //visible - then hide
       $('#l-dark-background').toggleClass('c-popup-hidden').removeAttr('style').unbind('click');
       $('#l-popup').toggleClass('c-popup-hidden');
     }
   };
   
   
	$('.c-service-tab').click(function() {
		$('.c-service-tab').removeClass('c-service-tab-active');
		$(this).addClass('c-service-tab-active');
		var classVar=$(this).attr('rel');
		$('.l-service1').hide();
		$('.l-service2').hide();
		$('.l-service3').hide();
		$('.'+classVar).fadeIn();
	});   
   
});


/**
 * фукнция проверяет похож ли возвращаемый текст на JSON
 * @param {Object} str
 */
jQuery.isJson = function(str) {
 if (jQuery.trim(str) == '') return false;
 //alert(str.replace(/\\./g, '@'));//убирает все экранирванные символы
 str=str.replace(/\\./g, '@');
 //alert(str); 
 str=str.replace(/["\'][^\'"\\\n\r]*["\']/g, '');
 //alert(str);
 return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
}


jQuery.isDigit = function(str) {
 if (jQuery.trim(str) == '') return false;
 return (/^[0-9]+$/).test(str);
}


