/**
 *  analytics7.com widget for google analytics on site
 *  copyright 2010 hans nauta - http://www.analytics7.com
 */
 
var jQueryTimeout;
var jQueryWait;
var jQuery_reqv = 132;
var initJsLoad = true;
var a7w_settings = {
  position: 'topRight', 
  showicon: true 
};
var a7w_posCss = {};

(function() {
	
	
function jquery_ver(){
    return parseInt(jQuery.fn.jquery.replace(/\./gi,'').substring(0,3));
}

jQueryWait = function() {
	if (typeof jQuery == "function") {
		
		if (jquery_ver() >= jQuery_reqv) {
			clearTimeout(jQueryTimeout);
			scriptLoadHandler();
		} else {
			jQueryTimeout=  setTimeout("jQueryWait()",50);
		}
	} else {
		jQueryTimeout =  setTimeout("jQueryWait()",50);
	}
}

function loadJquery() {
	var s = document.createElement("script");
	s.setAttribute("type","text/javascript");
	s.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
	document.getElementsByTagName("head")[0].appendChild(s);
	
}

function loadScript(url, callback){
        var script = document.createElement("script")
        script.type = "text/javascript";
        if (typeof script.readyState === 'undefined'){  
            script.onload = function(){
                callback();
            };            
        } else { // IE LAST!
            script.onreadystatechange = function(){
                if (script.readyState === "loaded" || script.readyState === "complete"){
                    script.onreadystatechange = null;
                    callback();
                }
            };            
        };
        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
        return script;
}
    
    

function loadNewerJquery() {
	var url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
	loadScript( url , function() {
		a7w_jQuery = jQuery.noConflict(true);
		loadLoader();
	});
}

if (typeof jQuery != "function"){
	loadJquery();
	jQueryWait();
	//jQuery.noConflict();
} else if (jquery_ver() < jQuery_reqv ) {
	loadNewerJquery();
} else {
	a7w_jQuery = window.jQuery;
	loadLoader();
}




function scriptLoadHandler() {
	a7w_jQuery = window.jQuery.noConflict(true);
//alert(a7w_jQuery.fn.jquery);
     //                   alert(window.jQuery.fn.jquery);
	loadLoader();
}


function loadLoader() {


// wrapper jquery namespace
(function($) {

$(document).ready(function() {




	function a7w_getCookie(key) {
		var result;
	    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decodeURIComponent(result[1]) : null;
	}


	function loadApp() {
	
	var script = document.createElement( 'script' );
	script.type = 'text/javascript';
	script.src = 'http://www.analytics7.com/a7w_app_v019.js';
	//script.src = 'http://www.analytics7.com/PRODUCTION/a7w_app_v019.js';
	$('head').append(script);
	
	var timer = setInterval( function(){ 
	    if (window.initApp !== undefined) {
	        clearInterval(timer);
//	        script.remove();
	        initApp();
	    }
	}, 200);
	
	}







	if (typeof a7w_options !== 'undefined') { 
		$.extend(a7w_settings, a7w_options);
	}
	//alert (a7w_settings.ga_profileid);
		
					
	var pos_h;
	var firstHover = true;
	switch (a7w_settings.position.toLowerCase()) {
		case 'topright': pos_v = 'top';pos_h = 'right';break;
		case 'topleft': pos_v = 'top';pos_h = 'left';break;
		case 'bottomright': pos_v = 'bottom';pos_h = 'right';break;
		case 'bottomleft': pos_v = 'bottom';pos_h = 'left';break;
		default: pos_v = 'top';pos_h = 'right';
	}

	a7w_posCss[pos_v] = "0px";
	a7w_posCss[pos_h] = "0px";
	a7w_posCss['margin'] = "3px";
	a7w_posCss['display'] = "none";
	a7w_posCss['position'] = 'fixed';
	a7w_posCss['z-index'] = '999999';

//iecss['background'] = "#123"; /* you can choose any colour you like, 1.0-fully visible */
//iecss['opacity']= "0.0";      /* opacity setting for all browsers except IE */
//iecss['filter'] = "alpha(opacity = 0)"; /* opacity setting for IE, 0-transparent & 100-fully visible */



	var RndSmpl=Math.floor(Math.random()*1);
	if (RndSmpl == 0) {
		var ord=Math.random();ord=ord*10000000000000000000;
		var logImg = new Image();logImg.src = 'http://www.analytics7.com/l.gif?r='+ord+'&d='+location.hostname;logImg.style.display = 'none';
		document.body.appendChild(logImg);
	}

	
	$('<div id="a7w_launcher" style="width: 16px; height: 16px;"><!-- --><img src="http://cdn.analytics7.com/img/blank.gif" style="width: 16px; height: 16px; border: none;background:none;padding:0px;"/></div>').css(a7w_posCss).click(function() {
		
		$(this).hide();
		$('#a7w_waiting').show();
		if (initJsLoad) {
			loadApp(); 
		} else {
			initApp2();
		}
		
	}).css('opacity', '0').hover(function(){
		//alert ('h');
		if (firstHover == true) {
			
			if (a7w_settings.showicon == true) {
				$('#a7w_launcher').html('<!-- --><img src="http://cdn.analytics7.com/img/launchicon.png" style="border: none;padding: 0px;background: none;"/>&nbsp;').css('cursor', 'pointer');
			}// else {
			//	$('#a7w_launcher').html('<!-- --><img src="http://cdn.analytics7.com/img/blank.gif" />&nbsp;');
			//}
			$('<div id="a7w_waiting"><img src="http://cdn.analytics7.com/img/loading.gif" style="border: none;padding: 0px;background: none;"/></div>').css(a7w_posCss).appendTo('body');
			firstHover = false;
		}
		
		$(this).animate({opacity: 1}, {duration: 300, queue: false });
	}, function() {
		$(this).animate({opacity: 0}, {duration: 300, queue: false });
	}).appendTo('body');
		
	
		
	if (a7w_getCookie('a7w_session') !== 'login' && a7w_getCookie('a7w_session') !== 'minimized') {
		$('#a7w_launcher').show();
	} else {
		if (a7w_settings.showicon == true) {
			$('#a7w_launcher').html('<!-- --><img src="http://cdn.analytics7.com/img/launchicon.png" style="border: none;padding: 0px;background: none;"/>&nbsp;').css('cursor', 'pointer');
		}
			
			
		if (firstHover == true) {
			$('<div id="a7w_waiting"><img src="http://cdn.analytics7.com/img/loading.gif" style="border: none;padding: 0px;background: none;"/></div>').css(a7w_posCss).appendTo('body');
			firstHover = false;
		}
		$('#a7w_waiting').show();
		loadApp(); 

	}

});
	
	
})(a7w_jQuery);

}

})(); // We call our anonymous function immediately


