_current_visual = 0;
_count_visual = 0;
_runed_visual = 0;
_vis_mc = 1;
_now_run = [];

function _changeVisual() {
    if (!_runed_visual) {
        setTimeout(_changeVisual,5000);
        return;
    }
    if (_now_run.length) {
        while (_now_run.length) {
            var el = _now_run.shift();
            el.stop(true,true);
        }
    }
    _current_visual++;
    if (_current_visual > _count_visual)
       _current_visual = 1;

    var for_hide = null;
    $('#visual div.visual').each(function(){
        if (this.style.display != 'none') {
            for_hide = $(this);
        }
    });
    $('#paging_visual a').each(function(){
            this.className = '';
    })

    if ($('#paging_'+_current_visual).length) {
        $('#paging_'+_current_visual)[0].className = 'current';
    }
    if (for_hide != null) {
        _now_run.push(for_hide);
        for_hide.fadeOut(500);
    }
    _now_run.push($('#visual_'+_current_visual));
    $('#visual_'+_current_visual).fadeIn(500);
    setTimeout(_changeVisual,5000);
}

_wait_i = null;
function _changeVisualManual(i) {
    if (_now_run.length) {
        while (_now_run.length) {
            var el = _now_run.shift();
            el.stop(true,true);
        }
    }
    _runed_visual = false;
    var for_hide = null;
    $('#visual div.visual').each(function(){
        if (this.style.display != 'none') {
            for_hide = $(this);
        }
    });
    $('#paging_visual a').each(function(){
            this.className = '';
    })
    $('#paging_'+i)[0].className = 'current';
    if (for_hide != null) {
        _now_run.push(for_hide);
        for_hide.fadeOut(500);
    }
    $('#visual_'+i).fadeIn(500);
    _now_run.push($('#visual_'+i));
    _current_visual = i;
}

_loadVisualCallback = null;
_loadVisualImgs = false;
function loadVisual() {
    if (_loadVisualImgs == false) {
        _loadVisualImgs = [];
        $('#visual div.visual').each(function(){
            _loadVisualImgs.push([$(this).attr('back'),0]);
            var img = $('<img />');
            img.attr('back',$(this).attr('back'))
			img.attr('src',$(this).attr('back'));
			if (!img[0].complete) {
				img.load(function() {
					for (var i=0;i<_loadVisualImgs.length;i++) {
						if (_loadVisualImgs[i][0] == $(this).attr('back'))
							_loadVisualImgs[i][1] = 1;
					}
				}).attr('src',$(this).attr('back'));
			} else {
				for (var i=0;i<_loadVisualImgs.length;i++) {
					if (_loadVisualImgs[i][0] == img.attr('back'))
						_loadVisualImgs[i][1] = 1;
				}
			}
        })
    }
    for (var i=0;i<_loadVisualImgs.length;i++) {
        if (!_loadVisualImgs[i][1]) {
            setTimeout(loadVisual,100);
            return false;
        } else {
        }
    }
    _loadVisualCallback();
}

$('document').ready(function(){
	if ($('.nav-cat-short li.cat-tab-active').length) {
		$('.nav-cat-short li.cat-tab-active').pngFix();
	}
	if ($('#description').length) {
		$('#description').pngFix();
	}
	if ($('#contacts-popup').length) {
		sendRequestINIT($('#contacts-popup form'));
	}

	new Image().src = '/images/bg_popup_contacts.png';
	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('span.ns-submit').each(function(){
		if (this.getAttribute('_nomake') == '1')
			return false;
		makePButton(this);
	})
   $(".select_sity a[rel]").click(function(){
	   sytyID = $(this).attr("rel");
	   $(".select_sity a").removeClass("thisSity");
	   $(".adress_block ul").hide();
	   $(".adress_block ul#"+sytyID).show();
	   $(this).addClass("thisSity");
	   
	   })

})

