var lang = {
       'noflash': 'Флеш не загружен',
        'search': 'Поиск',
        'noname': 'Не указаны ФИО',
       'noemail': 'Введите Ваш E-mail!',
    'wrongemail': 'Введите корректный E-mail!',
 'resumenotsent': 'Резюме не отправлено',
    'resumesent': '<p>Спасибо</p>',
      'fulllist': 'весь список <span>&nbsp;</span>',
      'hidelist': 'свернуть список <span>&nbsp;</span>',
       'loading': 'Загрузка...',
         'close': 'Закрыть',
     'nogallery': 'Галерея не подключена'   
};

var lang_en = {
       'noflash': 'Flash isn\'t loaded yet',
        'search': 'Search',
        'noname': 'Name required',
       'noemail': 'E-mail required',
    'wrongemail': 'Wrong e-mail',
 'resumenotsent': 'Resume wasn\'t sent',
    'resumesent': '<p>Thank you</p>',
      'fulllist': 'full list <span>&nbsp;</span>',
      'hidelist': 'short list <span>&nbsp;</span>',
       'loading': 'Loading...',
         'close': 'Close',
     'nogallery': 'Gallery us missing'   
};

function portfolioLoad()
{
    var hash = document.location.hash.replace('#', ''); 
    if (/\d+/.test(hash) && $('#movie'+hash).length) {
    	$('.clips .active').removeClass('active');
    	$('#movie'+hash).addClass('active');
    	$('.toggle', '.collapsed').click();
    	hash = parseInt(hash);
    	return parseInt(hash);
    }
    return false;
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
	return window[movieName];
    } else {
	return document[movieName];
    }
}

function reloadMe(value) {
    thisMovie("PortfolioaltContent").sendToActionScript(value);
}

var actionScriptReady = true;

function enableActionScript() {
    actionScriptReady = true;
}

function sendToActionScript2 (value, id) {
    if (!actionScriptReady)
    	return false;

    var $li = $('li#movie'+value);
    
    if (!$li.length)
    	return false;
    
    var $clips = $li.parents('.clips');
    
    if ($clips.parents('.leftbar').length)
    	return false;
   
    try {
	thisMovie(id).sendToActionScript(value);
    } catch(e) {
	alert(lang.noflash);
	return false;
    }
    
    actionScriptReady = false;
   
    if ($li.attr('id').length) {
	document.location.hash = $li.attr('id').replace('movie', '');
	$.scrollTo($('.'+id), 1000); 
    }

    $('.active', $clips).removeClass('active');
    $li.addClass('active');
    ajaxSynopsisRemove();
    return false;
}

/* synopsis via ajax */
var synopsisloading = false;

function ajaxSynopsis(id)
{
	if (synopsisloading)
		return false; 
	
	if ($('.detailed').length) {
		ajaxSynopsisRemove();
	} else {
	    synopsisloading = true;
	    $.get('/synopsis/' + id + '.html', function(html){
	    	synopsisloading = false;
	    	if ($('#content + .PortfolioaltContent.nomargin').length) {
		    $('.PortfolioaltContent.nomargin').after('<div style="width:1000px;margin:0 auto;"><div class="text detailed" style="display:none"></div></div>');	
	    	} else {
		    $('#content')
		    	.append('<div class="text detailed" style="display:none"></div>');
	    	}
	    	$('.detailed').html(html+'<a class="shortly" href="#" onclick="return ajaxSynopsisRemove();"></a>').show('normal');
	    });
	}
}

function ajaxSynopsisRemove()
{
	$('.shortly', '.detailed').hide();
	$('.detailed').hide('slow', function(){
		$('.detailed').remove();
	});
	return false;
}

