$(document).ready(function() {

	/* Adds class="active" to current page */
	
	$("#wrapper #header .float-right ul li a").each(function() {
		if(this.href == window.location) $(this).addClass("active");
	});

	/* Fancybox Homepage Video  
 
	$("a.home_modal").fancybox({
		'hideOnContentClick': true,
		'overlayShow': true,
		'overlayOpacity': '0.8',
		'centerOnScroll': false,
		'frameWidth': 640,		
		'frameHeight': 385
	}); */
	
	/* homepage video from YouTube */
	$("#youtube").click(function() {
	$.fancybox({
			'padding'		: 0, 
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

	/* Fancybox other modals */
 
	$("a.fancybox").fancybox({ 
		'zoomSpeedIn': 600,
		'zoomSpeedOut': 500,
		'overlayShow': true,
		'overlayOpacity': '0.4',
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack'
	}); 

	/* Post images opacity */

	$("#wrapper .post-body a img").css({ "opacity":"0.8" });


	$("#wrapper .post-body a img").hover(function(){
		$(this).animate({"opacity": "1"}, 150);
	},
	function(){
		$(this).animate({"opacity": "0.8"}, 150);
	});	

});

	/* Tooltip */

	$(function() {
		$(".tooltip").tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			fade: 250
			});
		});

	/* Accordion on FAQ */
	
	$(function() {
	//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
	$("#firstpanel p.menu_head").click(function()
    {
		$(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
       	$(this).siblings();
	});
});
	

	/* plugin for link fade*/
	jQuery.fn.dwFadingLinks = function(settings) {
		settings = jQuery.extend({
			color: '#FFFFFF',//color and duration here are meaningless
			duration: 500
		}, settings);
		return this.each(function() {
			var original = $(this).css('color');
			$(this).mouseover(function() { $(this).animate({ color: settings.color },settings.duration); });
			$(this).mouseout(function() { $(this).animate({ color: original },settings.duration); });
		});
	};
	
	/* usage of link fade*/
	$(function() {
		$('.fade').dwFadingLinks({
			color: '#0C9EE8',
			duration: 333
		});
	});
	
	$(function() {
		$("a.anchor-link").anchorAnimate()
	});
	
	jQuery.fn.anchorAnimate = function(settings) {
	
		settings = jQuery.extend({
			speed : 1100
		}, settings);	
		
		return this.each(function(){
			var caller = this
			$(caller).click(function (event) {	
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = $(caller).attr("href")
				
				var destination = $(elementClick).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
					window.location.hash = elementClick
				});
				return false;
			})
		})
	}
	
	
