/*
 *
 * Cufon and jQuery initialization code for GNU.com
 *
 */


		Cufon.replace('#footernav a, #footersocial span, .slogan p, #content_left h3 span, #content_right h3 span, #content_right h2 a, #content_left h4, #content_right h2.headline span, #content_full h2 span, #content_full h3 span, #content_full h3 a, .binding_features li span, .board_construction li a, .binding_features li a, #binding_colorway1_views h3, #binding_colorway2_views h3, #binding_colorway3_views h3, #sidebar h3 a, #sidebar h2 span, body.team #content_left h2, body.team #content_right h2, body.team #content_left strong, .bio_video_wrap h4 a, #home_posts h3 a, #home_posts p.postmeta, #video_left h3 span, body.videos strong, .weird_video_wrap h4 a, #softgood_content h2 span', { fontFamily: 'Dirty Headline' });

	
		
		var J = jQuery.noConflict();
	
		J(document).ready(function(){
			
// MEGA MENU INIT

//On Hover Over
function megaHoverOver(){
    J(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
//    (function(J) {
//        //Function to calculate total width of all ul's
//        jQuery.fn.calcSubWidth = function() {
//            rowWidth = 0;
//            //Calculate row
//            J(this).find("ul").each(function() { //for each ul...
//                rowWidth += $(this).width(); //Add each ul's width together
//            });
//        };
//    })(jQuery); 

//    if ( J(this).find(".row").length > 0 ) { //If row exists...
//
//        var biggestRow = 0;	
//
//        J(this).find(".row").each(function() {	//for each row...
//            J(this).calcSubWidth(); //Call function to calculate width of all ul's
//            //Find biggest row
//            if(rowWidth > biggestRow) {
//                biggestRow = rowWidth;
//            }
//        });
//
//        J(this).find(".sub").css({'width' :biggestRow}); //Set width
//        J(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
//
//    } else { //If row does not exist...
//
//        J(this).calcSubWidth();  //Call function to calculate width of all ul's
//        J(this).find(".sub").css({'width' : rowWidth}); //Set Width
//
//    }
}
//On Hover Out
function megaHoverOut(){
  J(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      J(this).hide();  //after fading, hide it
  });
}

// CONFIG MEGA MENU

//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 400, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

J("#supernav ul li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
J("#supernav ul li").hoverIntent(config); //Trigger Hover intent with custom configurations			
			
J("#supernav ul li .sub ul:first-child").css({'background':'none', 'padding-left':'0'}); //Fade sub nav to 0 opacity on default
		
		
		

// Binding Hovers
		
	
		  
		  J('#colorway1 a')
		  .bind('mouseenter',function() {
			J('#colorway1_img').removeClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway2_img').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway3_img').addClass('hide');
		  })
		 .bind('mouseenter',function() {
			J('#colorway2 a').removeClass('active');
		  })
		 .bind('mouseenter',function() {
			J('#colorway3 a').removeClass('active');
		  })
		  .bind('mouseleave',function() {
			J('#colorway1 a').addClass('active');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway2_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway3_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway1_views').removeClass('hide');
		  });
		  
		  
		  	J('#colorway2 a')
		  .bind('mouseenter',function() {
			J('#colorway2_img').removeClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway1_img').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway3_img').addClass('hide');
		  })
		 .bind('mouseenter',function() {
			J('#colorway1 a').removeClass('active');
		  })
		  .bind('mouseenter',function() {
			J('#colorway3 a').removeClass('active');
		  })
		  .bind('mouseleave',function() {
			J('#colorway2 a').addClass('active');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway1_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway3_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway2_views').removeClass('hide');
		  });
		  
		  
		  
		  	J('#colorway3 a')
		  .bind('mouseenter',function() {
			J('#colorway3_img').removeClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway1_img').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#colorway2_img').addClass('hide');
		  })
		 .bind('mouseenter',function() {
			J('#colorway1 a').removeClass('active');
		  })
		  .bind('mouseenter',function() {
			J('#colorway2 a').removeClass('active');
		  })
		  .bind('mouseleave',function() {
			J('#colorway3 a').addClass('active');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway1_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway2_views').addClass('hide');
		  })
		  .bind('mouseenter',function() {
			J('#binding_colorway3_views').removeClass('hide');
		  });
		  

						 
		// FancyBox

		J.fn.getTitle = function() {
			var arr = J("a.fancybox");
			J.each(arr, function() {
				var title = J(this).children("img").attr("title");
				if (title =="") {title = J(this).next().children("p").html()}; // create title from PWA + PHP captions
				if (title == "") {title = J(this).attr("title")}; // if nothing else, set title to that of the page
				J(this).attr('title',title);
			})
		}

		// Supported file extensions
		var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

	
		J(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();

		//J(thumbnails).addClass("fancybox").attr("rel","fancybox");

			J("a.fancybox").fancybox({
			'autoScale': false,
			'padding': 10,
			'zoomOpacity': true,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'zoomSpeedChange': 300,
			'overlayShow': true,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': false,
			'frameWidth':  560,
			'frameHeight':  340,
			'callbackOnStart': null,
			'callbackOnShow': null,
			'callbackOnClose': null,
			'centerOnScroll': false,
			'title'			: this.title,
			'titlePosition'	:	'over',
			'onComplete'	:	function() {
			J("#fancybox-wrap").hover(function() {
			J("#fancybox-title").show();
			}, function() {
			J("#fancybox-title").hide();
			});
		}

		});
			
			J("a.fancybox-notitle").fancybox({
			'autoScale': false,
			'padding': 10,
			'zoomOpacity': true,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'zoomSpeedChange': 300,
			'overlayShow': true,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': false,
			'frameWidth':  560,
			'frameHeight':  340,
			'callbackOnStart': null,
			'callbackOnShow': null,
			'callbackOnClose': null
	
			
		});
			
		J("a.more_info").fancybox({						   
				'hideOnContentClick': false,
				'autoDimensions' : true,
				'padding': 20
		});
		
		J("a.iframe").fancybox({
		'hideOnContentClick': false,
		'width'				: 660,
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
		
		J("a.backdoor").fancybox({
		'hideOnContentClick': false,
		'width'				: 940,
		'height'			: 722,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding'			: 0
		
	});
			
		J("a.get_specs").fancybox({
		'hideOnContentClick': false,
		'width'				: 980,
		'height'			: 500,
        'autoScale'     	: false,
		'overlayColor': "#333333",
		'overlayOpacity': 0.5,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding'			: 0
	});
		
		J("a.tooltip").fancybox({
		'hideOnContentClick': false,
		'width'				: 400,
		'height'			: 260,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'ajax',
		'padding'			: 0
	});
	
		J("a.tooltip-vid").fancybox({
		'hideOnContentClick': false,
		'width'				: 720,
		'height'			: 480,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding'			: 0
	});

	J("a.backdoor-vid").fancybox({
		'hideOnContentClick': false,
		'width'				: 900,
		'height'			: 506,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'padding'			: 0
	});	
		J("a.bio-vid").fancybox({
		'hideOnContentClick': false,
		'width'				: 720,
		'height'			: 410,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false,
		'padding'			: 0
	});
		
		J("a.shop_online").fancybox({
		'hideOnContentClick': false,
		'width'				: 400,
		'height'			: 260,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding'			: 0
	});
		
		J("a.acc_shop_online").fancybox({
		'hideOnContentClick': false,
		'width'				: 400,
		'height'			: 260,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleShow'				: false,
		'padding'			: 0
	});
		
	});