function makePButton(span) {
	if (span.getAttribute('_maked') == '1')
		return false;
	var value = $(span).find('input').get(0).value;
	$(span).find('input').after('<span class="ns-submit-center"><span>'+value+'</span></span>');
	$(span).css('display','block');
	$(span).css('float','left');
	$(span).find('input').hide();
	if ($(span).attr('_class')) {
		span.className = span.className+=' '+$(span).attr('_class');
	}
	span.setAttribute('_maked','1')
	$("html").scrollTop(0);
	$(span).disableTextSelect();
}

$(document).ready(function() {
	if ($('div.cart-big-img').length) {
		$('div.cart-big-img').each(function(){
			var img = $(this).find('img');
			img.bind('mouseover',function(){
				$(this).parent().parent().find('div.bigplus').show();
			})
			img.bind('mouseout',function(){
				$(this).parent().parent().find('div.bigplus').hide();
			})
			var div = $(this).find('div.bigplus');
			div.bind('mouseover',function(){
				$(this).show();
			})
			div.bind('mouseout',function(){
				$(this).hide();
			})
		})
	}
	if ($('#form_contact').length) {
		$('#form_contact').ajaxForm(function(data){
		
		//	var data = eval(' ('+data+') ');
			var data = jsonParse(data);
			//console.log(data)
			if (data.result != '1') {
				var elements = $('#form_contact')[0].elements;
				for (var i=0;i<elements.length;i++) {
					var el = elements[i];
					//alert([data.errors[el.name],data.errors['name'],el.name])
					if (data.errors[el.name]) {
						el.className = el.className.replace('error','')+' error';
						el.title = data.errors[el.name]
					} else {
						el.className = el.className.replace('error','');
						el.title = ''
					}
				}
				$('#form_contact').find('div.error-message').css('visibility','visible');
				$('#captcha').attr('src',$('#captcha').attr('src')+'&'+Math.random());
				$('#captcha_code').get(0).value = ''
			} else {
				$('#form_contact').find('div.popup-body').hide();
				$('#form_contact').find('#request-sended').show();
				$('#form_contact').find('div.error-message').css('visibility','hidden');
			}
			var elements = $('#form_contact')[0].elements;
			for (var i=0;i<elements.length;i++) {
				var el = elements[i];
				if (el.name!='' && el._d_value!=undefined && el.value == '' && el.name != 'code') {
					el.value = el._d_value;
				}
			}
		});
	}


	$(document).pngFix();
        if ($('#visual').length) {
            _loadVisualCallback = function(){
                $('#paging_visual').show();
                _count_visual = $('#visual div.visual').length;
                $('#visual').bind('mouseover',function(){
                    _runed_visual = false;
                })
                $('#visual').bind('mouseout',function(){
                    _runed_visual = true;
                })
                _runed_visual = true;
                _changeVisual();
            }
            loadVisual();
        }
		if ($('#form_contact').length) {
			$('#form_contact').get(0).reset();
			var elements = $('#form_contact')[0].elements;
			for (var i=0;i<elements.length;i++) {
				var el = elements[i]
				el._d_value = el.value;
				el.onfocus = function(){
					if (this.value == this._d_value)
						this.value = '';
				}
				el.onblur = function() {
					if (this.value == '') {
						this.value = this._d_value;
					}
				}
			}
		}
		if ($('#contacts-popup form').length) {
			$('#contacts-popup form').get(0).reset();
			var els = $('#contacts-popup form').get(0).elements;
			for (var i=0;i<els.length;i++) {
				els[i]._d_value = els[i].value;
				els[i].onfocus = function(){
					if (this.value == this._d_value)
						this.value = '';
				}
				els[i].onblur = function() {
					if (this.value == '') {
						this.value = this._d_value;
					}
				}
			}
		}
        if ($('#tabs_2').length) {
		
		$('#tabs_2').find('a.tab').bind('click',function(){
                        
			var parent = $(this).parent().parent().parent();                                             
                        //console.log(parent.attr("id"));
                        
                        // Работаем с формой на главной
                        
                        if(parent.attr("id") == "tabs_2_1") 
                        {
                            href = window.location.href;
                            if (href ==  "http://www.sst.by/#" || href ==  "http://www.sst.by/" || href ==  "http://www.sst.by/#profi" || href ==  "http://www.sst.by/#profi1")
                            {
                                $("#visual").hide();
                                //$("#main_form_feedback").show();
                                $(".up-profi").toggleClass("hide");
                                
                                window.location.hash = "profi";
                            } else
                            {
                                window.location = "http://www.sst.by/#profi1";
                            }
                            
                        } else 
                        {                            
                            $("#main_form_feedback").hide();
                            $(".up-profi").toggleClass("hide");
                            
                            $("#visual").show();
                            window.location.hash = "";
                        }                        
                        
			parent.parent().find('td').each(function(){
				this.className = this.className.replace('current','');
			})
                        
			parent[0].className = parent[0].className+' current';
                        
			$('#tabs_2_c').find('div.tabs_2').each(function(){
				this.className = 'tabs_2 none';
			})
                        
			$('#'+parent.attr('id')+'_c')[0].className = 'tabs_2';
		})
/*		
		if ($('.left_nav').length) {
			var active = $('.left_nav li.active');
			if (active.length) {
			var parent = active.parent();
				while (parent.length && !parent.hasClass('tabs_2')) {
					parent = parent.parent();
				}
				parent.parent().find('div.tabs_2').each(function(){
					this.className = 'tabs_2 none';
				})
				parent.get(0).className = 'tabs_2';
				var id = parent.attr('id').replace('_c','');
				var atd = $('#'+id).parent().find('td.current').get(0);
				atd.className = atd.className.replace('current','');
				$('#'+id).get(0).className = $('#'+id).get(0).className+=' current';
			}
		}
*/
	}
	$('a[rel*=lightbox_preview]').lightBox()
	$('a[rel*=lightbox_full]').lightBox()
	if ($('#tabs_1').length) {
		$('#tabs_1').find('a.tab').bind('click',function(){
			switchTab(this);
		})
		
	}

});

