	function resizeWArea(){
		var fullHeight = jQuery(window).height();
		var Height = jQuery('body').height();
		if(Height < fullHeight){
			var newHeight = fullHeight - (170 + 60 + 76);
			jQuery('#workarea').height(newHeight);
		}
	}

jQuery(document).ready(function(){
	// sub menus
	jQuery('li ul').each(function(){
		jQuery(this).prev('a').mouseenter(function(){
				jQuery(this).next('ul').show();
				if(!jQuery(this).closest('li').is('.selected')){
					jQuery(this).closest('li').addClass('sub-o');
				}
		});

		jQuery(this).closest('li').mouseleave(function(){
				jQuery(this).find('ul').hide();
				jQuery(this).removeClass('sub-o');
		});
	});
	
	
	
	//init carousel
	jQuery('.carousel').carousel({
		speed : 400
 	});
	autoscroll = true;
	jQuery('.carousel').bind({
		'mouseenter' : function(){autoscroll = false;},
		'mouseleave' : function(){autoscroll = true;}
	})
	
	setInterval(function(){
		if(autoscroll){
			jQuery('#rightArrow').click();
		}
	}, 5000);
	
 	jQuery('span.img').css('opacity','0.5');
 	
 	//icons after carousel
 	jQuery('.icons').delegate('a','mouseenter',function(){
 		jQuery('.icons').find('.img').stop().animate({opacity:0.5},300);
 		jQuery(this).find('.img').animate({opacity:1},300);
 	})

 	jQuery('.icons').delegate('a','mouseleave',function(){
 		jQuery(this).find('.img').stop().animate({opacity:0.5},300);
 	});
	
	//resize content if it's height lower than window height
	var waHeight = jQuery('#workarea').height();

	resizeWArea();
	
	//selecters in gallery
	jQuery('#lnks').delegate('a', 'click',function(){
		//make current link selected
		jQuery(this).parent().find('a').removeClass('selected');
		jQuery(this).addClass('selected');
		
		//hide all albums wich are NOT cur classes (video, photo or all)
		var selected = jQuery(this).attr('id').replace('s-','');
		var counter = 1;

		if(selected != 'all'){
			jQuery('.one-album').hide();
			jQuery('.one-album.'+selected).show();
		
			jQuery('.one-album.'+selected).each(function(){
				if(counter == 4){
					jQuery(this).addClass('last');
					counter = 1;
				}else{
					if(jQuery(this).is('.last')) jQuery(this).removeClass('last');
					counter++;
				}
			});
		}else{
			jQuery('.one-album').show();
			jQuery('.one-album').each(function(){
				if(counter == 4){
					jQuery(this).addClass('last');
					counter = 1;
				}else{
					if(jQuery(this).is('.last')) jQuery(this).removeClass('last');
					counter++;
				}
			});
		}
		resizeWArea();
		return false;
	});

	jQuery('#gallery').popup({
		openSelector : '.video a.lnk',
		width : '694px',
		height : '442px',
		dataType : 'img',
		title : 'alt'
	});

	jQuery('#gallery1').popup({
		openSelector : '.image a.txt, .image a.lnk, .image div.text a.lnk',
		width : '694px',
		height : '442px',
		dataType : 'img',
		title : 'alt'
	});

	jQuery('#img-list').popup({
		openSelector : '.one-image .txt',
		width : '694px',
		height : '442px',
		dataType : 'img',
		title : 'alt'
	});
	
	jQuery('input[type=text], textarea').each(function(){
		var placeholder = jQuery(this).attr('title');
		jQuery(this).val(placeholder);
		jQuery(this).focusin(function(){
			if(jQuery(this).val() == placeholder) jQuery(this).val('');
		});
		jQuery(this).focusout(function(){
			if(jQuery(this).val() == '') jQuery(this).val(placeholder);
		});
	});
	
	jQuery('a.submit').click(function(){
		var form = jQuery(this).attr('alt');
		jQuery('#'+form).submit();
		return false;
	})
});
jQuery(window).scroll(function(){
	var scr = jQuery(this).scrollTop();
	if(scr >= 170){
		if(jQuery('#nav').css('position') != 'fixed'){
			jQuery('#nav').css({
				'position' : 'fixed',
				'z-index' : 2000,
				'top' : -9
			});
			if(!jQuery('#nav').prev().is('#fill')){
				jQuery('#nav').before(jQuery('<div>',{'id':'fill'}).height(jQuery('#nav').height()));
			}
			jQuery('.little').fadeIn(500);
		}
	}else if(scr < 179 && jQuery('#nav').css('position') == 'fixed'){
		jQuery('#nav').css({
			'top' : 170,
			'position' : 'absolute'
		},200);
		jQuery('.little').hide();
	}
	
})

/* 
 * popup plugin
 * can be called for any collection(s) of photos/videos/ajax content
 */
