var 	state = new Object();
		state.sn = 0;
		state.set = function (n) {
			
			state.sn = n; 
			
		};
		

function countPages(){

	var pageCount = $('.browser').length;
	
	//$('#debug').text(state.sn);
	//$('#debug2').text(pageCount);
	
	if( pageCount == state.sn ) {
		$('#linkAll').attr('class', 'active');
		$('#linkAllPic').attr("src", "http://catlab.ru/img/blank.gif");
		$('#linkAll').html('Свернуть все');
	} else {
		$('#linkAll').attr('class', '');
		$('#linkAllPic').attr("src", "http://catlab.ru/img/blank.gif");
		$('#linkAll').html('Развернуть все');
	}
}

function shower(id, l){
	var el = document.getElementById(id);
	if(el.style.display == 'block'){
        $('#' + id).animate({height: "hide"}, 300, function(){
			state.set(state.sn - 1);
			countPages();
		});
		document.getElementById(l).className = '';
    } else {
		$('#' + id + '> div.pageScreen > img').attr('src',$('#' + id + '> div.pageScreen > img').attr('title'));
		$('#' + id).animate({height: "show"}, 300, function(){
			state.set(state.sn +1);
			countPages();
		});
		document.getElementById(l).className = 'active';
	}
}

function newsShower(id, l){
	var el = document.getElementById(id);
	if(el.style.display != 'block'){
		$('#' + id).animate({height: "show"}, 300);
		document.getElementById(l).className = 'captionTitleOpen';
    }
    else{
        $('#' + id).animate({height: "hide"}, 300);
		document.getElementById(l).className = 'captionTitle';
	}
}


function showClients(id){
	if(document.getElementById(id).style.height != 'auto'){
		$('#' + id).css('height', 'auto');
		$('#arrow').removeClass("arrow");
		$('#arrow').addClass("arrowTop");
	}
	else{
		$('#' + id).css('height', '110px');
		$('#arrow').removeClass("arrowTop");
		$('#arrow').addClass("arrow");
	}
}

function showAll(num){

	if($('#linkAll').attr('class')!= 'active'){
			
		$('div.onePage').each(function(){
			$(this).find('div.pageScreen > img').attr('src',$(this).find('div.pageScreen > img').attr('title'));
		});
	
		//	return;
		for (var i = 1; i <= num; i++){
			$('#page' + i).animate({height: "show"}, 300);
			document.getElementById('allPortfolio').getElementsByTagName('a')[i].className = 'active';
		}
		$('#linkAll').attr('class', 'active');
		$('#linkAllPic').attr("src", "http://webmaster.spb.ru/img/closeAll.gif");
		$('#linkAll').html('Свернуть все');
		
		var pageCount = $('.browser').length;
		state.set(pageCount);
		//$('#debug').text(state.sn);
		
	} else {
	
		for (var i = 1; i <= num; i++){
			$('#page' + i).animate({height: "hide"}, 300);
			document.getElementById('allPortfolio').getElementsByTagName('a')[i].className = '';
		}
		$('#linkAll').attr('class', '');
		$('#linkAllPic').attr("src", "http://webmaster.spb.ru/img/openAll.gif");
		$('#linkAll').html('Развернуть все');
		
		state.set(0);
		//$('#debug').text(state.sn);
		
	}
	
	
	
}




//for link opened in new tab
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
for (var i=0; i < anchors.length; i++) {
	if (anchors[i].getAttribute("href") &&

	anchors[i].getAttribute("rel") == "external") {
		anchors[i].target = "_blank";
	}
}
}

function portPopap(id, pos){
		$('.pPopap').each(function(){
			if($(this).attr('id')!=id){$(this).fadeOut()}
			else{
				if($(this).css('display')!='block'){
					$(this).fadeIn().css('left', pos);
					}
				else{$(this).fadeOut()}
				}
			});
		return false;
	}

function servisesPopapClose(){
	//alert('test');
	$('#shadow').fadeTo('fast', 0).hide();
	$(this).parents('.servisesPopap').fadeOut();
	}

function servisesPopapOpen(el){
	var e = el?el:'servisesPopap';
	var topX = document.documentElement.scrollTop + 100;
	$('#shadow').css({display:'block',opacity:0}).fadeTo('fast', 0.4);
	$('.'+e).css('top', topX + 'px').fadeIn();
}



(function($){
	$.fn.inputValue = function (val){
		$(this).click(function(){
							   this.value!=val?this.value=this.value:this.value='';
							   if (this.createTextRange){
								   var r = this.createTextRange();
								   r.collapse(false);
								   r.select();
							  }
							   });
		$(this).blur(function(){
							  this.value==''?this.value=val:this.value=this.value;
								});
		return this;
	}
})(jQuery);




$(function(){
		   var height = 100;
		   $.each($('#portfolio .scrollElementWrapper'),function(){
																if(height < $(this).height())height = $(this).height();
																				  });
		   $('#scrollBlock').height(height);
		   $('.servisesPopap .inputText, .servisesPopap textarea').each(function(){
														$(this).inputValue(this.value);
														});
		   $('.servisesPopap .blockClose').click(servisesPopapClose);
		   
		   $('.services .ordering').click(function(){servisesPopapOpen($(this).attr('rel'));return false;});
		   
		   $('#FrTGMenu a').hover(
								  function(){
									  $('a', $(this).parents('.noWrap')).addClass('hover');
									  },
								  function(){
									  $('a', $(this).parents('.noWrap')).removeClass('hover');
									  }
								  
								  );
		   
		   
		   });
























