function portfolioAnimations(){

	var $ = jQuery;

	var items = $('a[rel^="gallery-box"]');
	$(items).each(function(){

		if($(this).parent().parent().hasClass('flowy-hidden'))
			items = items.not(this);
	});

	$(items).fancybox({
		'padding'       : 5,
		'transitionIn'      : 'fade',
		'transitionOut'     : 'fade',
		'speedIn'       : 450,
		'centerOnScroll'    : false,
		'speedOut'      : 300,
		'cyclic'        : true,
		'autoScale'         : true,
		'overlayColor'      : '#0f0f0f',
		'overlayOpacity'    : 0.95,
		'scrolling'		: 'auto',
		'titlePosition'     : 'outside',
		'onStart'			: function(){
			if ( !$.browser.msie || $.browser.version == '9.0'){
				$('.image-hover, .image-hover-icon').fadeTo(0,0);
			}
			else{
				$('.image-hover').fadeTo(0,0);
				$('.image-hover-icon').css('display','none');
			}
		},
		'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
			return '<span style="position:absolute; width:80%;">'+(title.length ? '' + title : '')+'</span><span style="position:absolute;right:25px">'+(currentIndex + 1) + ' / ' + currentArray.length +  '</span>';
		}
	});
	
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var mydate = new Date(parsed_date);
  var month = 1+mydate.getMonth();
  if(month<10) month = '0'+month;
  var day = mydate.getDate();
  if(day<10) day = '0'+day;
  return mydate.getFullYear()+'-'+month+'-'+day;
}