function blockPage() {
	$('#fon').css('top', '-15px');
	$('#fon').css('width', $(".options").css('width'));
	var fonHeight = $(".options").height() + 30;
	$('#fon').css('height', fonHeight + 'px');
	$('#fon').css('opacity', '0.8');
	$('#fon').show();

	//var fonloaderHeight = $("#fon").height() / 2 - $('#fon-loader').height() + 10;
	//var fonloaderWidth = $("#fon").width() / 2 - $('#fon-loader').width();
	var topValue = ($(".options").height() + 30) / 2 - $('#fon-loader').height();
	$('#fon-loader').css('top', topValue + 'px');
	$('#fon-loader').css('left', '338px');
	$('#fon-loader').show();
	//$('#fon-loader').css('top', $("table.filters").css('top'));
	//$('#fon-loader').animate({'top':'+='+document.documentElement.scrollTop+'px'},0);
}

function sendFeedBackRequest() {
	var form = $('#form_contact');
	var elements = form.get(0).elements;
	for (var i=0;i<elements.length;i++) {
		var el = elements[i];
		//alert([el.name,el.value,el._d_value])
		if (el.name!='' && el.name!='code' && el._d_value == el.value)
			el.value = '';
	}
	//$('#form_contact').submit()
}

function sendRequestINIT(form) {
	var elements = form[0].elements;
	for (var i=0;i<elements.length;i++) {
		var el = elements[i];
		if (el._d_value == el.value)
			el.value = '';
	}
	form.bind('submit',function(){
		for (var i=0;i<this.elements.length;i++) {
			if (this.elements[i].value == this.elements[i]._d_value) {
				this.elements[i].value = '';
			}
		}
	})
	form.ajaxForm(function(data) {
		var data = eval(' ('+data+') ');
		var form = $('#contacts-popup form')
		if (data.result != '1') {
			var elements = form[0].elements;
			for (var i=0;i<elements.length;i++) {
				var el = elements[i];
				if (data.errors[el.name]) {
					el.className = el.className.replace('error','')+' error';
					el.title = data.errors[el.name]
				} else {
					el.className = el.className.replace('error','');
					el.title = ''
				}
			}
			form.find('div.error-message').css('visibility','visible');
			$('#captcha2').attr('src',$('#captcha2').attr('src')+'&'+Math.random());
			$('#captcha_code2').get(0).value = ''
		} else {
			form.find('div.popup-body').hide();
			form.find('#request-sended').show();
			form.find('div.error-message').css('visibility','hidden');
		}
		var elements = form[0].elements;
		for (var i=0;i<elements.length;i++) {
			if (elements[i].value == '' && elements[i].name != 'code') {
				elements[i].value = elements[i]._d_value;
			}
		}
	});
}


