$(document).ready( function(){

	// times are in milliseconds
	// see http://www.malsup.com/jquery/cycle/options.html for all options
	$('#right_testimonials').cycle({ 
    	fx:            'fade',
		timeout:       3500,
		speed:         5000,
		cleartypeNoBg: true,
		pause:         1
	});

	// Used on product pages (ex: talkswitch) for additional images.
	// generates needed thumbnails, to cut down on HTML code.
	// Note : cycle has added example/support for thumbnail pagers
	// see : http://jquery.malsup.com/cycle/pager2.html for details
	$(".cycle-thumbs").parent().append('<div id="smallimages" class="cyclethumbsnav"></div>');
	// Now, add all of the images as 'thumbnails' in the pager container,
	// with all needed html, ids, classes, etc for the cycle pager
	$(".cycle-thumbs img").each(function() {
		$("#smallimages").append('<span><a href="#"><img src="'+$(this).attr('src')+'" width="50" border="0" /></a></span>');
	});
	// Finally, call the cycle plug-in
	$(".cycle-thumbs").cycle({
		fx:      'scrollHorz',
		speed:   'slow',
		fit:     1,
		timeout: 0, 
		pager:   '#smallimages', 
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#smallimages span:eq(' + idx + ') a'; 
		}
	});
	$(".cycle").cycle();


	// Request quote forms. Provides 'slide through steps' interface
	function quoteOnAfter(curr, next, opts) {
		var index = opts.currSlide;
		$('.prev')[index == 0 ? 'hide' : 'show']();
		$('.next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		$('.done')[index == opts.slideCount - 1 ? 'show' : 'hide']();
	}

	$(".request-form").cycle({
		fx:    'scrollHorz',
		timeout:       0,
		next:          '.next',
		prev:          '.prev',
		nowrap:        1,
		pager:         '#pager',
		cleartypeNoBg: true,
		speed:         500,
		after:         quoteOnAfter
	});

	$('.dropshadow').dropShadow();

	$('.definition').each( function() { $(this).tinyTips(
		'light',
		'test text'
	)});


	$('.definition').each( function() {

		var url = $(this).attr('href');
		var prePound = url.substring( 0, url.indexOf('#') ) + '?nocache=' + Math.random();
		var postPound = url.substring( url.indexOf('#') + 1, url.length );
		var curObj = $(this);
		var curObjText = curObj.text();

		$(this).append('<img src="/images/icons/magnify.png" />')
			.css({
				 textDecoration : 'none',
				 color: '#000',
				 cursor: 'text',
				 borderBottom: '1px solid #ddd',
				 cursor: 'help'
		})
		$.get( prePound, function(data) {
			var tipContent = $(data).find( "a[name=" + postPound + "]" );
			if ( tipContent.text() == '' ) { tipContent = "<b>We're Sorry</b><br />There doesn't seem to be a definition for <i>\"" + curObjText + "\"</i>."; }
			curObj.tinyTips(
				'light',
				tipContent
			);
		});
	});
/*
	$('#footer > div > ul > li').each(function(){
			var obj = $(this);
			var objHtml = obj.html();
			var objChildHtml = obj.children('span').html();

			obj.hover(function(){
				obj.html('<div style="width:' + (obj.width()+10) + 'px;">' + objChildHtml + '</div>').stop(true,true).addClass('hover',750,'easeOutBounce');
			},
				function() { obj.stop(true,true).removeClass('hover').html(objHtml); }
			);
		});
*/
});

// Standard hover attachments for IE < 8

sfHover = function() {
	var sfEls = document.getElementById("footer").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
// IE is uber retarded and doesn't want to clear hte menus in some cases.
// So, force it once the ul is left.
doyIE = function() {
	var evObj = document.getElementById("footer").getElementsByTagName("UL");
	for (var i=0; i<evObj.length; i++) {
		evObj[i].onmouseout=function() {
			// We don't have classes on the LI's, so just clear them
			this.getElementsByTagName("LI").className='';
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", doyIE);
