var Tabs = {
	init: function() {
		if (! $.fn.tabs) return;
		var x = 0;
		var $tabs = $('#Tabs');
		var $tabnav = $tabs.prepend('<ul class="tabNav selfClear"></ul>').find('>ul');
		$tabs	.find('>div')
					.each( function(i) {
						var li_class = "";
						if (x == 0) { li_class = "first"; }
						var id = this.id;
						var title = $(this).metadata().tabTitle;
						var extra_class = $(this).metadata().liClass;
						li_class += " " + extra_class;
						$tabnav.append('<li class="' + li_class + '"><a href="#' + id + '" id="' + id + 'Tab" class="noPopup"><span>' + title + '</span></a></li>');
						x++;
					});
		setTimeout(function() { $tabs.tabs(); }, 500);
	}
};
$(document).ready(Tabs.init);


// Prevent ajax calls from caching.
$.ajaxSetup({
	cache: false
});
$('#Search select').live('change', function() {
	var selected_product = $('select#product').val();
	var selected_date = $('select#date').val();
	//var load_page = "/product-updates/" + selected_product + "/" + selected_date + " #ProductUpdateInfo";
	var load_page = "/product-updates/" + selected_product + " #ProductUpdateInfo"; // Using this until we have more content
	$('#ProductUpdateContainer').load(load_page, function(response, status, xhr) {
		if (status == "error") {
			var msg = "no data.";
			$("#ProductUpdateInfo").html(msg);
		}
		else {
			Tabs.init();
		}
	});
});

/* begin - open new window for external links and pdfs */
	$(function() {
		$('#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]:not([href^=http://])').popupwindow(); // PDFs by URL
		$('#Wrapper a.popup').popupwindow(); // specific links
	});
/* end - open new window for external links and pdfs */