function switchTab(a) {    
	if($(a).parent().parent().hasClass('tab-disabled')) {
		return false;
	}
	var parent = $(a).parent().parent().parent();
        
        
        
	parent.parent().find('td').each(function(){
		this.className = this.className.replace('current','');
	})
	parent[0].className = parent[0].className+' current';
	var n=1;
	parent.parent().find('td').each(function(i){
		if (this.className.replace('current','') != this.className)
			n=i+1
	})
	$('#tabs_1').parent().find('div.content').find('div').hide();
	$('#tabs_1').parent().find('div.content').find('#cnt_sw_1_'+n).show();
	$('#tabs_1').parent().find('div.content').find('#cnt_sw_1_'+n).find('div').show();
}

function ShowVisual(i) {
    $('#visual div.visual').hide();
    $('#visual_'+i).show();
    $('#paging_visual a').each(function(){
            this.className = '';
    })
    $('#paging_'+i)[0].className = 'current';
    $('#visual').css('background-image','url('+$('#visual_'+i)[0].getAttribute('back')+')')
}

var nsw = 1;
function switchBimg(id) {
	$('#tab-'+nsw).hide();
	$('#tab-'+id).show();
	nsw = id;
	var el = $('#tabs').find('li.active')[0];
	if ($(el).hasClass('last')) {
		el.className = 'last last-noactive'
	} else if ($(el).hasClass('first')) {
		el.className = 'first first-noactive'
	} else {
		el.className = ''
	}
	var el = $('#tabs').find('li')[id-1];
	if ($(el).hasClass('last')) {
		el.className = 'last last-active active'
	} else if ($(el).hasClass('first')) {
		el.className = 'first first-active active'
	} else {
		el.className = 'active'
	}
}

function expandDescription(expand) {
	if (expand) {
		$('table.filters').css('visibility','hidden');
		$('#descr_preview').css('display','none');
		$('#descr_full').css('display','block');
		$('#description').css('width','750px')
		$('#description')[0].className = 'description description_expanded';
		
		//$('#description').css('font-size','14px').css('lineHeight','18px')
		$('#description').css('maxHeight','none').css('zIndex','9999');
		$('#descr_full').css('zIndex','9998');
		$('.main-pic-list').css('zIndex','10000');
	} else {
		$('table.filters').css('visibility','visible');
		$('#descr_full').css('display','none');
		$('#descr_preview').css('display','block');
		$('#description').css('width','415px')
		.css('maxHeight','93px');
		$('.main-pic-list').css('zIndex','0');
		
		$('#description')[0].className = 'description';
		//$('#description').css('font-size','13px').css('lineHeight','16px')
	}
}