jQuery(function($) {

	if ( !$.browser.msie || $.browser.version != '6.0'){

		$('#social-container a').tipTip({
			defaultPosition: 'bottom',
			edgeOffset: 5
		});

		$('#scrolltop').tipTip({
			defaultPosition: 'top',
			edgeOffset: 0
		});

		$('#footer .social li a').tipTip({
			defaultPosition: 'top',
			edgeOffset: 10
		});

		$('.tooltip').tipTip({
			edgeOffset: 5
		});
	}

	if(inventSliderConfig != false && (!$.browser.msie || $.browser.version != '6.0')){
		// nivo slider
		if($('#slider-inner-wrapper').length)
			$('#slider-wrapper').css({backgroundColor: inventSliderConfig.bgcolors[0]});

		if(!$.browser.msie || parseInt($.browser.version)!='6.0') {
			$('#slider-wrapper .wrapper').nivoSlider({
					effect: inventSliderConfig.effect,
					slices:  inventSliderConfig.slices,
					animSpeed: inventSliderConfig.animSpeed, // transition speed
					pauseTime: inventSliderConfig.pauseTime,
					captionOpacity: inventSliderConfig.captionOpacity,
					directionNav: inventSliderConfig.directionNav,
					controlNav: inventSliderConfig.controlNav,
					beforeChange: function(){
						if(!$('#slider-wrapper').hasClass('narrow')){
								var slideId = $('#slider-wrapper .wrapper').data('nivo:vars').currentSlide;
								if (slideId<0) slideId += inventSliderConfig.bgcolors.length;
								slideId+=1
								if(slideId == inventSliderConfig.bgcolors.length) slideId=0;

							$('#slider-inner-wrapper').css({opacity:0, backgroundColor: inventSliderConfig.bgcolors[slideId]});

						}

						var curr = $('#slider').data('nivo:vars').currentSlide;
						var last = $('#slider').data('nivo:vars').lastSlide;

						$('.slider-box.actual').stop().animate({opacity:0},
						{
							easing: 'easeOutSine',
							duration:inventSliderConfig.animSpeed,
							queue: false,
							complete: function(){
								$(this).removeClass('actual');
							}
						});
						
					},

					afterChange: function(){
						var curr = $('#slider').data('nivo:vars').currentSlide;
						var last = $('#slider').data('nivo:vars').lastSlide;
						var newSliderBox = $('.slider-box').eq(curr).addClass('actual');

						var slideTitle = $('.slide-title', newSliderBox);
						var slideContent = $('.slide-content', newSliderBox);

						newSliderBox.css({height: slideTitle.outerHeight()+slideContent.outerHeight()+10});

						slideContent.css({top:460, opacity:0});
						slideTitle.css({opacity:0, top: -460}).stop().animate({opacity:1, top:13},{easing: 'easeInSine', duration:inventSliderConfig.animSpeed, queue: false});
						slideContent.animate({opacity:0},{duration:100, queue: false, complete:function(){
							$(this).animate({opacity:1, top:slideTitle.outerHeight()+19},{easing: 'easeInSine', duration:inventSliderConfig.animSpeed});
						}});
						newSliderBox.animate({opacity:1},{duration:inventSliderConfig.animSpeed, queue: false})

					},
					afterLoad: function(){
						var newSliderBox = $('.slider-box').eq(0).addClass('actual');

						var slideTitle = $('.slide-title', newSliderBox);
						var slideContent = $('.slide-content', newSliderBox).css({top:460, opacity:0});
						newSliderBox.css({height: slideTitle.outerHeight()+slideContent.outerHeight()+10});

						slideTitle.css({top: -460, opacity:0}).animate({top:13, opacity:1},{easing: 'easeInSine', duration:inventSliderConfig.animSpeed, queue: false});
						slideContent.animate({opacity:0},{duration:100, queue: false, complete:function(){
							$(this).animate({opacity:1, top:slideTitle.outerHeight()+19},{easing: 'easeInSine', duration:inventSliderConfig.animSpeed, queue: false});
						}});
						newSliderBox.animate({opacity:1},{duration:inventSliderConfig.animSpeed, queue: false})
						
						$('.slider-box').mouseenter(function(){
							$('#slider').data('nivo:vars').stop = true;

						});
						$('.slider-box').mouseleave(function(){
							$('#slider').data('nivo:vars').stop = false;

						});
					}
			});
		} else {
			$('#slider-wrapper .wrapper img:first-child').show();
		}
	}

	$('.jcarousel-skin-horizontal1.hidden').removeClass('hidden');
	$('.jcarousel-skin-horizontal1').each(function(carouselId){
		var $$=$(this);
		
		$('a[rel^="gallery-box"]', $$).attr('rel', 'carousel-images-'+carouselId).fancybox({
			'padding'       : 5,
			'transitionIn'      : 'fade',
			'transitionOut'     : 'fade',
			'speedIn'       : 450,
			'centerOnScroll'    : false,
			'speedOut'      : 300,
			'scrolling'			: 'auto',
			'cyclic'        : true,
			'autoScale'         : true,
			'overlayColor'      : '#0f0f0f',
			'overlayOpacity'    : 0.95,
			'titlePosition'     : 'outside',
			'onStart'			: function(){
				if ( !$.browser.msie || $.browser.version == '9.0'){
					$('.image-hover, .image-hover-icon').fadeTo(0,0);
				}
				else{
					$('.image-hover').fadeTo(0,0);
					$('.image-hover-icon').css('display','none');
				}
			},
			'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
				return '<span style="position:absolute; width:80%;">'+(title.length ? '' + title : '')+'</span><span style="position:absolute;right:25px">'+(currentIndex + 1) + ' / ' + currentArray.length +  '</span>';
			}
		});

		
		// IE7/IE8 fix
		$('li:last-child', $$.not('.testimonials-carousel')).not('.jcarousel-paginator li').css('padding-right', 0);

		var options = {
			scroll: 2,
			animation: 500,
			easing: 'easeOutBack'
		};

		// next and prev controls
		var controls = $$.prev();
		if(controls.hasClass('jcarousel-controls')){

			var prev = $('<a></a>').addClass('jcarousel-left').addClass('jcarousel-prev');
			var next = $('<a></a>').addClass('jcarousel-right').addClass('jcarousel-next');
			controls.append(prev);
			controls.append(next);

			options.buttonNextCallback = function(instance, elem, flag){
				var controls = instance.container.parent().prev();
				if(flag)
					$('.jcarousel-next', controls).removeClass('disabled');
				else
					$('.jcarousel-next', controls).addClass('disabled');
			};
			options.buttonPrevCallback = function(instance, elem, flag){
				var controls = instance.container.parent().prev();
				if(flag)
					$('.jcarousel-prev', controls).removeClass('disabled');
				else
					$('.jcarousel-prev', controls).addClass('disabled');
			};
		}

		

		// running carousel
		$$.jcarousel(options);
		var instance = $(this).data('jcarousel');

		if($$.hasClass('testimonials-carousel')) {
			var clip = $('.jcarousel-clip', $$.parent().parent())
			var h = $('li', clip).eq(0).outerHeight();
			if(h<110) h = 110;
			clip.css({'height': h, margin:'0 25px'});

			var container = clip.parent();
			container.append($('<div></div>').addClass('jcarousel-left-decorator'));
			container.append($('<div></div>').addClass('jcarousel-right-decorator'));
			$('.jcarousel-left-decorator, .jcarousel-right-decorator', container).css('height',h);

			$$.parent().parent().append(paginator).addClass('testimonials-carousel-container');


		$('.jcarousel-paginator a',container).click(function() {
				var n = $(this).parent().index()+1;
				var container = $(this).parent().parent().parent();

				var from = $('ul li:last-child', container).attr('jcarouselindex');
				var size = $('li', $(this).parent().parent()).length; // ok!
				if(from>size){

//					alert('n:' + n +', from: '+ from+', size:'+size);
					var newIndex = from - from%size + n;
					if(from%size==0) newIndex -= size;
	//				alert()
					//$(this).parent().siblings().removeClass('active');
					//$(this).parent().addClass('active');
				}
				else newIndex = n;
				instance.scroll(newIndex);
			    return false;
		    });
		}

		// next and prev controls
		var controls = instance.container.parent().prev();
		if(controls.hasClass('jcarousel-controls')){
			$('.jcarousel-prev',controls).click(function(){
				instance.prev();
		        return false;
			});

			$('.jcarousel-next',controls).click(function(){
				instance.next();
		        return false;
			});
		}

	});


		// testimonials
		$('.testimonials-carousel').each(function() {
			
			$$ = $(this);
			var maxHeight = 0;
			$('li',$$).each(function(){
				
				if($(this).outerHeight()>maxHeight) maxHeight = $(this).outerHeight();
			});
			$$.height(maxHeight);
$('li',$$).hide().eq(0).show();

		// paginator for testimonials carousel
			var paginator = $('<ul></ul>').addClass('jcarousel-paginator');
			var n = $('li',$$).length;
			for(var i=0; i<n; i++) {
				paginator.append($('<li></li>').append($('<a></a>')));
			}
			$('li',paginator).eq(0).addClass('active');
			$$.parent().append(paginator);
			$('a',paginator).click(function(){
				var $p = $(this).parent();
				if($p.hasClass('active')) return;

				var elements = $('li',$$);
				var n = $p.index();
				if(elements.filter(':animated').length) return false;
				var x = $('.active',paginator).removeClass('active');
				elements.eq(x.index()).fadeOut(200,function(){
					elements.eq(n).fadeIn(200);
				});

				$('li',paginator).eq(n).addClass('active');
//				$p.index()
			});

			/*options.itemFirstInCallback = {
				onBeforeAnimation: function(instance, li, n ) {
					var paginator = $('.jcarousel-paginator', instance.container);
					var items = $('li', paginator);
					var size = items.length;

					if(size == 0)
						size = $('.jcarousel-list li',instance.container).length;

					items.removeClass('active');
					items.eq(n%size-1).addClass('active');

					var clip = $('.jcarousel-clip', instance.container);
					var h = $('li', clip).eq(n%size-1).outerHeight();

					if(h<110) h = 110;
					clip.add('.jcarousel-left-decorator, .jcarousel-right-decorator',instance.container).stop().animate({'height': h}, 1000);
				}
			}*/
		});


	$('.invent-gallery').flowy({margin:20});
	portfolioAnimations()

	$('.nojs').removeClass('nojs');
	
		$('.social a').hover(function(){
			$(this).stop().animate({
				'margin-top':'-5px'
			}, 200);
		},function(){
			$(this).stop().animate({
				'margin-top':'0px'
			}, 200);
		});


		$('.widget_flickr a').hover(function(){
			$(this).stop().animate({
				'opacity':'1.0'
			}, 200);
		},function(){
			$(this).stop().animate({
				'opacity':'0.8'
			}, 200);
		});


	$('#content .widget-container>ul li a,#widgets-container .widget-container>ul li>a').not('.widget_flickr>ul li a, .widget_popular_posts>ul li a, .widget_recent_entries>ul li a, .widget_pages>ul li a, .widget_pages .children a').hover(function(){
		$(this).parent().stop().animate({paddingLeft: '10px'})
	},function(){
		$(this).parent().stop().animate({paddingLeft: '0px'});
	});

/*	if ( !$.browser.msie || $.browser.version != '9.0'){*/
		$('#scrolltop').click(function(){
			$.scrollTo(0,500);
			return false;
		});
/*	}*/
	
	$('#nav').superfish({
		autoArrows: false
	});

/* preloading images */

		$('[class^="attachment"]').not('.widget_popular_posts img,.widget_recent_entries img').each(function(){

			if(!$.browser.msie || parseInt($.browser.version)!='7.0' || !$(this).hasClass('attachment-post-thumbnail') ) {
				if($(this).hasClass('attachment-post-thumbnail'))
					$(this).parent().height($(this).height()+10);

				$(this).css('display','none');

				var p = $(this).parent();
				if(!p.hasClass('image_decorations'))
					p = p.parent();

				if ( !$.browser.msie || $.browser.version == '9.0')
					p.css({'height': $(this).height()+'px', 'width': $(this).width()+'px'});
			}
		});

		$('.hidden').removeClass('hidden');
		
		var t=$('[class^="attachment"]').length;
		var i=0;
		var init=setInterval(function(){
			if(i<t) {
				var img = $('[class^="attachment"]').eq(i);

							if($.browser.safari){
								var tmp = new Image();
								tmp.src = img.attr('src');
								tmp.onload = function(){
										img.fadeIn(600); /*.parent().parent().removeClass('hidden');*/
								}
							}
							else
								img.fadeIn(600);

				i++;
			}
			if(i>=t){
				clearInterval(init);
				delete init
			}
		},200);

function getImageDimensions(img)
{
	if(img.hasClass('attachment-invent-big')){
		return [450,235];
	} else if(img.hasClass('attachment-invent-medium')){
		return [290,150];
	} else if(img.hasClass('attachment-invent-small')){
		return [210,110];
	} else if(img.hasClass('attachment-invent-large')){
		return [610,315];
	} else if(img.hasClass('attachment-invent-huge')){
		return [690,360];
	} else if(img.hasClass('attachment-invent-full')){
		return [930,480];
	}
}

$('.image-hover-icon').each(function(){
	var img = $(this).next();
	var parent  = $(this).parent();
	if(parent.is('a')) parent = parent.parent();

	var imgSize = getImageDimensions(img);
	parent.css({
//		top:-10,
//		left:-10,
		width: imgSize[0],
		height: imgSize[1]
	});

});

if ( !$.browser.msie || $.browser.version == '9.0'){
		$('.image-hover, .image-hover-icon').fadeTo(0,0);

			$('.image-effect .image-hover-icon').each(function(){

				var image0 = $('<div></div>').addClass('invent-image-0');
				var image1 = $('<div></div>').addClass('invent-image-1');
				var image = $(this).next().css({display:'none', opacity:0});

				var containerSize =  getImageDimensions(image)
				var container = $(this).parent().css({width:containerSize[0], height:containerSize[1]});

//				image0.append(image);
				container.append(image0).append(image1);
				var canvas0 = $('<canvas></canvas>').attr('width',containerSize[0]).attr('height',containerSize[1]);
				image0.append(canvas0);
				var canvas1 = $('<canvas></canvas>').attr('width',containerSize[0]).attr('height',containerSize[1]);
				image1.append(canvas1);
				
				var animationObject = {
					state: false, // false = stopped, true = running
					interval: 0,
					canvas: null,
					time:50,
					image: null,
					selectedImage: 0,
					selectedEffect: 2,
					ctx: null,
					transitionDelay: false,
					init: function(){
						this.selectedEffect = Math.floor(Math.random()*12+1);
						
						this.image = new Image();
						this.image.src = image.attr('src');
						this.image.onload = function(){

							animationObject.prepare();
						}

					},
					scaleAndTranslate1: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);

						ctx.save();
						ctx.translate(-50/3, -time/2);
						ctx.scale(sineWave/6, sineWave/6);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);
						ctx.restore();

					},
					scaleAndTranslate2: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate(-50/4, -20+time/4);
						ctx.scale(8/sineWave, 8/sineWave);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate3: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate(time-80, 0);
						ctx.scale(sineWave/8, sineWave/8);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate4: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((time-80)/450*containerSize[0], (-20+time/4)/450*containerSize[1]);
						ctx.scale(8/sineWave, 8/sineWave);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate5: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate(-time/450*containerSize[0], 0);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate6: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((time-80)/450*containerSize[0], 0);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate7: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((time-80)/450*containerSize[0], (time-80)/450*containerSize[1]);
						ctx.scale(sineWave/7, sineWave/7);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();

					},
					scaleAndTranslate8: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((time/2-80)/450*containerSize[0], (time/2-80)/450*containerSize[1]);
						ctx.scale(10/sineWave, 10/sineWave);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate9: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((-time/2-80)/450*containerSize[0], (time/2-80)/450*containerSize[1]);
						ctx.scale(sineWave/6, sineWave/6);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate10: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate((time-80)/450*containerSize[0], (-20+time/4)/450*containerSize[1]);
						ctx.scale(8/sineWave, 8/sineWave);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate11: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate(0, (time-80)/450*containerSize[1]);
						ctx.scale(1.1, 1.1);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					scaleAndTranslate12: function(ctx, time){
						var sineWave =  Math.sqrt((300-(time-1))*0.25);
						ctx.save();

						ctx.translate(0, (-time)/450*containerSize[1]);
						ctx.scale(1.1, 1.1);
						ctx.drawImage(this.image,0,0,this.image.width,this.image.height);

						ctx.restore();
					},
					doEffect: function(ctx, time){
						switch(this.selectedEffect){
							
							case 1: // przyblizaj do gornego lewego
								this.scaleAndTranslate1(ctx, time);
								break;
							case 2: // oddalaj od gornego lewego
								this.scaleAndTranslate2(ctx, time);
								break;
							case 3: // przyblizaj do gornego prawego
								this.scaleAndTranslate3(ctx, time);
								break;
							case 4: // oddalaj od gornego prawego
								this.scaleAndTranslate4(ctx, time);
								break;
							case 5: // left to right
								this.scaleAndTranslate5(ctx, time);
								break;
							case 6: // right to left
								this.scaleAndTranslate6(ctx, time);
								break;
							case 7: // przyblizaj do dolneo prawego
								this.scaleAndTranslate7(ctx, time);
								break;
							case 8: // oddalaj z dolneo prawego
								this.scaleAndTranslate8(ctx, time);
								break;
							default:
							case 9: // przyblizaj do dolneo lewego
								this.scaleAndTranslate9(ctx, time);
								break;
							case 11: // bottom to top
								this.scaleAndTranslate11(ctx, time);
								break;
							case 12: // top to bottom
								this.scaleAndTranslate12(ctx, time);
								break;
						}
					},
					prepare: function(){
						this.time = 80;


						this.selectedImage = (this.selectedImage+1)%2;

						if(this.selectedImage==0) {
							this.canvas = $('canvas', image0)[0];

						}else{
							this.canvas = $('canvas', image1)[0];
						}

						this.ctx = this.canvas.getContext('2d');
						//this.image = new Image();
						//this.image.src = image.attr('src');

						this.canvas.width = containerSize[0];
						this.canvas.height = containerSize[1];

						// select new effect, other that actual
						var x = this.selectedEffect;
						while(Math.abs(x-this.selectedEffect)<2)
							var x = Math.floor(Math.random()*12+1);

						this.selectedEffect = x;

						this.doEffect(this.ctx, this.time);
						
						this.ctx.globalCompositeOperation = "darker";

					},
					start: function(){
						this.state = true;
						window.clearInterval(this.interval);
					},
					run: function(){
						var $$ = this;
							if(this.interval!=0)
								return true;

						if(this.state == true && this.transitionDelay == false && !this.interval){
							this.interval = window.setInterval(function(){

								if($$.time == 0 && $$.transitionDelay == false){
									//$$.transitionDelay = true;

									$$.prepare();

									var parentNode = ($$.selectedImage==0) ? image0 : image1;
									$('canvas', parentNode).animate({opacity:1},
									{
										queue: false,
										duration:1000
									});
									parentNode = ($$.selectedImage==1) ? image0 : image1;

									$('canvas', parentNode).css({display:'block'});
									$('canvas', parentNode).animate(
									{opacity:0},
									{
										queue: false,
										duration:1000,
										complete: function(){
											$$.transitionDelay=false;
										}
									});
								}
								
								if($$.state == true && $$.transitionDelay == false) {

//									var sineWave = Math.sqrt((300-($$.time-1))*0.25);

									$$.ctx.clearRect(0, 0, $$.canvas.width, $$.canvas.height);

									$$.doEffect($$.ctx, $$.time);

									$$.time--;
								}

								if($$.state == false && $$.transitionDelay == false){
									window.clearInterval($$.interval);
								}
							},60);
						}
					},
					stop: function(){
						this.state = false;
						window.clearInterval(this.interval);
						this.interval = 0;
					}
				}

				animationObject.init();
				
				$(this).hover(function(){
					$(this).prev().stop().fadeTo(600,0.5);
					$(this).stop().fadeTo(600,1);
					$(this).parent().parent().css({background: 'black'});
				},function(){
					$(this).add($(this).prev()).stop().fadeTo(600, 0);
					$(this).next().stop();
				});

				$(this).mouseenter(function(){
					animationObject.start();
					animationObject.run();
				}).mouseleave(function(){
					animationObject.stop();
				})
			});




		$('.image-no-effect .image-hover, .image-no-effect .image-hover-icon').fadeTo(0,0);
		$('.image-no-effect .image-hover-icon').each(function(){
			$(this).parent('')
			var image = $(this).next();
			var containerSize =  getImageDimensions(image);
			image.css({width:containerSize[0], height:containerSize[1]});
			var container = $(this).parent().parent().css({overflow:'visible', width:containerSize[0], height:containerSize[1]});

			$(this).hover(function(){
				$(this).prev().stop().fadeTo(600,0.5);
				$(this).stop().fadeTo(600,1);
			},function(){
				$(this).add($(this).prev()).stop().fadeTo(600, 0);
			});

		});
	}
	else if($.browser.version != '6.0') { /* IE 7 and 8 */
		$('.image-hover').fadeTo(0,0);
		$('.image-hover-icon').css('display','none');
		$('.image-hover').hover(function(){
			$(this).stop().fadeTo(600,0.5);
			$(this).next().css('display','block');
		},function(){
			$(this).next().css('display','none');
		});

		$('.image-hover-icon').hover(function(){
			$(this).css('display','block');
		},function(){
			$(this).css('display','none');
			$(this).prev().stop().fadeTo(600, 0);
		});
	}

	// portfolioAnimations();

	
	/* CONTACT FORM */
