function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

;(function($){
    $.fn.calendarLite = function(options) {
        var opts = $.extend({}, $.fn.calendarLite.defaults, options);
        return this.each(function() {
            $this = $(this);
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
            $.fn.calendarLite.draw(o);
        });
    };

    $.fn.calendarLite.getHead = function(opts) {
	    var html = [];
	    for (var i = 0; i < opts.days.length; i++) {
	        html.push('<th>' + opts.days[i] + '</th>');
	    }
	    return html.join('');
    };

    $.fn.calendarLite.draw = function(opts) {
        var o = $.extend({}, this.defaults, opts);

        month = parseInt(o.month, 10);
        year = parseInt(o.year, 10);

        var today = new Date();
        var srcDate = new Date();
        if (!isNaN(year)) {
            srcDate.setDate(1);
            srcDate.setFullYear(year);
        }
        if (!isNaN(month)) {
            srcDate.setDate(1);
            srcDate.setMonth(month);
        }
        var curDate = srcDate.getDate();
        var curMonth = srcDate.getMonth();
        var curYear = srcDate.getFullYear();

        var dates = [];
        var dayCount = new Date(curYear, curMonth + 1, 0).getDate();
        for (var i = 1; i <= dayCount; i++) {
            var tmpDate = new Date(curYear, curMonth, i);
            if (tmpDate.getMonth() == curMonth && tmpDate.getFullYear() == curYear) {
                dates.push(tmpDate);
            }
        }

        var table = $('<table cellspacing="1" class="table"></table>');
        var str = '<tbody><tr>' + this.getHead(o) + '</tr>', cl = '';
        var line = [];
        for (var j = 0; j < dates.length; j++) {
            var day = dates[j].getDay();
            var month = dates[j].getMonth();
            var year = dates[j].getFullYear();

            var date = dates[j].getDate();
            var rel = _formatLink(o.dateFormat, dates[j]);
            cl = '';
            if (date == today.getDate() && curMonth == today.getMonth() && curYear == today.getFullYear()) {
                cl = ' class="curr"';
            } else if (day == 6 || day == 0) {
                cl = ' class="weekend"';
            }

            /*
            if(date >= today.getDate() && curMonth == today.getMonth() && curYear == today.getFullYear()){
            	var href = '#';
	            if (o.linkFormat != null && o.linkFormat != undefined) {
	                href = _formatLink(o.linkFormat, dates[j]);
	            }
	            line.push('<td' + cl + '><a href="' + href + '" rel="' + rel + '">' + date + '</a></td>');
            } else {
            	line.push('<td class="disdate">' + date + '</td>');
            }
            */

            	var href = '#';
	            if (o.linkFormat != null && o.linkFormat != undefined) {
	                href = _formatLink(o.linkFormat, dates[j]);
	            }
	            line.push('<td' + cl + '><a href="' + href + '"><input type="checkbox" name="calendar" value="' + rel + '" />' + date + '</a></td>');

            if (dates[j].getDay() == 0) {
                if (line.length < 7) {
                    var ln = line.length;
                    var pad = [];
                    for (var k = 0; k < (7 - ln); k++) {
                    	var prevmonthDays = new Date(year, month, 0).getDate() - (6-ln)+k;
                        pad.push('<td class="disdate"><kbd>'+ prevmonthDays +'</kbd></td>');
                    }
                    line = pad.concat(line);
                }
                str += '<tr>' + line.join('') + '</tr>';
                line = [];
            } else if (j == (dates.length - 1)) {
                str += '<tr>' + line.join('') + '</tr>';
            }
        }
        str += '</tbody>';
        table.html(str);
        table.find('tr:last').each(function(){
        	var size = $(this).find('td').size();
        	if(size<7){
        		for(var jj = 1;jj<8-size;jj++){
        			$('<td class="disdate"><kbd>'+ jj +'</kbd></td>').appendTo($(this));
        		}
        	}
        });
        if (typeof o.onSelect == 'function') {
            table.find('a').click(function(){
            	var el = $(this);
                return o.onSelect(el);
            })/*.mouseenter(function(){
            	if($(this).find('input').is(':checked')){
            		$('<i></i>').prependTo($(this));
            	} else {
            		$('<b></b>').prependTo($(this));
            	}
            }).mouseleave(function(){
            	$(this).find('i,b').remove();
            })*/;
            /*
            table.find('tr').mouseenter(function(){
            	$(this).find('td:first').prepend('<em></em>').find('em').click(function(){
            		$(this).parent().parent().find('input').each(function(){
            			if(!$(this).is(':checked')){
            				$(this).parent().click();
            			}
            		});
            		$(this).parent().parent().find('i,b').remove();
            	});
            }).mouseleave(function(){
            	$(this).find('em').remove();
            });*/
        }
        var y = '';
        if (o.showYear == true) {
            y = ' ' + curYear + ' ';
        }
        $this[0].innerHTML = '<span class="state" style="display:none;">' + curMonth + '.' + curYear + '</span><div class="monthName"><a href="#" class="next"><!-- --></a><a href="#" class="prev"><!-- --></a><span class="mmth"> ' + o.months[curMonth] + y + ' </span></div>';
        $this.append(table)
             .find('.monthName').width($this.find('.table').width());
        this.next($this.find('.next'), o);
        this.prev($this.find('.prev'), o);
    };

    function _formatLink(format, objDate) {
        var date = objDate.getDate();
        var month = objDate.getMonth() + 1;
        var year = objDate.getFullYear();
        if (format.indexOf('{%dd}') != -1) {
            date = _formatNum(date);
        }
        if (format.indexOf('{%mm}') != -1) {
            month = _formatNum(month);
        }
        if (format.indexOf('{%yy}') != -1) {
            year = year.toString().slice(2);
        }
        var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year);
        return link;
    };

    function _formatDate(format, objDate) {
        var date = objDate.getDate();
        var month = objDate.getMonth();
        var year = objDate.getFullYear();
        if (format.indexOf('{%dd}') != -1) {
            date = _formatNum(date);
        }
        if (format.indexOf('{%mm}') != -1) {
            month = _formatNum(month);
        }
        if (format.indexOf('{%yy}') != -1) {
            year = year.toString().slice(2);
        }
        month++;
        var link = format.replace(/{%d(d)?}/, date).replace(/{%m(m)?}/, month).replace(/{%yy(yy)?}/, year);
        return link;
    };

    $.fn.calendarLite.next = function(button, o) {
        this.change(button, 1, o);
    };

    $.fn.calendarLite.prev = function(button, o) {
        this.change(button, -1, o);
    };

    $.fn.calendarLite.change = function(button, monthDelta, o) {
        var opts = $.extend({}, $.fn.calendarLite.defaults, o);
        var _self = this;
        var parent = button.parent('.monthName').parent();
        button.click(function(){
            var state = _self.getState(parent);
            var d = new Date(state[1], state[0] + monthDelta, 1);
            opts.month = d.getMonth();
            opts.year  = d.getFullYear();
            parent.calendarLite(opts);
            return false;
        });
    };

    $.fn.calendarLite.getState = function(div) {
        var st = div.find('.state')[0].innerHTML.split('.');
        return [parseInt(st[0], 10), parseInt(st[1], 10)];
    };

    function _formatNum(num) {
        num = parseInt(num, 10);
        if (num < 10) {
            return '0' + num;
        }
        return num;
    };

    $.fn.calendarLite.defaults = {

        days: ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'],
        months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август',
                 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
        linkFormat: null,
        dateFormat: '{%yyyy}-{%mm}-{%dd}',
        onSelect: null,
        showYear: false,
        prevArrow: '&laquo;',
        nextArrow: '&raquo;'
    };
})(jQuery);