function markstar(id) {
	var time = parseInt(new Date().getTime()/1000);
	$.get("/mark.ajax.php?e=set&id="+id+"&time="+time, function(data){
		data = eval(' ( '+data+' )');
		  if (data.result == "0" || data.result == "1") {
			  if (data.result == "0") {
				  document.getElementById('mark-name').className = 'cart-holder-nomarked';
				  document.getElementById('mark-lnk-inner').innerHTML = 'Поставить отметку';  
				  document.getElementById('mark-lnk').className = 'lnk-nomark';
			  } else {
				  document.getElementById('mark-name').className = 'cart-holder-marked';
				  document.getElementById('mark-lnk-inner').innerHTML = 'Убрать отметку';  
				  document.getElementById('mark-lnk').className = 'lnk-mark';
			  }
			  if (data.count > 0) {
				$('#cat-popup div.cat-marked-items').show();
			  } else {
				$('#cat-popup div.cat-marked-items').hide();
			  }
			  $('#cat-popup div.cat-marked-items span').html('('+data.count+')');
		  }
	});
}

function displaycat() {
	document.getElementById('cat-popup').className = document.getElementById('cat-popup').className== 'popup-catalog-visible' ? 'popup-catalog-hidden' : 'popup-catalog-visible';
	document.getElementById('cat-tab').parentNode.className = document.getElementById('cat-tab').parentNode.className== 'cat-tab-active' ? 'cat-tab' : 'cat-tab-active';	
}

function getOffsetSum(elem) {
    var top=0, left=0
    while(elem) {
        top = top + parseInt(elem.offsetTop)
        left = left + parseInt(elem.offsetLeft)
        elem = elem.offsetParent        
    }
 
    return {top: top, left: left}
}

function getOffsetRect(elem) {
    var box = elem.getBoundingClientRect()
    var body = document.body
    var docElem = document.documentElement
    var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop
    var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft
    var clientTop = docElem.clientTop || body.clientTop || 0
    var clientLeft = docElem.clientLeft || body.clientLeft || 0
    var top  = box.top +  scrollTop - clientTop
    var left = box.left + scrollLeft - clientLeft
    return { top: Math.round(top), left: Math.round(left) }
}
function getOffset(elem) {
    if (elem.getBoundingClientRect) {
        return getOffsetRect(elem)
    } else {
        return getOffsetSum(elem)
    }
}

$(document).ready(function() {
	var arem = $('div.b-cat-item td.pic div a.remove');
	if (arem.length) {
		arem.each(function(){
			this.href = this.href+'&time='+parseInt(new Date().getTime()/1000);
		})
	}
	$('#foptions span.dropdown_values span').each(function(){
		if (this.getAttribute('_selected') == 'selected') {
			var def_a = $(document.getElementById('span'+this.parentNode.id)).find('a');
			$(this).parent().prepend($('<span></span>').prepend(def_a));
			$(document.getElementById('span'+this.parentNode.id)).html($(this).find('a').html());
		}
	})
	$('#foptions span.dropdown_values span a.first').css('display','block')
	$('#foptions span.dropdown_values').each(function(i){
		$(this).show();
		var max = $('#foptions .dropdown_menu')[i].offsetWidth-10;
		$(this).find('a').each(function(){
			this.style.display = '';
			var w = $(this).width();
			this.style.display = 'block';
			max = max < w?w:max;
		})
		$(this).find('a').each(function(){
			$(this).css('width',max+'px');
			$(this).css('cursor','default');
		})
		$(this).hide();
	})
	$('#foptions .dropdown_menu').each(function(){
		$(this).bind('click',function(event){
			event.stopPropagation();
			event.preventDefault();
			$('#foptions span.dropdown_values').hide();
			var name = this.getAttribute('name');
			var drop = document.getElementById(name);
			if (drop._showed) {
				$(drop).hide();
				drop._showed = false;
				return;
			} else {
				drop._showed = true;
			}
			var pos = $(this).position();
			
			if($.browser.msie && $.browser.version == 6) {
			   pos.left-=131;
			}
			
			$(drop).css('left',pos.left+'px').css('top',(pos.top+this.offsetHeight)+'px').show();

			this.style.width = '1px'
			if (drop.offsetWidth < this.offsetWidth)
				$(drop).width(this.offsetWidth-2+'px');
			if(drop.offsetWidth+$(drop).position().left > 740) {
				$(drop).css('left',($(this).position().left+this.offsetWidth-drop.offsetWidth)+'px')
			}
		})
	});
	$(document).bind('click',function(){
		$('#foptions span.dropdown_values').hide();
	})

//nav tabs
			var eC = $(".menu_fire");
			var eR = $(".ln_next");
			var eF = $(".ln_prev");
			var eM = $(".menu_fire .tabs");
			var iWidth = eM.outerWidth();
			if(iWidth > 750) eR.show();
			eC.width(iWidth);
			iWidth -= 750;
			var iSpeed = 40;
			var lTimeout = function()
			{
				return 100*Math.ceil((iWidth + eC.position().left)/iSpeed);
			}
			var rTimeout = function()
			{
				return 100*Math.ceil(Math.abs((eC.position().left))/iSpeed);
			}
			eR.mouseenter(function()
			{
				eF.show();
				eC.stop(true,false).animate({left: "-"+iWidth+"px"}, lTimeout(),function()
				{
					eR.hide();
				});
			}).mouseleave(function()
			{
				eC.stop(true,false);
			});
			eF.mouseenter(function()
			{
				eR.show();
				eC.stop(true,false).animate({left: "0px"}, rTimeout(),function()
				{
					eF.hide();
				});
			}).mouseleave(function()
			{
				eC.stop(true,false);
			});

})

