var Stuyver = {
	
	homeEasingIn: 'easeOutExpo',
	homeEasingOut: 'easeOutQuart',
	homeDuration: 800,
	
	init: function() {
		$('.object-detail-bottom-top li').each(function(i,elmTarget){
			
			$(elmTarget)
				.click(function(){
					$('.object-detail-bottom-top li').removeClass('active');
					$(this).addClass('active');
					$('.tab-contents .tab-content').each(function(i,elm){
							$(elm)
								.slideUp(400,function(){
										$(this)
											.removeClass('active')
										;
								})
							;
					});
					$('#' + this.id + '-content').stop().slideDown(400,function(){ $(this).addClass('active'); });
				})
			;
			
		});
	},
	
	detail: {
		
		gMap: null,
		mapIsSet: false,
		
		imageScroller: {
			timer: null,
			
			scrollDownStart: function(e){
				var jqeImagesContainer = $('.object-detail-images-choice-images', $(this).parent()).get(0);
				$(jqeImagesContainer).animate(
					{ scrollTop : $(jqeImagesContainer).get(0).offsetHeight },
					{ duration : 1500, easing:'linear' }
				);
			},
			
			scrollUpStart: function(e){
				var jqeImagesContainer = $('.object-detail-images-choice-images', $(this).parent()).get(0);
				$(jqeImagesContainer).animate(
					{ scrollTop : 0 },
					{ duration : 1500, easing:'linear' }
				);
			},
			
			scrollEnd: function(e) {
				var jqeImagesContainer = $('.object-detail-images-choice-images', $(this).parent()).get(0);
				$(jqeImagesContainer).stop();
			}
		},
		
		currentImage: '',
		
		imageSwitch: function(e) {
			Stuyver.detail.currentImage = $(this).attr('imageLink') + '?action=resize&w=335&h=225'
			var sTitle = $(this).attr('title');
			var iNewScroll = $(this).get(0).offsetTop - $(this).parent().get(0).offsetTop - ($(this).height()*2);
			
			$(this).parent().animate(
				{ scrollTop : iNewScroll },
				{ duration : 200, easing:'linear' }
			);
				
			$('.object-detail-images-choice-images a').removeClass('active');
			$(e.currentTarget).addClass('active');
			
			$('#object-image-main').stop(true,true).animate({opacity:0},{duration:150,easing:'easeOutQuart',complete:function(){
				$('.object-detail-image-main-content h2').html(sTitle);
				$(this).attr('src', '').attr('src', Stuyver.detail.currentImage);
				$(this).load(function() { $(this).animate({opacity:1},{duration:500,easing:'easeOutQuart'}); });
			}});

			/*
			$('#object-image-main').stop(true,true).animate({opacity:0,width:400,height:280,left:-25,top:-20},{duration:150,easing:'easeOutQuart',complete:function(){
				$('.object-detail-image-main-content h2').html(sTitle);
				$(this).attr('src', Stuyver.detail.currentImage).animate({opacity:1,width:350,height:240,left:0,top:0},{duration:500,easing:'easeOutQuart'});
			}});
			*/
			
			/* ZOOM 
			$('#object-image-main').stop(true,true).animate({opacity:0,width:400,height:280,left:-25,top:-20},{duration:150,easing:'easeOutQuart',complete:function(){
				$(this).attr('src', Stuyver.detail.currentImage).animate({opacity:1,width:350,height:240,left:0,top:0},{duration:400,easing:'easeOutQuart'});
			}});
			*/
			
			/* DIA 
			$('#object-image-main').stop(true,true).animate({left:-350,opacity:.2},{duration:200,easing:'easeOutQuart',complete:function(){
				$(this).attr('src', Stuyver.detail.currentImage).animate({left:0,opacity:1},{duration:300,easing:'easeOutQuart'});
			}});
			*/
			
		},
		
		init: function() {
			
			$('.object-detail-images-choice').each(function(i,elmTarget){
				
				/*
				$('.object-detail-images-choice-up', $(elmTarget))
					.bind('mousedown',Stuyver.detail.imageScroller.scrollUpStart)
					.bind('mouseup',Stuyver.detail.imageScroller.scrollEnd)
				;
				$('.object-detail-images-choice-down', $(elmTarget))
					.bind('mousedown',Stuyver.detail.imageScroller.scrollDownStart)
					.bind('mouseup',Stuyver.detail.imageScroller.scrollEnd)
				;
				*/
				
				$('.object-detail-images-choice-down', $(elmTarget))
					.bind('click',function(){
						$($('.object-detail-images-choice-images a.active').next('a').get(0)).click();
					})
				;
				
				$('.object-detail-images-choice-up', $(elmTarget))
					.bind('click',function(){
						$($('.object-detail-images-choice-images a.active').prev('a').get(0)).click();
					})
				;
				
			});
			
			$('.object-detail-images-choice-images a').each(function(i,elmLink){
				$(elmLink)
					.attr('imageLink', $(elmLink).attr('href'))
					.removeAttr('href')
					.bind('click',Stuyver.detail.imageSwitch)
				;
			});
			
		},
		
		setMapAddress: function(sAddress) {
			if (Stuyver.detail.mapIsSet) return;
			var sUrl = global.baseUrl + '/googlemaps/getgeo/'+sAddress;
			
			Stuyver.detail.mapIsSet = true;
			
			$.ajax({
				type		:	'get',
				data		:	{},
				url			:	sUrl,
				dataType	:	'json',
				success		:	function(data){
					var iLat = data.Placemark[0].Point.coordinates[1];
					var iLng = data.Placemark[0].Point.coordinates[0];
					
					Stuyver.detail.gPosition = new google.maps.LatLng(iLat,iLng);
					
					Stuyver.detail.gMap = new google.maps.Map(document.getElementById("tab-map-content"), {
						zoom						: 15,
						center						: Stuyver.detail.gPosition,
						mapTypeId					: google.maps.MapTypeId.HYBRID,
						navigationControl			: true,
						navigationControlOptions	: { style : google.maps.NavigationControlStyle.ZOOM_PAN}
					});
					
					Stuyver.detail.gMarker = new google.maps.Marker({
						map			:	Stuyver.detail.gMap,
						position	:	Stuyver.detail.gPosition,
						title		:	$('#object-address-clear').val()
					});
				}
			});
		}
		
	},
	
	
	home: {
		
		init: function() {
			$('.home-arrowblock').each(function(i, elmTarget){
				$(elmTarget)
					.bind('mouseenter', function(){ Stuyver.animateHomeBlockBig($(this), true) })
					.bind('mouseleave', function(){ Stuyver.animateHomeBlockSmall($(this), true) })
				;
			});
			/*
			var slowDown = 0;
			$('.home-arrowblock').each(function(i,elmTarget){
				slowDown += 75;
				setTimeout(function(){
					Stuyver.animateHomeBlockBig(elmTarget, false, 400, 'easeInExpo');
					Stuyver.animateHomeBlockSmall(elmTarget, false, 1000, 'easeOutExpo');
				}, slowDown);
			});
			*/
		}
		
	},
	
	
	animateHomeBlockBig: function(elmTarget, bStop, speed, sEasing) {
		if (typeof bStop != 'undefined' && bStop !== false) {
			$(elmTarget).stop();
			$('.home-arrow-sign', $(elmTarget)).stop().animate({top:5},{duration:speed,easing:sEasing});
			$('.home-arrow-bottom-img', $(elmTarget)).stop();
		}
		
		if (typeof speed == 'undefined') {
			speed = Stuyver.homeDuration;
		}
		
		if (typeof sEasing == 'undefined') {
			sEasing = Stuyver.homeEasingIn;
		}
		
		$(elmTarget).animate({height:285},{duration:speed,easing:sEasing});
		$('.home-arrow-bottom-img', $(elmTarget)).animate({height:52},{duration:speed,easing:sEasing});
	},
	
	animateHomeBlockSmall: function(elmTarget, bStop, speed, sEasing) {
		if (typeof bStop != 'undefined' && bStop !== false) {
			$(elmTarget).stop();
			$('.home-arrow-sign', $(elmTarget)).stop();
			$('.home-arrow-bottom-img', $(elmTarget)).stop();
		}
		
		if (typeof speed == 'undefined') {
			speed = Stuyver.homeDuration;
		}
		
		if (typeof sEasing == 'undefined') {
			sEasing = Stuyver.homeEasingOut;
		}
		
		$(elmTarget).animate({height:275},{duration:speed,easing:sEasing});
		$('.home-arrow-bottom-img', $(elmTarget)).animate({height:36},{duration:speed,easing:sEasing});
		$('.home-arrow-sign', $(elmTarget)).animate({top:20},{duration:speed,easing:sEasing});
	}
}

$(document).ready(Stuyver.init);
