jQuery(document).ready(function(){	

	function direction(box_x, box_y, mouse_x, mouse_y, big) {
		var box_w = 374
		var box_h = 210
		var ret   = 'bottom'

		if (big == 'itemBig') {
			var box_w = 750
			var box_h = 422
		}

		if (mouse_y <= box_y) 			ret = 'top'
		if (mouse_x >= (box_x + box_w)) ret = 'right'
		if (mouse_y >= (box_y + box_h)) ret = 'bottom'
		if (mouse_x <= box_x) 			ret = 'left'

		return ret
	}


	// Show / Hide ProjectBar
	var projects = $('.itemBig, .item')
	var bars     = $('.project_bar_bg, .project_bar')

	// initial Bars hide
	bars.hide()

	// Show / Hide
	projects.hover(function(e){
		var bar = $(this).children( '.project_bar_bg, .project_bar' )	// current
		// bars.hide()						// hide all
		bar.show()						// show current
		
		bar.css('left', 0)
		bar.css('margin-left', 0)
		bar.css('bottom', 0)
		
	}, function(e){

		big    = $(this).attr('class')
		offset = $(this).offset();
		dir    = direction(offset.left, offset.top, e.pageX, e.pageY, big)

		var bar = $(this).children( '.project_bar_bg, .project_bar' )	// current

		
		// bar.hide()						// hide current

		if (dir == 'left') {
			bar.animate({
				left: parseInt(bar.css('left'),10) == 0 ?
				-bar.outerWidth() :
				0
			});
		} else if(dir == 'right') {
			bar.animate({
				marginLeft: parseInt(bar.css('marginLeft'),10) == 0 ?
				bar.outerWidth() :
				0
			});
		} else {
			bar.animate({
				bottom: parseInt(bar.css('bottom'),10) == 0 ?
				-110 :
				0
			});
		}
	})
	

	
	// Projects Index Click
	projects.bind('click', function(){
		id = $(this).attr('rel')
		link = '/projects/view/'+id

		if (id != '') document.location.href = link;
		
	})
	


	// Vacancies
	var showContact = $('.showContact')
	var hideContact = $('.hideContact')
	var formContact = $('div.contact')
	showContact.click(function(){
		if (formContact.is(":visible") == true) {
			formContact.hide()
		} else {
			formContact.show()
		}
	})
	hideContact.click(function(){
		formContact.hide()
	})
	
	// more Files
	var inputFile = $('.file')
	inputFile.bind('change', function(){
		var next = $(this).next()
		if (next.size() > 0) next.css('display', 'block')
	})

	// Address HIDE
	var email = $('#ContactEmail')
	email.bind('focus', function(){
		if (this.value == 'Обратный адрес') {
			this.value = '';
		}
	});
	email.bind('blur', function(){
		if (this.value == '') {
			this.value = 'Обратный адрес';
		}
	});


	// SEO
	var seo = $('.info')
	var bot = $('#bottom')
	
	if (seo.size() > 0) {
		
		seo.css('opacity', 0)
		
		$('.copy a').click(function(){
			var checkHeight = bot.css('height')
			if (checkHeight != '1050px') {
				// seo.show()
				seo.css('opacity', 1)
				bot.css('height', 1050)
			} else {
				// seo.hide()
				seo.css('opacity', 0)
				bot.css('height', 146)
			}
			return false
		})
	}
	

	
	

});