function filterListByOption(id,value) {
	$('#foptions').submit();
}






function AddHandlersToTable()
{

try {
 var tds = document.getElementById("table_nav").getElementsByTagName("TD");

 for (var i=0; i<tds.length; i++)
 {
  tds[i].onmouseover = function() {
   this.className = "over";
  }
  tds[i].onmouseout = function() {
   this.className = '';
  }
 }
 } catch (e) {}
}

if (window.attachEvent) window.attachEvent("onload", AddHandlersToTable);


/***** By Crys ********/
function displayContact(id) {
	$('div.p-address-visible').each(function(){
		this.className = 'p-address-visible hidden';
	});
	$('#p-contacts'+id)[0].className = 'p-address-visible';
	document.getElementById('contacts-popup').className = 'hidden';
}

function closeAddress() {
	$('div.p-address-visible').each(function(){
		this.className = 'p-address-visible hidden';
	});
	document.getElementById('contacts-popup').className = 'hidden';
}


/***** By Kuzzy *******/

function displayContacts() {
	$('div.p-address-visible').each(function(){
		this.className = 'p-address-visible hidden';
	});
	document.getElementById('contacts-popup').className = document.getElementById('contacts-popup').className== 'p-contacts-visible' ? 'hidden' : 'p-contacts-visible';
	//document.getElementById('addres-popup-01').className = document.getElementById('addres-popup-01').className== 'p-address-visible' ? 'hidden' : 'hidden';
	//document.getElementById('addres-popup-02').className = document.getElementById('addres-popup-02').className== 'p-address-visible' ? 'hidden' : 'hidden';
}

function displayAddress1() {
	//document.getElementById('addres-popup-01').className = document.getElementById('addres-popup-01').className== 'p-address-visible' ? 'hidden' : 'p-address-visible';
	document.getElementById('contacts-popup').className = document.getElementById('contacts-popup').className== 'p-contacts-visible' ? 'hidden' : 'hidden';
	//document.getElementById('addres-popup-02').className = document.getElementById('addres-popup-02').className== 'p-address-visible' ? 'hidden' : 'hidden';
}

