﻿function initGalery(elId,preview,fullscreen,alt)
{
	/*config*/
	var prev_h = 65;
	var prev_w = 90;
	var w = 912;
	var h = 565;
	var p_size_w = 22;
	var p_size_h = 75;
	var p_left = '/tpl/images/p_l.png';
	var p_right = '/tpl/images/p_r.png';
	var p_left_hover = '/tpl/images/p_l_h.png';
	var p_right_hover = '/tpl/images/p_r_h.png';
	var preview_border = '#1c97de';
	var footer_bg = '/tpl/images/p_f.png';
	/*end_config*/
	var l = p_size_w + 6;
	var len = preview.length;
	var insize = (prev_w * len) + (6 * len);
	var mp = insize - w;
	if(len != fullscreen.length || len != alt.length){$('#' + elId).html('Ошибка инициализации фото галлереи. Колличество превью не соответствует колличеству оригиналов или описаний.'); return false;}
	$('#' + elId).css({'position':'relative','width':w + 'px','height':h + 'px'});
	$('#' + elId).html('<div style="-moz-user-select:none;-khtml-user-select:none;user-select:none;" onselectstart="return false" id="' + elId + '_footer"><div id="' + elId + '_block_out"><div id="' + elId + '_block_in"></div><div id="' + elId + '_left"></div></div><div id="' + elId + '_right"></div></div>');
	$('#' + elId + '_footer').css({'position':'absolute','bottom':'0px','width':w + 'px','height':p_size_h + 'px','background':'url(' + footer_bg + ')'});
	$('#' + elId + '_block_out').css({'position':'relative','width':w + 'px','height':p_size_h + 'px','overflow':'hidden'});
	$('#' + elId + '_left').css({'position':'absolute','cursor':'pointer','left':'0px','top':'0px','width':p_size_w + 'px','height':p_size_h + 'px','background':'url(' + p_left + ')'});
	$('#' + elId + '_right').css({'position':'absolute','cursor':'pointer','right':'0px','top':'0px','width':p_size_w + 'px','height':p_size_h + 'px','background':'url(' + p_right + ')'});
	$('#' + elId + '_left').hover(function(){$(this).css({'background':'url(' + p_left_hover + ')'})},function(){$(this).css({'background':'url(' + p_left + ')'})});
	$('#' + elId + '_right').hover(function(){$(this).css({'background':'url(' + p_right_hover + ')'})},function(){$(this).css({'background':'url(' + p_right + ')'})});
	$('#' + elId + '_block_in').css({'position':'absolute','left':l + 'px','padding-top':'6px','width':insize + 'px'});
	for(i=0;i<len;i++)$('#' + elId + '_block_in').html($('#' + elId + '_block_in').html() + '<img class="' + i + '" src="' + preview[i] + '" alt="' + alt[i] + '" />');
	$('#' + elId + '_block_in img').css({'float':'left','margin-right':'6px','cursor':'pointer','height':prev_h + 'px','width':prev_w + 'px'});
	$('#' + elId).css({'background':'url(' + fullscreen[0] + ') center top no-repeat'});
	$('#' + elId + '_block_in img').click(function(){
		$('#' + elId).css({'background':'url(' + fullscreen[$(this).attr('class')] + ') center top no-repeat'});
	});
	$('#' + elId + '_block_in img').hover(function(){$(this).css({'height':(prev_h - 4) + 'px','width':(prev_w - 4) + 'px','border':'2px solid ' + preview_border});},function(){$(this).css({'height':prev_h + 'px','width':prev_w + 'px','border':'none'});});
	//$('#' + elId + '_right').click(function(){});
	$('#' + elId + '_right').click(function(){
		//alert(l + ':' + (insize - w));
		tmp123 = l;
		if(tmp123<0)tmp123 = tmp123 * -1;
		if(mp>0 && tmp123 <= mp)
		{
			//alert(tmp123 + ':' + (insize + w));
			l -= (prev_w + 6);
			$('#' + elId + '_block_in').animate({'left':l + 'px'});
		}
	});
	$('#' + elId + '_left').click(function(){
		if(mp>0 && l <= 0)
		{
			l += (prev_w + 6);
			$('#' + elId + '_block_in').animate({'left':l + 'px'});
		}
	});
}
browserTest = function()
{
	var u = navigator.userAgent.toLowerCase();
	var htmlClass=new Array();
	is = function(str){return (u.indexOf(str) != -1);}
	htmlClass[0] = is('linux')?'nix':is('windows')?'win' :is('macintosh')?'mac':'';
	if(!is('opera') && !is('webtv') && is('msie'))
	{
		htmlClass[1] = 'ie';
		htmlClass[2] = is('msie 6')?'ie6':is('msie 7')?'ie7':is('msie 8')?'ie8':'';
	}
	else
	{
		htmlClass[1] = is('safari')?'safari':is('gecko')?'gecko':is('opera')?'opera':'';
		htmlClass[2] = is('firefox/2')?'ff2':is('firefox/3')?'ff3':is('version/4.0 safari')?'safari4':is('opera/9')?'opera9':is('chrome')?'chrome':'';
	}
	document.getElementsByTagName('html')[0].className = htmlClass.join(' ');
}

