$(document).ready(function(){
	
	$('.language-selector').bind('mouseenter mouseleave', function(event){
		var $languages = $(this).find('.languages');
		if (event.type == 'mouseenter') {
			$languages.show();
		}
		else {
			$languages.hide();
		}
	});
	
	$('#slideshow').crossSlide({
		fade: 1 }, [{
	    	src:  '/static/images/slideshow/1.jpg',
	    	from: '90% 40% 1x',
	    	to:   '90% 100% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/2.jpg',
	    	from: '60% 60% 1x',
	    	to:   '20% 80% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/3.jpg',
	    	from: '20% 50% 1x',
	    	to:   '100% 60% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/4.jpg',
	    	from: '100% 50% 1x',
	    	to:   '30% 50% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/5.jpg',
	    	from: '90% 80% 1x',
	    	to:   '100% 30% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/6.jpg',
	    	from: '80% 40% 1x',
	    	to:   '30% 60% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/8.jpg',
	    	from: '60% 80% 1x',
	    	to:   '30% 100% 1x',
	    	time: 4
	  	}, {
	    	src:  '/static/images/slideshow/9.jpg',
	    	from: '40% 80% 1x',
	    	to:   '60% 60% 1x',
	    	time: 4
	  	}
		]);
	
	$('.fancybox').fancybox({transitionIn:"elastic"});
	$('a[rel=wheel]').fancybox();
	
	$(".scrollableArea").append($(".scrollableArea a").clone());
	
	$("div#logoParade").smoothDivScroll({
		autoScroll: "always", 
		autoScrollDirection: "endlessloopright", 
		autoScrollStep: 1, 
		autoScrollInterval: 25,
		visibleHotSpots: "always"
	});
	
	$("div#logoParade").bind("mouseover", function() {
		$(this).smoothDivScroll("stopAutoScroll");
	}).bind("mouseout", function() {
		$(this).smoothDivScroll("startAutoScroll");
	});
	
	$('.last-minute').cycle({ 
	    fx:         'scrollLeft',
	    speedIn:	2000,
	    speedOut:	500,
	    easeIn:		'easeOutBounce',
	    easeOut:	'easeInCirc',
	    delay:		-2000,
	    pager:		'.pager',
	    pagerEvent: 'mouseover',
	    fastOnEvent:true,
	    pause: 		1,
	    timeout:	7000
	});
	
	$('.box-text').bind('click', function(event){
		var $self = $(this);
		if (event.type == 'click') {
			event.preventDefault();
			location.href = this.getElementsByTagName('a')[0].href;
		}
	}).css("cursor", "pointer");
	
	$(".scrollable").scrollable({
		easing: 'custom',
		speed: 700,
		circular: true
	}).autoscroll({
		autoplay: true,
		interval: 4500
	});

	$(".items img").click(function() {
		if ($(this).hasClass("active")) { return; }
		var url = $(this).attr("src").replace("_t", "");
		var wrap = $("#image_wrap").fadeTo("medium", 0.5);
		var img = new Image();
		img.onload = function() {
			wrap.fadeTo("fast", 1);
			wrap.find("img").attr("src", url);
		};
		img.src = url;
		$(".items img").removeClass("active");
		$(this).addClass("active");
	}).filter(":first").click();
});

$.easing.custom = function (x, t, b, c, d) {
	var s = 1.70158; 
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}