function displayAddress2() {
	//document.getElementById('addres-popup-02').className = document.getElementById('addres-popup-02').className== 'p-address-visible' ? 'hidden' : 'p-address-visible';
	//document.getElementById('addres-popup-01').className = document.getElementById('addres-popup-01').className== 'p-address-visible' ? 'hidden' : 'hidden';
	document.getElementById('contacts-popup').className = document.getElementById('contacts-popup').className== 'p-contacts-visible' ? 'hidden' : 'hidden';
}





$(function() {
	// ?????? ?????????? ?? ?????? ? ?????? ???????
	$('a.darkbox').click(function() {				
		var link = $(this);		
		if(!$('div.darkbox-frame').length) {					
			// ???? ????? ?????? ?? ?????????,
			// ??????? ??? ? ??????? ? BODY
			darkbox = $('<div class="darkbox-frame"><div class="darkbox-shadow"></div><div class="darkbox-canvas"><div class="darkbox-button"></div></div></div>').appendTo('body');
		}
		// ????????? ?????,
		// ?????????? ???? ? BODY ? ?????????? ???
		var frame = darkbox.clone().appendTo('body').addClass('darkbox-frame-on');
		var shadow = frame.find('div.darkbox-shadow').animate({opacity:0.6},300);
		var canvas = frame.find('div.darkbox-canvas');
		var button = frame.find('div.darkbox-button');
		// ??????? ? ?????? ???????? ? ???? ?? ????????
		var image = $('<img style="border:1px solid #DDD" src="'+ link.attr('href') +'" alt="'+ link.attr('title') +'"/>');
		image.appendTo(canvas);
		image.load(function(){
			var imageWidth = image.width();
			var imageHeight = image.height();
			var frameWidth = frame.width()-40;
			var frameHeight = frame.height()-40;
			// ????????? ???????? ? ?????? ????,
			// ???? ??? ????, ??? ????
			if(imageWidth > frameWidth) {
				imageWidth = frameWidth;
				image.width(imageWidth);					
				while(image.height() > frameHeight) {
					image.width(imageWidth);
					imageWidth--;
				}
				imageHeight = image.height();
			}
			// ????????? ???????? ? ?????? ????,
			// ???? ??? ????, ??? ????
			if(imageHeight > frameHeight) {
				imageHeight = frameHeight;
				image.height(imageHeight);						
				while(image.width() > frameWidth) {
					image.height(imageHeight);
					imageHeight--;
				}
				imageWidth = image.width();
			}

			// ????????? ????????? ?? ???????? ????????
			// ? ???????????? ??????? ? ??????
			canvas.addClass('darkbox-canvas-load').animate({
				width:imageWidth,
				marginLeft:-imageWidth/2,
				height:imageHeight,
				marginTop:-imageHeight/2

			},500,function() {

				// ????? ?????????? ???????? ?????????? ?????? ? ????????
				canvas.addClass('darkbox-canvas-done');
				button.addClass('darkbox-button-on');
				button.addClass(navigator.platform.toLowerCase().indexOf('mac')+1?'darkbox-button-left':'darkbox-button-right');

				image.animate({opacity:1},500,function() {

					// ?????? ??????????? ????????
					shadow.click(closer);
					button.click(closer);

				});
			});
		});

		// ??????? ???????? ??????
		var closer = function() {
	
			canvas.remove();
			shadow.animate({opacity:0},300,function() {
				frame.remove();
			});
		}

		// ??????????? ??????? ??????? Esc
		$(document).keydown(function(e) {
			if(e.which==27) closer();
		});

		return false;
	});
});



function number_format (number, decimals, dec_point, thousands_sep) {
    var n = number, prec = decimals;
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };
 
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
 
    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}

var fhideTimer = null;
var fhide = {};
var ftds = {};

