function resizingWindowIsIE(){if(navigator.appName=='Microsoft Internet Explorer'){return true}return false}function resizingWindowIsOpera(){if(navigator.appName=='Opera'){return true}return false}var resizingWindowMaxResizes=3;var resizingWindowResizes=0;var dwidth;var dheight;function resizingWindowLoaded(a,b){dwidth=a;dheight=b;resizingWindowResizes=0;resizingWindowGo()}function resizingWindowEndOfBody(){jQuery('body').append("<div "+"id='resizingWindowTestSizeDiv' "+"style='width: 100%; "+"  height: 100%; "+"  position: fixed; "+"  left: 0; "+"  top: 0; "+"  visibility: hidden; "+"  z-index: -1'></div>\n")}function resizingWindowResized(){resizingWindowGo()}function resizingWindowGo(){var a;var b;var x,y,w,h;if(resizingWindowResizes==resizingWindowMaxResizes){return}resizingWindowResizes++;if(resizingWindowIsIE()){a=parseInt(document.documentElement.clientWidth);b=parseInt(document.documentElement.clientHeight)}else if(resizingWindowIsOpera()){a=parseInt(window.innerWidth)-16;b=parseInt(window.innerHeight)}else{resizingWindowEndOfBody();testsize=document.getElementById('resizingWindowTestSizeDiv');a=testsize.scrollWidth;b=testsize.scrollHeight}if((dwidth==a)&&(dheight==b)){resizingWindowResizes=resizingWindowMaxResizes;return}var c=dwidth-a;var d=dheight-b;window.resizeBy(c,d)}

var gallery = null;

