// Scripts to surve goods(objects) section
// v .01

 
// initializing varibles
loadingImg = '<img src="/iface/i/loadingSmall.gif" />' ;
 

$(document).ready(function () {
var dummy = '<span id = "dummy"> </span>'
$('body').append(dummy);
$('#toggler').hide().removeClass('hidden');	 
$('#party ul').tabs();	 

pre110(); 
initGallery();
focusSentence(0);
iterateSentence();
loadAndDisplay(0);
});

function  pre110(){
var theTxt = $('#congrats').text();

countTxt=theTxt.split(" ")
countP=theTxt.split(".")
//console.log(countTxt.length , countP.length );
cfrom = 0;
$('#congrats').html('');
$('#congratulator').prepend('<div id="congratPager">110 слов «Алкона»: </div>');
$.each(countP,function(i,n){
	if(i < (countP.length -1)){
	//  console.log(i + '/' + n);	
		var countTxt=n.split(" ");
		var cthil = countTxt.length  ;
		var rangeTo = (cthil  +cfrom-1);
		if (rangeTo >106){rangeTo = 110};
		$('#congratPager').append('<span class="shortcut" counter="'+i+'">'+ (cfrom+1)+' — '+rangeTo +'</span>   ');
		if(n !=" " || n !=""){$('#congrats').append('<p><span  counter="'+i+'" class="s sentence'+i+'">'+n+'.</span></p> ');}
		   cfrom = cfrom + cthil -1;
	};
});



$('.shortcut').hover(function(){
	$(this).addClass('hover');
	},function(){
	$(this).removeClass('hover');	
	}).click(function(){
			var counta = $(this).attr('counter') || 0;
			focusSentence(counta);
			 
			});

};
function deSentence(){$(this).removeClass('hover');}
function  onSentence(count){
 	var counta = $(this).attr('counter') || 0;
//	$(this).addClass('hover');
 	focusSentence(counta);
 	}; 

 function iterateSentence(i){
var co=$('#congrats p').size();
var i = i || 0;	
var n = i+1;
if(i < co){
	 $('#dummy').eq(0).animate({'opacity': 1.0}, 1500, function(){focusSentence(i); });
	
 

 $('#dummy').eq(0).animate({'opacity': 1.0}, 5500, function(){
 		iterateSentence(n);
// 		console.log('animation end' + n, i)
 		});
}
}
 	
 
 function  focusSentence(count){
 var preprev =parseInt(count)-2;
 	var prev =parseInt(count)-1;
 	var nekst = parseInt(count)+1;	
$('.current').removeClass('current'); 	
$('.shortcut[@counter='+count+']').addClass('current');

$('p#congrats span').each(function(){
 	var thisOne = $(this).attr('counter') || 0;
 
	if(thisOne == count){ 
          growObj($('span.sentence'+count), '200%', '#330000', '-0.05em');
//          console.log(count);
         }
	else if(thisOne == preprev){
          growObj($('span.sentence'+preprev), '100%', '#caae8e', '-0.02em');
         }
	else if(thisOne == prev){
          growObj($('span.sentence'+prev), '100%', '#996633', '-0.05em');
        }      
	else if(thisOne == nekst){
          growObj($('span.sentence'+nekst), '150%', '#996633', '-0.05em');
         }
else{
          growObj($(this), '100%', '#caae8e', '0em');
        };
 	
 		
});	

};

 function  growObj(o, newsize, newcolor, letterSpacing){
var newsize = newsize || "3em";
var newcolor = newcolor || "brown";
var letterSpacing = letterSpacing || "0";
 	$(o).animate({ 
    fontSize: newsize 
    ,color:newcolor
//    letterSpacing: letterSpacing,
//    lineHeight:'1.1em'
  }, 2000 );
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function  initGallery(){
totalNumber = $('#scrooler a').size();
$('#scrooler a').each(
    function(i){
 	$(this).attr('id','galleryImage'+ i);
  var bIm = $(this).attr('href') || false;
    if(bIm){
        $(this).click(function(){
        		loadAndDisplay(i);
        		return false;
           
        }).addClass('linked')
        .hover(
        	function(){$(this).addClass('hovered')}
        	,function(){$(this).removeClass('hovered')}
        );
    }
    }
);
};


dohilight = function(i){
	$('.current').removeClass('current');
	$('#galleryImage'+i).addClass('current');
 };    
loadAndDisplay = function(i){
$('#toggler').show();
 var imago = $('#galleryImage'+i);
var bIm = $(imago).attr('href') || false;
if(bIm){
var imgTitle = $(imago).find('img').attr('alt') || $(imago).find('img').attr('title');
var img = new Image(); 

//console.log(i, totalNumber,imgTitle); ;
var nexti = i+1; if (i == totalNumber-1){nexti = 0};
img.onload = function() {
	$('#bigTitle').html(imgTitle );
	 img_width = this.width;
	 img_height = this.height; 
	 $('#bigImage').html(this);
	 $('#bigImage img').click(function(){loadAndDisplay(nexti)}); 
	 $('#toggler').hide();	 
	 }; 
img.src = bIm;  
dohilight(i);       

}
};    

 

        	
/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery)

