$(function(){
	clearInputs();
	initScrollGallery();
	initCustomForms();
	initLightbox();
	mediaGallery();
	videoSort();
	videoLoad();
})
/*--- custom radio's ---*/
function initCustomForms(){
	$('.radio-list input:radio').customRadio();
}
function videoSort(){
	$('.video-categories li').live('click', function () {
		$('.video-categories li').removeClass("active");
		$(this).addClass("active");
		var section_id = $(this).attr("id");
		if($('.video-categories').length){
			window.location.hash = section_id;
			
		}
		
		$.ajax({
			url: '/projects/ajax_filter.php?section_id=' + section_id,
			success: function ( data ) {
				$('.sort').html(data);
				initScrollGallery();
				initLightbox();
				linkFix(locationH);
			}
		});
		return false;
	});
}
function videoLoad(){
	//loading of video player when you click on the icon of play
	$('.video_box .play').live('click', function () {
		var element_id = $(this).parents('.video_box').attr("id");
		var section_id = $(this).parents('.video_box').attr("sect_id");
		$.ajax({
			url: '/projects/ajax_video.php?element_id=' + element_id + '&section_id=' + section_id,
			success: function ( data ) {
				$('.slider_preview').html(data);
				initScrollGallery();
			}
		});
		return false;
	});
}
function mediaGallery(){
	var media = $('.media');
	var mediaList = media.find('.media-list');
	var placeholder = media.find('.place-holder');
	var slides = mediaList.find('>li');
	var slidesLength = slides.length;
	var currentIndex = 0;
	var currentSlide = 0;
	var slidesContainerWidth = media.find('.w2').width();
	var mediaLinks = media.find('.link');
	var mediaThumbnails = mediaLinks.siblings('img');
	var placeholderWidth = -placeholder.width();
	placeholder.css({
		'display':'block',
		'z-index':1
	});
	var btnPrev = $('.visual-holder .btn-prev');
	var btnNext = $('.visual-holder .btn-next');
	var tabs = media.find('.tab-content');
	var animSpeed = 500;
	var prevSlide = placeholder.eq(currentSlide).prev();
	var nextSlide = placeholder.eq(currentSlide).next();
	prevSlide.css({
		marginRight:placeholderWidth/2-0.5,
		marginLeft:195
	})
	nextSlide.css({
		marginLeft:placeholderWidth/2+0.5,
		marginRight:195
	})
	function switchImg(){
		prevSlide.animate({
			marginRight:0,
			marginLeft:-158
		},animSpeed);
		nextSlide.animate({
			marginLeft:0,
			marginRight:-160
		},animSpeed);
		tabs.fadeOut(animSpeed);
		tabs.eq(currentIndex).fadeIn(animSpeed);
		mediaThumbnails.animate({opacity:0.5},animSpeed);
		mediaThumbnails.eq(currentIndex).animate({opacity:1},animSpeed);
		
	}
	function switchSlide(){
		mediaList.animate({marginLeft:-currentSlide*slidesContainerWidth},animSpeed);
		
		prevSlide = placeholder.eq(currentSlide).prev();
		nextSlide = placeholder.eq(currentSlide).next();
		prevSlide.css({
			marginRight:placeholderWidth/2-0.5,
			marginLeft:195
		})
		nextSlide.css({
			marginLeft:placeholderWidth/2+0.5,
			marginRight:195
		})
		mediaThumbnails.css({opacity:1})
		
	}
	btnNext.click(function(){
		if(currentSlide < slidesLength-1){
			currentSlide++;
			switchSlide();
			
		}
		else{
			currentSlide = 0;
			switchSlide();
		}
		return false;
	});
	btnPrev.click(function(){
		
		if(currentSlide > 0){
			currentSlide--;
			switchSlide();
		}
		else{
			currentSlide = slidesLength-1;
			switchSlide();
		}
		return false;
	});
	mediaLinks.click(function(){
		var currentMediaLink = $(this);
		currentIndex = mediaLinks.index(currentMediaLink);
		switchImg();
		return false;
	});
}
jQuery.fn.customRadio = function(_options){
	var _options = jQuery.extend({
		radioStructure: '<div></div>',
		radioDisabled: 'disabled',
		radioDefault: 'radioArea',
		radioChecked: 'radioAreaChecked'
	}, _options);
	return this.each(function(){
		var radio = jQuery(this);
		if(!radio.hasClass('outtaHere') && radio.is(':radio')){
			var replaced = jQuery(_options.radioStructure);
			this._replaced = replaced;
			if(radio.is(':disabled')) replaced.addClass(_options.radioDisabled);
			else if(radio.is(':checked')) replaced.addClass(_options.radioChecked);
			else replaced.addClass(_options.radioDefault);
			replaced.click(function(){
				if($(this).hasClass(_options.radioDefault)){
					radio.attr('checked', 'checked');
					changeRadio(radio.get(0));
				}
			});
			radio.click(function(){
				changeRadio(this);
			});
			replaced.insertBefore(radio);
			radio.addClass('outtaHere');
		}
	});
	function changeRadio(_this){
		$('input:radio[name='+$(_this).attr("name")+']').not(_this).each(function(){
			if(this._replaced && !$(this).is(':disabled')) this._replaced.removeClass().addClass(_options.radioDefault);
		});
		_this._replaced.removeClass().addClass(_options.radioChecked);
		if(typeof($(_this).change) == 'function') $(_this).change();
		if(typeof(_this.onchange) == 'function') _this.onchange();
	}
}
var types = ['DOMMouseScroll', 'mousewheel'];
$.event.special.mousewheel = {
	setup: function() {
		if ( this.addEventListener ) for ( var i=types.length; i; ) this.addEventListener( types[--i], handler, false );
		else this.onmousewheel = handler;
	},
	teardown: function() {
		if ( this.removeEventListener ) for ( var i=types.length; i; ) this.removeEventListener( types[--i], handler, false );
		else this.onmousewheel = null;
	}
};
$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});
function handler(event) {
	var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
	event = $.event.fix(event || window.event);
	event.type = "mousewheel";
	if ( event.wheelDelta ) delta = event.wheelDelta/120;
	if ( event.detail     ) delta = -event.detail/3;
	args.unshift(event, delta);
	return $.event.handle.apply(this, args);
}
jQuery.fn.customScrollV = function(_options){
var _options = jQuery.extend({
	lineWidth: 12
}, _options);
return this.each(function(){
	var _box = jQuery(this);
	if(_box.is(':visible')){
		if(_box.children('.scroll-content').length == 0){
			var line_w = _options.lineWidth;
			/*--- init part ---*/
			var scrollBar = jQuery('<div class="scroll-bar"><div class="scroll-up"></div><div class="scroll-line"><div class="scroll-slider"></div></div><div class="scroll-down"></div></div>');
			_box.wrapInner('<div class="scroll-content"><div class="scroll-hold"></div></div>').append(scrollBar);
			var scrollContent = _box.children('.scroll-content');
			var scrollSlider = scrollBar.find('.scroll-slider');
			var scrollSliderH = scrollSlider.parent();
			var scrollUp = scrollBar.find('.scroll-up');
			var scrollDown = scrollBar.find('.scroll-down');
			/*--- different variables ---*/
			var box_h = _box.height();
			var slider_h = 0;
			var slider_f = 0;
			var cont_h = scrollContent.height();
			var _f = false;
			var _f1 = false;
			var _f2 = true;
			var _t1, _t2, _s1, _s2;
			/*--- set styles ---*/
			_box.css({
				position: 'relative',
				overflow: 'hidden',
				height: box_h
			});
			scrollContent.css({
				position: 'absolute',
				top: 0,
				left: 0,
				zIndex: 1,
				height: 'auto'
			});
			scrollBar.css({
				position: 'absolute',
				top: 0,
				right: 0,
				zIndex:2,
				width: line_w,
				height: box_h,
				overflow: 'hidden'
			});
			scrollUp.css({
				width: line_w,
				height: line_w,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			scrollDown.css({
				width: line_w,
				height: line_w,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			slider_h = scrollBar.height();
			if(scrollUp.is(':visible')) slider_h -= scrollUp.height();
			if(scrollDown.is(':visible')) slider_h -= scrollDown.height();
			scrollSliderH.css({
				position: 'relative',
				width: line_w,
				height: slider_h,
				overflow: 'hidden'
			});
			slider_h = 0;
			scrollSlider.css({
				position: 'absolute',
				top: 0,
				left: 0,
				width: line_w,
				height: slider_h,
				overflow: 'hidden',
				cursor: 'pointer'
			});
			box_h = _box.height();
			cont_h = scrollContent.height();
			if(box_h < cont_h){
				_f = true;
				slider_h = Math.round(box_h/cont_h*scrollSliderH.height());
				if(slider_h < 5) slider_h = 5;
				scrollSlider.height(slider_h);
				slider_h = scrollSlider.outerHeight();
				slider_f = (cont_h - box_h)/(scrollSliderH.height() - slider_h);
				_s1 = (scrollSliderH.height() - slider_h)/10;
				_s2 = (scrollSliderH.height() - slider_h)/3;
				scrollContent.children('.scroll-hold').css('padding-right', scrollSliderH.width());
			}
			else{
				_f = false;
				scrollBar.hide();
				scrollContent.css({width: _box.width(), top: 0, left:0});
				scrollContent.children('.scroll-hold').css('padding-right', 0);
			}
			var _top = 0;
			/*--- element's events ---*/
			scrollUp.mousedown(function(){
				_top -= _s1;
				scrollCont();
				_t1 = setTimeout(function(){
					_t2 = setInterval(function(){
						_top -= 4/slider_f;
						scrollCont();
					}, 20);
				}, 500);
			}).mouseup(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			}).mouseleave(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			});
			scrollDown.mousedown(function(){
				_top += _s1;
				scrollCont();
				_t1 = setTimeout(function(){
					_t2 = setInterval(function(){
						_top += 4/slider_f;
						scrollCont();
					}, 20);
				}, 500);
			}).mouseup(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			}).mouseleave(function(){
				if(_t1) clearTimeout(_t1);
				if(_t2) clearInterval(_t2);
			});
			scrollSliderH.click(function(e){
				if(_f2){
					_top = e.pageY - scrollSliderH.offset().top;
					/*
					if(scrollSlider.offset().top + slider_h < e.pageY) _top += _s2;
					else if(scrollSlider.offset().top > e.pageY) _top -= _s2;
					*/
					scrollCont();
				}
				else{
					_f2 = true;
				}
			});
			var t_y = 0;
			scrollSlider.mousedown(function(e){
				t_y = e.pageY - $(this).position().top;
				_f1 = true;
			}).mouseup(function(){
				_f1 = false;
			});
			$('body').mousemove(function(e){
				if(_f1){
					 _f2 = false;
					 _top = e.pageY - t_y;
					 scrollCont();
				}
			}).mouseup(function(){
				_f1 = false;
			});
			document.body.onselectstart = function(){
				if(_f1) return false;
			}
			_box.bind('mousewheel', function(event, delta){
				if(_f){
					_top -=delta*_s1;
					scrollCont();
					if((_top > 0) && (_top+slider_h < scrollSliderH.height())) return false;
				}
			});
			function scrollCont(){
				if(_top < 0) _top = 0;
				else if(_top+slider_h > scrollSliderH.height()) _top = scrollSliderH.height() - slider_h;
				scrollSlider.css('top', _top);
				scrollContent.css('top', -_top*slider_f);
			}
			this.scrollResize = function(){
				box_h = _box.height();
				cont_h = scrollContent.height();
				if(box_h < cont_h){
					_f = true;
					scrollBar.show();
					slider_h = Math.round(box_h/cont_h*scrollSliderH.height());
					if(slider_h < 5) slider_h = 5;
					scrollSlider.height(slider_h);
					slider_h = scrollSlider.outerHeight();
					slider_f = (cont_h - box_h)/(scrollSliderH.height() - slider_h);
					if(cont_h + scrollContent.position().top < box_h) scrollContent.css('top', -(cont_h - box_h));
					_top = - scrollContent.position().top/slider_f;
					scrollSlider.css('top', _top);
					_s1 = (scrollSliderH.height() - slider_h)/15;
					_s2 = (scrollSliderH.height() - slider_h)/3;
					scrollContent.children('.scroll-hold').css('padding-right', scrollSliderH.width());
				}
				else{
					_f = false;
					scrollBar.hide();
					scrollContent.css({top: 0, left:0});
					scrollContent.children('.scroll-hold').css('padding-right', 0);
				}
			}
			/*
			setInterval(function(){
				if(_box.is(':visible') && cont_h != scrollContent.height()) _box.get(0).scrollResize();
			}, 200);
			*/
		}
		else{
			this.scrollResize();
		}
	}
});
}
/*---- clear inputs ---*/
function clearInputs(){
	$('input:text, input:password, textarea').each(function(){
		var _el = $(this);
		var _val = _el.val();
		_el.bind('focus', function(){
			if(this.value == _val) {
				this.value = '';
			}
		}).bind('blur', function(){
			if(this.value == '') {
				this.value = _val;
			}
		});
	});
};
function initScrollGallery(){
	$('.projects').scrollGallery({
		sliderHolder:'div.holder',
		generatePagination:false,
		btnPrev:'a.btn-prev',
		btnNext:'a.btn-next',
		switchTime:5000
	});
	$('.client-slider').scrollGallery({
		sliderHolder:'div.slider-holder',
		generatePagination:false,
		btnPrev:'a.btn-prev',
		btnNext:'a.btn-next',
		switchTime:5000
	});
	$('.lightbox').scrollGallery({
		sliderHolder:'div.lightbox-gallery',
		generatePagination:false,
		btnPrev:'a.btn-prev',
		btnNext:'a.btn-next',
		switchTime:5000
	});
}
// scrolling gallery plugin
jQuery.fn.scrollGallery = function(_options){
	var _options = jQuery.extend({
		sliderHolder: '>div',
		slider:'>ul',
		slides: '>li',
		pagerLinks:'div.pager a',
		btnPrev:'a.link-prev',
		btnNext:'a.link-next',
		activeClass:'active',
		disabledClass:'disabled',
		generatePagination:'div.pg-holder',
		curNum:'em.scur-num',
		allNum:'em.sall-num',
		circleSlide:true,
		pauseClass:'gallery-paused',
		pauseButton:'none',
		pauseOnHover:true,
		autoRotation:false,
		stopAfterClick:false,
		switchTime:5000,
		duration:650,
		easing:'swing',
		event:'click',
		splitCount:false,
		afterInit:false,
		vertical:false,
		step:false
	},_options);
	

	return this.each(function(){
		// gallery options
		var _this = jQuery(this);
		var _sliderHolder = jQuery(_options.sliderHolder, _this);
		var _slider = jQuery(_options.slider, _sliderHolder);
		var _slides = jQuery(_options.slides, _slider);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _generatePagination = jQuery(_options.generatePagination, _this);
		var _curNum = jQuery(_options.curNum, _this);
		var _allNum = jQuery(_options.allNum, _this);
		var _pauseButton = jQuery(_options.pauseButton, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _pauseClass = _options.pauseClass;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _disabledClass = _options.disabledClass;
		var _easing = _options.easing;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;
		var _step = _options.step;
		var _vertical = _options.vertical;
		var _circleSlide = _options.circleSlide;
		var _stopAfterClick = _options.stopAfterClick;
		var _afterInit = _options.afterInit;
		var _splitCount = _options.splitCount;

		// gallery init
		if(!_slides.length) return;

		if(_splitCount) {
			var curStep = 0;
			var newSlide = $('<slide>').addClass('split-slide');
			_slides.each(function(){
				newSlide.append(this);
				curStep++;
				if(curStep > _splitCount-1) {
					curStep = 0;
					_slider.append(newSlide);
					newSlide = $('<slide>').addClass('split-slide');
				}
			});
			if(curStep) _slider.append(newSlide);
			_slides = _slider.children();
		}

		var _currentStep = 0;
		var _sumWidth = 0;
		var _sumHeight = 0;
		var _hover = false;
		var _stepWidth;
		var _stepHeight;
		var _stepCount;
		var _offset;
		var _timer;

		_slides.each(function(){
			_sumWidth+=$(this).outerWidth(true);
			_sumHeight+=$(this).outerHeight(true);
		});

		// calculate gallery offset
		function recalcOffsets() {
			if(_vertical) {
				if(_step) {
					_stepHeight = _slides.eq(_currentStep).outerHeight(true);
					_stepCount = Math.ceil((_sumHeight-_sliderHolder.height())/_stepHeight)+1;
					_offset = -_stepHeight*_currentStep;
				} else {
					_stepHeight = _sliderHolder.height();
					_stepCount = Math.ceil(_sumHeight/_stepHeight);
					_offset = -_stepHeight*_currentStep;
					if(_offset < _stepHeight-_sumHeight) _offset = _stepHeight-_sumHeight;
				}
			} else {
				if(_step) {
					_stepWidth = _slides.eq(_currentStep).outerWidth(true)*_step;
					_stepCount = Math.ceil((_sumWidth-_sliderHolder.width())/_stepWidth)+1;
					_offset = -_stepWidth*_currentStep;
					if(_offset < _sliderHolder.width()-_sumWidth) _offset = _sliderHolder.width()-_sumWidth;
				} else {
					_stepWidth = _sliderHolder.width();
					_stepCount = Math.ceil(_sumWidth/_stepWidth);
					_offset = -_stepWidth*_currentStep;
					if(_offset < _stepWidth-_sumWidth) _offset = _stepWidth-_sumWidth;
				}
			}
		}

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				prevSlide();
				pauseVideo();
				return false;
				
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				if(_stopAfterClick) stopAutoSlide();
				nextSlide();
				pauseVideo();
				return false;
			});
		}
		function pauseVideo(){
			var player = $('.lightbox iframe');
			player.each(function(){
				var currentPlayer = $(this)
				froogaloop = $f(currentPlayer.attr('id'))
				froogaloop.api('pause');
			})
			return false;
		}
		if(_generatePagination.length) {
			_generatePagination.empty();
			recalcOffsets();
			var _list = $('<ul />');
			for(var i=0; i<_stepCount; i++) $('<li><a href="#">'+(i+1)+'</a></li>').appendTo(_list);
			_list.appendTo(_generatePagination);
			_pagerLinks = _list.children();
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentStep != _ind) {
						if(_stopAfterClick) stopAutoSlide();
						_currentStep = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// gallery animation
		function prevSlide() {
			recalcOffsets();
			if(_currentStep > 0) _currentStep--;
			else if(_circleSlide) _currentStep = _stepCount-1;
			switchSlide();
		}
		function nextSlide() {
			recalcOffsets();
			if(_currentStep < _stepCount-1) _currentStep++;
			else if(_circleSlide) _currentStep = 0;
			switchSlide();
		}
		function refreshStatus() {
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentStep).addClass(_activeClass);
			if(!_circleSlide) {
				_btnPrev.removeClass(_disabledClass);
				_btnNext.removeClass(_disabledClass);
				if(_currentStep == 0) _btnPrev.addClass(_disabledClass);
				if(_currentStep == _stepCount-1) _btnNext.addClass(_disabledClass);
			}
			if(_curNum.length) _curNum.text(_currentStep+1);
			if(_allNum.length) _allNum.text(_stepCount);
		}
		function switchSlide() {
			recalcOffsets();
			if(_vertical) _slider.animate({marginTop:_offset},{duration:_duration,queue:false,easing:_easing});
			else 
			curStepSlider (_currentStep, _slider); //////////////////////////////////ja
			
				 
				 _slider.animate({marginLeft:_offset},{duration:_duration,queue:false,easing:_easing});
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function stopAutoSlide() {
			if(_timer) clearTimeout(_timer);
			_autoRotation = false;
		}
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		recalcOffsets();
		refreshStatus();
		autoSlide();

		// pause buttton
		if(_pauseButton.length) {
			_pauseButton.click(function(){
				if(_this.hasClass(_pauseClass)) {
					_this.removeClass(_pauseClass);
					_autoRotation = true;
					autoSlide();
				} else {
					_this.addClass(_pauseClass);
					stopAutoSlide();
				}
				return false;
			});
		}
		jQuery(window).focus(function(){
			autoSlide();
		}).blur(function(){
			clearTimeout(_timer);
		});

		if(_afterInit && typeof _afterInit === 'function') _afterInit(_this, _slides);
	});
}
function initLightbox() {
	function a() {
		if (g) {
			var o = jQuery(window).height(),
				v = jQuery(window).width();
			g.outerWidth();
			var p = g.outerHeight(),
				r = j.height();
			v < l ? f.css("width", l) : f.css("width", "100%");
			o < r ? f.css("height", r) : f.css("height", o);
			g.css({
				position: "absolute",
				zIndex: e + 1
			});
			if (o > p) jQuery.browser.msie && jQuery.browser.version < 7 ? g.css({
				position: "absolute",
				top: parseInt(jQuery(window).scrollTop()) + (o - p) / 2
			}) : g.css({
				position: "fixed",
				top: (o - p) / 2
			});
			else {
				o = f.height();
				o < p && f.css("height", p);
				if (!m) if (o - p > parseInt(jQuery(window).scrollTop())) m = o = parseInt(jQuery(window).scrollTop());
				else m = o - p;
				g.css({
					position: "absolute",
					top: m
				})
			}
			f.width() > g.outerWidth() ? g.css({
				left: (f.width() - g.outerWidth()) / 2
			}) : g.css({
				left: 0
			})
		}
	}

	function b(o) {
		if (g) if (o) {
			f.fadeIn(h, function () {
				g.fadeIn(h)
				$('.lightbox .box').customScrollV();
				initScrollGallery();
				boxScrol(g);
				
			});
			m = false;
			a()
		} else g.fadeOut(h, function () {
			f.fadeOut(h);
			if($('.lightbox iframe').length){
				$('.lightbox iframe').remove();
			}			
			$('.lightbox').remove();
			m = false
			var locHashsd = $('.video-categories').find('li.active').attr('id');
			if($('.video-categories').length){
				window.location.hash = locHashsd;
				
			}
			
			
		})
	}

	function d(o) {
		if (!o.get(0).jsInit) {
			o.get(0).jsInit = true;
			o.find(c).click(function () {
				g = o;
				b(false);
				return false
			})
		}
	}
	var e = 1E3,
		h = 500,
		c = "a.btn-close, a.close, a.cancel",
		f, g = null,
		i = jQuery("a.open-popup"),
		j = jQuery(document),
		l = jQuery("body > div:eq(0)").outerWidth(),
		m = false;
	f = jQuery("#lightbox-overlay");
	if (!f.length) {
		f = jQuery("<div />");
		f.attr("id", "lightbox-overlay");
		jQuery("body").append(f)
	}
	f.css({
		opacity: 0.65,
		backgroundColor: "#000",
		position: "absolute",
		overflow: "hidden",
		display: "none",
		top: 0,
		left: 0,
		zIndex: e
	});
	if (jQuery.browser.msie && jQuery.browser.version < 7) if (!f.children().length) {
		var k = jQuery('<iframe src="javascript:false" frameborder="0" scrolling="no" />');
		k.css({
			opacity: 0,
			width: "100%",
			height: "100%"
		});
		var s = jQuery("<div>");
		s.css({
			top: 0,
			left: 0,
			zIndex: 1,
			opacity: 0,
			background: "#595959",
			position: "absolute",
			width: "100%",
			height: "100%"
		});
		f.empty().append(k).append(s)
	}
	i.each(function () {
		var o = jQuery(this),
			v = o.attr("lightbox_href");
		if (o.hasClass("ajax-load")) o.click(function () {
			if (jQuery('div[rel*="' + v + '"]').length == 0) jQuery.ajax({
				url: v,
				type: "POST",
				dataType: "html",
				success: function (r) {
					var locHash = $('.video-categories').find('li.active').attr('id');
					var hastwo = o.attr('href').split("/");
					locationId = [];
					locationId = [locHash, hastwo[3]];
					if($('.video-categories').length){
						window.location.hash = locHash+'/'+hastwo[3];
					}
					
					g = jQuery(r);
					g.find("img").load(a);
					g.attr("rel", v).hide().css({
						position: "absolute",
						zIndex: e + 1,
						top: -9999,
						left: -9999
					});
					jQuery("body").append(g);
					d(g);
					b(true);
				},
				error: function () {
//					alert("AJAX error!");
					return false;
				}
			});
			
			
			else {
				g = jQuery('div[rel*="' + v + '"]');
				b(true)
			}
			return false
		});
		else if (jQuery(v).length) {
			var p = jQuery(v);
			d(p);
			o.click(function () {
				if (g) g.fadeOut(h, function () {
					g = p.hide();
					b(true)
				});
				else {
					g = p.hide();
					b(true)
				}
				
				return false
			})
		}
	});
	jQuery(window).resize(a);
	jQuery(window).scroll(a);
	jQuery(document).keydown(function (o) {
		if (!o) evt = window.event;
		o.keyCode == 27 && b(false)
	});
	f.click(function () {
		f.is(":animated") || b(false);
		return false
	})
}

	var locationH = '';
	var locationId = '';
	var locationRep = '';
	$(document).ready(function(){
		if($('div.projects').length == 1){
			if(location.hash.length != 0){
				locationH = window.location.hash;
				locationRep = locationH.replace('#', '');
				locationId = locationRep.split("/");
				if(locationId){ 
					$('.video-categories').find('li[id='+locationId[0]+']').trigger('click');
					linkFix();
				}
			}
		}
	});
	
	function linkFix (locH, loId) {
		$('.preview_projects').find('a').each(function(){
			var hr = $(this).attr('href');
			if(hr == '/projects/'+locationH){
				
				$(this).trigger('click');
				return false;
			}
		});
	}
	function boxScrol(qw) {
		
		if(locationId[1]){
			var posLe = qw.find('li.video_box[id='+locationId[1]+']').position().left;
			qw.find('.slider_preview').animate({'marginLeft': posLe*(-1)}, 500);
		}
		
	}
	function curStepSlider(ste, slider) {
		var stepId = slider.find('li.video_box:eq('+ste+')').attr('id');
		var locHash = $('.video-categories').find('li.active').attr('id');
		if($('.video-categories').length){
			window.location.hash = locHash+'/'+stepId;
		}
		
	}