jQuery.fn.serializeDict = function(){
    var result = {};
    jQuery.each(this.serializeArray(), function(i, item){
        result[item.name=="item_id" ? "id" : item.name] = item.value;
    });
    return result;
};

$(function(){

$('.cleared').each(function(){
	$(this).attr('def',$(this).val());
}).focus(function(){
	if($(this).val() == $(this).attr('def')) $(this).val('').removeClass('def');
}).blur(function(){
	if($(this).val() == '') $(this).val($(this).attr('def')).addClass('def');
});

$('a.pod').click(function(e){
	e.stopImmediatePropagation();
	if(!$(this).parent().hasClass('open')){
		$(this).parent().addClass('open');
	}
	else{
		$(this).parent().removeClass('open');
	}
	return false
});

var podTimer;
$('div.pod').hover(function(){
	clearTimeout(podTimer);
},function(){
	var self = $(this);
	podTimer = setTimeout(function(){
		self.removeClass('open');
	}, 1000);
});

$('div.sel').live("click", function(){
	if(!$(this).hasClass('opensel')){
		$(this).addClass('opensel');
		$('div.selOp').each(function(){
			$(this).hide().parent().removeClass('open');
		});
		$(this).parent().addClass('open');
		$(this).next().show();
	} else{
		$(this).removeClass('opensel');
		$('div.selOp').each(function(){
			$(this).hide().parent().removeClass('open');
		});
		$(this).parent().removeClass('open');
	}
});
var selTimer;
$('div.sl').hover(function(){
	clearTimeout(selTimer);
},function(){
	var self = $(this);
	selTimer = setTimeout(function(){
		self.removeClass('open').find('div.selOp').hide();
	}, 500);
});

$('div.selOp a').live("click", function(){
	$(this).parent().prev().find('span').text($(this).text());
	$(this).parent().hide().parent().removeClass('open');
	$(this).parent().next().val($(this).attr('rel'));
	return false
});

$('#nav a.active').each(function(){
	var size = $('#nav a').size()-1;
	var ind = $('#nav a').index($(this));
	if(ind!=0){
		$(this).css('border-left','1px solid #000').css('margin-left','-1px');
		$('<div id="ls"></div>').appendTo($(this));
	}
	if(ind != size){
		$('<div id="rs"></div>').appendTo($(this));
	}
});

$('#topline .tx').focus(function(){clearTimeout(topTimer);$('#topline').unbind('mouseleave');$(this).closest('.ct').addClass('fc');$(this).addClass('focus');if($(this).hasClass('email') || $(this).hasClass('lj')){$(this).parent().addClass('focus')}}).blur(function(){$(this).closest('.ct').removeClass('fc');$(this).removeClass('focus');if($(this).hasClass('email') || $(this).hasClass('lj')){$(this).parent().removeClass('focus')}});
$('#topline div.links a').click(function(){
	clearTimeout(topTimer);
	if($(this).attr('rel')){
		$('#'+$(this).attr('rel')).slideDown();
		$(this).siblings().css('visibility','hidden');
		$('<a href="#" class="clz"><!-- --></a>').insertAfter($(this));
		$(this).addClass('open');
		$('#topline').addClass('opn');
		return false
	}
});
$('#topline a.clz').live('click',function(){
		closeTopline();
		return false
});
var topTimer;
function closeTopline(){
	clearTimeout(topTimer);
	if(!$('#topline .ct:visible').hasClass('fc')){
		$('#topline').removeClass('opn');
		$('#topline .ct:visible').slideUp('400',function(){
			$('#topline .links a').removeClass('open').css('visibility','visible');
			$('#topline').unbind('mouseleave').unbind('mouseenter').hover(function(){
				clearTimeout(topTimer);
			},function(){
				var self = $(this);
				topTimer = setTimeout(function(){
					closeTopline();
				}, 2000);
			});
		});
			$('#topline a.clz').remove();

	}
}
$('#topline').unbind('mouseleave').unbind('mouseenter').hover(function(){
	clearTimeout(topTimer);
},function(){
	var self = $(this);
	topTimer = setTimeout(function(){
		closeTopline();
	}, 2000);
});

function html_escape(text) {
    if (!text) return "";
    return text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;');
}

url_regexp = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
function replaceURLWithHTMLLinks(text) {
    return text.replace(url_regexp,"<a href='$1' target='_blank'>$1</a>");
}

var twactive = false;

var tminit;
twBar_mouse_is_over = false;
function twitter(){
	var lnk = $('#twBar a.goright');
	var limit = 9;
	var step = 1;
	tminit = setInterval(function(){
        if (twBar_mouse_is_over) return;
		if(step<limit){
			lnk.css('background-position','0 -'+ step*15 +'px');
			step++;
		}
		else {
			clearInterval(tminit);
			twitter();
			$('#twBar a.goright').click();
		}
	}, 600);
}

function fetch_twitter_feed(args) {
    if (!args) args = {};
    var url = "http://api.twitter.com/1/statuses/user_timeline.json?"+
        "screen_name=LoftProektETAGI&count=30&include_rts=false&page=1&include_entities=false&exclude_replies=true&"+
        (args.max_id ? "max_id="+args.max_id+"&" : "")+
        "callback=?";
    $.getJSON(url, function(response) {
        if (!response.length) {
            return;
        }
        var jq_list = $("#twBarList");
        for (var i=0; i<response.length; i++) {
            var twit = response[i];
            var text = replaceURLWithHTMLLinks(html_escape(twit.text))
                .replace(/^\s*LoftProektETAGI:\s*/,'');
            var jq_twit = $('<div class="item text"/>').html(text);
            if (i > 0) jq_twit.hide();
            jq_list.append(jq_twit);
        }
        if (args.post_response_callback) {
            args.post_response_callback(response);
        }
    });
}

$('#twBar a.goleft').click(function(){
	if(twactive==false){
		clearInterval(tminit);
		$('#twBar a.goright').css('background-position','0 0');
		twactive = true;
		var el = $('#twBarList>div:visible');
		if(el.prev().size()>0 && el.prev().is('div')){
			el.hide('slow').prev().show('slow', function(){
				twactive = false;
			});
		}
		else{
			el.hide('slow').parent().find('>div:last').show('slow', function(){
				twactive = false;
			});
		}
		twitter();
	}
	return false;
});
$('#twBar a.goright').click(function(){

	if(twactive==false){
		clearInterval(tminit);
		$('#twBar a.goright').css('background-position','0 0');
		twactive = true;
		var el = $('#twBarList>div:visible');
		if(el.next().size()>0){
			el.hide('slow').next().show('slow', function(){
				twactive = false;
			});
		}
		else{
			el.hide('slow').parent().find('>div:first').show('slow', function(){
				twactive = false;
			});
		}
		twitter();
	}
	return false;
});

$('a.arr').click(function(){
	if($(this).prev().is(':hidden')){
		$(this).next().hide().prev().prev().show();
		$(this).hide();
	}
	return false
});

$('#bigSlide div.info a').click(function(){
	$(this).parent().hide().next().next().show();
	$('#arrlink').show();
	return false
});

function bigsliderBack(){
	if($("#flipPanel>div:first").is(':hidden')){

					var number = $('#flipPanel>div').index($('#sld0').parent());

					$("#flipPanel").quickFlipper({
						vertical:true,
						openSpeed:100,
						closeSpeed:200
					}, number);

					setTimeout(function(){
						$('#nameSlideBar a.ii').removeClass('iianim').removeClass('inn');
					}, 300);
	}
}

var slidebigtimer;
$('#flipPanel').hover(function(){
	clearInterval(slidebigtimer);
}, function(){
//slidebigtimer = setTimeout(function(){
//		bigsliderBack();
//	}, 5000);
});

// Slider Carousel
function SliderCarousel() {
	var blocks = $('.auto-slide');
        blocks.each(function(){

            var block = $(this),
                button = block.find('div.rg img'),
                delay = parseInt(block.attr('data-delay'));
                if (!delay) delay = 5000;

            setInterval(function(){
                if (!block.hasClass('hovered')) {
                    button.click();
                }
            }, delay);
        });
}
SliderCarousel();


$('.auto-slide').hover(
	function () {
		$(this).addClass('hovered');
	},
	function () {
		$(this).removeClass('hovered');
	}
);


var bigActive = 1;
var bigAnimate = false;
$('#bigSlide div.lnk').each(function(){
	var par = $(this);
	var max = par.next().find('td').size();
	$(this).find('div.lf').find('a,img').click(function(){

		if(bigAnimate){return false};
		clearInterval(slidebigtimer);

			bigActive--;
			if(bigActive<1){bigActive = max}

			var number = bigActive;

			par.next().find('td:last').prependTo(par.next().find('tr'));
			par.next().scrollTo({top:0, left:'+=822px'},0);
			par.next().find('td.active').removeClass('active');

				bigAnimate = true;

				$('#bigSlide .inf').addClass('anim');
				//$('#nameSlideBar a.ii').removeClass('inn');
				var arrlink_toggle = $('#arrlink').is(":visible");
				if (arrlink_toggle) $('#arrlink').hide();

				if($('#flipPanel').parent().parent().is(':visible')){
					$("#flipPanel").quickFlipper({
						vertical:true,
						openSpeed:100,
						closeSpeed:200
					}, number);
					setTimeout(function(){
						slidebigtimer = setTimeout(function(){
							bigsliderBack();
						}, 3500);

						$('#bigSlide .inf').removeClass('anim');
						if (arrlink_toggle) $('#arrlink').show();
						$('#nameSlideBar a.ii').addClass('inn').removeClass('iianim');

					}, 300);
				};

				par.next().scrollTo(par.next().find('td[rel='+ bigActive +']').addClass('active'), 600, {onAfter: function(){
					bigAnimate = false;
				}});

			$('#tdNow').text($('#bigSlide div.sld td.active').attr('rel'));
			$('#bigSlideBar a').removeClass('active');
			$('#bigSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');

		return false
	});
	$(this).find('div.rg').find('a,img').click(function(){

		if(bigAnimate){return false};
		clearInterval(slidebigtimer);

			bigActive++;
			if(bigActive>max){bigActive = 1}

			var number = bigActive;

			par.next().find('td.active').removeClass('active');
			bigAnimate = true;

			$('#bigSlide .inf').addClass('anim');
			//$('#nameSlideBar a.ii').removeClass('inn');
			var arrlink_toggle = $('#arrlink').is(":visible");
			if (arrlink_toggle) $('#arrlink').hide();

				if($('#flipPanel').parent().parent().is(':visible')){
					$("#flipPanel").quickFlipper({
						vertical:true,
						openSpeed:100,
						closeSpeed:200
					}, number);
					setTimeout(function(){
						slidebigtimer = setTimeout(function(){
							bigsliderBack();
						}, 3500);

						$('#bigSlide .inf').removeClass('anim');
						if (arrlink_toggle) $('#arrlink').show();
						$('#nameSlideBar a.ii').addClass('inn').removeClass('iianim');
					}, 300);
				};

				par.next().scrollTo(par.next().find('td[rel='+ bigActive +']').addClass('active'), 600, {onAfter: function(){

					par.next().find('td:first').appendTo(par.next().find('tr'));
					par.next().scrollTo({top:0, left:'-=822px'},0);

					bigAnimate = false;

				}});

			$('#tdNow').text($('#bigSlide div.sld td.active').attr('rel'));

			$('#bigSlideBar a').removeClass('active');
			$('#bigSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		return false
	});

	$('#tdAll').text($('#bigSlide div.sld td').size());
});
$('#nameSlideBar a.ii').click(function(){

	if(!$(this).hasClass('iianim')){
		$(this).addClass('iianim');
		var self = $(this);

		clearInterval(slidebigtimer);

		if(!$(this).hasClass('inn')){
			$(this).addClass('inn');
			var arrlink_toggle = $('#arrlink').is(":visible");
			if (arrlink_toggle) $('#arrlink').hide();

					if($('#flipPanel').parent().parent().is(':visible') && $('#'+ $('#bigSlide div.sld td.active img').attr('alt')).is(':hidden')){
						var number = parseInt($('#bigSlide td.active img').attr('alt').replace('sld',''));
						$("#flipPanel").quickFlipper({
							vertical:true,
							openSpeed:100,
							closeSpeed:200
						}, number);
						setTimeout(function(){
							//slidebigtimer = setTimeout(function(){
							//	bigsliderBack();
							//}, 3500);

							$('#bigSlide .inf').removeClass('anim');
						  if (arrlink_toggle) $('#arrlink').show();
							self.removeClass('iianim');

						}, 300);
					} else if($('#flipPanel').parent().parent().is(':visible') && $('#'+ $('#bigSlide div.sld td.active img').attr('alt')).is(':visible')){
						$(this).removeClass('inn');
						bigsliderBack();
					}
		}
		else{
						$(this).removeClass('inn');
						bigsliderBack();
		}
	}

	return false
}).mouseenter(function(){
	if(!$(this).hasClass('iianim')){
		var self = $(this);

		clearInterval(slidebigtimer);

		if(!$(this).hasClass('inn')){
			$(this).addClass('inn');
      var arrlink_toggle = $('#arrlink').is(":visible");
      if (arrlink_toggle) $('#arrlink').hide();

					if($('#flipPanel').parent().parent().is(':visible') && $('#'+ $('#bigSlide div.sld td.active img').attr('alt')).is(':hidden')){
						var number = parseInt($('#bigSlide td.active img').attr('alt').replace('sld',''));
						$("#flipPanel").quickFlipper({
							vertical:true,
							openSpeed:100,
							closeSpeed:200
						}, number);
						setTimeout(function(){
							//slidebigtimer = setTimeout(function(){
							//	bigsliderBack();
							//}, 3500);

							$('#bigSlide .inf').removeClass('anim');
						  if (arrlink_toggle) $('#arrlink').show();
							self.removeClass('iianim');

						}, 300);
					} else if($('#flipPanel').parent().parent().is(':visible') && $('#'+ $('#bigSlide div.sld td.active img').attr('alt')).is(':visible')){
						$(this).removeClass('inn');
						bigsliderBack();
					}
		}
	}
}).mouseleave(function(){

							slidebigtimer = setTimeout(function(){
								bigsliderBack();
							}, 4000);
});
$('#bigSlideBar a').click(function(){

	var par = $('#bigSlide div.lnk');
	var max = par.next().find('td').size();

	clearInterval(slidebigtimer);

	if(!$(this).hasClass('active') && !bigAnimate){

		var thisNumber = parseInt($(this).attr('rel'));
		var delta = bigActive - thisNumber;
		$('#nameSlideBar a.ii').removeClass('inn');
		$('#bigSlideBar a').removeClass('active');
    var arrlink_toggle = $('#arrlink').is(":visible");
    if (arrlink_toggle) $('#arrlink').hide();
		var steps = parseInt(delta);
		if(steps<0){
			steps*=-1;
		}
		if(delta>0){ //мотаем назад
			bigActive -= steps;

			while(steps>0){
				par.next().find('td:last').prependTo(par.next().find('tr'));
				par.next().scrollTo({top:0, left:'+=822px'},0);
				steps-=1;
			}
			par.next().find('td.active').removeClass('active');

				if($('#flipPanel').parent().parent().is(':visible')){
					$("#flipPanel").quickFlipper({
						vertical:true,
						openSpeed:100,
						closeSpeed:200
					}, bigActive);
					setTimeout(function(){
						slidebigtimer = setTimeout(function(){
							bigsliderBack();
						}, 3500);

						$('#bigSlide .inf').removeClass('anim');
						if (arrlink_toggle) $('#arrlink').show();
					}, 300);
				};

				par.next().scrollTo(par.next().find('td[rel='+ bigActive +']').addClass('active'), 600, {onAfter: function(){
					bigAnimate = false;
				}});
		}
		else{//мотаем вперед

				bigActive += steps;

				if($('#flipPanel').parent().parent().is(':visible')){
					$("#flipPanel").quickFlipper({
						vertical:true,
						openSpeed:100,
						closeSpeed:200
					}, bigActive);
					setTimeout(function(){
						slidebigtimer = setTimeout(function(){
							bigsliderBack();
						}, 3500);

						$('#bigSlide .inf').removeClass('anim');
						if (arrlink_toggle) $('#arrlink').show();
					}, 300);
				};

				par.next().scrollTo(par.next().find('td[rel='+ bigActive +']').addClass('active'), 600, {onAfter: function(){

					while(steps>0){
						par.next().find('td:first').appendTo(par.next().find('tr'));
						par.next().scrollTo({top:0, left:'-=822px'},0);
						steps -= 1;
					}
					bigAnimate = false;

				}});

		}


		$('#tdNow').text(bigActive);
		$('#bigSlideBar a').removeClass('active');
		$(this).addClass('active');
	}
	return false
});

var smlAnimate = false;
$('#smlSlide div.lnk').each(function(){
	var par = $(this);
	var max = (par.next().find('td').size()-1)*548;
	var inf = $('div.binfo');

	$(this).find('div.lf').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() < 540){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:last').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000', function(){
				$('#' + par.next().find('td.active img').attr('alt')).show();
			});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').prev();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		$('#smlSlideBar a').removeClass('active');
		$('#smlSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		return false
	});
	$(this).find('div.rg').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() > max){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:first').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').next();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		$('#smlSlideBar a').removeClass('active');
		$('#smlSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		return false
	});
});
$('div.slideBar:not(".smallSlideBar") a').click(function(){
	if(!$(this).hasClass('active') && !smlAnimate){
		if(smlAnimate){return false}
		if($('#smlSlide2').size()>0){
			$(this).parent().find('a').removeClass('active');
			var el = $(this).attr('class');
			$(this).addClass('active');
			var inf = $('div.binfo');

			var td = $('#smlSlide2 td img[alt='+ el +']').parent();
			td.siblings().removeClass('active');
			td.addClass('active');
			$('#smlSlide2 div.sld').scrollTo(td, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+el).show();
			});
		} else {
			$(this).parent().find('a').removeClass('active');
			var el = $(this).attr('class');
			$(this).addClass('active');
			var inf = $('div.binfo');

			var td = $(this).parent().prev().find('div.sml2Slide2 div.sld td img[alt='+ el +']').parent();
			td.siblings().removeClass('active');
			td.addClass('active');
			$(this).parent().prev().find('div.sml2Slide2 div.sld').scrollTo(td, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+el).show();
			});
		}

	}
	return false
});