$('#contact-form').submit(function(){

		var valid = true;

		if(!$('#contact-name').val()){
			$('#contact-name-error').fadeIn();
			valid = false;
		}
		else
			$('#contact-name-error').hide();


		if(!$('#contact-email').val())
		{
			$('#contact-email-error').fadeIn();
			valid = false;
		}
		else{
			$('#contact-email-error').hide();

			var email = $('#contact-email').val();
			if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email))
			{
				$('#contact-email-error2').fadeIn();
				valid = false;
			}
			else
				$('#contact-email-error2').hide();
		}

		if(!$('#contact-message').val()) {
			$('#contact-message-error').fadeIn();
			valid = false;
		}
		else
			$('#contact-message-error').hide();

		if(valid){

			$.post(
				$('#contact-form').attr('action'), {
					action: 'invent-contact-ajax',
					name: $('#contact-name').val(),
					email: $('#contact-email').val(),
					message: $('#contact-message').val(),
					subject: $('#contact-subject').val(),
					nonce: $('#contact-nonce').val()
				},
				function(response) {
					var className = (response.type == 'error') ? 'box-red' : 'box-green';
					var msg = $('<div></div>').addClass(className).append($('<h3></h3>').html(response.title)).append($('<p></p>').html(response.message)).hide().fadeIn(1500);
					$('#contact-form').html('').append(msg);
				},
				'text json'
			);
		}
		return false;
	});


	$('.code-container').hover(function(){
		$('.code-container').not(this).stop().css({'position':'relative', 'z-index':0, 'width': 'auto'});
		var h = $(this).height();
		
		var w1 = $(this).width();
		$(this).css({'position':'absolute', 'z-index':5}).height(h);
		var w2 = $(this).width()+5;

		if(w2>w1+5){
			$(this).width(w1);
			$(this).animate({'width': w2}, 300);
		}
		else
			$(this).css({'position':'relative', 'z-index':0});
	}, function(){
		$('.code-container-tmp').remove();
		$('.code-container').stop().css({'position':'relative', 'z-index':0, 'width': 'auto'});
	});


	/* accordions and toggles */
		var config = {
			container: '.invent-accordion',
			tab: '>h3',
			content: '.acc-content'
		}


		$(config.container).each(function(){
			var c = $(this);

			$(config.tab,c).each(function(i){

				$(this).click(function(){
					
					var d = $(config.content,c).eq(i);

					if(d.height()>0){
						var h = 0;

					} else {
						if(!d.is(':animated')) {
							d.css('display','block');
							d.height('auto');
							var h = d.height();
							d.height(0);
						}
					}

					if(h==0)
						d.prev().removeClass('selected');
					else
						d.prev().addClass('selected');

					d.stop().animate({'height':h},'600', function(){
						if($(this).height()==0){
							$(this).css('display','none');
							$(this).prev().removeClass('selected');
						}
					});
				});

			});

		});

		$.tools.tabs.addEffect("accSlide", function(tabIndex, done) {
			var panes = this.getPanes();
			var $$ = panes.eq(tabIndex);
			var parentNode = $$.parent();
			var h = $$.height();

			if(parentNode.height()>h) {
				panes.stop().animate({opacity:0},400);
				$$.stop().animate({opacity:1}, 400, function(){
					parentNode.stop().animate({height: h}, 400);
				});
			} else {
				parentNode.stop().animate({height: h}, 400, function(){
					panes.stop().animate({opacity:0},400);
					$$.stop().animate({opacity:1}, 400);
				});
			}
			done.call();
		});

		$(".invent-tabs").each(function(){
			$('ul', this).tabs($('.invent-panes>div', this), {effect: 'accSlide', current: 'current'});
		});


	$('.twitter-data').each(function(){
		var user = $('input[name="user"]',this).val();
		var number = $('input[name="number"]',this).val();
		var container = $(this).parent();
		container.append($('<div></div>').html('Loading...'));
		$(this).remove();
		$.ajax({
			url: 'http://twitter.com/statuses/user_timeline/'+user+'.json?count='+number,
			method: 'get',
			success: function(twitters){
				$('div', container).remove();
				var list = $('<ul></ul>').addClass('twitter-list');
				
				for (var i=0; i<twitters.length; i++){
					var username = twitters[i].user.screen_name;
					var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
						return '<a href="'+url+'" class="twitter-link schemehovercolor">'+url+'</a>';
					}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
						return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'" class="twitter-link schemehovercolor">'+reply.substring(1)+'</a>';
					});

					status += '<span>'+relative_time(twitters[i].created_at)+'</span>';
					list.append($('<li></li>')
							.append($('<div></div>').html(status))
							.append($('<div></div>').addClass('decorator')));
				}
				
				// cut long link names
				$('a', list).each(function(){
					var title = $(this).html().substr(0,20);
					title += '...';
					$(this).html(title);
				});
				container.append(list);

			},
			error: function(xhrObject, textStatus){
				$('div', container).remove();
				var message = $('<div></div>').html('Connection problem. Check twitter widget configuration...').hide().fadeIn();
				container.append(message);
			},
			timeout: 30000,
			dataType: "jsonp"
		});
	});

});
