Cufon.replace('.Kozuka_Gothic_B', { fontFamily: 'Kozuka_Gothic_B', hover: 'false', separate: 'none' });
Cufon.replace('.Kozuka_Gothic_EL', { fontFamily: 'Kozuka_Gothic_EL', hover: 'false', separate: 'none' });
Cufon.replace('.Kozuka_Gothic_H', { fontFamily: 'Kozuka_Gothic_H', hover: 'false', separate: 'none' });
Cufon.replace('.Kozuka_Gothic_M', { fontFamily: 'Kozuka_Gothic_M', hover: 'false', separate: 'none' });

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

function contactFormSubmit ( form )
{
	var url = jQuery(form).attr('action');
	var pars = jQuery(form).serialize();
	jQuery('#sendbuttoncontainer a').css('display', 'none');
	jQuery('#sendbuttoncontainer .ajax-loader').removeClass('hidden');
	jQuery('#contactokmsg').addClass('hidden');
	jQuery('#contacterrormsg').addClass('hidden');

	jQuery.post(url, pars, function(data){
		
		if ( data == '1' ) {
			jQuery.scrollTo('#kontakt', time, {
				easing:'easeOutQuart', 
				offset: -140,
				onAfter: function(){ jQuery('#contactokmsg').removeClass('hidden'); jQuery('#contactform').each(function(){ this.reset();}); jQuery('#sendbuttoncontainer a').css('display', ''); jQuery('#sendbuttoncontainer .ajax-loader').addClass('hidden'); }
			});
		}else{
			jQuery.scrollTo('#kontakt', time, {
				easing:'easeOutQuart', 
				offset: -140,
				onAfter: function(){ jQuery('#contacterrormsg').removeClass('hidden'); jQuery('#sendbuttoncontainer a').css('display', ''); jQuery('#sendbuttoncontainer .ajax-loader').addClass('hidden'); }
			});
		}
		
	});
}