jQuery(document).ready(function(){

	jQuery('input[type=text]').each(function(){
		jQuery(this).bind('focus', function() {
			this._value = this.value;
			this.value = '';
		});
		jQuery(this).bind('blur', function() {
			if (this._value && this.value == '' ) {
				this.value = this._value;
			}
		});
	});

	jQuery('input[type=password]').each(function(){
		var _label = jQuery('<label>'+jQuery(this).val()+'</label>');
		_label.css({
			'position':'absolute',
			'top':4,
			'display':'block',
			'clear':'both',
			'left':0,
			'zIndex':0,
			'fontSize':11,
			'height':10,
			'width': 152,
			'paddingLeft':1,
			'paddingRight':0,
			'paddingTop':0,
			'paddingBottom':0,
			'color':'#7A7A7A',
			'fontWeight':'normal',
			'backgroundColor':'#ffffff'
		});
		var _input = jQuery(this);
		_label.attr('for',_input.attr('id'));
		_input.parent().css('position','relative');
		_input.css({
			'position':'relative',
			'zIndex':2,
			'background':'#fff',
			'opacity':0
		});
		jQuery(this).val('');
		jQuery(this).after(_label);
		jQuery(this).focus(function(){
			_label.css('textIndent',-9999);
			_input.css({'opacity':1});
		});
		jQuery(this).blur(function(){
			if (_input.val() == '') {
				_label.css('textIndent',0);
				_input.css({'opacity':0});
			}
		});
	});

	if (typeof(_projects) != 'undefined') {
	// main code
	var _ajaxLoading = true;
	gallery = {
		// parametrs
		slideDuration : 1000, // 0.5 sec
		autoPlay : 30000, // 30 sec
		autoSwitch : 5000, // 5 sec

		imageClass : 'bg-img',
		imageHolder : jQuery('#wrapper'),
		nextBtn : jQuery('a.next-slide, a.lnk-r'),
		prevBtn : jQuery('a.prev-slide, a.lnk-l'),
		pauseBtn : jQuery('li.play a'),
		textHolder : jQuery('div.bottom-box div.inner'),
		allImg : jQuery('span.all'),
		curImg : jQuery('span.cur'),

		// def parametrs
		projectJSON : _projects,
		step : 0,
		imagesEl : {},
		projectNum : 0,
		projectNumTemp:0,
		imageNum : 0,
		imgSum : 0,
		totalProjectNum : 0,
		nextImg : false,
		nextProj : false,
		randomProject : true,
		postId : '',
		direction:0,
		nextPrevLoad:true,
		autoPlayTimer : 1,
		nextSlideImage : false,

		// parse
		random : function() {
			this.projectNum = this.randomIntervalNumber(0, this.projectJSON.length-1);
		},
		randomIntervalNumber: function(m,n)  {
			return Math.floor(Math.random()*(n-m+1))+ m;
		},
		projectJSONextend : function(json, _i){
			var _this = this;
			jQuery.extend(this.projectJSON[_i], json);
			jQuery(this.projectJSON[_i].images).each(function(i,el){
				_this.loadImage(el.urlImage);
			});
			if (this.nextPrevLoad === true) {
				this.imageState(false);
				this.nextPrevLoad = false;
			} else {
				this.imageState(true);
				this.nextPrevLoad = null;
			}
		},

		updateCounter : function() {
			var _this = this;

			var _total = _this.projectJSON[_this.projectNum]['imagesNum'];

			if (_total < 10 ) {
				_this.allImg.html('0'+(_total));
			} else {
				_this.allImg.html(_total);
			}

			var _current, _k = 0;

			for (var i = 0; i < _this.totalProjectNum; i++) {

				_k += _this.projectJSON[i]['imagesNum'];

				if (_this.projectNum>0){

					if (i == _this.projectNum-1) {
						_current =  _this.imageNum - _k + 1;
					}
				}
				else {
					_current =  _this.imageNum+1;
				}
			}

			if ((_current) < 10) {
				_this.curImg.html('0'+(_current));
			}
			else {
				_this.curImg.html(_current);
			}

			return;
		},
		// slider
		sliderSetup : function(){
			var _this = this;
			var _showNumImage = 0;
			var _tempImgSum = 0;
			var _eachBreack = false;
			if (jQuery.cookie('projectNum') != null) {
				jQuery(this.projectJSON).each(function(i,_el){
					if (_tempImgSum + _el.imagesNum-1 >= _this.imageNum && !_eachBreack) {
						_eachBreack = true;
						if (i != 0) {
							_showNumImage = _this.imageNum - _tempImgSum;
						} else {
							_showNumImage = _this.imageNum;
						}
					}
					_tempImgSum += _el.imagesNum;
				});
			}
			jQuery(this.imagesEl).filter('.active').attr('src',this.projectJSON[this.projectNum].images[_showNumImage].urlImage);
			this.nextBtn.mousedown(function(){
				if (!_this.pauseBtn.hasClass('pause')) _this.pauseBtn.trigger('click')
				if (_this.autoPlayTimer) clearTimeout(_this.autoPlayTimer);
			});
			this.nextBtn.click(function(){
				if (jQuery(_this.imagesEl).is(':animated')) return false;
				_this.direction = 1;
				_this.nextImage();



				_this.imageNum = _this.nextImg;
				_this.slide();
				_this.updateCounter();
				return false;
			});

			jQuery(document).keypress(function(e){

				var t = 0;
				if (e.keyCode) {
					t = e.keyCode;
				} else if(e.charCode) {
					t = e.charCode;
				} else if (e.which) {
					t = e.which;
				}

				if (t == 38) {
					if (jQuery("#wrapper").hasClass('medium')){
						window.location = jQuery('div.logo-hold a').attr('href');
					}
					else {
						handleScreen();
						window.location = jQuery("#screen-options").attr('href');
					}
					return false;
				} else if (t == 40) {
					if (jQuery("#wrapper").hasClass('medium')){
						handleScreen();
						window.location = jQuery("#screen-options").attr('href');
					}
					else {
					window.location = jQuery('div.logo-hold a').attr('href');
				}
				} else if (t == 37) {

					jQuery("a.lnk-l").css({'text-indent': '0'});

					setTimeout(function() {jQuery("a.lnk-l").css({'text-indent': '-9999px'});}, 300);
					_this.prevBtn.trigger('click');
					return false;
				} else if (t == 39) {
					jQuery("a.lnk-r").css({'text-indent': '0'});
					setTimeout(function() {jQuery("a.lnk-r").css({'text-indent': '-9999px'});}, 300);
					_this.nextBtn.trigger('click');
					return false;
				}
			});
			this.prevBtn.mousedown(function(){
				if (!_this.pauseBtn.hasClass('pause')) _this.pauseBtn.trigger('click')
				if (_this.autoPlayTimer) clearTimeout(_this.autoPlayTimer);
			});
			this.prevBtn.click(function(){
				if (jQuery(_this.imagesEl).is(':animated')) return false;
				_this.direction = 0;
				_this.prevImage();


				/*
				if ((_this.nextImg+1) < 10) {
					_this.curImg.html('0'+(_this.nextImg+1));
				}
				else {
					_this.curImg.html((_this.nextImg+1));
				} */
				_this.imageNum = _this.nextImg;
				_this.slide();

				_this.updateCounter();
				return false;
			});
			//this.pauseBtn.addClass('pause');
			this.pauseBtn.click(function(){
				if (_this.autoPlayTimer) clearTimeout(_this.autoPlayTimer);
			//alert(this.className);
				jQuery(this).toggleClass('pause');
				//console.log('click');
				if (!jQuery(this).hasClass('pause')) {
					jQuery(this).text(7);
					jQuery.cookie('projectPause', 'false');

					_this.autoPlayFn();
					//
				} else {
					jQuery(this).text(8);
					jQuery.cookie('projectPause', 'true');
					if (_this.autoPlayTimer) clearInterval(_this.autoPlayTimer);
				}
				return false;
			});
			this.projectNumTemp = this.projectNum;
			this.textHolder.html(this.projectJSON[this.projectNum].content);
			if (this.randomProject) {
				if (jQuery.cookie('projectPause')) {
					if (jQuery.cookie('projectPause') == 'false') {
						this.pauseBtn.removeClass('pause').text(7);
						_this.autoPlayFn();
					} else {
						this.pauseBtn.addClass('pause').text(8);
					}
				} else {
					this.pauseBtn.removeClass('pause').text(7);
					this.autoPlayTimer = setTimeout(function(){
						_this.autoPlayFn();
					}, this.autoPlay - this.autoPlayTimer);
				}
			} else {
				this.pauseBtn.trigger('click');
			}

			jQuery([this.imagesEl, this.textHolder, _otherColumns]).each(function(){
				jQuery(this).click(function(){
					if (!_this.pauseBtn.hasClass('pause')) {
						_this.pauseBtn.trigger('click');
					}
				});
			});

			jQuery.cookie('projectNum', this.projectNum);
			jQuery.cookie('imageNum', this.imageNum);
		},
		slide : function(){
			var _this = this;
			var _sumTemp = 0;
			var _k = 0;

			jQuery(this.projectJSON).each(function(i,_el){
				if (i == _this.projectNum) {
					if (_this.imageNum < _sumTemp)
						_k = _this.imageNum;
					else
						_k = -(_sumTemp - _this.imageNum);
				}
				_sumTemp += _el.imagesNum;
			});

			this.nextSlideImage.attr('src',this.projectJSON[this.projectNum].images[_k].urlImage);
			jQuery.cookie('projectNum', this.projectNum);
			jQuery.cookie('imageNum', this.imageNum);
			this.animate();
			if (this.projectNumTemp != this.projectNum) {
				this.textHolder.fadeOut(this.slideDuration/2, function(){
					_this.textHolder.html(_this.projectJSON[_this.projectNum].content).fadeIn(_this.slideDuration/2);
				});
				this.projectNumTemp = this.projectNum;
			}
		},
		autoPlayFn : function(){
			var _this = this;
			if (this.autoPlayTimer) clearInterval(this.autoPlayTimer);
			this.timer();
		},
		timer : function(){
			var _this = this;
			_this.autoPlayTimer = setInterval(function(){
				_this.pauseBtn.removeClass('pause').text(7);
				_this.nextBtn.trigger('click');
				jQuery.cookie('projectPause', 'false');
			//}, this.autoSwitch); //autoPlay
}, _this.autoPlay); //autoPlay
		},
		animate : function(){
			var _dir = 0;
			if (this.direction == 1) _dir = this.step;
			else _dir = -this.step;
			var _next = this.nextSlideImage;
			var _active = this.imagesEl.filter('.active');

			_active.removeClass('active').addClass('next');
			_next.addClass('active').removeClass('next');
			_next.css('left',_dir).animate({'left':0},{duration:this.slideDuration});
			_active.css('left',0).animate({'left':-_dir},{duration:this.slideDuration});

			this.nextSlideImage = _active;

		},
		nextImage : function(){
			this.nextImg = this.imageNum + 1;
			if (this.nextImg > this.imgSum-1) this.nextImg = 0;
			this.imageState(true);
		},
		prevImage : function(){
			this.nextImg = this.imageNum - 1;
			if (this.nextImg < 0) this.nextImg = this.imgSum - 1;
			this.imageState(false);
		},
		imageState: function(_n){
			var _this = this;
			var _tempImgSum = 0;
			jQuery(this.projectJSON).each(function(i,_el){
				if (_tempImgSum <= _this.nextImg && _this.nextImg <= _tempImgSum + _el.imagesNum-1) {
					if (_n == null) {
						_this.nextProj = i;
						_this.nextLoad(_this.nextProj);
					} else if (_n) {
						_this.nextProj = i + 1;
						if (_this.nextProj >= _this.totalProjectNum) _this.nextProj = 0;
						_this.nextLoad(_this.nextProj);
					} else {
						_this.nextProj = i - 1;
						if (_this.nextProj < 0) _this.nextProj = _this.totalProjectNum-1;
						_this.nextLoad(_this.nextProj);
					}
					_this.projectNum = i;
				}
				_tempImgSum += _el.imagesNum;
			});
		},

		// ajax
		firstLoad : function(){
			var _this = this;
			var _fxImage = jQuery('<img src="/wp-content/themes/theme-main/images/none.gif">');
			_fxImage.addClass(this.imageClass).addClass('next');
			jQuery(this.imageHolder).prepend(_fxImage);
			this.nextSlideImage = _fxImage;

			if (jQuery.cookie('projectNum') != null) {
				this.projectNum = parseInt(jQuery.cookie('projectNum'));
			} else {
				if (this.randomProject) this.random();
				else {
					jQuery(this.projectJSON).each(function(i){
						if (_this.postId === this.id) _this.projectNum = i;
					})
				}
			}

			if (!this.projectNum && jQuery.cookie('projectNum') == null) this.random();
			this.step = this.imageHolder.outerWidth();
			this.imagesEl = jQuery('img.'+this.imageClass);
			this.imagesEl.not('.next').addClass('active');
			this.totalProjectNum = this.projectJSON.length;

			if (jQuery.cookie('projectNum') != null) {
				this.imageNum = parseInt(jQuery.cookie('imageNum'));
				jQuery(this.projectJSON).each(function(i,_el){
					_this.imgSum += _el.imagesNum;
				});
			} else {
				jQuery(this.projectJSON).each(function(i,_el){
					_this.imgSum += _el.imagesNum;
					if (i == _this.projectNum) {
						_this.imageNum = _this.imgSum-_el.imagesNum;
					}
				});
			}

			this.nextImg = this.imageNum;
			this.loadProjectInf(this.projectJSON[this.projectNum].url, true);

			this.updateCounter();
			/*
			if (this.imageNum+1 < 10) this.curImg.html('0'+(this.imageNum+1));
			else this.curImg.html(this.imageNum+1);

			if (this.imgSum < 10) this.allImg.html('0'+this.imgSum);
			else this.allImg.html(this.imgSum);
			*/

			jQuery.cookie('projectNum', this.projectNum);
			jQuery.cookie('imageNum', this.imageNum);

		},
		nextLoad : function(_index){
			if (typeof this.projectJSON[_index].images == 'undefined') {
				this.loadProjectInf(this.projectJSON[_index].url, false);
			} else {
				_ajaxLoading = true;
			}
		},
		loadProjectInf : function(_url, _firstInit){
			var _this = this;
			jQuery.ajax({
				type:'POST',
				data:"mode=ajax",
				url:_url,
				dataType:'json',
				success:function(JSON){
					if (_firstInit) {
						_this.projectJSONextend(JSON, _this.projectNum);
						_this.sliderSetup();
					} else {
						_this.projectJSONextend(JSON, _this.nextProj);
						_ajaxLoading = true;
					}
				},
				error:function(e){
					//alert('ajax error');
				}
			});
		},
		loadImage : function(_src){
			var _newImage = new Image();
			var _imageLoad = false;
			_newImage.onload = function(){
				this.onload = function(){};
			}
			_newImage.src = _src;
		},

		// init gallery
		init : function(){
			this.postId = window.location.hash.toString().replace('#','');
			if (this.postId.length) this.randomProject = false;
			this.firstLoad();

			var _this = this;
			jQuery('#projects-ajax-holder a').live('click', function(){
				if (_this.autoPlayTimer) clearTimeout(_this.autoPlayTimer);
				if (!_this.pauseBtn.hasClass('pause')) {
					_this.pauseBtn.trigger('click');
				}
				_this.postId = this.href.substr(this.href.indexOf('#')+1);

				if (_this.postId) {
					jQuery(_this.projectJSON).each(function(i){
						if (_this.postId === this.id) {_this.projectNum = i;}
					});

					var _imgSum = 0;
					jQuery(_this.projectJSON).each(function(i,_el){
						_imgSum += _el.imagesNum;
						if (i == _this.projectNum) {
							_this.imageNum = _imgSum-_el.imagesNum;

							_this.updateCounter();
							/*
							if (_this.imageNum+1 < 10) {
								_this.curImg.html('0'+(_this.imageNum+1));
							}
							else {
								_this.curImg.html(_this.imageNum+1);
							} */
						}
					});
					_this.nextImg = _this.imageNum;
					_ajaxLoading = false;
					_this.imageState(null);

					var _thisTimer = setInterval(function(){
						if (_ajaxLoading) {
							clearInterval(_thisTimer);
							jQuery(_this.projectJSON[_this.projectNum].images).each(function(i,el){
								_this.loadImage(el.urlImage);
							});
							_this.slide();
						}
					}, 50);
				}

				return false;
			});
		}
	}


	// slide bar ***************************************************************
	var _slideHolder = jQuery('div.main');
	var _otherColumns = jQuery('div.slide');
	_slideHolder.h = _slideHolder.outerHeight();
	var _minHeight = 65;
	var _closeDuration = 300;

	jQuery('a.close').click(function(){
		
		//setOneCol();

		if (jQuery(this).hasClass('open')) {
		
			dropFlagUp();
			
			/*jQuery(this).removeClass('open');
			_slideHolder.removeClass('flagup');

			jQuery(this).text(1); */
			//_slideHolder.animate({'height':_slideHolder.h},{duration:_closeDuration, queue:false});

		} else {
		
			setFlagUp();
			
			/*jQuery(this).addClass('open');
			_slideHolder.addClass('flagup');
			jQuery(this).text(2);
			_otherColumns.hide(); */
			//_slideHolder.animate({'height':_minHeight},{duration:_closeDuration, queue:false, complete:function(){_otherColumns.hide()}});
		}
		return false;
	});

	// login *******************************************************************
	var _login = jQuery('a.login');
	var _loginBox = jQuery('div.login-box');

	_login.click(function(){
		if (jQuery(this).hasClass('active')) {
			jQuery(this).removeClass('active');
			_loginBox.hide(300);
//_otherColumns.show();
		} else {
			jQuery(this).addClass('active');
			_loginBox.show(300);
_otherColumns.hide();
		}
	});

	// info ********************************************************************
	/*var _infoBlock = jQuery('#info');

	if (_infoBlock.length && isOneCol()) {
		_infoBlock.hide();
	}*/

	jQuery('a.info-switch').click(function(){
		if (_partnersAjaxHolder.length) {
			if (_partnersAjaxHolder.is(':visible')) {
				_partnersAjaxHolder.hide();
				//_slideHolder.addClass('onecol');
			} else {
				_partnersAjaxHolder.show();
				//_slideHolder.removeClass('onecol');
			}
			return false;
		}
	});

	var _loginBlock = jQuery('#login');

	if (_loginBlock.length && isOneCol('login')) {
		_loginBlock.hide();
		setOneCol();
	}
	
	if (_loginBlock.length && isFlagUp('login')) {
		_loginBlock.hide();
		setFlagUp();
	}

	jQuery('a.login-switch').click(function(){

		if (_loginBlock.length) {
			setSection('login');
			if (_loginBlock.is(':visible')) {
				_loginBlock.hide();
				setOneCol();
				//_slideHolder.addClass('onecol');
			} else {
				_loginBlock.show();
				dropOneCol();
				//_slideHolder.removeClass('onecol');
			}
			return false;
		}
	});

	var _contactBlock = jQuery('#contact');

	if (_contactBlock.length && isOneCol('contact')) {
		_contactBlock.hide();
		setOneCol();
	}
	
	if (_contactBlock.length && isFlagUp('contact')) {
		_contactBlock.hide();
		setFlagUp();
	}

	jQuery('a.contact-switch').click(function(){

		if (_contactBlock.length) {
			setSection('contact');
			if (_contactBlock.is(':visible')) {
				_contactBlock.hide();
				setOneCol();
				//_slideHolder.addClass('onecol');
			} else {
				_contactBlock.show();
				dropOneCol();
				//_slideHolder.removeClass('onecol');
			}
			return false;
		}
	});


	// partners ********************************************************************
	var _partnersBlock = jQuery('#partners');
	if (_partnersBlock.length && isOneCol('partners')) {
		_partnersBlock.hide();
		setOneCol();
	}
	if (_partnersBlock.length && isFlagUp('partners')) {
		_partnersBlock.hide();
		setFlagUp();
	}
	jQuery('a.partners-switch').click(function(){

		if (_partnersBlock.length) {
			setSection('partners');
			if (_partnersBlock.is(':visible')) {
				_partnersBlock.hide();
				setOneCol();
				//_slideHolder.addClass('onecol');

				return false;
			} else {
			dropOneCol();
			}
			/*else {
				_partnersBlock.show();
				dropOneCol();
				//_slideHolder.removeClass('onecol');
			}*/

		}
	});


	var _partnersAjaxHolder = jQuery('#partner-ajax-holder');
	var _partnersMenu = jQuery('#partners .submenu a.txt');


	if ( window.location.toString().indexOf('#form') != -1) {
jQuery("#partner-text").toggle();
		jQuery("#partner-form").toggle();
if (jQuery("#partner-form").is(':visible')) {
jQuery('ul.submenu li.active').addClass('activeform');
}

}

	var _partnersEmail = jQuery('#partners .submenu a.email');


_partnersEmail.click(function() {
setSection('partners');
var _loc =  window.location.toString();



	if (_loc.indexOf(this.rel) != -1) {
		jQuery("#partner-text").toggle();
		jQuery("#partner-form").toggle();
if (jQuery("#partner-form").is(':visible')) {
jQuery(this.parentNode).addClass('activeform');
}
else{
jQuery(this.parentNode).removeClass('activeform');
}

		return false;
	}

});
/*
	_partnersMenu.click(function(){
		if (!jQuery(this).parent().hasClass('active')) {
			_partnersMenu.parent().removeClass('active');
			jQuery(this).parent().addClass('active');
			var _url = this.href;
			_partnersAjaxHolder.children().fadeTo(200, 0.5);
			jQuery.cookie('partnersTab', _partnersMenu.index(this));
			jQuery.ajax({
				url:_url,
				data: "mode=ajax",
				type: "POST",
				success:function(html){
					_partnersAjaxHolder.show();
					_partnersAjaxHolder.html(html).show();
					jQuery('div.column-r').removeClass('column-r');


					try {
		jQuery('div.wpcf7 > form').ajaxForm({
			beforeSubmit: wpcf7BeforeSubmit,
			dataType: 'json',
			success: wpcf7ProcessJson
		});
	} catch (e) {
	}

	try {
		jQuery('div.wpcf7 > form').each(function(i, n) {
			wpcf7ToggleSubmit(jQuery(n));
		});
	} catch (e) {
	}

	try {
		if (_wpcf7.cached) {
			jQuery('div.wpcf7 > form').each(function(i, n) {
				wpcf7OnloadRefill(n);
			});
		}
	} catch (e) {
	}

					jQuery('a.partner-switch').click(function() {


					/*
						jQuery('#partners .submenu li').each(function(){
							jQuery(this).removeClass('active');
						});

						if (_partnersAjaxHolder.length) {
							if (_partnersAjaxHolder.is(':visible')) {
								_partnersAjaxHolder.hide();
								//_slideHolder.addClass('onecol');
							} else {
								_partnersAjaxHolder.show();
								_slideHolder.removeClass('onecol');
							}
							return false;
						} *\/
					});


				},
				error:function(e){
					//alert('ajax error');
				}
			});
		} else {
			jQuery(this).parent().removeClass('active');
			_partnersAjaxHolder.hide();
		}
		return false;
	});
	*/
	//if (jQuery.cookie('partnersTab')) _partnersMenu.eq(parseInt(jQuery.cookie('partnersTab'))).trigger('click');


	// partners ********************************************************************
	var _projectsBlock = jQuery('#projects');
	if (_projectsBlock.length && isOneCol('projects')) {
		_projectsBlock.hide();
		setOneCol();
	}
	if (_projectsBlock.length && isFlagUp('projects')) {
		_projectsBlock.hide();
		setFlagUp();
	}

	var _projectslistSwitch = jQuery('a.projectslist-switch');

	/*	if (_projectsBlock.length) {
if (window.location.hash.toString().indexOf("#") != -1)
{
	_projectsBlock.hide();
	_slideHolder.addClass('onecol');
}

} */

	_projectslistSwitch.click(function(){

		if (_projectsBlock.length) {
			setSection('projects');

			if (!_slideHolder.hasClass('onecol')) {
				_projectsBlock.hide();
				setOneCol('projects');
				//_slideHolder.addClass('onecol');
			} else {
				_projectsBlock.show();
				dropOneCol();
				//_slideHolder.removeClass('onecol');
			}
			return false;
		}

	});

	var _projectsSwitch = jQuery('a.projects-switch');

	_projectsSwitch.click(function(){

		if (_projectsBlock.length) {
			setSection('projects');
			if (!_slideHolder.hasClass('onecol')) {
				_projectsBlock.hide();
				setOneCol('projects');
			} else {
				_projectsBlock.show();
				dropOneCol();
			}
			return false;
		}

	});

	if (_projectsBlock.length) {

		var _pagerHolder = _projectsBlock.find('div.title');
		var _pager = false;

		/*jQuery.ajax({
			url:_pagerUrl.attr('href'),
			success:function(html){
				_pager = jQuery(html).hide();
				_pagerHolder.append(_pager);
				_pager.fadeIn(200);
				pagerFn();
			},
			error:function(e){
				alert('ajax error');
			}
		}); */

		function pagerFn(){
			var _ajaxLinks = jQuery('#pager a');
			var _contentHolder = jQuery('#projects-ajax-holder');
			var _load = jQuery('.load');
			var _current = 0;

			_ajaxLinks.each(function(i){
				var _link = jQuery(this);
				_link.click(function(){
					loadPage(_link);
					_current = i;
					jQuery.cookie('ajaxTab', _current);
					return false;
				});
				if (parseInt(jQuery.cookie('ajaxTab')) == i) _link.trigger('click');
				/*if (_link.parent().hasClass('active')) {
					_link.trigger('click');
				}*/
			});

			function loadPage(link){
				_ajaxLinks.parent().removeClass('active');
				link.parent().addClass('active');
				var _href = link.attr('href');
				var _loadTab = _contentHolder.find('[rel="'+_href+'"]');

				var _visTab = _contentHolder.find('.loadContent:visible');

				if (!_loadTab.length) {
					_load.show();
					jQuery.ajax({
						url:_href,
						type: "POST",
						data: 'mode=ajax',
						success:function(_msg){
							_visTab.hide();
							var _contentP = jQuery(_msg).addClass('loadContent').hide().attr('rel',_href);

							_contentHolder.append(_contentP);
							jQuery(_contentP).show()
							_load.hide();
						}
					});
				} else {
					_visTab.hide()
					_loadTab.show();
				}
			}
		}
		pagerFn();
	}



		gallery.init();
	}

	// thumbnails *****************************************************************
	var _thumbsBlock = jQuery('#thubnails');
	jQuery('a', _thumbsBlock).click(function(){
		setSection('projects');
		setOneCol();
		jQuery.cookie('projectNum', this.rel);
		jQuery.cookie('imageNum', this.rev);
	});



});

