// JavaScript Document

$( function() {
	/*FILTERS 2.0*/
	
	$('.filter dt')
	.append('<span class="highlight"><span></span></span>')
	.find('.highlight').css({opacity:0})
	
	$('.filter')
	.mouseenter(function(){
		$(this).find('.highlight').stop().animate({opacity: 1}, 100);
		$(this).find('dt').stop().animate({color: '#fff'}, 100);
	})
	.mouseleave(function(){
		$(this).find('.highlight').stop().animate({opacity: 0}, 400)
		$(this).find('dt').stop().animate({color: '#878989'}, 400);
	})
	
	
	$('.filter ul').jScrollPane({dragMinHeight: 111, dragMaxHeight: 111, scrollbarWidth: 25, wheelSpeed: 21.5});
	$('.jScrollPaneDrag').append('<span></span>');
	$('.jScrollPaneDrag span')
	.css({opacity: 0})
	.mouseenter(function(){
		$(this).animate({opacity: 1}, 100);
	})
	.mouseleave(function(){
		$(this).animate({opacity: 0}, 400);
	});
	

	
	$('.filter dd a')
	.mouseenter(function(){
		$(this).stop().animate({color: "#fff"}, 200);
	})
	.mouseleave(function(){
		$(this).stop().animate({color: "#878989"}, 600);
	})
	.click(function(){
		var currentHref = this.href;
		$(this).parent().parent().parent().parent().toggle(300, function(){
			window.location = currentHref;
		});
		return false;
	});
	
	$('.filter dd').hide();
	$('.filter dt').click(function(){
		$(this).parent().children('dd').toggle(300);
	});


	/*MENU*/
	$('#header ul a').append('<span></span><span class="highlight"><span></span></span>');
	$('#header .highlight').css({opacity: 0});
	$('#header a.active .highlight').css({opacity: 1});
	$('#header ul a').mouseover(function(){
		$(this).children('.highlight').stop().animate({opacity: 1}, 100);
	});
	$('#header ul a:not(.active)').mouseout(function(){								
		$(this).children('.highlight').stop().animate({opacity: 0}, 600);
	});
	$('#contact-info-phone').append('<span></span>');
	
	/*THUMBNAILS*/
	$('#thumbnails li').append('<span class="border"></span><span class="selected"><span></span></span>');
	$('#thumbnails .selected').css({opacity: 0});
	$('#thumbnails h2').css({top: '0px'});
	$('#thumbnails li').mouseover(function(){
		$(this).children('.selected').stop().animate({opacity: 1}, 100);
		$(this).children('h2').stop().animate({top: '-98px'}, 50);
	});
	$('#thumbnails li').mouseout(function(){
		$(this).children('.selected').stop().animate({opacity: 0}, 400);
		$(this).children('h2').stop().animate({top: '0px'}, 400);
	});
	
		
	/*FILTERS*/	
	
	/*$('#filter-category, #filter-client').sSelect();
	$('#filter-works').FormSelectRestyled(true, 'filter-select', '-');
	
	$('.newList a')
	.mouseenter(function(){
		$(this).stop().animate({color: "#fff"}, 200);
	})
	.mouseleave(function(){
		$(this).stop().animate({color: "#878989"}, 600);
	})
	.click(function(){
		return false;
	});*/

	$('#filter-reset, #filter-sort').append('<span></span><span class="highlight"><span></span></span>');
	
	$('#filter-reset .highlight, #filter-sort .highlight')
	.css({opacity: 0})
	.mouseenter(function(){
		$(this).stop().animate({opacity: 1}, 100)
	})
	.mouseleave(function(){
		$(this).stop().animate({opacity: 0}, 600)
	})
	/*$('#filter-sort')
	.click(function(){
		if ( $('#order').val() == '0' ) {
			$('#filter-sort').removeClass('desc');
			$('#order').val(1);
		} else {
			$('#filter-sort').addClass('desc');
			$('#order').val(0);
		}
		$('#filter-form').submit();
		return false;
	});*/
	$('#filter-category, #filter-client').change(function(){
		$('#filter-form').submit();
	});


	/*GALLERY*/
	$('#project-info').prepend('<span class="project-bg" style="height: ' + $('#project-info').height() + 'px; amargin-bottom: -' + $('#project-info').height() + 'px"></span>');
	$('.project-bg').css({opacity:0.8});
	$('#open-website').append('<span class="highlight"><span></span></span>');
	$('#open-website .highlight')
	.css({opacity: 0})
	.mouseenter(function(){
		$(this).stop().animate({opacity: 1}, 100);
	})
	.mouseleave(function(){
		$(this).stop().animate({opacity: 0}, 400);
	});
	
	$('#gallery-overlay').append('<span class="mask-left"></span> <span id="gallery-center"><a id="gallery-prev" href="#">Előző</a> <span id="image-number"><span></span></span> <a id="gallery-next" href="#">Következő</a> <span class="mask-center"></span> </span> <span class="mask-right"></span>');

	$('#gallery-next').html('<span></span><span class="highlight"></span>').css({opacity: 0});
	$('#gallery-prev').html('<span></span><span class="highlight"></span>').css({opacity: 0});
	$('#gallery-overlay .highlight').css({opacity: 0});

	$('#h2_project-info, #project-info-show')
	.append('<span class="highlight"></span>')
	.mouseenter(function(){
		$(this).children('.highlight').stop().animate({opacity: 1}, 100);					 
	})
	.mouseleave(function(){
		$(this).children('.highlight').stop().animate({opacity: 0}, 300);					 
	})
	.children('.highlight').css({opacity: 0});

	$('#gallery-close')
	.html('<span></span><span class="highlight"><span></span></span>')
	.mouseover(function(){
		$(this).children('.highlight').stop().animate({opacity: 1}, 100);
	})
	.mouseout(function(){
		$(this).children('.highlight').stop().animate({opacity: 0}, 300);
	})
	.children('.highlight').css({opacity: 0});

	$('#image-number').css({opacity: 0});

	var number_of_images = $('#gallery ul>li').size();
	var current_image = 0;
	
	var switch_to = function( image ){
		var $current_image = $('#gallery li:eq(' + image + ')');
		$('#gallery').stop().scrollTo( $current_image, 300, {offset:-184} );
		$('#image-number span').html( (current_image+1) + '/' + (number_of_images) );
		$('#gallery-center').stop().animate({width: $current_image.width() +'px'}, 300);
		$('.mask-center').stop().animate({width: $current_image.width() - 2 +'px'}, 300);
		$('.mask-right, #gallery-close').stop().animate({left: $current_image.width() + 184 + 'px'}, 300);
		if ( current_image == 0 ) $('#gallery-prev').stop().animate({opacity: 0}, 600);
		if ( current_image == 1 ) $('#gallery-prev').stop().animate({opacity: 1}, 200);
		if ( current_image == number_of_images - 1 ) $('#gallery-next').stop().animate({opacity: 0}, 600);
		if ( current_image == number_of_images - 2 ) $('#gallery-next').stop().animate({opacity: 1}, 200);
	};

	$('#gallery-center, .mask-center').mouseover(function(){
		if ( current_image != number_of_images - 1 ) $('#gallery-next').stop().animate({opacity: 1}, 200);
		if ( current_image != 0 ) $('#gallery-prev').stop().animate({opacity: 1}, 200);
		$('#image-number').stop().animate({opacity: 1}, 200);
	});
	$('#gallery-center, .mask-center').mouseout(function(){
		$('#gallery-next').stop().animate({opacity: 0}, 600);
		$('#gallery-prev').stop().animate({opacity: 0}, 600);
		$('#image-number').stop().animate({opacity: 0}, 600);
	});

	$('#gallery-overlay a').mouseover(function(){
		$(this).children('.highlight').stop().animate({opacity: 1}, 50);
	});
	$('#gallery-overlay a').mouseout(function(){
		$(this).children('.highlight').stop().animate({opacity: 0}, 150);
	});

	$('#gallery ul').css({width:((number_of_images)*10000)+'px'});
	$('#gallery ul').append('<li style="width: 10000px;"></li>');
	
	switch_to( current_image );
	$('#gallery-next, .mask-right').click(function() {
		if ( current_image < number_of_images-1 ) {
			current_image++;
			switch_to( current_image );
		}
		return false;
	});
	$('#gallery-prev').click(function() {
		if ( current_image > 0 ) {
			current_image--;
			switch_to( current_image );
		}
		return false;
	});
	$('#project-info-show, #project-info h2, #filter-works h2').append('<span></span>');
	$('#h2_project-info').click(function() {
		$('#project-info').fadeOut();
		return false;
	});
	$('#project-info-show').click(function() {
		$('#project-info').fadeIn();
		return false;
	});
	
	/*ABOUT-US*/
	$('#about-gallery').cycle({
				fx: 'fade',
				speed: 1200,
				timeout: 6000
	});
	
	$('#go-to-team').click( function(){
		$('#about-us').stop().scrollTo( $('#team'), 300, 'easeOutQuart' );
		return false;
	});
	
	$('#button-team, #team-close')
	.mouseenter(function(){
		$(this).children('span').stop().animate({opacity: 1}, 100);
	})
	.mouseleave(function(){
		$(this).children('span').stop().animate({opacity: 0}, 600);
	})
	.click(function(){
		$('#about-us').stop().scrollTo( $('#team'), 300, 'easeOutQuart' );
		return false;
	})
	.prepend('<span class="highlight"><span></span></span>')
	.children('span').css({opacity : 0});
	
	$('#team-close')
	.unbind('click')
	.click(function(){
		$('#about-us').stop().scrollTo( 0, 300, 'easeOutQuart' );
		return false;
	});
	
	$('.member-picture').append('<span></span>');
	
	$('#team li#ordogh-laszlo, #team li#bolgar-attila')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -1680px'}, 1500, 'cartoon_15')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -1680px'})
		.animate({backgroundPosition: '0 0'}, 1500, 'cartoon_15');
	});
	$('#team li#szoke-peter')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -1560px'}, 1400, 'cartoon_14')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -1560px'})
		.animate({backgroundPosition: '0 0'}, 1400, 'cartoon_14');
	});
	$('#team li#drozsnyik-david')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -1080px'}, 1000, 'cartoon_10')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -1080px'})
		.animate({backgroundPosition: '0 0'}, 1000, 'cartoon_10');
	});
	$('#team li#vagfalvi-dori')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -1200px'}, 1100, 'cartoon_11')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -1200px'})
		.animate({backgroundPosition: '0 0'}, 1100, 'cartoon_11');
	});
	$('#team li#nonn-zsuzsi')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -2040px'}, 1100, 'cartoon_18')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -2040px'})
		.animate({backgroundPosition: '0 0'}, 1100, 'cartoon_18');
	});
	$('#team li#polyak-sandor')
	.mouseenter(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 0'})
		.animate({backgroundPosition: '0 -1800px'}, 1600, 'cartoon_16')
	})
	.mouseleave(function(){
		$(this).find('.member-picture span').stop()
		.css({backgroundPosition: '0 -1800px'})
		.animate({backgroundPosition: '0 0'}, 1600, 'cartoon_16');
	});
	
	
	/*CONTACT-US*/
	$('#contact-us input:not(#contact-send input), #contact-us textarea')
	.focus(function(){
		$(this).parent().children('label').fadeOut(600);
	})
	.blur(function(){
		if ( $(this).attr('value') == '' ) {
			$(this).parent().children('label').fadeIn(100);
		}
	})
	$('#contact-send label')
	.append('<span></span><span class="highlight"><span></span></span>');
	
	$('#contact-send .highlight')
	.css({opacity: 0})
	.mouseenter(function(){
		$(this).stop().animate({opacity: 1}, 100);
	})
	.mouseleave(function(){
		$(this).stop().animate({opacity: 0}, 600);
	});
	
	$('#contact-form').ajaxForm({beforeSubmit: validate});
	
	function validate(formData, jqForm, options) {
		var message = $('#message').fieldValue();
		var name = $('#name').fieldValue();
		var email = $('#email').fieldValue();
		var subject = $('#subject').fieldValue();
		var language = $('#language').fieldValue();
	
		if ( message == '' || name == '' || email == '' || subject == '' ) {
			if ( language == 'en' ) {
				alert('Please fill in all fields!');
			} else {
				alert('Kérjük, töltsd ki az összes mezőt!');
			}
			return false;
		}
			if ( language == 'en' ) {
				alert('Thank You!');
			} else {
				alert('Köszönjük!');
			}
		return true;
	}

	
	/*$('#send').click(function(){
		alert('Köszönjük!');
		return false;
	});*/
});
$(window).load(function(){
	$('#overlay').fadeOut(900);
});
