/**
 * namespacing emv 
 */
Emv = {
};

//namespacing for different services may be overwritten if logic is needed within specific services
Emv.Mediabizde = {
};

Emv.Videode = {
};

Emv.Kinode = {
};
//---


Emv.Config = {
	flashVersion: "9.0.124",
	fpDomain: {
	    videoDe: "http://flashplayer.video.de",
	    kinoDe: "http://flashplayer.kino.de",
	    mediabizDe: "http://flashplayer.mediabiz.de"
	}
};

Emv.Window = {
    open: function(url, width, height, target) {
        
        if (typeof('width') == "undefined") {
            
            width = 200;
        }
        if (typeof('height') == "undefined") {
            
            height = 200;
        }
        
        if (typeof('target') == "undefined") {
            
            target = 'popup';
        }

        var topPositon  = (screen.height/2)-(height/2);
        var leftPositon = (screen.width/2)-(width/2);

        var oWindow = window.open(url, target, "fullscreen=no, resizable=yes, status=yes, toolbar=no, menubar=no, location=no, width=" + width + ", height=" + height +", top=" + topPositon + ", left=" + leftPositon);

        if (!oWindow) {
    
            alert("Bitte lassen Sie Popup-Fenster zu.");
        } else {
    
            oWindow.focus();
        }

        return false;
    }
};

Emv.Dom = {
	isChildOf: function(parent, child) {
		if( child != null ) {			
			while( child.parentNode ) {
				if( (child = child.parentNode) == parent ) {
					return true;
				}
			}
		}
		return false;
	},
	
	/**
	 * checks, if mouseout is realy on this element 
	 * and not a mouseout with mouseover on nested elements
	 * @param current element
	 * @param event
	 * @return boolean - is mouse really outside this element
	 */
	isMouseOut: function(element, event) {
		var currentMouseTarget = null;
		if( event.toElement ) {				
			currentMouseTarget 			 = event.toElement;
		} else if( event.relatedTarget ) {				
			currentMouseTarget 			 = event.relatedTarget;
		}
		if( !Emv.Dom.isChildOf(element, currentMouseTarget) && element != currentMouseTarget ) {
			return true;
		}
		else
		{
			return false;
		}
	}
};

/**
 * Registry for storing objects
 * all stored objects has to have getId implemented
 */
Emv.Registry = 
{
	// strored objects
	objects: new Array(),
	// stored key-value pairs
	params: new Array(), 
	
	/**
	 * storing javascript objects
	 * all objects has to implement function getId otherwise an exception is thrown 
	 * @params object obj
	 */
	setObject: function(obj)
	{
//		console.log('+++ Emv.Registry.setObject: ' + obj.getId());
		if(typeof(obj.getId) != 'function')
		{
			throw (typeof(obj) + ' hat keine Funktion "getId()" definiert - bitte noch implementieren');
		}
		else
		{
			//only if not already stored
			if(null == Emv.Registry.getObject(obj.getId()))
			{
//			    console.log('+++ Emv.Registry.setObject: ' + obj.getId());
				this.objects[this.objects.length] = obj;
			}
		}
	},

    /**
     * returns object for id
     * @param string id
     * 
     * @return object/null
     */
	getObject: function(id)
	{
//		console.log("<<< Emv.Registry.getObject: " + id);
		var j = 0;
		for(j = 0; j < this.objects.length; j++)
		{
			var o = this.objects[j];
			if(o.getId() == id)
			{
				return o;
			}
		}
		return null;
	},
	
	/**
	 * storing of key value pairs
	 * @param string key
	 * @param mixed  value
	 */
	setParam: function(key, value)
	{
		//already set - overwrite
		if(Emv.Registry.getParam(key) != null)
		{
			var j = 0;
			for(j = 0; j < this.params.length; j++)
			{
				var p = this.params[j];
				if(p.getKey() == key)
				{
					this.params[j] = new Emv.Registry.Param(key, value);
				}
			}
		}
		//store new
		else
		{
			this.params[this.params.length] = new Emv.Registry.Param(key, value);
		}
	},
	
	/**
	 * returns value for key
	 * @param string key
	 * @return mixed value
	 */
	getParam: function(key)
	{
		var j = 0;
		for(j = 0; j < this.params.length; j++)
		{
			var p = this.params[j];
			if(p.getKey() == key)
			{
				return p.getValue();
			}
		}
		return null;
	}
};

/**
 * object to store key-value pairs in registry
 * dataholder for Emv.Registry params
 * @param string key
 * @param mixed  value
 */
Emv.Registry.Param = function(key, val)
{
	this.key = key;
	this.value = val;
	
	/**
     * returns key
     * @param string key
     */
	this.getKey = function()
	{
		return this.key;
	};
	
	/**
	 * returns stored value
	 * @param mixed value
	 */
	this.getValue = function()
	{
		return this.value;
	};
};

//prototyping
//adding trim function to String object
//because ie doesn't support it
if('undefined' == typeof String.prototype.trim)
{
	String.prototype.ltrim = function(){
    
        return this.replace(/^\s+/, '');
    }
    
    String.prototype.rtrim = function(){
    
        return this.replace(/\s+$/, '');
    }
    
	String.prototype.trim = function(){

	    return this.ltrim().rtrim();
	}
}