$('div.smallSlideBar a').click(function(){
	if(!$(this).hasClass('active') && !smlAnimate){
		if(smlAnimate){return false}

			$(this).parent().find('a').removeClass('active');
			var el = $(this).attr('class');
			$(this).addClass('active');

			var td = $(this).parent().prev().find('div.sld td img[alt='+ el +']').parent();
			td.siblings().removeClass('active');
			td.addClass('active');
			$(this).parent().prev().find('div.sld').scrollTo(td, 600, {onAfter:function(){
				smlAnimate = false;
			}});

	}
	return false
});

$('#topline a.snd').click(function(){
	$(this).parents('form').submit();
	return false
});
$('#search .tx').keyup(function(){
	$('#search').addClass('active');
	$('#search .tim').hover(function(){$('#search').css('background-position','0 -18px')},function(){$('#search').css('background-position','0 0')});
}).blur(function(){
	$('#search').removeClass('active');
});
$('#srch').click(function(){
	$('#clicked').remove();
	$('#search').show().css('visibility','visible').find('.tx').focus();
	$('<div id="clicked"></div>').prependTo('body');
	$('#clicked').click(function(){
		$('#clicked').remove();
		$('#search').removeClass('active').hide();
		$('#search .tim').unbind('hover');
	});
	return false
});

