$(document).ready(function(){
if($('#preloader').length){
$('body').css({overflow: 'hidden'});
/*The next line should be added*/ $('#preloader').css({opacity: 0.8})
}
	// opacity *****************************************************************
	$('ul.thumbnails a').each(function(i,link){
		if (!$(link).parents('li').hasClass('active')) {
			$(link).css('opacity',0.5);
			$(link).hover(function(){
				$(link).animate({'opacity':1}, {duration:200, queue:false});
			}, function(){
				$(link).animate({'opacity':0.5}, {duration:200, queue:false});
			}).click(function(){
				var _text = $(link).parents('li').find('h2').text();
				$.cookie('title', _text, {expires: 1});
			});
		}
	});

	var _title = $('.load-title');
	if (_title.length) {
		_title.html($.cookie('title'));
	}
})
$(window).bind('load',function(){
	$('#preloader').fadeOut(600,function(){
		$(this).remove();
		$('body').css('overflow','');
	});
	$('ul.thumbnails img').each(function(){
		$(this).css({
			'width':this.width*0.25
		});
	});

	// slideshow ***************************************************************
	if (typeof($().slideShow) == 'function'){
		var _autoslideEnable = false;
		var _animationTime = 500;
		var _autoFadeTimeout = 3000;

		$('div.g-hold').slideShow({
			slideParent: '.gallery-main',
			slideEl:'div.gallery-main li',
			linkNext:'a.next',
			linkPrev:'a.prev',
			numElementLink:'div.gallery-nav ul li a',
			animHeight: true,
			onStart: function(){
				_def = 600;
				$('img', $(this)).each(function(){
					var _height = this.offsetHeight;
					var _width = this.offsetWidth;
					if( _height > _width){
						this.style.height = _def+'px';
					}else{
						this.style.width = _def+'px';
					}
				});
			},
			duration:_animationTime,
			autoSlideShow: _autoslideEnable,
			switchTime: _autoFadeTimeout
		});
		$('div.g-hold').slideShow({
			slideParent: '.gallery-descr',
			slideEl:'div.gallery-descr li',
			linkNext:'a.next',
			linkPrev:'a.prev',
			numElementLink:'div.gallery-nav ul li a',
			animHeight: true,
			duration: _animationTime,
			autoSlideShow: _autoslideEnable,
			switchTime: _autoFadeTimeout
		});
		$('div.slideshow').slideShow({
			slideParent:'.gallery-main',
			slideEl:'div.gallery-main li',
			duration:600,
			autoSlideShow:true,
			switchTime:3000
		});
	}

});

jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
