$(document).ready(function() {

// Open External Links in New Window --------------------//	
  	$("a[href^='http:']").not("[href*='onboardwatersports.com']").attr('target','_blank');
						   
// IE Cleartype Fix	--------------------//				   
	$.fn.fadeIn = function(speed, callback) {
		return this.animate({
			opacity: 'show' }, speed, function() {
				if ($.browser.msie)
					this.style.removeAttribute('filter');
				if (typeof callback == 'function')
					callback();
		});
	};
	
	$.fn.fadeOut = function(speed, callback) {
		return this.animate({
			opacity: 'hide' }, speed, function() {
				if (jQuery.browser.msie)
					this.style.removeAttribute('filter');
				if (typeof callback == 'function') callback();
		});
	};
	
	$.fn.fadeTo = function(speed,to,callback) {
		return this.animate({opacity: to }, speed, function() {
			if (to == 1 && $.browser.msie)
				this.style.removeAttribute('filter');
			if (typeof callback == 'function') callback();
		});
	};
	
// Fading Links --------------------//
	$("#logo span, .mainmenu span, #social span").css("opacity","0");
	$("#logo span, .mainmenu span, #social span").hover(function (){
		$(this).stop().animate({opacity: 1}, 200);
	},
	function (){
		$(this).stop().animate({opacity: 0}, 200);
	});
	
	$(".popup span").css("opacity","0.5");
	$(".popup span").hover(function (){
		$(this).stop().animate({opacity: 1}, 200);
	},
	function (){
		$(this).stop().animate({opacity: 0.5}, 200);
	});

	$(".nthumb a, .thumbrow a").css("opacity","1");
	$(".nthumb a, .thumbrow a").hover(function (){
		$(this).stop().animate({opacity: 0.25}, 200);
	},
	function (){
		$(this).stop().animate({opacity: 1}, 200);
	});
	
	$(".boardbox span").css("opacity","0");
	$(".boardbox span").hover(function (){
		$(this).stop().animate({opacity: 1}, 200);
	},
	function (){
		$(this).stop().animate({opacity: 0}, 200);
	});

// About Image Zoom --------------------//	
	$("img.aboutimgleft, img.aboutimgright, img.aboutimgbleft, img.aboutimgbright").hover(function (){
		$(this).stop().animate({width: [570, 'easeOutQuint'], height: [330, 'easeOutQuint']}, 200);
	},
	function (){
		$(this).stop().animate({width: [300, 'easeOutQuart'], height: [174, 'easeOutQuart']}, 400);
	});
						   
// Subnav --------------------//
	$(function () {
        $(".bubbleInfo").each(function () {
            var distance1 = 10;
            var distance2 = -10;
            var time = 350;
            var hideDelay = 350;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 32,
                        left: 0,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance2 + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance1 + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });

// Colorbox --------------------//
	$(".boardbox a, a[rel='gal'], .riderphoto a").colorbox({speed:400, opacity:1, current:'{current} / {total}'});
	$("a[rel='ytvid']").colorbox({iframe:true, innerWidth:640, innerHeight:385});
	$("a[rel='vmvid']").colorbox({iframe:true, innerWidth:640, innerHeight:360});
	$("a[rel='llvid']").colorbox({iframe:true, innerWidth:640, innerHeight:400});
	
	$("a.b1, a.p1, a.bio-1").colorbox({inline:true, href:".cbox_b1"});
	$("a.b2, a.p2, a.bio-2").colorbox({inline:true, href:".cbox_b2"});
	$("a.b3, a.p3, a.bio-3").colorbox({inline:true, href:".cbox_b3"});
	$("a.b4, a.p4, a.bio-4").colorbox({inline:true, href:".cbox_b4"});
	$("a.b5, a.p5, a.bio-5").colorbox({inline:true, href:".cbox_b5"});
	$("a.b6, a.p6, a.bio-6").colorbox({inline:true, href:".cbox_b6"});
	$("a.b7, a.p7, a.bio-7").colorbox({inline:true, href:".cbox_b7"});
	$("a.b8, a.p8, a.bio-8").colorbox({inline:true, href:".cbox_b8"});
	$("a.b9, a.p9, a.bio-9").colorbox({inline:true, href:".cbox_b9"});
	$("a.b10, a.p10, a.bio-10").colorbox({inline:true, href:".cbox_b10"});
	$("a.b11, a.p11, a.bio-11").colorbox({inline:true, href:".cbox_b11"});
	$("a.b12, a.p12, a.bio-12").colorbox({inline:true, href:".cbox_b12"});
	$("a.b13, a.p13, a.bio-13").colorbox({inline:true, href:".cbox_b13"});
		$("a.b13-2").colorbox({inline:true, href:".cbox_b13-2"});
	$("a.b14").colorbox({inline:true, href:".cbox_b14"});
	$("a.b15").colorbox({inline:true, href:".cbox_b15"});
	$("a.b16").colorbox({inline:true, href:".cbox_b16"});
	$("a.b17").colorbox({inline:true, href:".cbox_b17"});
	$("a.b18").colorbox({inline:true, href:".cbox_b18"});
	$("a.b19").colorbox({inline:true, href:".cbox_b19"});
	$("a.b20").colorbox({inline:true, href:".cbox_b20"});
	$("a.b21").colorbox({inline:true, href:".cbox_b21"});
	$("a.b22").colorbox({inline:true, href:".cbox_b22"});
	$("a.b23").colorbox({inline:true, href:".cbox_b23"});
	$("a.b24").colorbox({inline:true, href:".cbox_b24"});
	$("a.b25").colorbox({inline:true, href:".cbox_b25"});
	$("a.b26").colorbox({inline:true, href:".cbox_b26"});
	$("a.b27").colorbox({inline:true, href:".cbox_b27"});
	$("a.b28").colorbox({inline:true, href:".cbox_b28"});
	$("a.b29").colorbox({inline:true, href:".cbox_b29"});
	$("a.b30").colorbox({inline:true, href:".cbox_b30"});

});