var time = 1200;
jQuery(document).ready(function(){
	if(jQuery('#menu').length)
	{
		jQuery('#menu li a').mouseover(function(){
			jQuery(this).attr('href', jQuery(this).attr('rel') );
		});
	}
	
	jQuery('#offerlist1').click(function(){
		jQuery.scrollTo('#head', time, {
			easing:'easeOutQuart', 
			offset: -128,
			onAfter: function(){jQuery('.navi1').click();}
		});

	});
	
	jQuery('#offerlist2').click(function(){
		jQuery.scrollTo('#head', time, {
			easing:'easeOutQuart', 
			offset: -128,
			onAfter: function(){jQuery('.navi2').click();}
		});

	});
	
	jQuery('#offerlist3').click(function(){
		jQuery.scrollTo('#head', time, {
			easing:'easeOutQuart', 
			offset: -128,
			onAfter: function(){jQuery('.navi3').click();}
		});

	});
	jQuery('#menu a').click(function(){
		jQuery('#menu li').removeClass('active');
		jQuery(this).parent().addClass('active');
		id= jQuery(this).attr('href');
		jQuery.scrollTo(id, time, {
			easing:'easeOutQuart', 
			offset:-140,
			onAfter: function(){}
		});
	});
	jQuery('.projectslist a').mouseover(function(){
		jQuery(this).attr('href', jQuery(this).attr('rel'));
		jQuery(this).attr('target', '_blank');
	});
	
	if(jQuery('#mycarousel').length)
	{
		jQuery('#mycarousel').jcarousel({
			scroll: 1,
			auto: 10, 
			start: 1,
			wrap: 'both',
        	initCallback: mycarousel_initCallback,
        	itemVisibleInCallback: {
          		onBeforeAnimation:  mycarousel_itemVisibleInCallbackBeforeAnimation,
          		onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        	},
        	// This tells jCarousel NOT to autobuild prev/next buttons
        	buttonNextHTML: null,
        	buttonPrevHTML: null
		});
	}
	
	jQuery('#best a').click(function(){
		id = jQuery(this).attr('class');
		jQuery('#'+id+'-content').slideDown(); 
		jQuery('#naviright').css('display', 'block');
		jQuery('#navileft').css('display', 'block');
		return false;
	});
	
	jQuery('.close').click(function(){
		jQuery(this).parent().slideUp();
		jQuery('#naviright').css('display', 'none');
		jQuery('#navileft').css('display', 'none');
		return false;
	});
	
	jQuery('#naviright').click(function(){
		jQuery('.bestcontent').each(function(){
			if( jQuery(this).css('display') == 'block' )
			{
				id = jQuery(this).attr('id');
			}
		});
		
		if(id == 'onet-content'){
			jQuery('#onet-content').slideUp(function(){
				jQuery('#allegro-content').slideDown();	
			});
		}
		if(id == 'allegro-content'){
			jQuery('#allegro-content').slideUp(function(){
				jQuery('#apple-content').slideDown();	
			});
		}
		if(id == 'apple-content'){
			jQuery('#apple-content').slideUp(function(){
				jQuery('#onet-content').slideDown();	
			});
		}
		
		return false;
	});
	jQuery('#navileft').click(function(){
		jQuery('.bestcontent').each(function(){
			if( jQuery(this).css('display') == 'block' )
			{
				id = jQuery(this).attr('id');
			}
		});
		
		if(id == 'onet-content'){
			jQuery('#onet-content').slideUp(function(){
				jQuery('#apple-content').slideDown();	
			});
		}
		if(id == 'apple-content'){
			jQuery('#apple-content').slideUp(function(){
				jQuery('#allegro-content').slideDown();	
			});
		}
		if(id == 'allegro-content'){
			jQuery('#allegro-content').slideUp(function(){
				jQuery('#onet-content').slideDown();	
			});
		}
		
		return false;
	});

	jQuery('#allegro-content .bestcontent').click(function(){
		jQuery(this).parent().slideUp(function(){
			jQuery('#apple-content').slideDown();	
		});
	});
	
	jQuery('#apple-content .bestcontent').click(function(){
		jQuery(this).parent().slideUp(function(){
			jQuery('#onet-content').slideDown();	
		});
		
	});
	
});

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
	if(idx > 0){
		id = (idx%3);
		if(id == 0)
		{
			id = 3;
		}
	}else{
		id = 9999-Math.abs(idx);
		id = id%3;
		if(id == 0)
		{
			id = 3;
		}
		
	}
	
//	jQuery('h1').fadeOut(function(){
//		jQuery(this).attr('class', 'logo'+id).fadeIn();
//	})

}
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	if(idx > 0){
		id = (idx%3);
		if(id == 0)
		{
			id = 3;
		}
	}else{
		id = 9999-Math.abs(idx);
		id = id%3;
		if(id == 0)
		{
			id = 3;
		}
		
	}
	jQuery('.bestcontent').removeAttr('style');
	jQuery(item).parent().parent().parent().children('.jcarousel-control').children('a').removeClass('active');
	jQuery(item).parent().parent().parent().children('.jcarousel-control').children('.navi'+id).addClass('active');
	
}
function mycarousel_initCallback(carousel, state) {
  	if (state == 'init') { 
		carousel.startAutoOrig = carousel.startAuto; 
        carousel.startAuto = function() { 
	        if (!carousel.paused) { 
    	        carousel.startAutoOrig(); 
            }
        } 
        carousel.pause = function() { 
        	carousel.paused = true; 
            carousel.stopAuto(); 
        }; 
        carousel.play = function() { 
        	carousel.paused = false; 
            carousel.startAuto(); 
        }; 
        jQuery('#head').mouseover(function() { 
        	carousel.pause(); 
        }); 
        jQuery('#head').mouseout(function() { 
        	carousel.play(); 
        }); 
	}
    carousel.play(); 
              	
    jQuery('.jcarousel-control a').bind('click', function() {
    	jQuery(this).parent().find('a').removeClass('active');
    	jQuery(this).addClass('active');
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

 	jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });    
};

