/*!
 * Copyright (c) 2011 cytrus GmbH, http://www.cytrus.de/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HowTo:
 * 	Just insert the following at the end of your pages body tag:
 * 	<script id="ieupdatenotice" data-deprecated="msie:6.0,msie:7.0" src="http://www.cytrus.de/fileadmin/browserupdate/ieupdatenotice.js"></script>
 * 		@id Identifies the script, so it can self reference its parameters
 * 		@data-deprecated Browsers which should display a deprecation dialog; for syntax see http://api.jquery.com/jQuery.browser
 * 		@src This script
 */

var UPDN = UPDN || {};
UPDN.jQInserted = false;

// checks if jQuery is already loaded, if not it gets lazily loaded from jQuery CDN
UPDN.jQueryInit = function() {
	if (typeof jQuery == 'undefined') {
		var jQ = document.createElement('script');
		jQ.setAttribute('id', 'ieupdatenotice');
		jQ.setAttribute('src', 'http://code.jquery.com/jquery-latest.min.js');
		
		if (this.jQInserted == false) {
			document.getElementsByTagName("head")[0].appendChild(jQ);
			this.jQinserted = true;
		}
		var self = this;
		setTimeout(function(){
			self();
		}, 50);

	}
	else {
		(function($) {
			$(function(){
				var deprecated = $('#ieupdatenotice').data('deprecated').split(',') || ['msie:6.0', 'msie:7.0'];
				for(var dep in deprecated) {
					var browser = deprecated[dep].split(':');
					if($.browser[ browser[0] ] == true && $.browser.version == browser[1] && document.cookie.search(/cyt-browserupdate/) < 0) {
						appendUpdateNote();
						break;
					}
				}
			});
			
			function appendUpdateNote(){
				$('head').append('<link rel="stylesheet" type="text/css" href="http://www.cytrus.de/fileadmin/browserupdate/ieupdatenotice.css" />');
				$('<div id="cyt-browserupdate"><a href="#close" id="cyt-closebrowserupdate"></a><iframe allowtransparency="true" frameborder="0" src="http://www.cytrus.de/fileadmin/browserupdate/ieupdatenotice.html"></iframe></div>').appendTo('body');
				
				$('#cyt-closebrowserupdate').click(function(ev){
					ev.preventDefault();
					document.cookie = 'cyt-browserupdate=true;';
					$('#cyt-browserupdate').remove();
				});
			}
			
		})(jQuery);
	}
}


UPDN.jQueryInit();

