//general jQuery
jQuery(document).ready(function() {
	jQuery('ul#main_catnav ul').addClass('clearfix');
	jQuery('#slider ul').attr('id', 'mycarousel').addClass('clearfix jcarousel-skin-tango');
	jQuery('li.dsq-widget-item a').attr('target', '_blank').removeAttr("onclick");
	jQuery('div.text_area img[title=auto-gallery], div.text_area img[title=title-gallery]').removeAttr("width").removeAttr("height");
});


//jQuery solution for VERY long drop down menus
var maxHeight = 406;

jQuery(document).ready(function(){
	
	var config = {
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		interval: 200, // number = milliseconds for onMouseOver polling interval
		over: doOpen, // function = onMouseOver callback (REQUIRED)
		timeout: 600, // number = milliseconds delay before onMouseOut
		out: doClose // function = onMouseOut callback (REQUIRED)
	};

	function doOpen() {
	
		jQuery(this).addClass("hover");
		jQuery('ul:first',this).fadeIn();
	
		if( jQuery(this).hasClass('catvehmake') ) {
			var jQuerycontainer = jQuery(this);
			jQuerylist = jQuerycontainer.find("ul");
            jQueryanchor = jQuerycontainer.find("a");
            height = jQuerylist.height() * 1.1;       // make sure there is enough room at the bottom
            multiplier = height / maxHeight;     // needs to move faster if list is taller
			
			// need to save height here so it can revert on mouseout            
			jQuerycontainer.data("origHeight", jQuerycontainer.height());
        
			// so it can retain it's rollover color all the while the dropdown is open
			//jQuery('ul#main_catnav li.catvehmake').addClass("hover");
			
			// make sure dropdown appears directly below parent list item    
			jQuerylist
				.show()
				.css({
					marginTop: "42px"
				});	
			
			// hides the dropdown beneath the parent	
			jQuery('ul#main_catnav').css({overflow: "hidden"});
        
			// don't do any animation if list shorter than max
			if (multiplier > 1) {			
				jQuerycontainer
					.css({
						height: maxHeight					
					})
					.mousemove(function(e) {
						var offset = jQuerycontainer.offset();
						//console.log(jQuerycontainer.offset());
						var relativeY = ((e.pageY - offset.top) * multiplier) - (jQuerycontainer.data("origHeight") * multiplier);
						if (relativeY > jQuerycontainer.data("origHeight")) {
							jQuerylist.css("top", -relativeY + jQuerycontainer.data("origHeight"));
						};
					});
			}
		} 
	}

	function doClose() {
		jQuery(this).removeClass("hover");
		jQuery('ul:first',this).fadeOut();
		
		if( jQuery(this).hasClass('catvehmake') ) {
			var jQueryel = jQuery(this);
			// put things back to normal
			jQueryel
				.height(jQuery(this).data("origHeight"))
				.find("ul")
				.css({ top: 0 })
				.hide()
				.end();
			jQuery('ul#main_catnav').css({overflow: "visible"});

		}
	}
	
	jQuery("ul#main_catnav li, ul#main_catnav li ul li:has(ul)").hoverIntent(config);


    // Add down arrow only to menu items with submenus
    jQuery("#main_catnav ul > li:has('ul')").each(function() {
        jQuery(this).find("a:first").append("<span class='has_ul'>&nbsp;&nbsp;&nbsp;&gt;</span>");
    });


});

