var utils = new function()
{
	this.getBrowser = function()
	{
		var browser = 'unknown';
		
		if (navigator.userAgent.indexOf("Chrome") != -1)
			browser = 'chrome';
		else if (navigator.userAgent.indexOf("MSIE") != -1)
			browser = 'ie';
		else if(navigator.userAgent.indexOf("Safari") != -1)
			browser = 'safari';
		else if (navigator.userAgent.indexOf("Firefox") != -1)
			browser = 'firefox';
		
		return browser;
	}
	
	function guide(browser,text)
	{
		var shade = jQuery('<div />');
		shade.addClass('downloadGuideBg');
		
		var tooltip = jQuery('<div><ol>'+text+'</ol></div>');
		
		tooltip.addClass('downloadGuide');
		tooltip.attr('id',browser);

		jQuery('body').append(shade);
		shade.fadeIn('slow',function(){
				jQuery('body').append(tooltip);
				tooltip.fadeIn('slow');		
			});

		shade.click(function(){
				tooltip.fadeOut('slow',function(){
						shade.fadeOut('slow',function(){
								shade.remove();
								tooltip.remove();
							});
					});
			});
		
		if (typeof pageTracker != 'undefined')
			pageTracker._trackPageview('/download');
	}
	
	function guideForFirefox()
	{
		guide('firefox','<li>Click "Allow"<li>Click "Install Now"<li>After installing, restart Firefox');
	}

	function guideForChrome()
	{
		guide('chrome','<li>Click "Continue"<li>Click "Install"<li>Wait for WiseStamp to be opened');
	}

	this.showDownloadGuide = function()
	{
		var func = null;
		
		switch (this.getBrowser())
		{
		case 'firefox':
			guideForFirefox();
			break;
		case 'chrome':
			guideForChrome();
			break;
		}
	}
	
	this.initDownloadGuide = function()
	{
		var thisObj = this;
		jQuery('body a[href^="/download"]').click(function(){thisObj.showDownloadGuide()});
		jQuery('body a[href^="http://www.wisestamp.com/download"]').click(function(){thisObj.showDownloadGuide()});
		jQuery('body a.downloadGuideLink').click(function(){thisObj.showDownloadGuide()});
	}
	
	this.showPopup = function(html,width,height)
	{
		if (typeof width == 'undefined')
			width = 400;
		
		if (typeof height == 'undefined')
			height = 300;
		
		var shade = jQuery('<div />');
		shade.addClass('overlay_shade');
		
		var content = jQuery('<div id=popupDlg></div>');
		content.append(html);
		
		jQuery('body').append(shade);
		shade.fadeIn('fast',function(){
				jQuery('body').append(content);
				content.css({
						'margin-left':'-'+width/2+'px',
						'margin-top':'-'+height/2+'px',
						'width': width+'px',
						'height': height+'px'
					});
			
				content.fadeIn('fast',function(){content.find('input:eq(0)').focus();});		
			});

		function closePreview()
		{
			content.fadeOut('fast',function(){
					shade.fadeOut('fast',function(){
							shade.remove();
							content.remove();
						});
				});
		}
		
		shade.click(closePreview);
		content.find('input#close').click(closePreview);
	}
}