$(document).ready(function(){
	$('#topsubmenu div').each(function(){
		var root = $(this).attr('_root');
		fhide[root] = null;
	})
	$('#topsubmenu div').bind('mouseout',function(event){
		var root = $(this).attr('_root');
		hideSubmenu(root);
	});
	$('#topsubmenu div').bind('mouseover',function(event){
		var root = $(this).attr('_root');
		$(ftds[root]).find('a')[0].className = ftds[root].className.replace('active','')+' active';
		if (fhide[root] != null) {
			clearTimeout(fhide[root]);
			fhide[root] = null;
		}
	})
})
function showSubmenu(root,td) {
	ftds[root] = td;
	if (fhide[root] != null) {
		clearTimeout(fhide[root]);
		fhide[root] = null;
	}
	var el = $('#topsubmenu div[_root="'+root+'"]');
	if (!el.length)
		return false;
	$('#topsubmenu').css('left',parseInt($(td).position().left)+'px').css('width','auto');
	el.show();
	if ($(ftds[root]).width() > el.width()+32) {
		el.css('width',($(ftds[root]).width()-32)+'px');
		//el.css('min-width','56px');
	}
	$(ftds[root]).find('a').get(0).className = ftds[root].className.replace('active','')+' active';
}
function hideSubmenu(root) {
	fhide[root] = setTimeout(function(){
		var el = $('#topsubmenu div[_root="'+root+'"]');
		if (!el.length)
			return false;
		el.hide();
		$(ftds[root]).find('a').get(0).className = ftds[root].className.replace('active','');
	},50);
}

window.jsonParse=function(){var r="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)",k='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';k='(?:"'+k+'*")';var s=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+r+"|"+k+")","g"),t=new RegExp("\\\\(?:([^u])|u(.{4}))","g"),u={'"':'"',"/":"/","\\":"\\",b:"\u0008",f:"\u000c",n:"\n",r:"\r",t:"\t"};function v(h,j,e){return j?u[j]:String.fromCharCode(parseInt(e,16))}var w=new String(""),x=Object.hasOwnProperty;return function(h,
j){h=h.match(s);var e,c=h[0],l=false;if("{"===c)e={};else if("["===c)e=[];else{e=[];l=true}for(var b,d=[e],m=1-l,y=h.length;m<y;++m){c=h[m];var a;switch(c.charCodeAt(0)){default:a=d[0];a[b||a.length]=+c;b=void 0;break;case 34:c=c.substring(1,c.length-1);if(c.indexOf("\\")!==-1)c=c.replace(t,v);a=d[0];if(!b)if(a instanceof Array)b=a.length;else{b=c||w;break}a[b]=c;b=void 0;break;case 91:a=d[0];d.unshift(a[b||a.length]=[]);b=void 0;break;case 93:d.shift();break;case 102:a=d[0];a[b||a.length]=false;
b=void 0;break;case 110:a=d[0];a[b||a.length]=null;b=void 0;break;case 116:a=d[0];a[b||a.length]=true;b=void 0;break;case 123:a=d[0];d.unshift(a[b||a.length]={});b=void 0;break;case 125:d.shift();break}}if(l){if(d.length!==1)throw new Error;e=e[0]}else if(d.length)throw new Error;if(j){var p=function(n,o){var f=n[o];if(f&&typeof f==="object"){var i=null;for(var g in f)if(x.call(f,g)&&f!==n){var q=p(f,g);if(q!==void 0)f[g]=q;else{i||(i=[]);i.push(g)}}if(i)for(g=i.length;--g>=0;)delete f[i[g]]}return j.call(n,
o,f)};e=p({"":e},"")}return e}}();

$(document).ready(function(){
    hash = window.location.hash;
    // Работаем с формой на главной
    if(hash == "#profi") 
    {
        $("#tabs_2 #tabs_2_1 .tab").click();
    } else if (hash == "#profi1")
    {
        $("#tabs_2 #tabs_2_1 .tab").click();
        $("#main_form_feedback").show();
    }
    
    $("#cc-btn").click(function(){
        window.location.hash = "profi1";
        window.location.reload();
        //$("#main_form_feedback").show().focus();
        return false;
    });
        
});
