function addToCart(drid) {
	var quantity = $("#quantity" + drid).val();
	document.location = DR_addToCart_URL + '/productID.' + drid + '/quantity.' + quantity;
}
// Fix background image flickering in IE
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }

// IE6 alpha PNG support
// http://www.dillerdesign.com/experiment/DD_belatedPNG/
var DD_belatedPNG;
if (DD_belatedPNG) {
	DD_belatedPNG.fix('body.home #Mast li.one, .featureBox .channel .icon img, .featuredWebcast p.image img, .featureBox .speaker p.logo img, .featuredWebcast p img');
}

/* Special search behavior */
var Search = {
  prompt: "Search", // default value - should get real value from markup
  init: function() { this.prompt = jQuery('#search').focus(this.focus).blur(this.blur).val(); },
  focus: function() { if (this.value == Search.prompt) { this.value = ''; } },
  blur: function() { if (this.value.length == 0) { this.value = Search.prompt; } }
};

jQuery(function() {
  Search.init();
});

// Convert on-tabbed display into tabbed display and activate tabs
$(document).ready(function() {
	var $tabs = $('div.tabs');
	var $tabnav = $tabs.find('ul.tabNav');
	if ($tabnav.length == 0) {
		$tabnav = $tabs.prepend('<ul class="tabNav selfclear"></li>').find('> ul');
		$tabs	.find('> div')
			.each( function(i) {
				var id = this.id;
				var $h2 = $(this).find('h2');
				var title = $h2.html();
				$tabnav.append('<li><a href="#' + id + '" class="noPopup"><span>' + title + '</span></a></li>');
				$h2.remove();
			});
			// Need delay for browsers to get their DOM in order
			setTimeout(function() { $tabs.tabs(); }, 500);

			window.scrollTo(0,0);
	}
});

/* begin - Navigation Primary */
var NavigationPrimary = {
  init: function() {    
		var c = this;
		var n = $('#NavigationPrimary ul');
		
		// Use bgiframe to fix dropdowns over selects if it's available.
		$.fn.bgiframe && $('li', n).bgiframe();

		// Mark parent elements so that we can style them with CSS
		$('> li', n).each(function() { c.markParents(this); });
  	
  	// Use the hoverintent plugin if it's available
  	// if ($.fn.hoverIntent)
  	//     {
  	//   $('li', n).hoverIntent( {
  	//     sensitivity: 1,
  	//     over: this.mouseenter,
  	//     out: this.mouseleave,
  	//     timeout: 100
  	//   });
  	//     }
  	// else
  	  $('li', n).hover(this.mouseenter, this.mouseleave);
  },
  markParents: function(li) {
    var c = this;
    if ($('> ul', li).size() > 0)
	    $(li).addClass('parent').find('> a').addClass('parent').end().find('> ul li').each( function() { c.markParents(this); });
	},
	mouseenter: function() { $(this).addClass('over').children('a').addClass('over'); },
	mouseleave: function() { $(this).removeClass('over').children('a').removeClass('over'); }
};
$(function() { NavigationPrimary.init(); });
/* end - Primary Navigation */


$(function() {
	// open new window for external links and pdfs
	$('#Wrapper a[href^=http://]')
		.not($('a.noPopup'))
		.popupwindow(); // Fully qualified links
	$('#Wrapper a[href^=https://]')
		.not($('a.noPopup'))
		.popupwindow(); // Secure HTTP connection links
	$('#Wrapper a[href$=.pdf]').popupwindow(); // PDFs by URL
	$('#Wrapper a[href$=.png]').popupwindow(); // PDFs by URL
	$('#Wrapper a.popup').popupwindow(); // specific links
	
	// Setup jCarousel for rotating quotes on the Home page
	$('.carousel > ul > li').removeClass('hiddenQuote');
   $(".carousel").jCarouselLite({
       btnPrev: ".previous",
       btnNext: ".next",
       visible: 1
   });
	
	// Fix PNGs on Solutions index 
	var DD_belatedPNG;
	
	if (DD_belatedPNG)
		DD_belatedPNG.fix('.solutionsBox .solution, .resourceCenter p.more a');
});

