// avoid jQuery namespace issues with mootools library
jQuery.noConflict();

jQuery(document).ready(function() {

	// initialize superfish nav bar with drop downs
	jQuery('ul#nav').supersubs({ 
		minWidth:    13.5,
		maxWidth:    45,
		extraWidth:  1
	}).superfish({
		delay:       500,
		animation:   {opacity:'show',height:'show'},
		speed:       'fast',
		autoArrows:  false,
		dropShadows: false
	});
	
	// add pseudo-class functionality
	jQuery('ul#nav li:first-child a').addClass('nav-start');
	jQuery('ul#nav li:last-child a').addClass('nav-end');
	jQuery('#videos h3:first-child').css('margin-top','0');
	jQuery('.box:first-child').css('margin-left','0');
	jQuery('.category:last-child').css('border','0');
	jQuery('blockquote p:last-child').css('margin-bottom','0');
	jQuery('.webcasts ul.webcast-listing li .webcast-date').prepend('<span>&#8226;</span>');
	
	// when user is logged in toggle h1 tag on "My Account" screen
	//jQuery('.logged-in h1').html(jQuery('#header ul li:first-child a').html());
	
	// add form fields' default values
	jQuery('#txt-email').defaultValue('Email Address');
	jQuery('#txt-search').defaultValue('Search');
	
	// convert mailto links
	jQuery('span.mailme').mailme();
	
	// expand/contract "read more" links
	jQuery('.read-more-desc').click(function () {
		jQuery(this).closest('p').next().slideToggle();
		return false;
	});
	
	// show/hide our homepage seo text
	jQuery('#seoinsert h3 a').click(function() {
		jQuery('#seoinsert div').slideToggle();
		return false;
	});
	
	// generate random banner for subpages
	var iRand = Math.ceil(Math.random()*7);
	jQuery('body:not(.home) #banner').css('background','url("/squirrelcart/themes/jackdaly/images/bg-banner-quote_0'+iRand+'.jpg") 0 0 no-repeat');
	
	// configure hoverIntent
	var hi_config = {
		sensitivity:	7,				// number = sensitivity threshold (must be 1 or higher)
		interval:		200,			// number = milliseconds for onMouseOver polling interval
		over:			toggleAction,	// function = onMouseOver callback (REQUIRED)
		timeout:		200,			// number = milliseconds delay before onMouseOut
		out:			toggleAction	// function = onMouseOut callback (REQUIRED)
	};
	
	function toggleAction() { jQuery('.action-more',this).slideToggle(400); }
	
	// attach hoverIntent to our "actions." chain the hover method as well to retain our desired mouseover action before hoverIntent takes over
	jQuery('ul#actions li').hoverIntent(hi_config).hover(function () {
		jQuery('div.action',this).toggleClass('action-over');
	});
	
	// force target="_blank" equivalent
	jQuery('a[rel="external"]').click(function(){
		window.open(this.href);
		return false;
	});
	
	// ensure certain forms submit to a new window
	jQuery('form#newsletter').attr('target','_blank');
	
	var cache = [];
	// arguments are image paths relative to the current page.
	jQuery.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
	
	jQuery.preLoadImages('/squirrelcart/themes/jackdaly/images/actions-over.png');
	
});

// after all images have loaded...
jQuery(window).load(function() {
	jQuery('.box').equalHeights();
});