/* DOCUMENT.READY */
$(function(){
/* язык */
if ($('body').hasClass('eng'))
    lang = lang_en;

/* градиентные заголовки */
if (!$.browser.msie)
    $('h1').each(function(){
    	if (!$(this).parents('.proc-header').length)
    	    $(this).css({
    	    	color: '#bfbfbf'  
	    }).FontEffect({
    	    	gradient: true,
    	    	gradientColor: '#fff'
	    });
    });

/* внешние ссылки */
$('a[href^=http://]').not('.lang-switch a').click(function(){
    window.open($(this).attr('href'));
    return false;
});

/* ссылки на распечатку */
$('a.print').click(function(){
    window.print();
    return false;
});

/* oh FF */
if ($.browser.mozilla && $.browser.version < '2.0')
    $('button span', '.resume').css({
	position: 'relative',
	top: '-2px'
    });

/* oh IE */
if ($.browser.msie && $.browser.version < 7) {
    /*$('a', '.grape').click(function(){
    	document.location = $(this).attr('href');
    	return false;
    });*/
    $('img').ifixpng();    
}

/* vacancy toggler */
$('.vacancy-collapsed h3, .vacancy-expanded h3').click(function(){
	$(this).parent().toggleClass('vacancy-collapsed').toggleClass('vacancy-expanded');
	return false;
});        

/* search form */
$('#s_query').focus(function(){
    if ($(this).val() == lang.search)
    	$(this).val('');
}).blur(function(){
    if ($(this).val() == '')
    	$(this).val(lang.search);
});

/* process brief link */
$brief = $('.brief-link', '.grape');
if ($brief.length)
	$('.nodetails').attr('href', $brief.attr('href'));

/********************************* RESUME *************************************/
$('.resume form').submit(function(){
    
    if (!$('#r_fio').val().length) {
       alert(lang.noname);
       $('#r_fio').focus();
       return false;
    }
    
    if (!$('#r_email').val().length) {
        alert(lang.noemail);
        $('#r_email').focus();
        return false;
    }
    
    var re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)\.(.)+/;
    if ($('#r_email').val().match(re) == null) {
        alert(lang.wrongemail);
        $('#r_email').focus();
        return false;
    }

    var $form = $(this);
    $.post('/company/vacancy/send/', $(this).serialize(), function(data){
    	if (0 == data)
	    alert(lang.resumenotsent);
	else {
	   $form.replaceWith(lang.resumesent);
	}
    });
    
    return false;
});

/********************************* PROCESS SWITCHER ***************************/
var $sw = $('.details-switch');
var sw_l = 67;
var sw_r = 86;
var sw_o = 7;
var sw_go = false;
if ($sw.length) {
    var sw_center = Math.floor($sw.width() / 2);
    var sw_class = $sw.parents('a').attr('class');
    var sw_x = $sw.position().left;
    if (sw_class == 'nodetails')
	$sw.parents('a').addClass('nd-a');
    else
	$sw.parents('a').addClass('d-a');
}

var swDocumentMousemove = function(e){
    sw_x = e.clientX - $sw.parents('a').offset().left + document.documentElement.scrollLeft - sw_center;

    if (sw_x > sw_r)
        sw_x = sw_r;
    else if (sw_x < sw_l)
        sw_x = sw_l;

    $sw.css({left: sw_x + 'px'});

    if (sw_x <= sw_l + sw_o) {
	$('.details, .nodetails').addClass('nd-a').removeClass('d-a');
        if (sw_class == 'details')
		sw_go = true;        
    } else if (sw_x >= sw_r - sw_o ) {
	$('.details, .nodetails').removeClass('nd-a').addClass('d-a');
        if (sw_class == 'nodetails')
		sw_go = true;
    } else {
    	sw_go = false;
    	$('.nodetails, .details').removeClass('nd-a').removeClass('d-a');
    }
    
    return stopEvent(e);
};

var swDocumentMouseup = function(e){
    $('body').removeClass('cmove');
    $sw.removeClass('cmove').addClass('omove');

    if (sw_go)  {
        var to = sw_l;
    	if ($sw.parents('a').hasClass('nodetails'))
    	    to = sw_r;
    	$sw.animate({left: to}, 100, function(){
	    document.location = $('.details-switch').parents('a').attr('href');	    
	});
    } else {
        var to = sw_r;
    	if ($sw.parents('a').hasClass('nodetails'))
    	    to = sw_l;
    	$sw.animate({left: to}, 100);
    }
    
    $(document)
        .unbind('mousemove', swDocumentMousemove)
        .unbind('mouseup', swDocumentMouseup);
    return stopEvent(e);
};

$sw.addClass('omove').mousedown(function(e){
    $('body').addClass('cmove');
    $sw.removeClass('omove').addClass('cmove');
    $(document)
        .mouseup(swDocumentMouseup)
        .mousemove(swDocumentMousemove);
    return stopEvent(e);
}).click(function(){
    return false;
});

function stopEvent(e)
{
    if (e.preventDefault) {
    	e.preventDefault();
    	e.stopPropagation();
    } else {
    	e.returnValue = false;
    	e.cancelBubble = true;
    }
    return false;
}

/********************************* DETAILED LONG MOVIES ***********************/
$('.detailed')
    .append('<a class="shortly" href="#" onclick="return ajaxSynopsisRemove();"></a>');
$('.detailed, .detailed .shortly').live('mouseover', function(){
    $('.detailed .shortly').css({display: 'block'});
}).live('mouseout', function(){
    $('.detailed .shortly').css({display: 'none'});
});

/********************************* CLIPS CAROUSEL *****************************/
/* clips active */

$('.clips a').click(function(){
    if ($(this).parents('.leftbar').length) {
    	document.location = $(this).attr('href');
    	return false;
    }
    
    eval($(this).attr('href').replace('javascript:', ''));
    return false;
});

/* подсчет количеств и размеров .clips и иже с ними */
var clips = {
    toggle: '<div><div class="toggle">'+lang.fulllist+'</div></div>',
    next: '<a class="next" href="#"></a>',
    prev: '<a class="prev" href="#"></a>',
    shades: '<div class="carousel-shade-l"></div><div class="carousel-shade-r"></div>',
    per_row: 4,
    li_width: 225,
    animated: false
};

$('.rounded.collapsed, .rounded.expanded').each(function(){
    var count = 0;
    var height = 0;
    var row_max_height = 0;
    var total_max_height = 0;
    
    var total_clips = $('.clips li', this).length; 
    $('.clips li', this).each(function(){
	count++;
	row_max_height = Math.max(row_max_height, $(this).outerHeight());
	if ((count % clips.per_row == 0) || (count == total_clips)) {
	    height += row_max_height;
	    total_max_height = Math.max(total_max_height, row_max_height);
	    row_max_height = 0;
	}
    });	

    if (count > clips.per_row) {
    	$('.b', this).append(clips.toggle);
    	$('.carousel-arrows', this).append(clips.prev + clips.next);
    	$('.carousel', this).append(clips.shades);
    }

    if ($(this).hasClass('collapsed')) {
	$('.carousel', this).height(total_max_height);
	$('.clips', this).height(total_max_height);
    } else {
        $('.carousel', this).css({height: 'auto'});
	$('.clips', this).css({position: 'static'});
        $('.prev, .next', this).css({opacity: 0});
        $('.toggle', this).html(lang.hidelist);
    }
    
    $(this).data('calculated', {
    	'height': height,
	'max': total_max_height,
	'count': count
    });
});

/* сворачивание/разворачивание .rounded:has('.clips') */
$('.toggle', '.rounded').css({cursor: 'pointer'}).click(function(){
	if (clips.animated)
	    return false;
	clips.animated = true;
	    
	var c = '';
	var $r = $(this).parents('.rounded');

	var clips_expand = function(){
	    $('.clips', $r).css({
	    	height: 'auto',
	        width:  '900px'
	    });
	    $('.prev, .next', $r).css({
	    	opacity: 1
	    }).animate({
	    	opacity: 0
	    }, 250);
	    
	    $('.carousel', $r).animate({
	    	height: $r.data('calculated').height
	    }, 1000, function(){
	    	$('.clips', $r).css({
		    position: 'static'
	    	});
		$r.removeClass('collapsed').addClass('expanded');
		$('.toggle', $r).html(lang.hidelist);
	    	clips.animated = false;
	    });
	};

	if ($r.hasClass('collapsed')) {
	    if ($('.clips', $r).position().left < 0) {
	    	$('.clips', $r).animate({
	    		left: 0
	    	}, 500, function(){
	    		clips_expand();	    
	    	});
	    } else
	        clips_expand();
	    
	} else if ($r.hasClass('expanded')) {
	    setTimeout(function(){
	    	$('.prev, .next', $r).css({
	    	    opacity: 0,
	    	    display: 'block'
	    	}).animate({
	    	    opacity: 1
	    	}, 250);
	    }, 750);
	    
	    $('.carousel', $r).animate({
	    	height: $r.data('calculated').max
	    }, 1000, function(){
	    	$('.clips', $r).css({
	            height: $r.data('calculated').max,
	            width:  '9999em',
	            position: 'absolute',
	            left: 0
	    	});
		$r.removeClass('expanded').addClass('collapsed');
		$('.toggle', $r).html(lang.fulllist);
		clips.animated = false;	    
	    });
	}
});

/* карусель .clips */
$('.next', '.carousel-arrows').click(function(){
    if (clips.animated)
    	return false;
    	
    $r  = $(this).parents('.rounded');
    $ul = $('ul.clips', $r);
    var pos = Math.abs($ul.position().left); 
    if (pos < ($r.data('calculated').count - clips.per_row) * clips.li_width) {
    	clips.animated = true;
    	$ul.animate({
	    left: 0 - pos - clips.li_width 
	}, 1000, function(){
	    clips.animated = false;
	});
    } 	

    return false;
});
$('.prev', '.carousel-arrows').click(function(){
    if (clips.animated)
    	return false;
    	
    $r  = $(this).parents('.rounded');
    $ul = $('ul.clips', $r);
    var pos = Math.abs($ul.position().left); 
    if (pos >= clips.li_width) {
    	clips.animated = true;
    	$ul.animate({
	    left: 0 - pos + clips.li_width 
	}, 1000, function(){
	    clips.animated = false;
	});
    } 	

    return false;
});


/********************************* GALLERY ************************************/
var fader = {
    show: function(){
    	$('body').append('<div id="fader"></div>');
    	var self = this;
    	$('#fader').css({
    	    height: $('#content').outerHeight(),
    	    top: $('#content').offset().top,
    	    opacity: 0
	}).animate({
	    opacity: .75
	}, 143);
	$('.prev a, .next a').css({visibility: 'hidden'});
	$(window).bind('resize', function(){
	    self.resize();
	});
	$('.gallery').css({visibility: 'hidden'}); 
    },
    
    hide: function(){
    	if ($.browser.msie)
	    $('#shadow-big, #shadow-left, #shadow-right', '#gal').hide();
	$('#fader, #gal').animate({
	    opacity: 0    
	},250, function(){
	    $('.prev a, .next a').css({visibility: 'visible'});
	});
    	setTimeout(function(){
	    $('#fader, #gal').remove();
	}, 300);
    	var self = this;
	$(window).unbind('resize', function(){
	    self.resize();
	});
	$('#content').css({height: 'auto'});
	$('.gallery').css({visibility: 'visible'});
    },
    
    resize: function(){
    	$('#fader').css({
    	    height: Math.max($('#content').outerHeight(), $('#gal').outerHeight()),
    	    top: $('#content').offset().top
	});
    },
    
    loaderShow: function() {
    	$('#fader').append('<img id="loader" src="/i/loader.gif" alt="'+lang.loading+'" />');
    },
    
    loaderHide: function() {
    	$('#loader', '#fader').remove();
    }
};

var gal = {
    $div: null,
    $lis: null,
    $ul: null,
    big_width: 700,
    min_pad: 77,
    img_width: 88,
    li_width: 93,
    //li_pad: 353,
    height: 0,
    top: 0,
    time: 1000,
    sizes: [],
    inprocess: false,
    shadow_pad: 90,
    
    show: function(i, $gal) {
    	var self = this;
    	this.height = 0;
    
    	var html = '<div id="gal">' +
	       '<a class="close" href="#" title="'+lang.close+'"></a>' + 
	       '<div class="gal-carousel"><ul>';
	var foo = new Image();
	for (var j = 0; j < gallist.length; j++) {
	    html += (j + 1 == i ? '<li class="big">' : '<li>');
	    html += gallist[j];
	    html += '</li>';
	    $('body').append('<div id="foo" style="opacity:0;position:absolute;left:-9999em;">' + gallist[j] + '</div>');
	    this.height = Math.max($('img', '#foo').height(), this.height);
	    $('#foo').remove();
	}
	var max_height = this.height;
	this.height += this.min_pad + this.shadow_pad;
	html += '</ul></div>';
	
	html += '</div>';
    	$('body').append(html);
    	
	this.$div = $('#gal');
	this.$ul  = $('ul', this.$div);
	this.$lis = $('li', this.$ul);
    	$('div', this.$div).css({height: this.height});
    	
    	var scrollTop = self.pageYOffset || document.documentElement.scrollTop;
    	
	this.top = Math.max(scrollTop + parseInt($(window).height()/2 - this.height / 2), $('#content').offset().top);
	
	if (this.height + this.top - $('#content').offset().top > $('#content').outerHeight()) {
	    $('#content').animate({
		height: this.height - ($('#content').outerHeight() - $('#content').height()) + this.top - $('#content').offset().top
	    }, 286);
	    $('#fader').animate({
		height: this.height + this.top - $('#content').offset().top
	    }, 286);	
	};
	
	var k = 0;
	$('img', this.$ul).each(function(){
	    var width = $(this).attr('width');
	    var height = $(this).attr('height'); 
	    self.sizes[k] = {
	    	width: width,
	    	height: height,
	    	small_height: Math.ceil(height * self.img_width / width),
	    	big_pad: self.min_pad + Math.ceil(max_height/2 - height/2),
		small_pad: self.min_pad + Math.ceil(
		  max_height/2 - (self.img_width*height/width)/2
		) 
	    };
	    var $li = $(this).parents('li'); 
	    if ($li.hasClass('big')) {
	    	$li.css({paddingTop: self.sizes[k].big_pad});
	    	$('img', $li).css({
		    height: self.sizes[k].height,
		    width: self.sizes[k].width		    
		});
	    } else {
		$li.css({paddingTop: self.sizes[k].small_pad});
		$('img', $li).css({
		    height: self.sizes[k].small_height,
		    width: self.img_width		    
		});
	    }
	    k++;
	});
	
	this.$ul.css({
	    left: 2 * this.li_width - i * this.li_width
	});
	
	$('img', this.$div).css({opacity: 0});
	$('.big img', this.$div).css({opacity: 1});
	$('.big', this.$div).next('li').children('img').css({opacity: 1});
	$('.big', this.$div).prev('li').children('img').css({opacity: 1});
    	
    	this.$div.addClass('gal').css({
	    top: this.top
	});
	
	fader.loaderHide();
	
	if (!$.browser.msie)
	    this.$div.css({
	    	opacity: 0    
	    }).animate({
	    	opacity: 1
	    }, 143);
	
	
	html  = '<table id="shadow-left"><tr><td class="t"></td></tr><tr><td class="c"><div>&nbsp;</div></td></tr><tr><td class="b"></tr></table>';
	html += '<table id="shadow-right"><tr><td class="t"></td></tr><tr><td class="c"><div>&nbsp;</div></td></tr><tr><td class="b"></tr></table>';
	html += '<table id="shadow-big">' +
		'<tr><td class="lt"></td><td class="t"></td><td class="rt"></td></tr>' +
		'<tr><td class="l"></td><td class="pic"><div>&nbsp;</div></td><td class="r"></td></tr>' +
		'<tr><td class="lb"></td><td class="b">&nbsp;</td><td class="rb"></td></tr>' +
		'</table>';
	self.$div.append(html);
	self.shadows(i - 1);
	
	$('#gal,#fader,.gal-carousel').click(function(){
	    fader.hide();
	    return false;
	});
	
	$('a.close', this.$div).click(function(){
	    fader.hide();
	    return false;
	});
	
	$('#gal img').click(function(){
	    return false;
	});
	
	$('#shadow-right', this.$div).click(function(){
	    if (!self.inprocess)
	    	self.next();
	    return false;
	});	
	
	$('#shadow-left', this.$div).click(function(){
	    if (!self.inprocess)
	    	self.prev();
	    return false;
	});
    },
    
    shadows: function(i){
    	$('#shadow-big', this.$div).css({
	    width: this.sizes[i].width + 84 + 84 + 'px',
	    height: this.sizes[i].height + 90 + 58 + 'px',
	    left: (this.$div.width() - this.sizes[i].width - 84 - 84) / 2,
	    top: this.sizes[i].big_pad - 58
	});
	
	$('#shadow-big .pic div', this.$div).css({
	    height: (this.sizes[i].height - 152) + 'px'
	});
	
	if (typeof this.sizes[i - 1] != 'undefined') {
	    $('#shadow-left', this.$div).css({
	    	cursor: 'pointer',
	    	top: this.sizes[i - 1].small_pad - 6
	    });
	    $('#shadow-left .c div', this.$div).css({
	    	height: this.sizes[i - 1].small_height 
	    });
	} else
	    $('#shadow-left', this.$div).css({cursor: 'default'});
	 
	if (typeof this.sizes[i + 1] != 'undefined') {
	    $('#shadow-right', this.$div).css({
	    	cursor: 'pointer',
		top: this.sizes[i + 1].small_pad - 6
	    });
	    $('#shadow-right .c div', this.$div).css({
	    	height: this.sizes[i + 1].small_height
	    });
	} else
	    $('#shadow-right', this.$div).css({cursor: 'default'});
	
	if ($.browser.msie) {
    	    $('#shadow-big', this.$div).show();
    	    $('#shadow-left', '#shadow-right').hide();
    	    if (typeof this.sizes[i - 1] != 'undefined')
	    	$('#shadow-left', this.$div).show();
	    else
	        $('#shadow-left', this.$div).hide(); 
	    if (typeof this.sizes[i + 1] != 'undefined')
	    	$('#shadow-right', this.$div).show();
	    else
	    	$('#shadow-right', this.$div).hide();
    	} else {
	    $('#shadow-big', this.$div).animate({
	    	opacity: 1	    
	    }, this.time/8);
	    $('#shadow-left', '#shadow-right').css({opacity: 0});
	    if (typeof this.sizes[i - 1] != 'undefined') {
	    	$('#shadow-left', this.$div).animate({
	    	    opacity: 1	    
	    	}, this.time/8);
	    } else {
	    	$('#shadow-left', this.$div).css({opacity: 0});
	    }
	    if (typeof this.sizes[i + 1] != 'undefined') {
	    	$('#shadow-right', this.$div).animate({
	    	    opacity: 1	    
	    	}, this.time/8);
	    } else {
	    	$('#shadow-right', this.$div).css({opacity: 0});
	    }
	}
    
    },
    
    noshadows: function() {
    	$('#shadow-left, #shadow-right', this.$div).css({cursor: 'default'});
	if ($.browser.msie) {
    	    $('#shadow-big', this.$div).hide();
    	    $('#shadow-left', this.$div).hide();
    	    $('#shadow-right', this.$div).hide();
    	} else {
	    $('#shadow-big', this.$div).animate({
	    	opacity: 0	    
	    }, this.time/16);
	    $('#shadow-left', this.$div).animate({
	    	opacity: 0	    
	    }, this.time/16);
	    $('#shadow-right', this.$div).animate({
	    	opacity: 0	    
	    }, this.time/16);
	}
    },
    
    next: function(){
        var self  = this;
	var $next = $('.big', this.$ul).next('li');
	var $prev = $('.big', this.$ul).prev('li');
        
	if ($next.length) {
	    this.noshadows();	
	    self.inprocess = true;
	    
	    var big  = self.$lis.index($('.big', this.$ul));
	    var next = big + 1;
	    
	    $('img', $prev).animate({
	    	opacity: 0
	    }, this.time/2);
	    setTimeout(function(){
	    	$('img', $next.next('li')).animate({
		    opacity: 1
		}, self.time/2)
	    }, this.time/3*2);
	    
	    this.$ul.animate({
	    	left: (self.$ul.position().left - self.li_width) + 'px'  
	    }, this.time);
	    
	    $('.big img', this.$ul).animate({
	    	width: self.img_width + 'px',
	    	height: self.sizes[big].small_height + 'px'
	    }, this.time);
	    
	    $('.big', this.$ul).animate({
	    	width: self.li_width + 'px',
	    	paddingTop: self.sizes[big].small_pad + 'px'
	    }, this.time);
	    
	    
	    $('img', $next).css({
	    	height: self.sizes[next].small_height + 'px',
	    	width: '88px'
	    }).animate({
	    	width: self.sizes[next].width + 'px',
	    	height: self.sizes[next].height + 'px'
	    }, this.time);
	    
	    $next.animate({
	    	width: self.big_width,
	    	paddingTop: self.sizes[next].big_pad
	    }, this.time);
	    
	    
	    setTimeout(function(){
	    	self.shadows(next);
	    }, this.time*0.9);
	    
	    setTimeout(function(){
	    	$('.big', self.$ul).removeClass('big');
	    	$next.addClass('big');
	    	self.inprocess = false;			
	    }, this.time + 1);
	}	
    },
    
    prev: function(){
	var self  = this;
        var $next = $('.big', this.$ul).next('li');
	var $prev = $('.big', this.$ul).prev('li');
        
	if ($prev.length) {
	    self.inprocess = true;
	    this.noshadows();
	    
	    var big  = self.$lis.index($('.big', this.$ul));
	    var prev = big - 1;
	    
	    $('img', $next).animate({
	    	opacity: 0
	    }, this.time/2);
	    setTimeout(function(){
	    	$('img', $prev.prev('li')).animate({
		    opacity: 1
		}, self.time/2)
	    }, this.time/3*2);
	    
	    this.$ul.animate({
	    	left: (self.$ul.position().left + self.li_width) + 'px'  
	    }, this.time);
	    
	    $('.big img', this.$ul).animate({
	    	width: self.img_width + 'px',
	    	height: self.sizes[big].small_height + 'px'
	    }, this.time);
	    
	    $('.big', this.$ul).animate({
	    	width: self.li_width + 'px',
	    	paddingTop: self.sizes[big].small_pad + 'px'
	    }, this.time);
	    
	    $('img', $prev).css({
	    	height: self.sizes[prev].small_height + 'px',
	    	width: '88px'
	    }).animate({
	    	width: self.sizes[prev].width + 'px',
	    	height: self.sizes[prev].height + 'px'
	    }, this.time);
	    
	    $prev.animate({
	    	width: self.big_width,
	    	paddingTop: self.sizes[prev].big_pad
	    }, this.time);
	    
	    setTimeout(function(){
	    	self.shadows(prev);
	    }, this.time*0.9);
	    
	    setTimeout(function(){
	    	$('.big', self.$ul).removeClass('big');
	    	$prev.addClass('big');
	    	self.inprocess = false;
	    }, this.time + 1);
	}    
    }   
};


$('.gallery img').css({cursor: 'pointer'}).click(function(){
    if (typeof gallist != 'undefined') {
	fader.show();
	fader.loaderShow();
	gal.show($('.gallery img').index(this) + 1, $(this).parents('.gallery'));
    } else {
	alert(lang.nogallery);    
    }
    return false;
});

// end of document.ready
});
