
$(document).ready(function() {
	if ($('#s3slider').attr('id')) {
		$('#s3slider').s3Slider({
			timeOut: 4000
		});
	}
	if($('.Ierror')[0]) {
		$('html, body').animate({scrollTop:$('.Ierror:eq(0)').offset().top}, 'fast',
			function() {
					$.fancybox(
					'<h2>'+$('h1').text()+'</h2><p style="color:red">'+$('legend').text()+'</p>',
					{
			        		'autoDimensions'	: false,
						'width'         		: 350,
						'height'        		: 'auto',
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
					);	
			}
		
		);
			
	}
	

		
	// set external links
	$("a[href^=http]").each(
	    function(){
	      if(this.href.indexOf(location.hostname) == -1) {
		  	$(this).attr('target','_blank');
	      }
	    }
	);
	$(".gallery a").fancybox();
	$('a[target="_fancybox"]').fancybox();
	$('a._newsletter').fancybox({
		type : 'iframe'
	});
	$('a.media').media();
	// CLEAR INPUT FIELD
	$('.clear_input').each(function() {
		if($(this).val()=='') {
			$(this).val($(this).attr('alt'));
		}
		$(this).focus(function() {
				if($(this).val()==$(this).attr('alt')) {
					$(this).val('');
				}
			})
			.blur(function() {
				if(!$(this).val()) {
					$(this).val($(this).attr('alt'));
				}
			});
	});

	var s = $('.mainMedia img:eq(0)');
	s.hide();
	$('.topBox').css('top',-50);
	var orgTop = 0
	if($('body').hasClass('home') && $('.pin')[0]) {
		orgTop = $('.pin').css('top');
		$('.pin').css('top',-150);
	}
	var InitBig = function() {
		s.css('visibility','visible');
		
		s.fadeIn(800,function() {
			ShowTop();	
		});
	};
	var ShowTop = function() {
		if(orgTop) {
			$('.pin').animate({
				top : orgTop
			},1000,'easeOutBounce');
		}
				$('.topBox').animate({
					top : '+=64'
				},500,'easeOutBounce');
	};
	if (s.height() > 100) {	InitBig();			}
	else 				  {	s.load(InitBig);	}
	if(!s.attr('src')) {
		ShowTop();	
	}
	
});
