$(document).ready(
   function() {
      $(".container").wtGridGallery({
            num_col:4,
            num_row:2,
            screen_width:990,
            screen_height:410,
            item_width:75,
            item_height:75,
            item_margin:8,
            display_number:true,
            display_playbutton:false,
            display_dbuttons:true,
            display_advbuttons:false,
            display_textbutton:false,
            display_downloadbutton:false,
            display_tooltip:false,
            display_caption:true,
            display_timer:true,
            display_gallery_info:false,
            effect:"slide",
            transition_speed:700,
            easing:"",
            text_effect:"fade",
            text_sync:true,
            text_on:true,
            cpanel_float:false,
            cpanel_mouseover:false,
            auto_scale:true,
            cont_nav:true,
            auto_rotate:true,
            delay:5000,
            initial_open:false,
            selected_category:1,
            selected_image:1
      });
      

	$("#various5").fancybox({
		'width'				: 535,
		'height'			: 580,
        'autoScale'     	: false,
        'transitionIn'		: 'elastic',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$("a#example1").fancybox();
	
	$("#vimeo_test1").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28108210',
		'type'			: 'swf'
	});
	
	$("#vimeo_test2").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28107694',
		'type'			: 'swf'
	});
	
	$("#vimeo_test3").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28000478',
		'type'			: 'swf'
	});
	
	$("#vimeo_test4").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=27809681',
		'type'			: 'swf'
	});
	
	$("#vimeo_test5").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=33900759',
		'type'			: 'swf'
	});
	
	
	
	
	
	
	
	
	
	$("#vimeo_test1a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28108210',
		'type'			: 'swf'
	});
	
	$("#vimeo_test2a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28107694',
		'type'			: 'swf'
	});
	
	$("#vimeo_test3a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=28000478',
		'type'			: 'swf'
	});
	
	$("#vimeo_test4a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=27809681',
		'type'			: 'swf'
	});
	
	$("#vimeo_test5a").fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'			: 635,
		'height'		: 358,
		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=33900759',
		'type'			: 'swf'
	});

      
      $('INPUT.auto-hint').each(function(i, el){
			
			if($(this).val() == ''){
				$(this).val($(this).attr('title'));
			}
			
			$(el).focus(function(){
				if ($(this).val() == $(this).attr('title')) {
					$(this).val('');
				}       
			});
			
			$(el).blur(function(){
				if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
				}
			});
		});
		
		$('#news-item').jcarousel({
    		wrap: 'circular',
			scroll: 1,
			auto: 4
    	});
    	
    	function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}

//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: 500, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
   }
);
