$(document).ready(function(){

	/* smart columns (gallery) */
	function smartColumns() { 
	$("#gallery ul").css({'width':"100%"});
		var colWrap = $("#gallery ul").width();
		var colNum = Math.floor(colWrap / 150);
		var colFixed = Math.floor(colWrap / colNum);
		$("#gallery ul").css({'width':colWrap});
		$("#gallery ul li").css({'width':colFixed});
	}
	smartColumns();
	
	/* superfish */
	$('.sf-menu ul').superfish({ 
		delay: 100,
		animation: {opacity:'show',height:'show'},
		speed: 200,
		dropShadows: false
	});
	
	/* slider */
	$('#slider').nivoSlider({
        effect:'fade',
        slices:10,
        boxCols: 1,
        boxRows: 1,
        animSpeed:200,
        pauseTime:3000,
		directionNavHide:false
    });
	
	/* sliding tabs */
	$('div#tabs_horizontal').slideTabs({			
		orientation: 'horizontal',
		/* slideLength: 900, */
		contentAnim: 'slideH',
		contentEasing: 'easeInOutExpo',
		tabsAnimTime: 300,
		contentAnimTime: 600			
	});
	
	/* prettyphoto */
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	/* fade in */
	$(".fade-in").fadeTo(100, 0.8);
	$(".fade-in").hover(function(){
		$(this).fadeTo(400, 1.0);
		},function(){
		$(this).fadeTo(200, 0.8);
	});
	
	/* fade out */
	$(".fade-out").hover(function(){
		$(this).fadeTo(400, 0.8);
		},function(){
		$(this).fadeTo(200, 1.0);
	});

	/* animate menu background */
	$('.sf-menu a')
		.css({backgroundPosition: "-300px 0"})
		.mouseover(function(){
			$(this).stop().animate(
			{backgroundPosition:"(-100px 0)"}, 
			{duration:600})
		})
		.mouseout(function(){
			$(this).stop().animate(
			{backgroundPosition:"(-300px 0)"}, 
			{duration:200})
	})
		
	/* toggle */
	$('.toggle-container').hide();
	$('.toggle-trigger').click(function(){
		$(this).toggleClass("active").next().slideToggle(800,'easeOutExpo');
		return false;
	});

	/* accordion */
	$('.accordion-content').hide();
	$('.accordion-heading').click(function(){
		$(this).toggleClass("active").next().slideToggle(800,'easeOutExpo');
		return false;
	});
	
	/* tooltips */
    $(".tip_trigger").hover(function(){
        tip = $(this).find('.tip');
        tip.fadeIn('400');
    },function(){
        tip.fadeOut('200');
    }).mousemove(function(e) {
        var mousex = e.pageX + 20; // x
        var mousey = e.pageY + 20; // y
        var tipWidth = tip.width();
        var tipHeight = tip.height();
        var tipVisX = $(window).width() - (mousex + tipWidth);
        var tipVisY = $(window).height() - (mousey + tipHeight);
        if (tipVisX < 20){mousex = e.pageX - tipWidth - 20;}
		if (tipVisY < 20){mousey = e.pageY - tipHeight - 20;}
        tip.css({top:mousey,left:mousex});
    });
	
	/* page scrolling */
	$(function(){
		$('.page-scroll').bind('click',function(event){
			var $anchor = $(this);
			$('html, body').stop().animate({
				scrollTop:$($anchor.attr('href')).offset().top
			},1500,'easeInOutExpo');
			event.preventDefault();
		});
	});

});
