var kleinermann = {
	successful: function() {
		$(document).ready(function() {
			kleinermann.successful.slideNavigation();
			kleinermann.successful.zoomProjects();
			kleinermann.successful.slideProjects();
			kleinermann.successful.slideServices();
			kleinermann.successful.displayMap();
			kleinermann.successful.updateInputs();
			
			if (location.hash) $('body').scrollTo($(location.hash.replace('#', '.')), 1000);
			$('.Button').click(function() {
				$.post("/", {
					first_name: $('#first_name').val(),
					last_name: $('#last_name').val(),
					email: $('#email').val(),
					phone: $('#phone').val(),
					website: $('#website').val(),
					skype: $('#skype').val(),
					subject: $('#subject').val(),
					content: $('#content').val(),
					send_email: '1'
				}, function(data) {
					$('.Contact').animate({left: '1000px'}, function() {
						$(this).css({left: '-1000px'}).html(data);
						$(this).animate({left: '0'});
					});
				});
			});
		});
	}
};

kleinermann.successful.zoomProjects = function() {
	var zoom = 9;
	var duration = 600;
	$('.More').click(function() {
		if (zoom == 9) {
			$('.Thumbnails').animate({width: '833px'}, duration);
			$('.Thumbnails .Block').animate({paddingRight: '16px'}, duration);
			$('.Less').css({display: 'block'}).animate({opacity: '1'}, duration);
			$('.More').animate({opacity: '0'}, duration).css({display: 'none'});
			zoom = 15;
		}
	});
	$('.Less').click(function() {
		if (zoom == 15) {
			$('.Thumbnails').animate({width: '535px'}, duration);
			$('.Thumbnails .Block').animate({paddingRight: '42px'}, duration);
			$('.More').css({display: 'block'}).animate({opacity: '1'}, duration);
			$('.Less').animate({opacity: '0'}, duration).css({display: 'none'});
			zoom = 9;
		} 
	});
}

kleinermann.successful.slideNavigation = function() {
	$('.Navigator').click(function() {
		$('body').scrollTo($($(this).attr('href').replace('#', '.')), 1000);
	});
}

kleinermann.successful.slideProjects = function() {
	$('.Thumbnail').unbind('click').click(function() {
		$project = $('.Projects').find('.Project');
		$container = $project.find('.Container');
	
		$.getJSON('/?project_ajax=true&id=' + $(this).attr('project'),  function(data) {
			$container.find('.Snapshots').html(data.snapshots);
			$container.find('.Provided').html('<p class="bold">Service Provided</p>' + data.services);
			$container.find('.Title').html(data.title);
			$container.find('.Url').html('<a href="' + data.url + '">See project</a>');
			$container.find('.Details').html(data.description);
			$container.find('.Testimonial').html(data.testimonials + '<div class="Speech"></div>');
			$('.Project').find("Projecta[href^='http']").attr('target','_blank');
			kleinermann.successful.slideServices();
			
			if ($project.css('display') == 'block') {
			$container.animate({left: '-1000px'}, 300, function() {
						$(this).css({left: '1000px'})
							   .animate({left: '0'}, 300);
					});
			} else {
				$project.css({display: 'block'})
						.animate({height: "440px"}, 300, function() {
							$container.css({left: '0'});
						})
			}
			
			$('.Services').css({paddingTop: '0'});
			$('body').scrollTo($('.Project'), 1000);
		});
		
	});
	
	$('.Projects .Close').click(function() {
		$(this).parents('.Projects').find('.Project').animate({height: "0"}, 300, function() {
			$(this).css({display: 'none'});
			$('.Services').css({paddingTop: ''});
		});
	});
}

kleinermann.successful.slideServices = function() {
	$('.Link').unbind('click').click(function() {
		$service = $('.Services').find('.Service');
		$container = $service.find('.Container');
		
		$.getJSON('/?service_ajax=true&id=' + $(this).attr('service'),  function(data) {
			$service.css({paddingTop: '6px'});
			if ($service.css('display') == 'block') {
				$container.animate({left: '-1000px'}, 300, function() {
							$container.find('.Description').find('.Title').html(data.title);
							$container.find('.Details').html(data.description);
							$container.find('.Examples').html('<p class="bold">Provided for:</p>' + data.examples);
							kleinermann.successful.slideProjects();
							$(this).css({left: '1000px'})
								   .animate({left: '0'}, 300);
						});
			} else {
				$container.find('.Description').find('.Title').html(data.title);
				$container.find('.Details').html(data.description);
				$container.find('.Examples').html('<p class="bold">Provided for:</p>' + data.examples);
				kleinermann.successful.slideProjects();
				$service.css({display: 'block'})
						.animate({height: "320px"}, 300, function() {
							$container.css({left: '0'});
						})
			}
			$('body').scrollTo($('.Service'), 1000);
		});
	});
	
	$('.Services .Close').click(function() {
		$(this).parents('.Services').find('.Service').animate({height: "0"}, 300, function() {
			$(this).css({display: 'none', paddingTop: '6px'});
		});
	});
}


kleinermann.successful.displayMap = function() {
	var latlng = new google.maps.LatLng(-25.125393,133.374023);
	var logo_location = new google.maps.LatLng(-37.800209,144.968158);
	var KLEINERMANN_MAP = 'kleinermann';
	var stylez = [
		{featureType: "all", elementType: "all", stylers: [{hue: "#ffffff"},{lightness: 0},{saturation: -100}]}, // Reset
		{featureType: "water", elementType: "all", stylers: [{hue: "#99ccff"},{lightness: 0},{saturation: 50}]},	// Water
		{featureType: "landscape", elementType: "all", stylers: [{hue: "#ffff33"},{lightness: -10},{saturation: 50}]},// Landscape Global
		{featureType: "poi", elementType: "all", stylers: [{hue: "#ffff33"},{lightness: 10},{saturation: 50}]},// Landscape Global
		{featureType: "road", elementType: "all", stylers: [{hue: "#FBF36E"},{lightness: 0},{saturation: 50}]},// Road
		{featureType: "road.highway", elementType: "geometry", stylers: [{hue: "#FBF36E"},{lightness: 100},{saturation: 0}]},	// Road	Highway	
		{featureType: "all", elementType: "labels", stylers: [{hue: "#cc3399"},{lightness: 0},{saturation: 50}]},//  Labels
	];
	
	var mapOptions = {
		zoom: 5,
		center: latlng,
		mapTypeControlOptions: {mapTypeIds: [google.maps.MapTypeId.ROADMAP, KLEINERMANN_MAP]},
		disableDefaultUI: false,
		mapTypeControl: false,
		disableDoubleClickZoom: false,
		scrollwheel: false,
		scaleControl: false,
		mapTypeId: KLEINERMANN_MAP
	};
	
	var map = new google.maps.Map(document.getElementById('Map'), mapOptions);
	map.mapTypes.set(KLEINERMANN_MAP, new google.maps.StyledMapType(stylez, {name: KLEINERMANN_MAP}));

	new google.maps.Marker({
		position: logo_location,
		map: map,
		icon: '/wp-content/themes/kleinermann/images/littleman.png'
	});
}

kleinermann.successful.updateInputs = function() {
	$('.Contact > form > input').each(function() {
		var originalvalue = $(this).val();
		$(this).focus( function(){
			if( $.trim($(this).val()) == originalvalue ){ $(this).val(''); }
		});
		$(this).blur( function(){
			if( $.trim($(this).val()) == '' ){ $(this).val(originalvalue); }
		});
	});
}
