/**
 * upgrade plugin
 * ----------------------------------------------------------------------------------------------------
 * jquery.upgrade.js
 * 
 * Detects if IE 6 is the current browser, if it is and displays options to upgrade include IE 8,
 * FF 3.5, Chrome 4, and Safari 4.
 *
 * requires:
 * ----------------------------------------------------------------------------------------------------
 * jquery.cookie.js
 * http://plugins.jquery.com/project/cookie
 *
 */
 
jQuery.upgrade = function(options){ 
	
	// defaults
	var defaults = {z_index: 1000, image_path:'./images/upgrade/', delay:2000, expires:(3 * 24 * 60 * 60 * 1000)}
	
	// options
	var options =  $.extend(defaults, options);  
	
	//IE 6 browser and cookie check
	if($.browser.msie && $.browser.version < 7 && $.cookie('jquery-browser-upgrade') != 'true'){
		
		//get browser window to set width as 100% doesn't work correctly in IE 6
		var browser		= $(window);
		
		//styles for bar
		var linkStyle	= 'style="margin-left: 20px; text-decoration: none; color: #000000;"';
		var imgStyle	= 'style="vertical-align: middle; margin: 0px 10px 0px 10px; border: 0px;"';
		
		//add bar
		$('body').append('<div id="upgrade" style="display: none; position: absolute; top: 0px; left: 0px; width: '+browser.width()+'px; padding-top: 8px; padding-bottom: 8px; font-family: Helvetica, Arial, sans-serif; font-size: 12px; background: #eeeeee; border-bottom: 1px solid #cccccc; z-index: '+options.z_index+';"><div id="upgrade_msg" style="float: left; display: block;"><img src="'+options.image_path+'error.gif" style="vertical-align: middle; margin: 0px 10px 0px 10px;" /><strong>WARNING</strong>: Your current browser is not fully supported. Please upgrade to one of these more modern browsers.</div><div id="upgrade_links" style="float: right; display: block; width: 560px;"><a href="http://www.microsoft.com/windows/internet-explorer/" target="_blank" '+linkStyle+'><img src="'+options.image_path+'ie8.gif" '+imgStyle+' />Internet Explorer 8</a> <a href="http://www.mozilla.com/firefox/" target="_blank" '+linkStyle+'><img src="'+options.image_path+'ff.gif" '+imgStyle+' />FireFox 3.5</a> <a href="http://www.google.com/chrome/" target="_blank" '+linkStyle+'><img src="'+options.image_path+'c.gif" '+imgStyle+' />Chrome 4</a> <a href="http://www.apple.com/safari/" target="_blank" '+linkStyle+'><img src="'+options.image_path+'s.gif" '+imgStyle+' />Safari 4</a> <a href="#" id="upgrade_close" style="margin-left: 20px;"><img src="'+options.image_path+'cross.gif" '+imgStyle+' /></a></div></div>');
	   
		//set onclick for close button
		$('#upgrade_close').click(function(){ $('#upgrade').slideUp(); });
	   
	   	//set cookie and display object
		function delay(){
			var date = new Date();
			date.setTime(date.getTime() + options.expires);
			$.cookie('jquery-browser-upgrade', 'true', { path: '/', expires: date });

			$('body>#upgrade').slideDown();
		}
		
		//move object on resize
		browser.resize(function(){
			$('body>#upgrade').width(browser.width());
		});
	   
	   //delay display of object
		initialDelay = setTimeout(delay,options.delay);
	}
				
}