jQuery.fn.popup = function(options){
	var options = jQuery.extend({
		width : 300,						// width of new popup
		height : 300,						// height of new popup
		openSelector : 'a.popup',			// selector wich will open popup
		closeSelector : 'a#popup-close',	// selector wich will close popup
		dataType : 'ajax',					// type of data (can be ajax, img or frame)
		content : 'href',					// link of image or other content will be taken from it
		contentSelector : false,			// if using ajax you can load data from any selector in ajax response
		title : 'title',					// attr wich contents title of content
		fadeSpeed : 300						// fading speed (fadeIn, fadeOut)
	}, options);
	
	return this.each(function(){
		
		options.width = parseInt(options.width.replace('px',''));
		options.height = parseInt(options.height.replace('px',''));

		var holder = jQuery(this);
		jQuery(this).find(options.openSelector).live('click', function(){
			popup = "";
			var overlay = jQuery('<div id="popup-overlay"></div>').height(jQuery(document).height());
			var image = false;

			popup += '<div id="popup">';
			popup += '	<div id="popup-wrapper">';
			popup += '		<div id="popup-control">';
			popup += '			<a href="#" id="popup-close"></a>';
			popup += '		</div>';
			popup += '		<div id="popup-body">';
			if(options.dataType == "img"){
				popup += '			<a href="#" class="toggle left">&#8249;</a>';
				popup += '			<a href="#" class="toggle right">&#8250;</a>';
			}
			popup += '			<div id="popup-content">';
			popup += '			</div>';
			popup += '			<div id="popup-title">';
			popup += '			</div>';
			popup += '		</div>';
			popup += '	</div>';
			popup += '</div>';
			
			popup = jQuery(popup).hide();

			count = jQuery('.one-image').length;
			index = jQuery(this).closest('.one-image').index();
			checkIndex(index);
			thisobj = jQuery(this);
			if(index < count){
				var next = index + 1;
			}
			if(index > 0){
				var prev = index - 1;
			}

			switch (options.dataType){
				case "ajax":
					popup.find('#popup-content').load(jQuery(this).attr(options.content)+ " " + options.contentSelector);
					break;
				case "img":
					function loadCur(link){
						if(link != 'loadfirst'){
							imagelnk = link;
						}else{
							imagelnk = thisobj.attr(options.content);
						}
						popup.css({
							'left' : '50%',
							'top' : '50%',
							'margin-left': Math.ceil(options.width / 2) * (-1)
						})
						popup.find('#popup-content').html("<div style='text-align: center;'>Загрузка...</div>");
						img = jQuery("<img/>",{
							src : imagelnk
						}).load(function(){
							jQuery(this).css({
								'max-height' : '500px',
								'max-width' : '640px'
							})
							popup.find('#popup-content').html(jQuery(this));
							popup.find('#popup-content').animate({
								height : popup.find('#popup-content img').height()
							},300);
							h = popup.find('#popup-content img').height() + (27*2);
							popup.css('height', h);
							var image = true;
						})
					}
					loadCur('loadfirst');
					break;
				case "frame":
					popup.find('#popup-content').html('<iframe src="'+jQuery(this).attr(options.content)+'" frameborder="0"></iframe>');
					break;
			}
			popup.find('#popup-title').text(jQuery(this).attr(options.title));
			popup.width(options.width);
			if(image == false){
				popup.find('#popup-content').height(options.height - (27*2));
				popup.height(options.height);
				popup.css({
					'left' : '50%',
					'top' : "50%",
					'margin' : Math.ceil(popup.height() / 2) * (-1) + "px 0 0 " +Math.ceil(options.width / 2) * (-1) + "px"
				});
			}else{
				image = false;
			}

			function checkIndex(ind, resize){
				if(ind == 0)		popup.find('.toggle.left').hide();
				if(ind == jQuery('.one-image').length - 1)	popup.find('.toggle.right').hide();
				if(ind > 0)			popup.find('.toggle.left').show();
				if(ind != jQuery('.one-image').length - 1)		popup.find('.toggle.right').show();
				if(resize){
					newh = popup.height();
					popup.css({
						'margin-top' : -(newh / 2)
					})
				}
			}
			
			jQuery('body').prepend(popup);
			jQuery('body').prepend(overlay);
			
			overlay.fadeIn(options.fadeSpeed);
			popup.fadeIn(options.fadeSpeed);
			popup.find('.toggle.left').click(function(){
				var img = jQuery('.one-image:eq('+ prev +') a').attr('href');
				if(prev > (-1)){
					prev--;
					next--;	
					loadCur(img);
					checkIndex(prev + 1, true);
				}
				return false;
			});
			popup.find('.toggle.right, #popup-content').click(function(){
				var img = jQuery('.one-image:eq('+ next +') a').attr('href');
				if(next != jQuery('.one-image').length){
					next++;
					prev++;
					loadCur(img);
					checkIndex(next - 1, true);
				}
				return false;
			});
			return false;
		});
		
		jQuery('#popup').find(options.closeSelector).live('click', function(){
			jQuery('#popup').fadeOut();
			jQuery('#popup-overlay').fadeOut(function(){
				jQuery('#popup').remove();
				jQuery(this).remove();
			});
			return false;
		});

		jQuery('#popup-overlay').live('click', function(){
			jQuery('#popup').fadeOut();
			jQuery('#popup-overlay').fadeOut(function(){
				jQuery('#popup').remove();
				jQuery(this).remove();
			});
			return false;
		});
	});
}
