// JavaScript Document


/// active link select
$(function(){
		var $page = jQuery.url.attr("file");
		$('#container a').each(function(){
			var $href = $(this).attr('href');
			if ( ($href == $page) || ($href == '') ) {
				$(this).addClass('act');
			} else {
				$(this).removeClass('act');
			}
		});
});

/// box opacity
$(function() {
				//settings
				var opacity = 0.7, toOpacity = 1, duration = 250;
				//set opacity ASAP and events
				$('.opacity').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
	$(this).fadeTo(duration,opacity);
}
);
});

/// hover opacity change
$(function() {
	$('#topmenu a').animate({"opacity": 0.6 });
		$('#topmenu a').hover(function() {
			$(this).stop().animate({ "opacity": 1 }, 300);
}, function() {
	$(this).stop().animate({ "opacity": 0.6 }, 300);
 });
});

/// always visible
$(function() {
	var stickerTop = parseInt($('#sticker').offset().top);
	$(window).scroll(function() 
	{
		$("#sticker").css((parseInt($(window).scrollTop())+parseInt($("#sticker").css('margin-top')) > stickerTop) ? {position:'fixed',top:'0px'} : {position:'relative'});
	});
});

/// JQ UI accordion
$(function() {
	$("#accordion").accordion({
		event: "click hoverintent"
	});
});

var cfg = ($.hoverintent = {
	sensitivity: 7,
	interval: 100
});

$.event.special.hoverintent = {
	setup: function() {
		$( this ).bind( "mouseover", jQuery.event.special.hoverintent.handler );
	},
	teardown: function() {
		$( this ).unbind( "mouseover", jQuery.event.special.hoverintent.handler );
	},
	handler: function( event ) {
		event.type = "hoverintent";
		var self = this,
			args = arguments,
			target = $( event.target ),
			cX, cY, pX, pY;
		
		function track( event ) {
			cX = event.pageX;
			cY = event.pageY;
		};
		pX = event.pageX;
		pY = event.pageY;
		function clear() {
			target
				.unbind( "mousemove", track )
				.unbind( "mouseout", arguments.callee );
			clearTimeout( timeout );
		}
		function handler() {
			if ( ( Math.abs( pX - cX ) + Math.abs( pY - cY ) ) < cfg.sensitivity ) {
				clear();
				jQuery.event.handle.apply( self, args );
			} else {
				pX = cX;
				pY = cY;
				timeout = setTimeout( handler, cfg.interval );
			}
		}
		var timeout = setTimeout( handler, cfg.interval );
		target.mousemove( track ).mouseout( clear );
		return true;
	}
};

/// NIVO SLIDER
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:800, //Slide transition speed
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.4, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});

/// 