pngfix=function()
{
	var clear='/tpl/images/blank.gif';
	var els=document.getElementsByTagName('*');
	var ip=/\.png/i;
	var i=els.length;
	while(i-- >0)
	{
		var el=els[i];
		var es=el.style;
		if(el.src&&el.src.match(ip)&&!es.filter)
		{
			es.height=el.height;
			es.width=el.width;
			es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";
			el.src=clear;
		}
		else
		{
			var elb=el.currentStyle.backgroundImage;
			if(elb.match(ip))
			{
				var path=elb.split('"');
				var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';
				es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";
				es.height=el.clientHeight+'px';
				es.backgroundImage='none';
				var elkids=el.getElementsByTagName('*');
				if(elkids)
				{
					var j=elkids.length;
					if(el.currentStyle.position!="absolute")es.position='static';
					while(j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";
				}
			}
		}
	}
}

mainLoader = function()
{
	browserTest();
	if(document.getElementsByTagName('html')[0].className.indexOf('ie6') != -1)pngfix();
}

window.onload = mainLoader;

$(document).ready(function(){
	var curpg = $('#selected').attr('class');
	var titles = new Array(5);
	titles[0] = 'УК «Фаркон» - Аренда офисных помещений в Санкт-Петербурге | Стоимость аренды офиса Петербург';
	titles[1] = 'УК «Фаркон» - Аренда складских помещений, аренда земли в СПб | Аренда производственных помещений Петербург';
	titles[2] = 'УК «Фаркон» - Как проехать';
	titles[3] = 'УК «Фаркон» - Контакты';
	//titles[3] = 'УК «Фаркон» - Акции';
	titles[4] = 'УК «Фаркон» - Арендаторы';
	var functions = new Array(5);
	functions[0] = function(){
		var prev = new Array(17);
		var full = new Array(17);
		var alter = new Array(17);
		prev[0]='/images/about/preview/13.jpg';
		full[0]='/images/about/13.jpg';
		prev[1]='/images/about/preview/14.jpg';
		full[1]='/images/about/14.jpg';
		prev[2]='/images/about/preview/15.jpg';
		full[2]='/images/about/15.jpg';
		prev[3]='/images/about/preview/16.jpg';
		full[3]='/images/about/16.jpg';
		prev[4]='/images/about/preview/17.jpg';
		full[4]='/images/about/17.jpg';
		prev[5]='/images/about/preview/4.jpg';
		full[5]='/images/about/4.jpg';
		prev[6]='/images/about/preview/1.jpg';
		full[6]='/images/about/1.jpg';
		prev[7]='/images/about/preview/2.jpg';
		full[7]='/images/about/2.jpg';
		prev[8]='/images/about/preview/3.jpg';
		full[8]='/images/about/3.jpg';
		prev[9]='/images/about/preview/5.jpg';
		full[9]='/images/about/5.jpg';
		prev[10]='/images/about/preview/6.jpg';
		full[10]='/images/about/6.jpg';
		prev[11]='/images/about/preview/7.jpg';
		full[11]='/images/about/7.jpg';
		prev[12]='/images/about/preview/8.jpg';
		full[12]='/images/about/8.jpg';
		prev[13]='/images/about/preview/9.jpg';
		full[13]='/images/about/9.jpg';
		prev[14]='/images/about/preview/10.jpg';
		full[14]='/images/about/10.jpg';
		prev[15]='/images/about/preview/11.jpg';
		full[15]='/images/about/11.jpg';
		prev[16]='/images/about/preview/12.jpg';
		full[16]='/images/about/12.jpg';
		for(i=0;i<17;i++)
		{
			//prev[i]='/images/about/preview/' + (i+1) + '.jpg';
			//full[i]='/images/about/' + (i+1) + '.jpg';
			alter[i]='';
		}
		initGalery('pg',prev,full,alter);
	};
	functions[1] = function(){
		trackbar.getObject('trackdiv').init(
	    {
			onMove : function() {
			},
			dual : true,
			width : 714,
			leftLimit : 15,
			leftValue : 20,
			rightLimit : 60,
			rightValue : 30
	    },
	    "trackdiv");
		$('#b_do').click(function(){
			$('#restbl').html('<div style="text-align:center; width:100%; position:absolute; top:150px;"><img src="/tpl/images/loader.gif" alt="Загрузка..." /></div>');
			$.post('/filter.html',{ajax:'1',left:$('#leftBlock_trackdiv span.invis:first').text(),right:$('#rightBlock_trackdiv span.invis:first').text()},function(data){
				$('#restbl').html(data);
				/*$('#restbl tr').hover(function(){
					$(this).find('.showbtn').show(0);
				},function()
				{
					$(this).find('.showbtn').hide(0);
				});*/
				$('#restbl table').tablesorter({sortList:[[1,0]]});
				$('#resaults tr:odd').css("background-color", "#ffedd5");
				$('#resaults tr:even').css("background-color", "#fff");
				$('#resaults th').click(function(){
					$('#content').oneTime(1,function(){
						$('#resaults tr:odd').css("background-color", "#ffedd5");
						$('#resaults tr:even').css("background-color", "#fff");
					});
				});
				$('.c011').click(function(){$('.c111,.c222,.c333,.c444,.c111 span,.c222 span,.c333 span,.c444 span').css("color","#826e60");$('.c111,.c111 span').css("color","#3e3e3e");});
				$('.c022').click(function(){$('.c111,.c222,.c333,.c444,.c111 span,.c222 span,.c333 span,.c444 span').css("color","#826e60");$('.c222,.c222 span').css("color","#3e3e3e");});
				$('.c033').click(function(){$('.c111,.c222,.c333,.c444,.c111 span,.c222 span,.c333 span,.c444 span').css("color","#826e60");$('.c333,.c333 span').css("color","#3e3e3e");});
				$('.c044').click(function(){$('.c111,.c222,.c333,.c444,.c111 span,.c222 span,.c333 span,.c444 span').css("color","#826e60");$('.c444,.c444 span').css("color","#3e3e3e");});
				$('#movingblock').animate({'height':$('#content').height()+100},1000);
			});
		});
		$('a.ajax').click(function(){
			$('#block_2').html('<div style="text-align:center; width:100%; position:absolute; top:150px;"><img src="/tpl/images/loader.gif" alt="Загрузка..." /></div>');
			var url = $(this).attr('href');
			//var oldhtml = $('#content').html();
			$('#movingblock').animate({'height':'400px'},1000);
			$.post(url,{ajax:'1'},function(data){
				$('#block_2').oneTime(500,function(){
					$('#block_2').html(data);
					$('#movingblock').animate({'height':$('#content').height()+50},1000);
					$('#movingblock').animate({left:'0px'},500);
					//document.title = titles[pgn];
					//functions[pgn]();
					//$('#topsubmenu').html(topmenus[pgn]);
					//$('#topsubmenu').slideDown(500);
					/*$('#topsubmenu a').click(function(){
						showblock($(this).attr('rel'));
						$('#topsubmenu a').attr('class','');
						$(this).attr('class','selected');
						return false;
					});*/
				});
			});
			return false;
		});
	};
	functions[2] = function(){};
	functions[3] = function(){};
	functions[4] = function(){		
		$('#apragma').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 97, 112, 114, 97, 103, 109, 97, 46, 114, 117, 47));
		$('#stroyfinance').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 115, 116, 114, 111, 121, 102, 105, 110, 97, 110, 99, 101, 46, 114, 117, 47));
		$('#peterhost').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 112, 101, 116, 101, 114, 104, 111, 115, 116, 46, 114, 117, 47));
		$('#taxii').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 105, 99, 101, 116, 97, 120, 105, 46, 114, 117, 47));
		$('#lel').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 108, 101, 108, 46, 115, 112, 98, 46, 114, 117, 47));
		$('#medsil').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 102, 109, 101, 100, 115, 105, 108, 46, 114, 117, 47));
		$('#asport').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 97, 115, 112, 111, 114, 116, 46, 98, 105, 122, 47));
		$('#agat').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 97, 103, 97, 116, 115, 112, 98, 46, 114, 117, 47, 100, 111, 99, 117, 109, 101, 110, 116, 47));
		$('#1c').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 49, 99, 45, 109, 117, 108, 116, 105, 109, 101, 100, 105, 97, 46, 115, 112, 98, 46, 114, 117, 47));
		$('#sweb0').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 115, 119, 101, 98, 46, 114, 117, 47));
		$('#sweb1').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 115, 119, 101, 98, 46, 114, 117, 47, 115, 101, 114, 118, 105, 99, 101, 115, 47, 104, 111, 115, 116, 105, 110, 103, 47));
		$('#sweb2').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 115, 119, 101, 98, 46, 114, 117, 47, 115, 101, 114, 118, 105, 99, 101, 115, 47, 100, 111, 109, 97, 105, 110, 115, 47));
		$('#sweb3').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 115, 119, 101, 98, 46, 114, 117, 47, 115, 101, 114, 118, 105, 99, 101, 115, 47, 115, 101, 114, 118, 101, 114, 115));
		$('#sweb4').attr('href',String.fromCharCode(104, 116, 116, 112, 58, 47, 47, 115, 119, 101, 98, 46, 114, 117, 47, 115, 101, 114, 118, 105, 99, 101, 115, 47, 115, 101, 111, 47));
	};
	//var topmenus = new Array(5);
	var topmenus = new Array(5);
	topmenus[0] = '<a class="selected" href="#" rel="1">О компании</a><a class="" href="#" rel="2">Фотографии бизнес-центра</a><!--<a class="" href="#" rel="3">Отчет ФКЦБ</a>-->';
	topmenus[1] = '<a class="selected" href="#" rel="1">Выбрать офис</a><a href="#" rel="2">Аренда офисов</a>';
	topmenus[2] = '<a class="selected" href="#">Как проехать</a>';
	topmenus[3] = '<a class="selected" href="#">Контакты</a>';
	topmenus[4] = '<a class="selected" href="#">Арендаторы</a>';
	functions[1]();functions[curpg]();
	$('#topsubmenu').html(topmenus[curpg]);
	$('#topsubmenu a').click(function(){
		showblock($(this).attr('rel'));
		$('#topsubmenu a').attr('class','');
		$(this).attr('class','selected');
		return false;
	});
	function showblock(num)
	{
		$('.block').slideUp(500);
		$('#block_' + num).slideDown(500);
		$('#movingblock').oneTime(500,function(){$('#movingblock').animate({'height':$('#content').height()+50},1000);});
	}
	$('#topmenu a').click(function(){
		var url = $(this).attr('href');
		var pgn = $(this).attr('class');
		if(pgn<curpg)$('#movingblock').animate({left:'-1000px'},500).animate({left:'1000px'},0);
		if(pgn>curpg)$('#movingblock').animate({left:'1000px'},500).animate({left:'-1000px'},0);
		if(pgn==curpg)return false;
		$('#content').html('<div style="text-align:center; width:100%; position:absolute; top:150px;"><img src="/tpl/images/loader.gif" alt="Загрузка..." /></div>');
		$('#movingblock').animate({'height':'400px'},1000);
		$('#topsubmenu').slideUp(500);
		$.post(url,{ajax:'1'},function(data){
			$('#content').oneTime(500,function(){
				$('#content').html(data);
				$('#movingblock').animate({'height':$('#content').height()+50},1000);
				$('#movingblock').animate({left:'0px'},500);
				document.title = titles[pgn];
				functions[pgn]();
				$('#topsubmenu').html(topmenus[pgn]);
				$('#topsubmenu').slideDown(500);
				$('#topsubmenu a').click(function(){
					showblock($(this).attr('rel'));
					$('#topsubmenu a').attr('class','');
					$(this).attr('class','selected');
					return false;
				});
			});
		});
		$('.' + curpg).attr('id','');
		curpg=pgn;
		$('.' + curpg).attr('id','selected');
		return false;
	});
	$('#rt').click(function(){
		var clk = parseInt(curpg) + 1;
		if(clk == 5)clk = 0;
		$('.' + clk).click();
	});
	$('#lft').click(function(){
		var clk = parseInt(curpg) - 1;
		if(clk == -1)clk = 4;
		$('.' + clk).click();
	});
	$('#leftfoot span').click(function(){
		$('#content').html('<div style="text-align:center; width:100%; position:absolute; top:150px;"><img src="/tpl/images/loader.gif" alt="Загрузка..." /></div>');
		$('#topsubmenu').slideUp(500);
		$.post('/about.html',{ajax:'1'},function(data){
			$('#content').html(data);
			functions[0]();
			showblock(2);
			document.title = titles[0];
			$('#topsubmenu').html(topmenus[0]);
			$('#topsubmenu').slideDown(500);
			//$('#topsubmenu').each('a',function(){if($(this).attr('rel') == '2')$(this).attr('class','selected');else $(this).attr('class','');})
			$('#topsubmenu a').click(function(){
					showblock($(this).attr('rel'));
					$('#topsubmenu a').attr('class','');
					$(this).attr('class','selected');
					return false;
			});
		});
	});
	$('#spoff_show').click(function(){
		$('#spoff_info').show();
		$('#spoff_info').height($('#container').height());
		return false;
	});
	$('#spoff_info').click(function(){
		$(this).hide();
	});
	$('#bnr_m').hover(function(){$('#bnr_m_hover').show(0);},function(){$('#bnr_m_hover').hide(0);});
});
