$(document).ready(function() {
	
	//On Hover Over
function megaHoverOver(){
    $(this).find("#showroom").stop().fadeTo(10, 1).show();
  }
//On Hover Out
function megaHoverOut(){
  $(this).find("#showroom").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: 10, // 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 li.top_navi_item #showroom").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul li.top_navi_item").hoverIntent(config); //Trigger Hover intent with custom configurations
	
});

//MAIN SLIDER

		$(function(){
			$('#loopedslider').loopedSlider({
			autoStart: 8000,
			addPagination: true,
			containerClick: false
			});
		});
//CAR CONTENT SLIDER
		$(function(){
			$('#loopedslider_car_gallery').loopedSlider({
			autoStart: 8000,
			addPagination: true,
			container: ".gallery_container",
			slides: ".gallery_slides",
			addPagination: true 
			});
		});

//QUICK BOSES CAROUSEL		
		$(function(){
    		$(".quick_boxes_carousel").jCarouselLite({
        		btnNext: ".next",
        		btnPrev: ".prev",
        		visible: 4,
				mouseWheel: true

    		});
		});
		


/* Navigation SubMenu */
$(document).ready(function(){
		$("#Showroom1").click(function() { 
		$("div.showroom_recreational").stop(true, true).hide();
        $("div.showroom_lifestyle").stop(true, true).show();
		$("#Showroom1").addClass('active');
		$("#Showroom2, #Showroom3 ").removeClass('active');
		
}); 
		$("#Showroom2").click(function() { 
		$("div.showroom_lifestyle").stop(true, true).hide();
        $("div.showroom_recreational").stop(true, true).show();
		$("#Showroom2").addClass('active');
		$("#Showroom1, #Showroom3 ").removeClass('active');
}); 

});  

/* Navigation MOUSE ON Slider */
$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.showroom_lifestyle'),
		ul = $('ul.showroom_lifestyle'),
		ulPadding = 15;
	
	//Get menu width
	var divWidth = 780;
 
	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});

// JavaScript Document
//Thanks to Karl Swedberg 
//http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12

$(document).ready(function(){
  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 500);
       return false;
      }
    }
  });
});

/*new car color selection*/
$(document).ready(function(){
	$(".colors_list li").hover(
	function () {
		$(this).addClass("hover_color");
		$('.hover_color span').stop(true, true).fadeIn(100);
		if( $(this).hasClass('active_color') ) {}
		else
		{
		$('.active_color span').stop(true, true).fadeOut();
		};
		$(this).siblings("li").stop(true, true).removeClass("hover_color");
	},
	function () {
		if( $(this).hasClass('active_color') ) {}
		else
		{
		$('.hover_color span').fadeOut();
		};
		$(this).removeClass("hover_color");
		$('.active_color span').stop(true, true).delay(500).fadeIn(500);

});
});

/* NEW CAR GALLERY*/
$(document).ready(function() {

			$("a[rel=hyundai_gallery_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Hyundai image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

		});



