$(document).ready(function(){
	$("ul.nav").superfish({ 
		delay:       800,                            // delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false,
		dropShadows: false
	}); 
	$(".tablesorter").tablesorter({
		widgets: ['zebra']
	});
	googleTrackDownloads();
	if($.browser.msie) selectFixes.init();
});

function googleTrackDownloads(){
	$("a.trackLink").bind("click", function(e) {
		var pageViewed = $(this).attr("href");
		pageTracker._trackPageview(pageViewed);
		return true;
	});
}

function valRegForm() {
	$(document).ready(function() {
		$('#whitepaper').submit(function() {
			var reqFields = {
				'#first_name':'First name',
				'#last_name':'Last name',
				'#phone':'Phone',
				'#email':'Business email',
				'#userTitle':'Title',
				'#department':'Department',
				'#company':'Company',
				'#address':'Address',
				'#city':'City',
				'#state':'State or province',
				'#country':'Country',
				'#zip':'Zip or postal code',
				'#industry':'Business/Industry',
				'#employees':'Number of Employees',
				'#interest_level':'Level of Interest'
			};
			var isError = false;
			var error = 'The following fields are required:'+"\n";
			$.each(reqFields, function(id,label) {
				var field = $(id);
				if(field.val() == false) {
					isError = true;
					error = error + label + "\n";
				}
			})
			if(isError == true) {
				alert(error);
				return false;
			} else {
				return true;
			}
		});
	});
}

var selectFixes = {
	init: function() {
		$(".expandSelect select").mousedown(function(){
			if(!$(this).data('oW')) $(this).data('oW', $(this).width() + 7);
			$(this).css('width', 'auto');
		}).bind('change blur select',function(){
			$(this).css('width', $(this).data('oW'));
		});
	}
}

// var IEDropdown = {
// 	initialize: function() {
// 		$('.expandSelect').each(function() {
// 			$(this).data('originalWidth') = $(this).width();
// 			$(this).data('dontWiden') = false;
// 			Event.observe(this.element, 'mousedown', this.widen.bindAsEventListener(this));
// 			Event.observe(this.element, 'blur', this.shrink.bindAsEventListener(this));
// 			Event.observe(this.element, 'change', this.shrink.bindAsEventListener(this));
// 		});
// 		
// 	},
// 
// 	widen: function(e) {
// 		if(this.dontWiden) return;
// 		var styledWidth = this.element.offsetWidth;
// 		this.element.style.width = 'auto';
// 		var desiredWidth = this.element.offsetWidth;
// 		// If this control needs less than it was styled for, then we don't need to bother with widening it.
// 		if(desiredWidth < styledWidth) {
// 			this.dontWiden = true;
// 			this.element.style.width = this.originalWidth;
// 			this.element.click(); // Simulate another click, since setting styles has already caused the box to close at this point.
// 		}
// 	},
// 
// 	shrink: function(e) {
// 		this.element.style.width = this.originalWidth;
// 	}
// };

function showVideo(flvFile,fWidth,fHeight,id,autoPlay,image) {
	var flashvars = {
		autostart : autoPlay,
		image : image,
		file : flvFile
	};
	var params = {
		wmode : 'transparent'
	};
	var attributes = {};
	swfobject.embedSWF('fileadmin/templates/flash/flvplayer.swf', id, fWidth, fHeight,"9.0.0",'',flashvars, params, attributes);
}