function isOneCol(_section) {
if (!_section) {
	_section = jQuery.cookie('section');
}
	if ((jQuery.cookie('onecol') != null) && (jQuery.cookie('section') == _section) ) {
		return true;
	}
	return false;

	var _loc =  window.location.toString();
	if ((_loc.indexOf("?switch") != -1) && (jQuery.cookie('onecol') != null)) {
		jQuery.cookie('onecol', null);
		jQuery('div.main').addClass('onecol');
		return true;
	}
	return false;
}

function isFlagUp(_section) {
if (!_section) {
	_section = jQuery.cookie('section');
}
	if ((jQuery.cookie('flagup') != null) && (jQuery.cookie('section') == _section) ) {
		return true;
	}
	return false;

	var _loc =  window.location.toString();
	if ((_loc.indexOf("?switch") != -1) && (jQuery.cookie('flagup') != null)) {
		setFlagUp();
		return true;
	}
	return false;
}

function setSection(section) {
	jQuery.cookie('section', section);
}

function setOneCol() {
	var _section = jQuery.cookie('section');
	if (!_section) {_section = '1';}
	jQuery.cookie('onecol', _section);
	jQuery('div.main').addClass('onecol');
}

function dropOneCol() {
	jQuery.cookie('onecol', null);
	jQuery('div.main').removeClass('onecol');
}

function setFlagUp() {
	setOneCol();
	var _section = jQuery.cookie('section');
	if (!_section) {
		_section = '1';
	}
	jQuery.cookie('flagup', _section);
	jQuery('div.main').addClass('flagup');
	jQuery('a.close').addClass('open').text(2);
	jQuery('div.slide').hide();
}

function dropFlagUp() {
	jQuery.cookie('flagup', null);
	jQuery('div.main').removeClass('flagup');
	jQuery('a.close').removeClass('open').text(1);
}


/**
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 */
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 path = '; 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;
    }
};

