/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/9/2009
 * @author Ariel Flesler
 * @version 1.4.1
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function($){
    var m=$.scrollTo=function(b,h,f){
        $(window).scrollTo(b,h,f)
        };m.defaults={
        axis:'xy',
        duration:parseFloat($.fn.jquery)>=1.3?0:1
        };m.window=function(b){
        return $(window).scrollable()
        };$.fn.scrollable=function(){
        return this.map(function(){
            var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement
            })
        };$.fn.scrollTo=function(l,j,a){
        if(typeof j=='object'){
            a=j;j=0
            }if(typeof a=='function')a={
            onAfter:a
        };if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){
            var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){
                case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){
                    d=n(d);break
                }d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()
                    }$.each(a.axis.split(''),function(b,h){
                var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){
                    g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){
                        g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0
                        }g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]
                        }else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){
                    if(r!=g[c])t(a.onAfterFirst);delete g[c]
                }
                });t(a.onAfter);function t(b){
                o.animate(g,j,a.easing,b&&function(){
                    b.call(this,l,a)
                    })
                };function u(b){
                var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])
                }
            }).end()
        };function n(b){
        return typeof b=='object'?b:{
            top:b,
            left:b
        }
        }
    })(jQuery);

jQuery(function( $ ){
  /*  $.easing.elasout = function(x, t, b, c, d) {
        var s=1.70158;var p=0;var a=c;
        if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
        if (a < Math.abs(c)) {
            a=c; var s=p/4;
        }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
    };
	*/
	 /*

    //by default, the scroll is only done vertically ('y'), change it to both.
    $.scrollTo.defaults.axis = 'xy';
    //this one is important, many browsers don't reset scroll on refreshes
    $('div.pane').scrollTo( 0 );//reset all scrollable panes to (0,0)
    $.scrollTo( 0 );//reset the screen to (0,0)
	

   
	//Target examples bindings
	var $paneTarget = $('#content');

	$('#relative-selector').click(function(){
		$paneTarget.stop().scrollTo( 'li:eq(14)', 800 );
	});
	$('#jquery-object').click(function(){
	var $target = $paneTarget.find('.d');
		$paneTarget.stop().scrollTo( $target , 800 );
	});

	$('#dom-element').click(function(){
		var target = $paneTarget.find('ul').get(0).childNodes[20];
		$paneTarget.stop().scrollTo( target, 800 );
	});

	$('#absolute-number').click(function(){
		$paneTarget.stop().scrollTo( 150, 800 );
	});
	$('#absolute-number-hash').click(function(){
		$paneTarget.stop().scrollTo( { top:800,left:700} , 800 );
	});
	$('#absolute-position').click(function(){
		$paneTarget.stop().scrollTo( '520px', 800 );
	});
	$('#absolute-position-hash').click(function(){
		$paneTarget.stop().scrollTo( {top:'110px',left:'290px'}, 800 );
	});

*/


    

//simple hack to make scroll pane not so big

    var $paneMenu = $('#toper');
    var $menuid=$('.topmenu');
    var $menuFirst=$('#path');
    
var alevem = $('#path a').size();
var lengthstring=0;
var beg=2;
while (beg<alevem){
  str=$('#path a:eq('+beg+')').html();
  str=str.replace(/<\/?[^>]+>/gi, '');
    if(str==="Ивано-Франковск"){
      lengthstring=lengthstring+5;
    }
  leng=str.length;
  lengthstring+=leng;
// alert("|"+str + "|\n lenght "+  leng + " = " + beg);
    beg++;
}

//alert("lenght is = "+lengthstring);
  
var  widt=lengthstring*10;

    //var widt=$menuid.css("width");
   // alert(widt);
        if(widt){
    // widt=widt.replace("px", '')*1;
        if(widt<650){
            widt="650px";
            $(".arr-l").css("display", "none");
            $(".arr-r").css("display", "none");
        }else{
            widt=widt+"px";
        }
        $menuid.css("width", widt);
     }

    

//scrol actions
    $('.arr-l').click(function(){
        $paneMenu.stop().scrollTo( {
            left:'+=400'
        }, 400 );
    });

    $('.arr-r').click(function(){
        $paneMenu.stop().scrollTo( {
            left:'-=400'
        }, 400 );
    });


   $("#send").click(function(){

        if($("#qu").val()!=''){   
      $('#buttone').css('display', 'none');
      $('#addin').css('height', '16px');
      $('#addin').css('width', '16px');
      $('#addin').css('position', 'relative');
      $('#addin').css('background', 'url(\'/images/load.gif\') center center no-repeat'); 
    
           $.post("/", { action: "add_question", qu: $("#qu").val(), fio:$("#fio").val(), email:$("#email").val() },  function(data){
          //alert("Data Loaded: " + data);
           $("#qu").val('');
            $("#fio").val('');
            $("#email").val('');
            alert("Ваш вопрос успешно отправлен.");
             //window.location="/club_marycohr";
           $('#buttone').css('display', 'block');  
           $('#addin').css('display', 'none'); 
          });
         
        }else{
            alert("Поле \"Текст вопроса\" обязательно для заполнения");
            $("#qu").focus();
        }
                   
    });



});


function cataloger(url){
   var hash = window.location.hash;
   var uri=window.location.pathname;

   if(uri=='/catalog/'){
      if(url=='yhod_za_licom'){
        scrollToId('wn', 'yhodzalicom', 'lyr1', 200);    
     }else{
        scrollToId('wn', 'yhodzatelom', 'lyr1', 200);    
     }
   }else{
     location.href='/catalog/#c'+url;
   }

 }

function catscroll(){
  var hash = window.location.hash;
  if(hash=='#cyhod_za_telom'){
    scrollToId('wn', 'yhodzatelom', 'lyr1', 200);    
  }
}