if($('html').hasClass('ipad')){
	$('h1').addClass('typeface-js');
}

$('td.needmore a,a.nmlink').hover(
	function(){
		$(this).closest('div').addClass('hoved');
	},
	function(){
		$(this).closest('div').removeClass('hoved');
	}
);

$('.smlSlide div.lnk').each(function(){
	var par = $(this);
	var max = (par.next().find('td').size()-1)*548;
	var nameslider = false;
	if($(this).closest('.smlSlide').next().is('.smallSlideBar')){nameslider = true;var namesld = $(this).closest('.smlSlide').next();}

	$(this).find('div.lf').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() < 490){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:last').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').prev();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
		}
		if(nameslider){
			namesld.find('a').removeClass('active');
			namesld.find('a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		}

		return false
	});
	$(this).find('div.rg').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() > max){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:first').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').next();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
		}

		if(nameslider){
			namesld.find('a').removeClass('active');
			namesld.find('a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		}

		return false
	});
});

if($.browser.msie){
	$('div.icos a').hover(function(){$(this).addClass('hvv')},function(){$(this).removeClass('hvv')});
}
var relLeft = $('div.wrap').position().left;
$('div.cld span.col').hover(
function(){
	var self = $(this).find('div.ovl');
	self.show();
	$(document).mousemove(function(e){
		var x = e.pageX + 27 - relLeft;
		var y = e.pageY - 176;
		self.css('top',y + 'px').css('left',x + 'px');

	});
},
function(){
	$(this).find('div.ovl').hide();
	$(window).unbind('mousemove');
}
);

