// nom de domaine
var wagwire_siteroot = "www.wagwire.com";


function wagwire_get_domain() {
	if (document.domain!="" && document.domain!="undefined") return document.domain;
	else return "http://" + window.location.toString().split("//")[1].split("/")[0] + "/";
}

function wagwire_get_nav_language() {
  var lct="en";
  if (navigator.language) {
    lct=navigator.language.toLowerCase().substring(0, 2);
  } else if (navigator.userLanguage) {
    lct=navigator.userLanguage.toLowerCase().substring(0, 2);
  } else if (navigator.userAgent.indexOf("[")!=-1) {
    var debut=navigator.userAgent.indexOf("[");
    var fin=navigator.userAgent.indexOf("]");
    lct=navigator.userAgent.substring(debut+1, fin).toLowerCase();
  }
  if (lct=="fr") return "fr";
  else return "en";
}

var wagwire_browser_test = {
	ie_test: function() {
        return navigator.userAgent.indexOf("MSIE") >= 0;
    },
    iepre7_test: function() {
        return navigator.userAgent.indexOf("MSIE 6") >= 0 || navigator.userAgent.indexOf("MSIE 5.5") >= 0;
    },
	opera_test: function() {
        return navigator.userAgent.indexOf("Opera") >= 0;
    }
}

// Construction du Wag Mini
function Wagwire(key) {
    this.wagwire_build_app = wagwire_build_app;
    
    var wagmini_div = null;
    
    var key = key;
    
    function wagwire_build_app() {
        if (wagmini_div != null)
            return;

		var doc = window.document;
        var body = wagwire_get_body_element();

        wagmini_div = doc.createElement("div");
        wagmini_div.id = "wagwire_wagmini_div";
        body.appendChild(wagmini_div);
        
        with (wagmini_div.style) {
/*         	backgroundImage = "url(http://"+wagwire_siteroot+"/app/recorder/diaLog/resources/images/wag/background.png)"; */
            margin = "40px";
        	width = "227px";
            height = "227px";
        	border = "none";
            position = "absolute";
            right = "0px";
            top = "0px";
            left = "auto";
            bottom = "auto";
            zIndex = "3";
/*             textAlign = "center"; */
        }
        
		// the close window link
		var close_button = doc.createElement("a");
		if (wagwire_get_nav_language()=="fr") close_button.appendChild(doc.createTextNode("fermer"));
		else close_button.appendChild(doc.createTextNode("close"));
		with (close_button.style) {
	        position = "absolute";
			top = "5px";
			left = "5px";
			paddingTop = "2px";
			paddingBottom = "2px";
			paddingLeft = "5px";
			paddingRight = "5px";
			fontSize = "14px";
			fontFamily = " \"Helvetica Neue\", Helvetica, Geneva, Arial, sans-serif";
			fontWeight = "bold";
			color = "#aaa";
			cursor = "pointer";
		}
        
        close_button.onclick = close;
        close_button.onmousedown = function() {
			with (close_button.style) {
				color = "#26b1fd";
			}
        }
        close_button.onmouseover = function () {
			with (close_button.style) { 
				color = "#fff";
			}
        }        
        close_button.onmouseout = function () {
			with (close_button.style) {
				color = "#aaa";
			}
        }
        
        // wag mini object
				
		var wagminibeta = '<div style="">'
			+ '<objec'+'t '
		    + 'classi'+'d='+'"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
		    + 'codebas'+'e='+'"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" '
		    + 'widt'+'h='+'"225" '
		    + 'heigh'+'t='+'"225" '
		    + 'i'+'d='+'"myFlash">'
		
		    + '<para'+'m '
		    + 'nam'+'e='+'"allowScriptAccess" '
		    + 'valu'+'e='+'"always" />'
		
		    + '<para'+'m '
		    + 'nam'+'e='+'"movie" '
		    + 'valu'+'e='+'"http://'+wagwire_siteroot+'/app/recorder/diaLog/gateway/wag/?id='+key+'&siteRoot='+wagwire_siteroot+'" />'
		
		    + '<para'+'m '
		    + 'nam'+'e='+'"quality" '
		    + 'valu'+'e='+'"high"/>'
		
		    + '<'+'para'+'m '
		    + 'nam'+'e='+'"bgcolor" '
		    + 'valu'+'e='+'"#333333"/>'
		
/*
		    + '<para'+'m '
		    + 'nam'+'e='+'"wmode" '
		    + 'valu'+'e='+'"transparent"/>'
*/
		
		    + '<embe'+'d '
		    + 'sr'+'c='+'"http://'+wagwire_siteroot+'/app/recorder/diaLog/gateway/wag/?id='+key+'&siteRoot='+wagwire_siteroot+'" '
		    + 'qualit'+'y='+'"high" '
		    + 'bgcolo'+'r='+'"#333333" '
		    + 'widt'+'h='+'"225" '
		    + 'heigh'+'t='+'"225" '
		    + 'nam'+'e='+'"myFlash" '
 			+ 'allowScriptAcces'+'s='+'"always"'
 			+ 'swLiveConnec'+'t='+'"true" '
/* 		    + 'wmod'+'e='+'"transparent" ' */
		    + 'typ'+'e='+'"application/x-shockwave-flash" '
		    + 'pluginspac'+'e='+'"http://www.macromedia.com/go/getflashplayer">'
		    + '<\/embed>'
		
		    + '<\/objec'+'t>';
		    + '<\/div>';
		    
		wagmini_div.innerHTML = wagminibeta;

		// attach close button
		// wagmini_div.appendChild(close_button);
		
		//fix IE and Opera position problem
		fixPosition();
    }
    
	    
    function wagwire_get_body_element() {
        var bodyElement = window.document.body;

        var bodyElements = window.document.getElementsByTagName("body");
        if (bodyElements && bodyElements.length == 1 && bodyElements.item(0))
            bodyElement = bodyElements.item(0);

        return bodyElement;
    }

        

    function close() {
    	if (wagmini_div)
            wagmini_div.parentNode.removeChild(wagmini_div);
    }	

    
    // IE has problem with fixed position, so we have to adjust it
    function fixPosition() {
    	if (wagwire_browser_test.opera_test() || (wagwire_browser_test.ie_test() && !(!wagwire_browser_test.iepre7_test() && window.document.compatMode != "BackCompat"))) {
           	wagmini_div.style.position = "absolute";
    		
			window.onresize = _fixPosition;
			window.onscroll = _fixPosition;
			wagwire_get_body_element().onscroll = _fixPosition;
			
			_fixPosition();
		}
    }
    
    function _fixPosition() {
    	if(wagmini_div) {
			wagmini_div.style.top = (wagwire_get_body_element().scrollTop) + "px";
    	}
    }
    
}

// Affichage du Recorder
function wagwire_build_app (key) {
	wagwire = new Wagwire(key);
    wagwire.wagwire_build_app();
}

// FERMETURE DU RECORDER
function wagwire_close_app () {
	wagmini_div = document.getElementById('wagwire_wagmini_div');
	wagmini_div.parentNode.removeChild(wagmini_div);
}

