/*
* ASF
* standard.js
*
* Author: 
* Date: Oktober 2010
*/


$(document).ready(function(){
	
	
	/* JS enable */
	$("html").addClass("js");
	
	
	/* ScrollTo */
	$('a.top').click(function(){
		$.scrollTo( '#pageTop', 800 );
		return false;
	});


	$(".containerCenterB").parent().css("background-image","none");

	// Self-maximize Textaraes
	$('textarea').elastic();
	
	
	// Search Field Hover
	$('#searchTerm').focus(
		function() {
			if ( $(this).attr('value') == 'Suchbegriff' ) {
				$(this).attr('value','');	
				$(this).addClass('edit');
			}
		}
	);
	
	$('#searchTerm').blur(
		function() {
			if ( $(this).attr('value') == '' ) {
				$(this).attr('value','Suchbegriff');
				$(this).removeClass('edit');
			}
		}
	);
	
	
	
	$('.containerTeaser .teaserGallery').each(function(){
		
		var $teaserGalleryBox = $(this);
		var $teaserGalleryImages = $('thumbBoxInner', this);
		
		var scrollable = $(".thumbImages", this).scrollable({ 
			easing: 'easeInOutExpo',
			speed: 400,
			items:'.thumbBoxInner',
			prev:'.thumbArrowLeft',
			next:'.thumbArrowRight',
			clickable: true,
			size: 1,
			onSeek: function() {
				$('.currentPage', $teaserGalleryBox).text( this.getIndex()+1 );	 
				//$('.caption', $teaserGalleryBox).text( $('a',this).attr('title') ); WRONG	 
			}
		});
		var scrollableAPI = $(".thumbImages", this).scrollable({api: true});
		
		if ( $(".thumbImages", this).scrollable().getSize() > 1 ) {
			$('.currentPage', $teaserGalleryBox).text( $(".thumbImages", this).scrollable().getIndex()+1 );
			$('.totalPages', $teaserGalleryBox).text( $(".thumbImages", this).scrollable().getSize() ); 
			//$('.caption', $teaserGalleryBox).text( $('a:first', this).attr('title') );	
		} else {
			$('.currentPage', $teaserGalleryBox).hide();
			$('.totalPages', $teaserGalleryBox).hide();
		}
		
	});
	
	
	
	$('.containerThumbnails').each(function(){
		
		var $teaserGalleryBox = $(this);
		var $teaserGalleryImages = $('thumbBoxInner', this);
		
		var scrollable = $(".thumbImages", this).scrollable({ 
			easing: 'easeInOutExpo',
			speed: 400,
			items:'.thumbBoxInner',
			prev:'.thumbArrowLeft',
			next:'.thumbArrowRight',
			clickable: true,
			size: 1,
			onSeek: function() {
				$('.currentPage', $teaserGalleryBox).text( this.getIndex()+1 );	 
				//$('.caption', $teaserGalleryBox).text( $('a',this).attr('title') ); WRONG	 
			}
		});
		var scrollableAPI = $(".thumbImages", this).scrollable({api: true});
		
	});
	
	
	
	// SelectBox
	$('.countryBox .selectBox').hoverIntent({
			sensitivity: 3,
			interval: 100,
			over: nothing,  
			timeout: 300,
			out: closeQuickBox
		}).click(function(){
			if ( $(this).hasClass('selectBoxActive') ) {
				$(this).removeClass('selectBoxActive');
			} else {
				$(this).addClass('selectBoxActive');
			}
		}).find('.option span').click( function() {
			var $thisClicked = $(this);
			var $thisSelectBox = $(this).parent().parent().parent();
			$thisClicked.parent().css()
			$thisSelectBox
				.find('.selectedBox span').text( $thisClicked.text() ).end()
				.find('input').attr('value', $(this).attr('class') );
		})
	function closeQuickBox(){
		$(this).removeClass('selectBoxActive');
	}
	function nothing(){ return true;}
	
	
	// SelectBox
	$('.teaserTestimonial').hoverIntent({
		sensitivity: 5,
		interval: 200,
		over: function(){
			$(this).find(".textBox p").css("height","193px");
			$(this).find(".textBox").animate({
						height:193
					},200, function(){
						$(this).addClass('textBoxActive');
					});
			},   
		timeout: 500, 
		out: function(){
			$(this).find(".textBox").animate({
					height:18
				},500, function(){
					$(this).removeClass('textBoxActive');
					$("p",this).css("height","18px");	
				});
			}     
	});
	
	
	$("a.zoom").fancybox({
		'titleShow' : false,
		'zoomOpacity' : true,
		'overlayShow' : true,
		'overlayColor' : '#ffffff',
		'overlayOpacity' : 0.8,
		'padding' : 10,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade',
		'centerOnScroll' : true
	});
	
	//$(".linkBox p:empty").css('padding', '0');
	
});