$('div.yearchange a.up').live("click", function(){
	if(!$(this).hasClass('dis')){
		var val = parseInt($(this).parent().find('input').val());
		val += 1;
		var max = parseInt($(this).parent().attr('rel'));
		if(val >= max){
			$(this).addClass('dis');
		}
		$(this).parent().find('input').val(val);
	}
	return false
});
$('div.yearchange a.dn').live("click", function(){
	if(!$(this).hasClass('dis')){
		var val = parseInt($(this).parent().find('input').val());
		val -= 1;
		var max = parseInt($(this).parent().attr('rel'));
		if(val < max){
			$(this).prev().removeClass('dis');
		}
		$(this).parent().find('input').val(val);
	}
	return false
});
$('div.yearchange input').live("keypress", function(){return false});

$('div.answ input').click(function(){
	$(this).parent().parent().hide().closest('.ww').next().removeClass('hide').parent().find('>.poz').addClass('hide');
});

$('a.qu').click(function(){
	if(!$(this).hasClass('opd')){
		$(this).addClass('opd').closest('.coml2').find('>.poz').removeClass('hide').end().find('>.cform:first').addClass('hide').end().find('div.answ span.button').show();
	} else {
		$(this).removeClass('opd').closest('.coml2').find('>.poz').addClass('hide');
	}

	return false
});


