/*log*/
function log(a,a1,a2,a3,a4,a5,a6,a7) {
 window.console && window.console.log && window.console.log(a,a1,a2,a3,a4,a5,a6,a7);
}

try{
	var playerVersion = swfobject.getFlashPlayerVersion();
	var majorVersion = playerVersion.major;
  }catch(err){}
if(!curMod){var curMod,gallObjs}
var GallPreloader ={};

$(document).ready(function(){


$('a[rel*=facebox]').facebox({title:this.title});

//	$('body').append('<a href="javascript:$.facebox({ ajax: \'/\' }, \'popup_slim\');">test</a>')

	var preLoader = $('.main_photo .preloader').clone();
	$('.type3').after(preLoader.clone());
	$('.type3').find('.round').after(preLoader.clone());
	var wr = $('.wr:first').html();
	cuRobj = new Object();


	if($('.type1').height() != null){//обычные блоки
							$('.second_block').css({
									'overflow':'hidden',
									'height' : ($('.type1').height() + 50)
							})
	}

	$('.second_block').find('.wr').html(wr);

//$('body').prepend('czxczcx<a href="javascript:faceboxOpen(\'/catalogue/leather/158.html\')">sd</a>')
/*
gallery
-------------------------------------
*/
if(gallObjs){
var collect2 = $('#simpgall_main')

var pageView = $.cookie("pageby");
var _location = $('#m_node_href').html()
var wrp = $('.wrp:first')
var viewFload
	pageView = pageView ? pageView : '6';
$('#navview').css({zoom:1})
$(window).bind('scroll',function(){	setGallLogerSize(GallPreloader)})


	$('#nav_links .active:first').removeClass('active')

		if(parseInt(pageView,10) != -1){
			$('#nav_links').find('span,a').each(function(){			
				if($(this).html() == pageView){
					$(this).addClass('active')
				}
			})
		}else{
			$('#nav_links span:last').addClass('active')
		}

viewFload = curMod == gallObjs[1].coocieName ? false : true

if(collect2.length){

	window.scrollMaxY = 0;
	document.documentElement.scrollTop = 0	
	
	$.facebox({ ajax: location.href }, 'popup_slim')
	$('.dis').removeClass('dis')
	$('#flashgall').after('<ul class="collect collect2 hor" id="simpgall"></ul>')

	viewFload = false
}
	setTimeout(function() { 
	setJsonGallery(pageView,0,'heights')
	 }, 0)

	
if(majorVersion >= 9){
	$('#gal').removeClass('disabled')

   $('#navview span').bind('click',function(){
		changeView(this)
	})
	
	if(curMod == gallObjs[1].coocieName){
		setMode($('#' + gallObjs[1].navName),gallObjs[1])
	}
	else if(curMod == gallObjs[2].coocieName)
		setMode($('#' + gallObjs[2].navName),gallObjs[2])
}

setTimeout(function() { 
	$('.js_hide').removeClass('js_hide')

}, 0)

	$('.tmclass').removeClass('tmclass')
}
	function changeView(o){
		
		if(o.id ==gallObjs[1].navName){
			setMode(o,gallObjs[1])
		}else if(o.id ==gallObjs[2].navName){
			setMode(o,gallObjs[2])
		}
	}

	function setMode(o,block){
		if(!$(o).hasClass('active')){

			$(o).addClass('active').siblings().removeClass('active')
			$.cookie("curmod",block.coocieName);

			$('.b_block:first')[0].className = 'b_block b_gallered mode_' + block.idBlock
		}
	}

initViewPager()

pagerActive = $('#pager .active:first')

var curPage = parseInt(pagerActive.html() - 1,10);
	curPage = curPage ? curPage : 0;

initPagePager(false,pagerActive)

function initViewPager(){
	var nav_links = $('#nav_links')
	if(nav_links.length){
		nav_links[0].pageBy = pageView;
		nav_links.find('span').bind('click',function(){
			if(!$(this).hasClass('active')){
				$('.active',nav_links).removeClass('active')
				
				$(this).addClass('active')
				var pageBy = parseInt($(this).html(),10);
				pageBy = pageBy ? pageBy : -1;
				nav_links[0].pageBy = pageBy;
	
				$.cookie("pageby",pageBy,{path: "/"});
	
				setJsonGallery(pageBy,0)
			}
			return false
		})
	}
}
function initPagePager(pages,curPage){
	var pager = $('#pager')
	
	pager.empty()
	if(pages > 1){

	
		for (ii = 0; ii < pages ; ii++){	
			var oins = curPage == ii ? ' class="active"' : '';
			var o = $('<span' + oins + '>' + (ii + 1 ) + '</span>')
			pager.append(o)
		}	
	}

	
	pager.find('a,span').bind('click',function(){
		if(!$(this).hasClass('active')){
			$('.active',pager).removeClass('active')
			
			$(this).addClass('active')
			
			var curPage = parseInt($(this).html() - 1,10);
			curPage = curPage ? curPage : 0;
			
			var pageBy = $('#nav_links')[0].pageBy;
			pageBy = pageBy ? pageBy : $('#nav_links span:first').html();
			
			setJsonGallery(pageBy,curPage)

		}
		return false
	})
	
	//RUFF 09/09/2011
	//pager - 'show all'
	if(pages > 1){
		pager.append($('#nav_links').children().last().clone(true));
		pager.find('.all').bind('click', function(){
			$(this).siblings().removeClass('active');
			$('#nav_links').find('.all').addClass('active');
		});
	}
	//--end
}
function setJsonGallery(pageBy,curPage,heights){
	
	var simpgall = $('#simpgall');

	var data = 'json=1&limit=' + pageBy + '&page=' + curPage + '&cid=' + $('#collectId').html();

//	console.log(simpgall)
	simpgall.height(simpgall.height()).addClass('invis')
	simpgall.empty()

		viewFload = setLoader(simpgall,viewFload)
		$.getJSON('/collections', data, function(json_data){
		
				var elem = json_data.items
		
				simpgall.append('<div class="simp_wr"></div>')
				simpgallWr = $(simpgall).find('.simp_wr:first')
				for (ii = 0; ii < elem.length ; ii++){
					
					var o = $('<li id="subgall_1">\
									<div class="round rc rc_r10 gall-img gall-2">\
										<a rel="facebox" title="' + elem[ii].name + '" href="' + elem[ii].path + '" class="c"><b class="cc">\
											<img alt="' + elem[ii].name + '" src="' + elem[ii].img + '">\
										</b></a>\
										<i class="tt"></i><i class="bb"></i><i class="b bl"></i><i class="b br"></i><i class="t tl"></i><i class="t tr"></i>\
									</div>\
									<p class="name">' + elem[ii].name + '</p>\
								</li>').find('a').facebox({title:this.title}).end()

				simpgallWr.append(o)
				}
		
			if(heights !='heights'){
				simpgall.animate({height:simpgallWr.height()},300,function(){
					removeLoader(simpgall)
					simpgall.removeClass('invis')	

				});			
			}else{
				simpgall.height('auto')
				removeLoader(simpgall)
				simpgall.removeClass('invis')			
			}
			
			setTimeout(function() { 
				if($('.mode_flashgall:first').length){
				$('#layout').height('auto')				
				}

			 }, 0)

			
					
			initPagePager(json_data.pages,curPage)
								
		}, 'json')

	

}

function setLoader(O,viewFload){

	if(!viewFload){
		GallPreloader =$('#facebox_preloader')
		viewFload = true
	}else{
		$('body').append('<div id="facebox_preloader" class="preloader" style="position:absolute"><i></i></div>')
		GallPreloader = $('#facebox_preloader')
		setGallLogerSize(GallPreloader)		
	}
	
return viewFload
}
function removeLoader(O){
	
	GallPreloader.remove()

}
function setGallLogerSize(o){
	
	if(o.length){
		var wrpTop = wrp.offset().top;
		var wrpHeight = wrp.height() + (!$.browser.msie6 ? 0 : -100)
		var wrpBottom = wrpTop + wrpHeight;
		var tmMarg = 200;
	
	
		var topTm = document.documentElement.scrollTop + ( document.documentElement.clientHeight / 2)
		topTm = wrpTop + tmMarg < topTm  ? topTm : wrpTop + tmMarg;
		topTm = topTm > wrpBottom - tmMarg ? wrpBottom - tmMarg : topTm;
	
		o.css({top:topTm})
	}
}

/*
----------------------
*/

 //$('.content-element .tube').before('<b class="preloader"><i></i></b>').wrapInner('<div class="out-rem"><div class="in-rem"></div></div>')
 

	//	$('.main-img .cc').height($('.main-img .cc').find('img').height())
		//Запрос
	//	$('.collect li img').after('<i class="preloader"></i>')


/*
		HrefObjectLoaded = new Object();			

		$('.collect li a').bind('click',function(){

			data='json=1';
			
			$('.out-rem:first').height($('.in-rem:first').height()).find('.in-rem:first').add('.preloader i').fadeOut('100',function(){})
				$('.collect li img').hide()  
		
			$.get($(this).attr('href'), data, function(json_data){

					HrefObjectLoaded.Loaded = 0;
					
					
					$('.in-rem:first,.preloader i').fadeIn('100',function(){
							$('.out-rem:first').animate(
									{
							         height: ($('.in-rem:first').height()) 
									},
									300)
					});
					
					
					cur = json_data[2];
				//	console.log(cur)
					$('#collection_name').html(cur.name);

					if (cur.price !=''){
						$('.price:first').html(cur.price + ' руб.').show();
					}else{
						$('.price:first').hide();
					}
					if (cur.disabled != 0){
						$('.has_collection:first').html('Временно нет в продаже').show();
					}else{
						$('.has_collection:first').hide();
					}
					if (cur.shortcontent !=''){
						$('.shortcontent:first').html(cur.shortcontent).show();
					}else{
						$('.shortcontent:first').hide();
					}
					if (cur.fullcontent !=''){
						$('.content-element .decor2:first').find('.fullcontent').html(cur.fullcontent).end().show();
					}else{
						$('.content-element .decor2:first').hide();
					}

					  					
					$('.collect li:has(img)').each(function(){
						var index = $('.collect li:has(img)').index(this);
						
						changeImage(this,json_data[index],index)
					});


					$('.botton_prev a').attr('href',json_data[1].href);
					$('.botton_next a').attr('href',json_data[3].href);

 


				}, 'json');

		return false;
		}); 
 
   function changeImage(hrefObject,element,index){
		
 
  		hrefObject.newImg = new Image();
 				  if(index != 2){
				 		hrefObject.newImg.onload = function(){
							//	newImg.onload = null;
		
							  $(hrefObject).find('a').attr('href',element.href)
								  								.attr('title',element.name)
												.find('img').attr('alt',element.name)
															  .attr('src',hrefObject.newImg.src)
															  .attr('height',hrefObject.newImg.height)
															  .attr('width',hrefObject.newImg.width)
														//	  .fadeIn('100')
			// 	console.log(hrefObject.newImg)
							  HrefObjectLoaded.Loaded = HrefObjectLoaded.Loaded + 1;
							  loaded()
						  }
						  hrefObject.newImg.src = element['preview'].src;
			///			  $(hrefObject).find('a')[0].Loaded = false;
				  }else{
				 		hrefObject.newImg.onload = function(){
							//	newImg.onload = null;
					  			$(hrefObject).find('img')
								  							.attr('alt',element.name)
														  .attr('src',hrefObject.newImg.src)
														  .attr('height',hrefObject.newImg.height)
														  .attr('width',hrefObject.newImg.width)
														//  .fadeIn('100')
										//	.parent().animate(
										//								{
										//						         height: (element['image'].height) 
										//								},
										//								100)
								HrefObjectLoaded.Loaded = HrefObjectLoaded.Loaded + 1;
								loaded()
							}
						  	hrefObject.newImg.src = element['image'].src;
				//		  	hrefObject.Loaded = false;
				  }

  }

 function loaded(){
//console.log(HrefObjectLoaded.Loaded);
		if(HrefObjectLoaded.Loaded > 4){
		
			$('.collect li img').each(function(){
				$(this).fadeIn('100')//.show()
				
			})
		}
 
 }
 */
 
 
 
 /*
 конфигуратор / выбрать мех
 */
 
 
 
 
  		//Запрос
 
 /*second_block*/    
    $('.sub_block a').click(function(){
    
    	$(this).toggleClass('submore');
    	$(this).parent().find('.more').toggleClass('more_opened');
    	
  	   $('.sub_block .opener').slideToggle('slow');
 
 			
 
 	    return false;
    });
      
 $('.main_photo').find('.choos:first').find('a:first').bind('click',function(){
 /*		o = $('#choose_mod')[0];
 		
 	//	console.log($('#choose_mod').scrollTop);
 		Position = getAbsolutePosition(o)
 		$('#layout').scrollTop(Position.y);
*/





 	//	return false
 })
 
    
    $('dl.second_block dt').bind('click',function(){
     // console.log(this);
		if($(this).hasClass('unabled')){
	     
	      $(this)
	      .siblings().removeClass('selected').end()
	      .next('dd').andSelf().addClass('selected')
			.end().next().addClass('unabled');
   					var textBl = $(this).next().find('div.ttype');
					
						if(textBl.height() != null){//обычные блоки
							animateBl(textBl.height(),$('.second_block'))
						}
		}
	
	
	      return false;
    })
	 $('.mod').bind('click'
	 ,function(){
		
				$(this).parent().children('.mod').removeClass('actt').end().end().addClass('actt').parents('dd').prev().andSelf().removeClass('selected').addClass('unabled')
					 					.end().end().next().next().andSelf().addClass('selected unabled')
				
					if($(this).parents('div').hasClass('type1')){
				
										$(this).parents('dd').prev().siblings().removeClass('unabled')
										.end().addClass('unabled')//.and().and().prev().addClass('unabled');

					}
					if($(this).parents('div').hasClass('type2')){

									/*последнее окно*/
									
									
										json2($(this).attr('id'),$(this))
						}
						var textBl = $(this).parents('dd').next().next().find('div.ttype');
						if(textBl.height() != null){//обычные блоки
							$('.second_block').animate(
									{
							         height: (textBl.height() + 50) 
									},
									300)
						}	
	 
	 });
	 
 		/* $('.second_block').removeClass('disabled').find('dd:first')
		  					.prev().andSelf().addClass('selected unabled')
							.prev().addClass('selected').end()
						/	.find('.deff').hide().next().fadeIn('100')
*/
    
function json2(coeff,obj){


	var preType1 = $('.type1').find('.actt');

	var length = new Object()
	length.name = outBr(preType1.find('.title').html())


	var vorot = {
			name : obj.find('.title').text()
		};

	var lengthVal = preType1.attr('id');
	var lid = lengthVal.substring(4,lengthVal.length);
	var cid = coeff.substring(4,coeff.length);


							data='json=1' + '&' + 'cid=' + cid + '&' + 'lid=' + lid + '&' + 'tid=' + cuRobj.ElementID + '&' + 'param=form';

	$('.type3').hide().next().find('i').hide();


		getJsonData2(data,cuRobj,length,vorot);




		function outBr(name){
			return name.split('\<br\>').join(' ').split('\<br/\>').join(' ').split('\<br /\>').join(' ');
		}

}

function getJsonData2(data,cuRobj,length,vorot){

		var _location = window.location.pathname + '';


//console.log(data,cuRobj,length,vorot)

							$.getJSON(_location, data, function(json_data){
							
//console.log(json_data)

								element = json_data;
		
								newImg2 = new Image();
								newImg3 = new Image();

								$('.type3').find('.round').hide();
								
								newImg3.onload = function(){
									$('.type3').find('img.c').attr('src',newImg3.src)
																	.attr('height',newImg3.height)
																	.attr('width',newImg3.width)
																	.attr('alt',cuRobj.ElementName)
																	.parents('.round').fadeIn('100');			
																	
								}
								newImg3.src = element.bigimg.src;

		//						alert('a')
								newImg2.onload = function(){
						//		alert('a')
								//newImg2.onload = null;
								//newImg3.onload = null;

//console.log(cuRobj)
							//			var price = nbspAdder(parseInt(element.price_pref*cuRobj.type_coeff));
										var price = $(element).size() == 0 || element.price == 0 ? '0' :  element.price;

										if($(element).size() == 0){
											$('.type3').find('.price_of_good').hide().next().remove().end().after('<b class="notloaded">Эскиз не найден</b>')
										}else{
											$('.type3').find('.price_of_good').show().next().remove()
										}

	//	console.log(nbspAdder(price))
								//		console.log(length.coeff,vorot.coeff,cuRobj.price_type);
									
								//		var mehImageWidth = cuRobj.bigimg.width > 250 ? 250 : cuRobj.bigimg.width;
								//		var mehImageHeight = cuRobj.bigimg.width > 250 ? parseInt((cuRobj.bigimg.height) * 250 / (cuRobj.bigimg.width)) : cuRobj.bigimg.height;
		
										$('.type3').find('img#big_photo').attr('src',newImg2.src)
																	.attr('height',newImg2.height)
																	.attr('width',newImg2.width)
																	.attr('alt',length.name)

								.end().find('.meh_of_good').html(' ' + cuRobj.ElementName)
			.end().find('.type_of_good').find('span').html(length.name)
		.end().end().find('.form_of_good').find('span').html(' ' + vorot.name)
		.end().end().find('.price_of_good').find('ins').html(price);
						
												$('.type3').fadeIn(100);
												$('.type3').next().find('i').fadeIn(100)
		

							}

								newImg2.src = $(element).size() == 0 ? '/_pic/drw1_none.jpg' : element['img'].src ;
							
								
								}, 'json')
//)
}


/*перемещение шага 1*/
//     move(0,'wrpap');
     
    $('.lf #up').click(function(){
        move(-92,'wrpap')
        $('#up img').css({backgroundPosition:'top'})
        return false;      
    });
    $('.lf #down').click(function(){
        move(92,'wrpap')
        return false;      
    })
    $('.md #up2').click(function(){
        move2(-92,'wrpap2');
        $('#up2 img').css({backgroundPosition:'top'})
        return false;      
    });
    $('.md #down2').click(function(){
        move2(92,'wrpap2');
        return false;      
    })
if($('#wrpap')[0] != undefined){
	move(0,'wrpap')
}
//
/*Перемещение влево*/
    $('.lf ins, .lf .title').bind('click',
     function(){
		
		$(this).parent().addClass('act')
	  			.siblings().removeClass('act')
	  			
		var tmParent = $(this).parent().parent();
		var tmParentSiblings = tmParent.siblings();
				if(tmParentSiblings.length){
					tmParentSiblings.fadeOut('10000',sectCur);
				}else{
					sectCur(1)
				}
				

		 $('.lf ins, .lf .title').unbind('click').bind('click',function(){
				$(this).parent().addClass('act')
			  			.siblings().removeClass('act')

				actObject = $(this).hasClass('title') ? $(this).prev()[0] : this;
				json1(actObject,function(){});
		 });



function sectCur(nonext){

//.hide().each(function(){
					  	var act = $('.lf .f_body.act').parent()
						var preAll = act.prevAll();
						var preAllLength = act.prev().find('.f_body').length
						var nextAll = act.nextAll();
						var All = preAll.add(nextAll);
						log(All)
						if(All.index(this) == 0 || (!window.floaded && !All.length )){	
									window.floaded = true;		
									act.css({'marginLeft': (preAll.length ) * 245 + 'px'})
										  	.animate({marginLeft: '65px'},400).parent().parent().animate({width: '440px'},400);
								
								var prevChildren = $(preAll).children('.f_body');
								
								$(act).prepend(prevChildren)
										.append($(nextAll).children('.f_body'));

								move( prevChildren.length * 92,'wrpap');	

								$('.md').animate({top: '0px',right:'-50px',width:'380px'},800,
										
								function(){
										//$(this).find('.preloader').find('i').fadeOut('100')
										json1($(act).find('.act ins'),function (){});
								});
							//		console.log($(act).find('.act ins'));
	
									/*end json_pre*/	
	
						/*/json1*/

					  	}
				  }


	 });


 function json1(ins,func){


				var wrpap2 = $('#wrpap2 .el-sect');
								
				cuRobj.valut = $(ins).parent().find('.pre_price').html();
				
				classes = ($(ins).attr('class')).split(' ');
						//	console.log(classes);
			   var textBl = $('div.type1');

				/*нижний блок*/
 											 $('.second_block').addClass('disabled').find('dd:first').siblings().removeClass('selected unabled')
											  						.end().addClass('selected')
											  						.find('.deff').fadeIn('100').next().hide()
						if(textBl.height() != $('.second_block').height()){//обычные блоки
							
							animateBl(textBl.height(),$('.second_block'))
						}

				$('.md .preloader i,.main_wrap').fadeOut('100');
			
				 var pid = classes[0].substring(3,classes[0].length);

							data='json=1' + '&' + 'pid=' + pid + '&' + 'param=type';
				$('#wrpap2').fadeOut('100',function(){
	var _location = window.location.pathname + '';
							$.getJSON(_location, data, function(json_data){
//console.log(json_data)

									cur = json_data;
						//	console.log(cur.length)
									func();
										
						var tmp = $('.md .f_body:last').removeClass('act').clone().hide();
				
						$('.md .f_body').hide().not('.f_body:last').remove();
				
						if(cur.length > 0){
										
										
											

								
											for(ii in json_data){
												element = json_data[ii];
								//				console.log(json_data[ii]);

												var leftTT =  parseInt((66 - element['image_name'].preview.width)/2);
												
												
												var cont =	$(wrpap2.append(tmp.clone()).find('.f_body')[ii]).attr('_id',ii).show();
													cont.find('span.title').html(element.ElementName)
																	cont.find('span.price').find('span:first').html(element.price_type)
																	.next().html(cuRobj.valut)
																	
																	cont.find('img')
																			.attr('src',element['image_name'].preview.src)
																			.attr('height',element['image_name'].preview.height)
																			.attr('width',element['image_name'].preview.width)
																			.attr('alt',element.ElementName)
																			.css({'marginLeft':leftTT + 'px'})
											}					
											
																    $('.md ins,.md .title').unbind('click').bind('click',
																		     function(){
//	console.log(this)
																				var act2 = $(this).parent().addClass('act')
																			  					.siblings().removeClass('act').end().parent().parent().parent()
																						  		.animate({right: '0'},400).animate({width: '310px'},400);
						
																		  $('.main_photo .preloader i').fadeOut('100');
																		  $('.main_wrap').fadeOut('100'
																		  ,function(){
 	
																				 
																														
																				var element = json_data[act2.find('.f_body.act').attr('_id')];
																	
																	//			console.log(element)	
																				valut = cuRobj.valut;
																				cuRobj = element;
																				cuRobj.valut = valut;


									//			console.log(this)
						
																newImg = new Image();
													//		alert('a')
																newImg.onload = function(){
													//		alert('a')
																//	newImg.onload = null;
								
														var lLefter = parseInt((161 - newImg.width)/2);

																
															//	console.log($('.main_wrap .c img:first'))		
																					$('.main_wrap .c').find('img:first').attr('src',newImg.src)
																												.attr('height',newImg.height)
																												.attr('width',newImg.width)
																												.attr('alt',element.ElementName)
																												.css({'marginLeft':lLefter + 'px'/*,'height':newImg.height + 'px','width':newImg.width + 'px','display':'block'*/})
																				$('.main_wrap p.title').html(element.ElementName)
																				$('.main_wrap p.price').find('span:first').html(element.price_type)
																				.next().html(cuRobj.valut)

																		 /*нижний блок*/

																		 $('.second_block').find('.selected').find('.ttype').hide().end().end()
																		 						.removeClass('disabled').find('dt:first').next()
																								 .find('.ttype').fadeIn('fast').end().andSelf()
																								 .siblings().removeClass('selected unabled')
																								 .end().each(function(){
																		 $(this).addClass('selected unabled')
																		 
																		 })

																			 $('.type1').find('.models').fadeIn('100').end().find('.deff').hide();
															
															
																		$('.main_photo .preloader i').fadeIn('100'
																								  ,function(){
																								  			$('.main_wrap').fadeIn('fast',function(){
																											 // 	$(this).find('img').css({'display':'block'});
																								//			  	alert($(this).find('img').height())
																											  })
																								  });
															
																}
																newImg.src = element['image_name'].src;
																		  });    

	
																										$('.lf .f_body.act').parent().animate({marginLeft: '0'},400).parent().parent().animate({width: '275px'},400,
																										
																												function(){
																												//		console.log(this);
																														  
																												}
																										
																										);

																		 });								
								
		


						}else{
										$('.md .f_body').hide()
						
						}
								//		move2( 0,'wrpap2');
											
											//chengVals('#wrpap2')
	
											$('#wrpap2').fadeIn('100');
											$('.md .preloader i').fadeIn('100');				
								move2(0,'wrpap2');			
							
								}, 'json');
				});
				
						return false;		
  		}


function move(m, id) {
 var up = document.getElementById('up');
 var down = document.getElementById('down');
 var o = document.getElementById(id);

 o.scrollTop += m;
//console.log(o.scrollTop)
 up.className = "up";
 down.className = "down";
 if(o.scrollTop <= 0) {
 o.scrollTop = 0;
 up.className += " d";
 }
if(o.scrollTop + o.clientHeight >= o.scrollHeight) {
 o.scrollTop = o.scrollHeight - o.clientHeight;
 down.className += " d";
 }
return false;
}
function move2(m, id) {
 var up = document.getElementById('up2');
 var down = document.getElementById('down2');
 var o = document.getElementById(id);
 o.scrollTop += m;

 up.className = "up";
 down.className = "down";
 if(o.scrollTop <= 0) {
 o.scrollTop = 0;
 up.className += " d";
 }

 if(o.scrollTop + o.clientHeight >= o.scrollHeight) {
 o.scrollTop = o.scrollHeight - o.clientHeight;
 down.className += " d";
 }
return false;
}   
 
 
  });

function getAbsolutePosition(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function animateBl(hheight,second_block){
			second_block.animate(
							{
					         height: (hheight + 50) 
							},
								300)
}

/* input,textarea */
$(function() {
		$('input,textarea').parents('.errored').find('input,textarea').one('focus',function(){
						if(!($(this).attr('fval'))){
							$(this).attr('fval',$(this).attr('value')).attr('value','')
						}			
		}
		).focus(function(){
				if($(this).attr('fval') == $(this).attr('value')){
					$(this).attr('value','');
				}
		}).blur(function(){
				if($(this).attr('value') == ''){
					$(this).attr('value',$(this).attr('fval'));
				}
		})
});


//		console.log(nbspAdder('123456789'))
		
function nbspAdder(_string){
	_string = _string + '';
	arr = new Array();
	var lng = _string.length;
	kk = 0;
	for (ii = lng; ii >-1; ii = ii - 3 ){
		arr[kk] = _string.slice(lng - ii - 3,lng - ii)
		kk = kk + 1
	}
	return arr.join(' ');
}

function initZoom(){
	if($.browser.msie6){
		
	}
}