function moduleImageSwap(img) {
	if (img) {
		$('#ContentChannel .productModules img').attr('src','/images/products/' + img);
	}
	else {
		$('#ContentChannel .productModules img').attr('src','/images/products/modules-default.png');
	}
}

function platformImageSwap(img) {
	if (img) {
		$('#ContentChannel .platformGraphic img').attr('src','/images/products/' + img);
	}
	else {
		$('#ContentChannel .platformGraphic img').attr('src','/images/products/platform-default.png');
	}
}

var HomeCarousel = {
	carousel: null,
	clicked: 0,
	init: function() {
		$('#HomeCarousel').each(function(i) {
			$(this).find('li.hideOnLoad').removeClass('hideOnLoad').css({opacity: .001});
			$(this).jcarousel({
				// auto: 2,
				wrap: 'last',
				visible: 1,
				scroll: 1,
				itemVisibleInCallback: HomeCarousel.itemVisibleInCallback,
				initCallback: HomeCarousel.initCallback,
				animation: 0
}).after('<ul class="carouselNav"><li class="one active">1</li><li class="two">2</li><li class="three">3</li><li class="four">4</li><li class="five">5</li></ul>');
			$('ul.carouselNav li')	.live('click', HomeCarousel.navClick)
									.live('mouseover', HomeCarousel.navMouseover)
									.live('mouseout', HomeCarousel.navMouseout);
		});
	},
	/* Called when the image/slide loads. First it fades in the new image, then
		it uses jQuery's animate function to delay before fading out the image.
		Once the image has faded out there is a callback to tell the carousel
		to transition to the next slide/image and the process starts over again.
	*/
	itemVisibleInCallback: function(c, el, i, state) {
		$('ul.carouselNav').find('li.active').removeClass('active').end().find('li:eq(' + (i - 1) + ')').addClass('active');
		$(el).fadeTo('slow', 1.0, function() {
			setTimeout(function() {
				$(el)
		 				// Must animate almost to 0, cause if we go to 0, then the element
						// gets display="none" and it auto switches to the next slide
						.fadeTo('slow', 0.001, function() {
							if (HomeCarousel.clicked == 0)
								c.next();
							else
								HomeCarousel.clicked--;
						} );
			}, 3000); // delay
		});
	},
	initCallback: function(carousel) {
		HomeCarousel.carousel = carousel;
	},
	navClick: function(e) {
		HomeCarousel.clicked++;
		HomeCarousel.carousel.scroll($.jcarousel.intval($(this).text()));
	},
	navMouseover: function(e) {
		$(this).addClass('hover');
	},
	navMouseout: function(e) {
		$(this).removeClass('hover');
	}
};
$(document).ready(HomeCarousel.init);

var NewsletterSubscribe = {
	prompt: 'Your Email Address',
	init: function() {
		var NS = NewsletterSubscribe;
		NS.prompt = $('#subscribe_email').focus(NS.focus).blur(NS.blur).val();
		$('#SubscribeForm,#SubscribeForm2').submit(NS.submitForm);
	},
	focus: function(e) {
		if (this.value == NewsletterSubscribe.prompt) this.value = '';
	},
	blur: function(e) {
		if (this.value.length == 0) this.value = NewsletterSubscribe.prompt;
	},
	submitForm: function(e) {
		e.preventDefault();
		var post_data = $(this).serialize();
		post_data += '&submit=Submit';
		var $form = $('#SubscribeForm,#SubscribeForm2');
		var url = $form.attr('action');
		$.post(url, post_data, function(data) {
			$form.replaceWith($(data).find('#SubscribeResult').html());
		});
	}
};

$(document).ready(NewsletterSubscribe.init);