$('div.sml2Slide2 div.lnk').each(function(){
	var par = $(this);
	var max = (par.next().find('td').size()-2)*822;
	var inf = $('div.binfo');

	$(this).find('div.lf').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() < 540){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:last').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000', function(){
				$('#' + par.next().find('td.active img').attr('alt')).show();
			});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').prev();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		$('#smlSlideBar a').removeClass('active');
		$('#smlSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		return false
	});
	$(this).find('div.rg').find('a,img').click(function(){
		if(smlAnimate){return false}
		if(par.next().scrollLeft() > max){
			par.next().find('td.active').removeClass('active');
			par.next().scrollTo(par.next().find('td:first').addClass('active'), 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		else{
			var el = par.next().find('td.active').removeClass('active').next();
			el.addClass('active');
			par.next().scrollTo(el, 600, {onAfter:function(){
				smlAnimate = false;
			}});
			inf.find('>div:visible').fadeOut('1000',function(){
				$('#'+par.next().find('td.active img').attr('alt')).show();
			});
		}
		$('#smlSlideBar a').removeClass('active');
		$('#smlSlideBar a.'+par.next().find('td.active img').attr('alt')).addClass('active');
		return false
	});
});

            fetch_twitter_feed({
                post_response_callback: function(response) {
                    $("#twBar").show();
                    twitter();
                }
            });
            $("#twBar").hover(function() {
                twBar_mouse_is_over = true;
            }, function() {
                twBar_mouse_is_over = false;
            });

			$('#topline .icos a.jj').mouseenter(function(){
				$(this).parent().find('div.ljlogin').show();
			});
			$('#topline .icos div.ljlogin').mouseleave(function(){
				$(this).hide();
			});
			$('#topline input.sw').mouseenter(function(){
				if($(this).hasClass('sw')){
					$(this).removeClass('sw').val('');
				}
			});
            $('#ex a.jq_submit').live("click", function(){
                var jq_this = $(this);
                var jq_form = $("#ex form");
                $("#id_preferred_date").val($("#id_month").val()+"-"+$("#id_day").val());
                var form_data = jq_form.serialize();
                var post_url = jq_form.attr("action");
                $.post(post_url, form_data, function(response) {
                    jq_this.addClass("jq_submit");
                    $("#ex td.error").removeClass("error");
                    if (response.status == 1) {
                        $("#ex .in").html('<span class="exthx">Ваша заявка принята и будет обработана нашими менеджерами в течение 24 часов. Спасибо!</span>');
                    } else if (response.errors) {
                        var errors = response.errors;
                        for (var f in errors) {
                            $('#ex form input[name="'+f+'"]').closest("td").addClass("error");
                        }
                    }
                });
                jq_this.removeClass("jq_submit");
                return false;
            });
			$('a.gobutton').click(function(){
          $(this).closest('form').submit();
          return false
      });
      $('#scal').parent("form").find(".clearbutton").click(function(event) {
          $("#scal .selected a").click().mouseleave();
          event.preventDefault();
      });
            var selected_date = $("#jq_reports_date").val();
			$('#scal').calendarLite({
				dateFormat: '{%yyyy}-{%mm}-{%dd}',
				showYear: true,
                month: selected_date ? parseInt(selected_date.split("-")[1], 10)-1 : null,
                year: selected_date ? selected_date.split("-")[0] : null,
				onSelect: function(el) {
					var inp = el.find('input');
                    document.location = el.closest("form").attr("action")+"date/"+inp.val()+"/";
                    return false;

                    /*
					el.find('i,b').remove();

					if(!inp.is(':checked')){
						inp.attr('checked','checked').parent().parent().removeAttr('style').addClass('selected');
						$('<i></i>').prependTo(el);
					} else {
						inp.removeAttr('checked').parent().parent().removeClass('selected').css('background','none');
						$('<b></b>').prependTo(el);
					}
					return false;
                    */
				}
			});
      if($('div.comment').size()>0){
	$('div.comment div.cont').each(function(){
		var el = $(this).find('span');
		var id = $(this).closest('.comment').attr('id').replace('c','');
		var first = true;
		el.click(function(e){
			e.stopImmediatePropagation();
			if(first){
				first = false;
				var ln = $('body>div.lang_ru').size()>0?'ru':'en';
				if(!$(this).hasClass('hnd')){ //жмем делаем +1
					$.ajax({
						type: "GET",
						url: "/comments/post/"+ id +"/up/",
						data: "id="+ id,
						success: function(msg){
							var rating = parseInt(el.text()) + 1;
							el.text(rating).addClass('hnd');
							first = true;
						}
					});
				} else { //жмем делаем -1
                    if(!$(this).attr('disabled')){
					$.ajax({
						type: "GET",
						url: "/comments/post/"+ id +"/down/",
						data: "id="+ id,
						success: function(msg){
							var rating = parseInt(el.text()) - 1;
							el.text(rating).removeClass('hnd');
							first = true;
						}
					});
							var rating = parseInt(el.text()) - 1;
							el.text(rating).removeClass('hnd');
                    }
				}
			}
		});

		var qu = $(this).find('a.qu');
		qu.click(function(e){
			e.preventDefault();
			if(!$(this).hasClass('complaint')){
				$.ajax({
					type: "POST",
					url: "/comments/post/"+ id +"/complaint/",
					data: "id="+ id,
					success: function(msg){
						$(this).addClass('complaint');
					}
				});
			}
		});

	});

}

    $('a.showForm').click(function(){
        var sml = $(this).closest('.smlTopic').next();
        if (sml.is(":visible")) {
          sml.hide();
        } else {
          sml.show();
          /* .find('span.button:first').unbind('click').click(function(){
              $(this).closest('form').submit();
          }).end().find('span.button:last').unbind('click').click(function(){
              //$(this).closest('.smlForm').hide();
          }); */
        }
        return false
    });

	if($('#topbar>div.col').size()<3){
		$('<div class="col"><!-- --></div>').insertAfter('#topbar>div.col:last');
	}

	$('div.sld').each(function(){
		if($(this).find('td').size()<2 && $(this).prev().is('.lnk')){
			$(this).prev().remove();
		}
	});

    $("form.jq_comment").live("submit", function(event) {
        event.preventDefault();
        var jq_form = $(this);
        jq_form.find(".cleared").each(function() {
            var jq_item = $(this);
            if (jq_item.val() == jq_item.attr("def")) jq_item.val('');
        });
        var form_data = jq_form.serialize();
        jq_form.find(".cleared").each(function() {
            var jq_item = $(this);
            if (jq_item.val() == '') jq_item.val(jq_item.attr('def'));
        });
        $.post("/comments/ajax/", form_data, function(response) {
            jq_form.find(".error").removeClass("error");
            if (response.status == 1) {
                if (response.comment_id) {
                    document.location.hash = '#c'+response.comment_id;
                }
                document.location.reload(true);
            }
            if (response.status == 0 && response.errors) {
                var errors = response.errors;
                jq_form.find(".jq_captcha .goleft").click();
                for (var f in errors) {
                    if (f == 'captcha') f = 'captcha_1';
                    jq_form.find('[name="'+f+'"]:visible').parent().addClass("error");
                }
            }
        });
        event.preventDefault();
    });

    var smlForm = $(".smlForm");
    if (smlForm.length) {
        $(function() {
          $('.jq_append_tx > input[type="text"]').addClass("tx");
        });
        $('input[name="start_date"],input[name="end_date"]', smlForm).hide()
            .after($("#jq_datepicker_widget_template").clone().removeAttr("id"))
            .each(function(i, e) {
                var input = $(e);
                var date = input.val();
                if (!date) return;
                var container = input.closest("td");

                date = date.split("-");
                $(".datepicker_day", container).val(date[2]);
                $('.selOp a[rel="'+date[1].replace(/^0/, "")+'"]', container).click();
                $(".datepicker_year", container).val(date[0]);
            });

        smlForm.find("form").submit(function() {
            $('input[name="start_date"],input[name="end_date"]', smlForm).each(function(i, e) {
                var input = $(e);
                var container = input.closest("td");
                input.val($("input.datepicker_year", container).val() + "-" +
                    $("input.datepicker_month", container).val() + '-' +
                    $("input.datepicker_day", container).val());

            });
        });
    }

});