var Froogaloop=function(){function e(c){return new e.fn.init(c)}function g(c,b,a){if(!a.contentWindow.postMessage)return!1;var d=a.getAttribute("src").split("?")[0],c=JSON.stringify({method:c,value:b});a.contentWindow.postMessage(c,d)}function i(c){var b,a;try{b=JSON.parse(c.data),a=b.event||b.method}catch(l){}"ready"==a&&!h&&(h=!0);if(c.origin!=j)return!1;var c=b.value,e=b.data,f=""===f?null:b.player_id;b=f?d[f][a]:d[a];a=[];if(!b)return!1;void 0!==c&&a.push(c);e&&a.push(e);f&&a.push(f);return 0<
a.length?b.apply(null,a):b.call()}function k(c,b,a){a?(d[a]||(d[a]={}),d[a][c]=b):d[c]=b}var d={},h=!1,j="";e.fn=e.prototype={element:null,init:function(c){"string"===typeof c&&(c=document.getElementById(c));this.element=c;for(var c=this.element.getAttribute("src").split("/"),b="",a=0,d=c.length;a<d;a++){if(3>a)b+=c[a];else break;2>a&&(b+="/")}j=b;return this},api:function(c,b){if(!this.element||!c)return!1;var a=this.element,d=""!==a.id?a.id:null,e=!b||!b.constructor||!b.call||!b.apply?b:null,f=
b&&b.constructor&&b.call&&b.apply?b:null;f&&k(c,f,d);g(c,e,a);return this},addEvent:function(c,b){if(!this.element)return!1;var a=this.element,d=""!==a.id?a.id:null;k(c,b,d);"ready"!=c?g("addEventListener",c,a):"ready"==c&&h&&b.call(null,d);return this},removeEvent:function(c){if(!this.element)return!1;var b=this.element,a;a:{if((a=""!==b.id?b.id:null)&&d[a]){if(!d[a][c]){a=!1;break a}d[a][c]=null}else{if(!d[c]){a=!1;break a}d[c]=null}a=!0}"ready"!=c&&a&&g("removeEventListener",c,b)}};e.fn.init.prototype=
e.fn;window.addEventListener?window.addEventListener("message",i,!1):window.attachEvent("onmessage",i,!1);return window.Froogaloop=window.$f=e}();
