$(document).ready(function() {


	/* Main Nav */
	$("ul#main_nav li").hover(function(){
	
	    $(this).addClass("hover");
	    $('ul:first',this).css('visibility', 'visible');
	
	}, function(){
	
	    $(this).removeClass("hover");
	    $('ul:first',this).css('visibility', 'hidden');
	
	});

	/* Linkscrubber */	
	$("a").bind("focus",function(){if(this.blur)this.blur();});
	$("input[type='image']").bind("focus",function(){if(this.blur)this.blur();});
	
	/* Cufon */
	Cufon.set('fontFamily', 'ColossalisMedium').replace('h1');
	Cufon.set('fontFamily', 'ColossalisBold').replace('h2');
	Cufon.set('fontFamily', 'UniversLTStd').replace('.intro');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.oldest-isuzu h3');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.oldest-isuzu h4');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.oldest-isuzu h4');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.bottom_block .hmc h2');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.bottom_block .hmc h3');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.ora-image-gallery .quick-tools a');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.ora .image-upload div.uploader span.action');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.ora .image-upload h3');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.ora #map_container .panel_title div');
	Cufon.set('fontFamily', 'ColossalisMedium').replace('.ora h3');
	//Cufon.set('fontFamily', 'UniversLTStd').replace('.bottom_block .hmc p');
	
	
//	/* Right Nav */
//	$('#right_nav ul').hide();
//	$('#right_nav > li a').click(
//		function(e) {
//			if ($(e.target).has('ul').is('#right_nav > li a')) {
//             e.preventDefault();
//         }
// 			var checkElement = $(this).next();
//			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
//				return false;
//			}
//			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
//				$('#right_nav ul:visible').slideUp('normal');
//				checkElement.slideDown('normal');
//				return false;
//			}
//		}
//	);
	
	// smooth back to top
	$("a.btop").click(function() {
		$("html, body").animate({
			scrollTop: $($(this).attr("href")).offset().top + "px"
		}, {
			duration: 500,
			easing: "swing"
		});
		return false;
	});
	
	//Table Style
	$(".table_style tr").hover(
		function() {
			$(this).addClass('over');
		},
		function() {
			$(this).removeClass('over');
		}
	);
	
	$(".table_style tr:even, .table_style_comparison tr:even").addClass('alt');
	$(".table_style tr td:nth-child(1), .table_style tr th:nth-child(1)").addClass('first');
	
	// send to friend modal
	$("a.send, a.email,").live("click", (function(event) {
		event.preventDefault();
		$('#sendtofriend').modal({containerCss:{marginLeft: -180, marginTop: -190, padding:0}});
	}));
	
	// send to friend modal
	$(".share-buttons a.gallery_stf").live("click", (function(event) {
		event.preventDefault();
		$('#sendtofriend_gallery').modal({containerCss:{marginLeft: -180, marginTop: -190, padding:0}});
	}));
	
	$(".hmc .entries a.entry_fullstory, #mileage-feature .mf-entry-content a, #mileage-feature .mf-entry-content a.entry_fullstory").fancybox({
                                'width'				: 648,
                                'height'			: 780,
                                'autoScale'			: false,
                                'transitionIn'		: 'none',
                                'transitionOut'		: 'none',
                                'type'				: 'iframe'
        });
	
	$("a.iframe-modal").fancybox({
                        'width'				: 701,
                        'height'			: 1500,
                        'autoScale'			: true,
                        'transitionIn'		: 'none',
                        'transitionOut'		: 'none',
                        'type'				: 'iframe'
        });

	$("#load_fb").fancybox({
                                'width'				: 648,
                                'height'			: 780,
                                'autoScale'			: false,
                                'transitionIn'		: 'none',
                                'transitionOut'		: 'none',
                                'type'				: 'iframe'
        }).trigger('click');
	// High Mileage Club Infographic Modal
	
	$(".hmc #content_bottom_left .content_body .infographic a").fancybox();
	
	$("a.modal").fancybox({
                'width' : 977,
                'height' : 570,
                'autoScale' : false,
                'type' : 'iframe'
        });
	
	$(".wallpaper:nth-child(3n), .video:nth-child(3n)").addClass('last');

	// Gallery Album Rollovers
	$('.oa_gallery_albumlist .clickthrough, .oa_shop_albumlist .clickthrough').hide();
	$('.oa_gallery_albumlist li, .oa_shop_albumlist li').hover(function() {
		$('.clickthrough', this).show();
	}, function() {
		$('.clickthrough', this).hide();
	});
	
	$("input.file, textarea, .uniform").uniform();
	//$(".ora .image-upload input:file").uniform({fileDefaultText: 'Select a file please', fileBtnText: 'Click here to upload an image'});
	
	function setupPinpoints()
	{
            $("a.pinpoint").fancybox({
                    'width'			: 701,
                    'height'			: 534,
                    'autoScale'			: true,
                    'transitionIn'		: 'none',
                    'transitionOut'		: 'none',
                    'type'			: 'iframe'
            });
        }

	$.setupPinpoints = setupPinpoints;
	$.setupPinpoints();
	
        function setupMapModal()
	{
            $("a.map-modal").fancybox({
                    'width'			: 701,
                    'height'			: 534,
                    'autoScale'			: true,
                    'transitionIn'		: 'none',
                    'transitionOut'		: 'none',
                    'type'			: 'iframe'
            });
        }

	$.setupMapModal = setupMapModal;
	$.setupMapModal();
	
	//console.log('done');
});
