Cufon.set('fontFamily', 'Sansa-light');
Cufon.replace('h2, h2 a, h1, .menu span', {hover: true});
Cufon.replace('.readmore', {hover: {color: 'white'}});
Cufon.replace('#slogan p, .title p');
Cufon.replace('p.videotitel');
Cufon.set('fontFamily', 'Sansa-bold');
Cufon.replace('.slogan p.headertitle', {textShadow: '#fff 0px 1px, #c78322 0px -1px'});
Cufon.replace('.slogan p span.headertitleshort');
Cufon.replace('.slogan p span.headertitleshort a', {hover: true});
Cufon.set('fontFamily', 'TitilliumText22L Lt');
Cufon.replace('h3, #breadcrumbs');
Cufon.replace('p.h3like');
		
function getInternetExplorerVersion(){
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
	  var ua = navigator.userAgent;
	  var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	  if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

function setCookie(c_name, value, exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

$(document).ready(function() {
	
	$('#subForm').validate();
	
	$('.tooltip').tipsy({ html: true, gravity: 'se' });
	
	//$('#homevideo').hover(function(){ $('#videotitel').hide(); }, function(){ $('#videotitel').show(); });

	$('.overlay').css({opacity: 0});
	$('.title').css({opacity: 0});
	
	jQuery.easing.def = 'easeOutQuad';
			
	$(".menu li.select").find('div').css('width', $(".menu li.select").find('span').width()+18);
	
	$(".menu li").hover(
		function () {$(this).find('div').animate({width: $(this).find('span').width()+18 + 'px'}, {queue:false, duration: 250, easing: 'easeOutBack'});},
		function () { if(!$(this).hasClass('select')){ $(this).find('div').animate({width: '0px'}, {queue:false, duration: 250, easing: 'easeOutBack' }); } }
	);
	
	$(".readmore").hover(
		function () {$(this).find('div').animate({width: $(this).find('span').width() + 'px'}, {queue:false, duration: 250, easing: 'easeOutBack'});},
		function () {$(this).find('div').animate({width: '0px'}, {queue:false, duration: 250, easing: 'easeOutBack' });}
	);

	
	if(getCookie('ani-only-first-time')!='1'){
		$('.header-image').fadeIn(1000, function(){
			$('.slogan').fadeIn(500, function(){
				$('.wrapper, #footer').delay(250).fadeIn(1000);
				
				setCookie('ani-only-first-time', '1', 1);
			});
		});
	}else{
		$('.header-image').show();
		$('.slogan').show();
		$('.wrapper, #footer').show();
	}
	
	$("#portfolio .item").hover(
		function () { 
			$(this).find('.overlay').animate({opacity: 0.6}, {queue:false, duration: 200, easing: 'easeInQuad'});
			$(this).find('.title').animate({top: '40px', opacity: 1}, {queue:false, duration: 200, easing: 'easeInQuad'});
			
		},
		function () {
			$(this).find('.overlay').animate({opacity: 0}, {queue:false, duration: 200, easing: 'easeInQuad'});
			$(this).find('.title').animate({top: '80px', opacity: 0}, {queue:false, duration: 200, easing: 'easeInQuad'});
		}
	);
	
	$(".border").css("opacity","0");

	$(".portfolio ul li").hover(function() {
		$(this).find('.overlay').animate({opacity: 0.6}, {queue:false, duration: 200, easing: 'easeInQuad'});
		$(this).find('.title').animate({top: '70px', opacity: 1}, {queue:false, duration: 200, easing: 'easeInQuad'});
		$(this).find('.border').animate({opacity: 1}, {duration: 500, queue: false});
		$(this).find('.block').animate({top: '170px'}, {queue:false, duration: 5, easing: 'easeOutBack'});
	}, function() {
		$(this).find('.overlay').animate({opacity: 0}, {queue:false, duration: 200, easing: 'easeInQuad'});
		$(this).find('.title').animate({top: '100px', opacity: 0}, {queue:false, duration: 200, easing: 'easeInQuad'});
		$(this).find('.border').animate({opacity: 0}, {duration: 500, queue: false});
		$(this).find('.block').animate({top: '100px'}, {queue:false, duration: 250, easing: 'easeOutBack'});
	});

	$('#open_maps').click(function() {
						
		if($(this).attr('class') == 'close'){
			$('#maps').show();
			initialize();
			$('#maps').animate({height: '500px', scrollTop:0}, {duration: 1000, easing: 'easeInOutExpo'});
			$(this).removeClass('close');
			$(this).addClass('open');
		}else{
			$('#maps').animate({height: '0px', scrollTop:0}, {duration: 1000, easing: 'easeInOutExpo'}, function(){ $('#maps').hide(); });
			$(this).removeClass('open');
			$(this).addClass('close');
		}
		
		$('html,body').animate({scrollTop: $('body').height()+500}, 1000);
		
	});
	
	$('.text').focus(function() {
		$(this).parent('.holder').find('span').fadeOut();
	});
	
	$('.formeffect span').click(function() {
		$(this).parent('.holder').find('.text').focus();
	});
	
	$('.text').blur( function() {
		if($(this).val()=='') {  
			$(this).parent('.holder').find('span').fadeIn();
		}
	});
	
	$('.tweets').cycle({ 
		fx:     'scrollUp', 
		timeout: 6000, 
		delay:  -2000 
	});
	
	
	$('.shortcut a').live('click', function() {
		$('.shortcut a').css('background-position', 'left');
		$(this).css('background-position', 'right');
		$('.shortcut .popup').slideUp(250);
		var offset 		= $(this).position();
		var item		= $('.shortcut').find('#' + $(this).attr('rel'));
		var set_left	= item.width()-$(this).width()-(offset.left)+20;
		
		item.slideDown(250);
		item.css('left', '-' + set_left + 'px');
	
	});
	
	
	$('.shortcut').mouseleave(function() {
		$('.shortcut a').delay(1000).css('background-position', 'left');
		$('.shortcut .popup').delay(1000).slideUp(250);
	});
	
	
	$(".item").hover(
		function () {
			$(this).find('.block').animate({width: '325px', height: '155px'}, {duration: 250, easing: 'swing', queue: false}); 
		}, 
		function () {
			$(this).find('.block').animate({width: '0px', height: '0px'}, {duration: 250, easing: 'swing', queue: false}); 
		}
	);  
	
		
	$(".provider .inside").hover(
			function () {$(this).animate({left: '-7px', top: '-7px', height: '50px', width: '50px'}, {queue:false, duration: 250, easing: 'swing' });}, 
			function () {$(this).animate({left: '1px', top: '1px', height: '36px', width: '36px'}, {queue:false, duration: 250, easing: 'swing' });}
	);
	
	
	var index = 1;
		
	$(".photo .inside").hover(
		function () {
			index++;
			$(this).css('z-index', index);
			$(this).stop().animate({left: '-6px', top: '-6px', height: '86px', width: '86px'}, {queue:false, duration: 200, easing: 'easeOutCubic' });
		}, 
		function () {
			$(this).stop().animate({left: '0', top: '0', height: '75px', width: '75px'}, {queue:false, duration: 100, easing: 'easeOutSine' });
		}
	);
	
});

$(window).scroll(function () {
		var scrt = $(document).scrollTop();
		
		if(getInternetExplorerVersion() == 7){
			
			var get_height = ($(document).height()-$('#footer').outerHeight()-$('#case .info').outerHeight()-58-$('#maps').outerHeight());
			
			if(scrt > get_height){
				scrt     = get_height;
			}else{
			
				if(scrt < 400){
					scrt = 400;
				}else{
					scrt = scrt;
				}
			}
			
		}else{
			
			var get_height = ($(document).height()-$('#footer').outerHeight()-$('#case .info').outerHeight()-78-$('#maps').outerHeight());
			
			if(scrt > get_height){
				scrt     = get_height;
			}else{
			
				if(scrt < 380){
					scrt = 380;
				}else{
					scrt = scrt-20;
				}
			}
		} 
			
		$('#case .info').animate({top:scrt + 'px'},{duration: 500, easing: 'swing', queue: false}); 
	});