/*
 * jQuery Cycle Plugin (with Transition Definitions)
 * Examples and documentation at: http://malsup.com/jquery/cycle/
 * Copyright (c) 2007 M. Alsup
 * Version: 1.98
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(3($){k j=\'1.29\';$.8.9=3(g){I 5.W(3(){4(g&&g.1M==1K){2I(g){1G\'2w\':4(5.O)1H(5.O);5.O=0;I;1G\'1z\':5.Y=1;I;1G\'28\':5.Y=0;I;27:g={17:g}}}k b=$(5),$M=b.26(),D=$M.21();4(D.G<2)I;k c=$.2A({},$.8.9.1V,g||{},$.2u?b.2s():{});4(c.1A)c.1U=c.2k||D.G;c.l=c.l?[c.l]:[];c.Q=c.Q?[c.Q]:[];c.Q.2c(3(){c.1y=0});k d=5.2a;k w=1w((d.1v(/w:(\\d+)/)||[])[1])||c.y;k h=1w((d.1v(/h:(\\d+)/)||[])[1])||c.B;c.A=1w((d.1v(/t:(\\d+)/)||[])[1])||c.A;4(b.s(\'1r\')==\'25\')b.s(\'1r\',\'24\');4(w)b.y(w);4(h&&h!=\'1p\')b.B(h);$M.W(3(i){$(5).s(\'z-1I\',D.G-i)}).s(\'1r\',\'2G\').1m();$(D[0]).C();4(c.1b&&w)$M.y(w);4(c.1b&&h&&h!=\'1p\')$M.B(h);4(c.1z)b.2B(3(){5.Y=1},3(){5.Y=0});k e=$.8.9.E[c.17];4($.1W(e))e(b,$M,c);$M.W(3(){k a=$(5);5.S=(c.1b&&h)?h:a.B();5.R=(c.1b&&w)?w:a.y()});c.r=c.r||{};c.m=c.m||{};c.u=c.u||{};$M.1i(\':1D(0)\').s(c.r);4(c.L)$($M[0]).s(c.L);4(c.A){4(c.K.1M==1K)c.K={2j:2i,2h:2e}[c.K]||2d;4(!c.1h)c.K=c.K/2;1T((c.A-c.K)<2b)c.A+=c.K}4(c.1x)c.1g=c.1f=c.1x;4(!c.19)c.19=c.K;4(!c.18)c.18=c.K;c.q=c.X?(1e.1S(1e.X()*(D.G-1)))+1:1;c.T=0;k f=$M[0];4(c.l.G)c.l[0].1d(f,[f,f,c,1R]);4(c.Q.G>1)c.Q[1].1d(f,[f,f,c,1R]);4(c.V&&!c.J)c.J=c.V;4(c.J)$(c.J).1u(\'V\',3(){I 1t(D,c,c.16?-1:1)});4(c.1s)$(c.1s).1u(\'V\',3(){I 1t(D,c,c.16?1:-1)});4(c.14)1Q(D,c);4(c.A)5.O=1P(3(){13(D,c,0,!c.16)},c.A+(c.1N||0))})};3 13(a,b,c,d){4(b.1y)I;k p=a[0].1q,12=a[b.T],J=a[b.q];4(p.O===0&&!c)I;4(!c&&!p.Y&&b.1A&&(--b.1U<=0))I;4(c||!p.Y){4(b.l.G)$.W(b.l,3(i,o){o.1d(J,[12,J,b,d])});k e=3(){$.W(b.Q,3(i,o){o.1d(J,[12,J,b,d])})};4(b.q!=b.T){b.1y=1;4(b.1c)b.1c(12,J,b,e);1n 4($.1W($.8.9[b.17]))$.8.9[b.17](12,J,b,e);1n $.8.9.1L(12,J,b,e)}4(b.X){b.T=b.q;1T(b.q==b.T)b.q=1e.1S(1e.X()*a.G)}1n{k f=(b.q+1)==a.G;b.q=f?0:b.q+1;b.T=f?a.G-1:b.q-1}4(b.14)$(b.14).23(\'a\').22(\'1o\').20(\'a:1D(\'+b.T+\')\').1O(\'1o\')}4(b.A)p.O=1P(3(){13(a,b,0,!b.16)},b.A)};3 1t(a,b,c){k p=a[0].1q,A=p.O;4(A){1H(A);p.O=0}b.q=b.T+c;4(b.q<0)b.q=a.G-1;1n 4(b.q>=a.G)b.q=0;4(b.1j&&1J b.1j==\'3\')b.1j(c>0,b.q,a[b.q]);13(a,b,1,c>=0);I 1Z};3 1Q(b,c){k d=$(c.14);$.W(b,3(i,o){k a=$(\'<a 2F="#">\'+(i+1)+\'</a>\').2D(d).1u(\'V\',3(){c.q=i;k p=b[0].1q,A=p.O;4(A){1H(A);p.O=0}4(c.1l&&1J c.1l==\'3\')c.1l(c.q,b[c.q]);13(b,c,1,!c.16);I 1Z});4(i==0)a.1O(\'1o\')})};$.8.9.1L=3(a,b,c,d){k e=$(a),$n=$(b);$n.s(c.r);k f=3(){$n.1k(c.m,c.19,c.1g,d)};e.1k(c.u,c.18,c.1f,3(){4(c.H)e.s(c.H);4(!c.1h)f()});4(c.1h)f()};$.8.9.E={1Y:3(a,b,c){b.1i(\':1D(0)\').s(\'1F\',0);c.l.F(3(){$(5).C()});c.m={1F:1};c.u={1F:0};c.H={P:\'N\'}}};$.8.9.2z=3(){I j};$.8.9.1V={17:\'1Y\',A:2y,K:2x,19:v,18:v,V:v,J:v,1s:v,1j:v,14:v,1l:v,l:v,Q:v,1x:v,1g:v,1f:v,1a:v,m:v,u:v,r:v,H:v,1c:v,B:\'1p\',1h:1,X:0,1b:0,1z:0,1A:0,1N:0}})(x);x.8.9.E.2v=3(d,e,f){d.s(\'U\',\'11\');f.l.F(3(a,b,c){$(5).C();c.r.6=b.10;c.u.6=0-a.10});f.L={6:0};f.m={6:0};f.H={P:\'N\'}};x.8.9.E.2t=3(d,e,f){d.s(\'U\',\'11\');f.l.F(3(a,b,c){$(5).C();c.r.6=0-b.10;c.u.6=a.10});f.L={6:0};f.m={6:0};f.H={P:\'N\'}};x.8.9.E.2r=3(d,e,f){d.s(\'U\',\'11\');f.l.F(3(a,b,c){$(5).C();c.r.7=b.Z;c.u.7=0-a.Z});f.L={7:0};f.m={7:0}};x.8.9.E.2q=3(d,e,f){d.s(\'U\',\'11\');f.l.F(3(a,b,c){$(5).C();c.r.7=0-b.Z;c.u.7=a.Z});f.L={7:0};f.m={7:0}};x.8.9.E.2p=3(f,g,h){f.s(\'U\',\'11\').y();h.l.F(3(a,b,c,d){$(5).C();k e=a.Z,1B=b.Z;c.r=d?{7:1B}:{7:-1B};c.m.7=0;c.u.7=d?-e:e;g.1i(a).s(c.r)});h.L={7:0};h.H={P:\'N\'}};x.8.9.E.2o=3(f,g,h){f.s(\'U\',\'11\');h.l.F(3(a,b,c,d){$(5).C();k e=a.10,1C=b.10;c.r=d?{6:-1C}:{6:1C};c.m.6=0;c.u.6=d?e:-e;g.1i(a).s(c.r)});h.L={6:0};h.H={P:\'N\'}};x.8.9.E.2n=3(a,b,c){c.m={y:\'C\'};c.u={y:\'1m\'}};x.8.9.E.2m=3(a,b,c){c.m={B:\'C\'};c.u={B:\'1m\'}};x.8.9.E.1a=3(f,g,h){k w=f.s(\'U\',\'2l\').y();g.s({7:0,6:0});h.l.F(3(){$(5).C()});h.K=h.K/2;h.X=0;h.1a=h.1a||{7:-w,6:15};h.D=[];1X(k i=0;i<g.G;i++)h.D.F(g[i]);h.1c=3(a,b,c,d){k e=x(a);e.1k(c.1a,c.19,c.1g,3(){c.D.F(c.D.2C());1X(k i=0,1E=c.D.G;i<1E;i++)x(c.D[i]).s(\'z-1I\',1E-i);e.1k({7:0,6:0},c.18,c.1f,3(){$(5).1m();4(d)d()})})}};x.8.9.E.2E=3(d,e,f){f.l.F(3(a,b,c){$(5).C();c.r.6=b.S;c.m.B=b.S});f.L={6:0};f.r={B:0};f.m={6:0};f.u={B:0};f.H={P:\'N\'}};x.8.9.E.2g=3(d,e,f){f.l.F(3(a,b,c){$(5).C();c.m.B=b.S;c.u.6=a.S});f.L={6:0};f.r={6:0,B:0};f.u={B:0};f.H={P:\'N\'}};x.8.9.E.2f=3(d,e,f){f.l.F(3(a,b,c){$(5).C();c.r.7=b.R;c.m.y=b.R});f.r={y:0};f.m={7:0};f.u={y:0};f.H={P:\'N\'}};x.8.9.E.2H=3(d,e,f){f.l.F(3(a,b,c){$(5).C();c.m.y=b.R;c.u.7=a.R});f.r={7:0,y:0};f.m={7:0};f.u={y:0};f.H={P:\'N\'}};x.8.9.E.2J=3(d,e,f){f.L={6:0,7:0};f.H={P:\'N\'};f.l.F(3(a,b,c){$(5).C();c.r={y:0,B:0,6:b.S/2,7:b.R/2};c.m={6:0,7:0,y:b.R,B:b.S};c.u={y:0,B:0,6:a.S/2,7:a.R/2}})};',62,170,'|||function|if|this|top|left|fn|cycle|||||||||||var|before|animIn||||nextSlide|cssBefore|css||animOut|null||jQuery|width||timeout|height|show|els|transitions|push|length|cssAfter|return|next|speed|cssFirst|slides|none|cycleTimeout|display|after|cycleW|cycleH|currSlide|overflow|click|each|random|cyclePause|offsetWidth|offsetHeight|hidden|curr|go|pager||rev|fx|speedOut|speedIn|shuffle|fit|fxFn|apply|Math|easeOut|easeIn|sync|not|prevNextClick|animate|pagerClick|hide|else|activeSlide|auto|parentNode|position|prev|advance|bind|match|parseInt|easing|busy|pause|autostop|nextW|nextH|eq|len|opacity|case|clearTimeout|index|typeof|String|custom|constructor|delay|addClass|setTimeout|buildPager|true|floor|while|countdown|defaults|isFunction|for|fade|false|filter|get|removeClass|find|relative|static|children|default|resume|98|className|250|unshift|400|200|turnLeft|turnDown|fast|600|slow|autostopCount|visible|slideY|slideX|scrollVert|scrollHorz|scrollRight|scrollLeft|data|scrollDown|meta|scrollUp|stop|1000|4000|ver|extend|hover|shift|appendTo|turnUp|href|absolute|turnRight|switch|zoom'.split('|'),0,{}))