function banner_show(id) {
  $.get("/b/show/"+id+"/");
}


/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CCAttribution-ShareAlike 2.5 Brazil - http://creativecommons.org/licenses/by-sa/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */

// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
	/**
	 * $ is an alias to jQuery object
	 *
	 */
	$.fn.lightBox = function(settings) {
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			// Configuration related to overlay
			overlayBgColor: 		'#000',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
			// Configuration related to navigation
			fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			// Configuration related to images
			imageLoading:			'i/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'i/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			'i/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			'i/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				'i/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
			// Configuration related to container image box
			containerBorderSize:	0,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
			// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
			txtImage:				'',	// (string) Specify text "Image"
			txtOf:					'/',		// (string) Specify text "of"
			// Configuration related to keyboard navigation
			keyToClose:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
			keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
			keyToNext:				'n',		// (string) (n = next) Letter to show the next image.
			// Donґt alter these variables in any way
			imageArray:				[],
			activeImage:			0
		},settings);
		// Caching the jQuery object with all elements matched
		var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		function _initialize() {
			_start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
			return false; // Avoid the browser following the link
		}
		/**
		 * Start the jQuery lightBox plugin
		 *
		 * @param object objClicked The object (link) whick the user have clicked
		 * @param object jQueryMatchedObj The jQuery object with all elements matched
		 */
		function _start(objClicked,jQueryMatchedObj) {
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'hidden' });
			// Call the function to create the markup structure; style some elements; assign events in some elements.
			_set_interface();
			// Unset total images in imageArray
			settings.imageArray.length = 0;
			// Unset image active information
			settings.activeImage = 0;
			// We have an image set? Or just an image? Letґs see it.
			if ( jQueryMatchedObj.length == 1 ) {
				settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
			} else {
				// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
				for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
					settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
				}
			}
			while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
				settings.activeImage++;
			}
			// Call the function that prepares image exibition
			_set_image_to_view();
		}
		/**
		 * Create the jQuery lightBox plugin interface
		 *
		 * The HTML markup will be like that:
			<div id="jquery-overlay"></div>
			<div id="jquery-lightbox">
				<div id="lightbox-container-image-box">
					<div id="lightbox-container-image">
						<img src="../fotos/XX.jpg" id="lightbox-image">
						<div id="lightbox-nav">
							<a href="#" id="lightbox-nav-btnPrev"></a>
							<a href="#" id="lightbox-nav-btnNext"></a>
						</div>
						<div id="lightbox-loading">
							<a href="#" id="lightbox-loading-link">
								<img src="../images/lightbox-ico-loading.gif">
							</a>
						</div>
					</div>
				</div>
				<div id="lightbox-container-image-data-box">
					<div id="lightbox-container-image-data">
						<div id="lightbox-image-details">
							<span id="lightbox-image-details-caption"></span>
							<span id="lightbox-image-details-currentNumber"></span>
						</div>
						<div id="lightbox-secNav">
							<a href="#" id="lightbox-secNav-btnClose">
								<img src="../images/lightbox-btn-close.gif">
							</a>
						</div>
					</div>
				</div>
			</div>
		 *
		 */
		function _set_interface() {
			// Apply the HTML markup into body tag
			$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a><a href="#" id="lightbox-nav-btnClose"></a></div></div></div><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"></a></div></div></div></div>');
			$('#lightbox-container-image-box').append($('div.sliderBottom:first').clone());
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				backgroundColor:	settings.overlayBgColor,
				opacity:			settings.overlayOpacity,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#jquery-lightbox').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			}).show();
			// Assigning click events in elements to close overlay
			$('#jquery-overlay,#lightbox-nav-btnClose').click(function() {
				_finish();
			});
			// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
			$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
				_finish();
				return false;
			});
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				$('#jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				// Get page scroll
				var arrPageScroll = ___getPageScroll();
				// Calculate top and left offset for the jquery-lightbox div object and show it
				$('#jquery-lightbox').css({
					top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
					left:	arrPageScroll[0]
				});
			});
		}
		/**
		 * Prepares image exibition; doing a imageґs preloader to calculate itґs size
		 *
		 */
		function _set_image_to_view() { // show the loading
			// Show the loading
			$('#lightbox-loading').show();
			if ( settings.fixedNavigation ) {
				$('#lightbox-image,#jquery-lightbox .sliderBottom').hide();
			} else {
				// Hide some elements
				$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber,#jquery-lightbox .sliderBottom').hide();
			}
			// Image preload process
			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {
				$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
				// Perfomance an effect in the image container resizing it
				_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
				//	clear onLoad, IE behaves irratically with animated gifs otherwise
				objImagePreloader.onload=function(){};
			};
			objImagePreloader.src = settings.imageArray[settings.activeImage][0];
		};
		/**
		 * Perfomance an effect in the image container resizing it
		 *
		 * @param integer intImageWidth The imageґs width that will be showed
		 * @param integer intImageHeight The imageґs height that will be showed
		 */
		function _resize_container_image_box(intImageWidth,intImageHeight) {
			// Get current width and height
			var intCurrentWidth = $('#lightbox-container-image-box').width();
			var intCurrentHeight = $('#lightbox-container-image-box').height();
			// Get the width and height of the selected image plus the padding
			var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the imageґs width and the left and right padding value
			var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the imageґs height and the left and right padding value
			// Diferences
			var intDiffW = intCurrentWidth - intWidth;
			var intDiffH = intCurrentHeight - intHeight;
			// Perfomance the effect
			$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
			if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
				if ( $.browser.msie ) {
					___pause(250);
				} else {
					___pause(100);
				}
			}
			//$('#lightbox-container-image-data-box').css({ width: intImageWidth });
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
		};
		/**
		 * Show the prepared image
		 *
		 */
		function _show_image() {
			$('#lightbox-loading').hide();
			$('#lightbox-image').fadeIn();
			$('#jquery-lightbox .sliderBottom').show();

			$('.sliderBottom div.pod').hover(function(){
				$(this).addClass('open');
				clearTimeout(podTimer);
			},function(){
				var self = $(this);
				podTimer = setTimeout(function(){
					self.removeClass('open');
				}, 1000);
			});

							_show_image_data();
				_set_navigation();
			_preload_neighbor_images();
		};
		/**
		 * Show the image information
		 *
		 */
		function _show_image_data() {
			$('#lightbox-container-image-data-box').show();
			$('#lightbox-image-details-caption').hide();
			if ( settings.imageArray[settings.activeImage][1] ) {
				var htm = settings.imageArray[settings.activeImage][1];
				var htm2 = htm.split('::');
				var htm3 = htm2[0]+'<span class="ccsl">'+ htm2[1] +'</span>';
				$('#lightbox-image-details-caption').html(htm3).show();
			}
			// If we have a image set, display 'Image X of X'
			if ( settings.imageArray.length > 1 ) {
				$('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
			}
		}
		/**
		 * Display the button navigations
		 *
		 */
		function _set_navigation() {
			$('#lightbox-nav').show();

			// Instead to define this configuration in CSS file, we define here. And itґs need to IE. Just.
			//$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });

			// Show the prev button, if not the first image in set
			if ( settings.activeImage != 0 ) {
				if ( settings.fixedNavigation ) {
					$('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage - 1;
							_set_image_to_view();
							return false;
						});
				} else {
					// Show the images button for Next buttons
					$('#lightbox-nav-btnPrev').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
					},function() {
						//$(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage - 1;
						_set_image_to_view();
						return false;
					});
				}
			}

			// Show the next button, if not the last image in set
			if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
				if ( settings.fixedNavigation ) {
					$('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage + 1;
							_set_image_to_view();
							return false;
						});
				} else {
					// Show the images button for Next buttons
					$('#lightbox-nav-btnNext').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
					},function() {
						//$(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage + 1;
						_set_image_to_view();
						return false;
					});
				}
			}
			// Enable keyboard navigation
			_enable_keyboard_navigation();
		}
		/**
		 * Enable a support to keyboard navigation
		 *
		 */
		function _enable_keyboard_navigation() {
			$(document).keydown(function(objEvent) {
				_keyboard_action(objEvent);
			});
		}
		/**
		 * Disable the support to keyboard navigation
		 *
		 */
		function _disable_keyboard_navigation() {
			$(document).unbind();
		}
		/**
		 * Perform the keyboard actions
		 *
		 */
		function _keyboard_action(objEvent) {
			// To ie
			if ( objEvent == null ) {
				keycode = event.keyCode;
				escapeKey = 27;
			// To Mozilla
			} else {
				keycode = objEvent.keyCode;
				escapeKey = objEvent.DOM_VK_ESCAPE;
			}
			// Get the key in lower case form
			key = String.fromCharCode(keycode).toLowerCase();
			// Verify the keys to close the ligthBox
			if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
				_finish();
			}
			// Verify the key to show the previous image
			if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
				// If weґre not showing the first image, call the previous
				if ( settings.activeImage != 0 ) {
					settings.activeImage = settings.activeImage - 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
			// Verify the key to show the next image
			if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
				// If weґre not showing the last image, call the next
				if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {
					settings.activeImage = settings.activeImage + 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
		}
		/**
		 * Preload prev and next images being showed
		 *
		 */
		function _preload_neighbor_images() {
			if ( (settings.imageArray.length -1) > settings.activeImage ) {
				objNext = new Image();
				objNext.src = settings.imageArray[settings.activeImage + 1][0];
			}
			if ( settings.activeImage > 0 ) {
				objPrev = new Image();
				objPrev.src = settings.imageArray[settings.activeImage -1][0];
			}
		}
		/**
		 * Remove jQuery lightBox plugin HTML markup
		 *
		 */
		function _finish() {
			$('#jquery-lightbox').remove();
			$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}
		/**
		 / THIRD FUNCTION
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
		 /**
		  * Stop the code execution from a escified time in milisecond
		  *
		  */
		 function ___pause(ms) {
			var date = new Date();
			curDate = null;
			do { var curDate = new Date(); }
			while ( curDate - date < ms);
		 };
		// Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
		return this.unbind('click').click(_initialize);
	};
})(jQuery); // Call and execute the function immediately passing the jQuery object

