
/*

width			:int
position		:string [top, right, bottom, left]
x				:int
y				:int
drag			:boolean
multiple		:int
contentType		:string [clone, ajax]

<div onclick='btip.tip(this, "hoi", "position:bottom,drag:true");' style='border:1px solid red;width:200px;position:relative;left:300px;'>Jawis</div>

*/

function makeJSParams(params)
{
	//alert('go');
	
	return '';
}

this.makeJSParams = makeJSParams;


function btip()
{
	this.nextZIndex = 4000;
	this.allTips = new Array();
	
	function tip(element, content, paramsString)
	{
		var id = new Date().getTime();
		
		if (typeof element == 'string') element = document.getElementById(element);
		if (!element.id)
		{
			element.id = 'element_' + id;
		}
		
		
		// params --------------------------------->
		
		var params = new Array();
		if (paramsString)
		{
			var allParams = paramsString.split(",");
			for (var i = 0; i < allParams.length; i ++)
			{
				var split = allParams[i].split(":");
				params[split[0]] = split[1];
			}
		}
		
		
		// remove old --------------------------------->
		
		if (!params['multiple'] && this.allTips[element])
		{
			document.body.removeChild(this.allTips[element]);
			this.allTips[element] = false;
		}
		
		
		// tip creation --------------------------------->
		
		var tipDiv = document.createElement('div');
		tipDiv.id = 'btip_' + id;
		
		$(tipDiv).addClass('btip');
		
		
		$(tipDiv).css('display', 'block');
		$(tipDiv).css('position', 'absolute');
		if (params['width']) $(tipDiv).css('width', parseInt(params['width']));
		$(tipDiv).css('z-index', this.nextZIndex); this.nextZIndex ++;
		
		
		var html = "";
		
		if (!params['hideClose'] || params['title'])
		{
			html = "<div class='top'>";
			if (params['title']) html += "<div class='title'>" + params['title'] + "</div>";
			if (!params['hideClose']) html += "<div class='close' onclick='btip.close(this, \"" + element.id + "\")'></div>";
			html += "</div>";
		}
		
		html += "<div class='content' id='content_" + id + "'>";
		if (!params['contentType'])
		{
			html += content;
		}
		else if (params['contentType'] == 'clone')
		{
			html += document.getElementById(content).innerHTML;
		}
		html += "</div>";
		
		tipDiv.innerHTML = html;
		
		
		document.body.appendChild(tipDiv);
		
		
		if (params['contentType'] == 'ajax')
		{
			jsParams = makeJSParams(params);
			ajaxObject.request(content, 'content_'+id, jsParams);
		}
		
		if (params['drag'])
		{
			$(tipDiv).draggable();
		}
		
		
		// tip position --------------------------------->
		
		var position = $(element).offset();
		if (params['position'])
		{
			if (params['position'] == 'top')
			{
				position.top -= $(tipDiv).height();
			}
			else if (params['position'] == 'bottom')
			{
				position.top += $(element).height();
			}
			else if (params['position'] == 'left')
			{
				position.left -= $(tipDiv).width();
			}
			else if (params['position'] == 'right')
			{
				position.left += $(element).width();
			}
		}
		
		if (params['x'])
		{
			position.left += parseInt(params['x']);
		}
		
		if (params['y'])
		{
			position.top += parseInt(params['y']);
		}
		
		$(tipDiv).css('left', position.left);
		$(tipDiv).css('top', position.top);
		if (params['closeClick'])
		{
			$('#btip_' + id).click(function() {
				btip.close(this, element.id);
			});
		}
		this.allTips[element] = tipDiv;
		
		
	}
	
	this.tip = tip;
	
	
	function close(closeBtn, elementID)
	{
		var tipDiv = closeBtn.parentNode.parentNode;
		document.body.removeChild(tipDiv);
		
		element = document.getElementById(elementID);
		this.allTips[element] = false;
	}
	
	this.close = close;
	
	
	function closeByElement(element)
	{
		if (typeof element == 'string') element = document.getElementById(element);
		
		document.body.removeChild(this.allTips[element]);
		this.allTips[element] = false;
	}
	
	this.closeByElement = closeByElement;
	
	
	
	
	this.currentBG;
	this.currentBox;
	
	
	function box(content, paramsString)
	{
		
		var id = new Date().getTime();
		
		// check
		
		if (this.currentBox != undefined) this.boxclose();
		
		// params --------------------------------->
		
		var params = new Array();
		if (paramsString)
		{
			var allParams = paramsString.split(",");
			for (var i = 0; i < allParams.length; i ++)
			{
				var split = allParams[i].split(":");
				params[split[0]] = split[1];
			}
		}
		//document.body.scroll = "no";
		//document.body.style.overflow = "hidden";
		
		// background creation --------------------------------->
		/*
		var backgroundDiv = document.createElement('div');
		backgroundDiv.id = 'box_background_' + id;
		$(backgroundDiv).addClass('box_background');
		
		var scrollInfo = this.getScroll();
		
		$(backgroundDiv).css('display', 'block');
		$(backgroundDiv).css('position', 'absolute');
		$(backgroundDiv).css('top', scrollInfo[1]+'px');
		$(backgroundDiv).css('left', scrollInfo[0]+'px');
		$(backgroundDiv).css('width', '100%');
		$(backgroundDiv).css('height', '100%');
		$(backgroundDiv).css('z-index', this.nextZIndex); this.nextZIndex ++;
		
		this.currentBG = backgroundDiv;
		document.body.appendChild(backgroundDiv);
		*/
		
		// container creation --------------------------------->
		
		var boxDiv = document.createElement('div');
		
		var html = "<div class='top'>";
		if (params['title']) html += "<div class='title'>" + params['title'] + "</div>";
		if (!params['noClose']) html += "<div class='close' onclick='btip.boxclose()'></div>";
		html += "</div>";
		
		html += "<div class='content' id='boxcontent'>";
		if (!params['contentType'])
		{
			html += content;
		}
		else if (params['contentType'] == 'clone')
		{
			html += document.getElementById(content).innerHTML;
		}
		html += "</div>";
		
		boxDiv.innerHTML = html;
		
		
		boxDiv.id = 'box_' + id;
		$(boxDiv).addClass('box');
		
		$(boxDiv).css('display', 'block');
		$(boxDiv).css('position', 'absolute');
		$(boxDiv).css('z-index', this.nextZIndex); this.nextZIndex ++;
		if (params['width']) $(boxDiv).css('width', parseInt(params['width']));
		if (params['height']) $(boxDiv).css('height', parseInt(params['height']));
		if (params['textCenter']) $(boxDiv).css('text-align', 'center');
		
		this.currentBox = boxDiv;
		document.body.appendChild(boxDiv);
		
		if (params['contentType'] == 'ajax')
		{
			addParams = 'onComplete>btip.centerBox();';
			if (params['onComplete']) addParams += params['onComplete'];
			if (params['method']) addParams += "|method>"+params['method'];
			if (params['formID']) addParams += "|formID>"+params['formID'];
			ajaxObject.request(content, 'boxcontent', addParams);
		}
		
		document.onscroll = function()
		{
			btip.centerBox();
		};
		
		this.centerBox();
		
		generalScripts.pausePlayer();
		$("#jquery_jplayer_1").jPlayer("pause");
	}
	
	this.box = box;
	
	
	function centerBox()
	{
		var screenInfo = this.getScreenSize();
		var scrollInfo = this.getScroll();
		
		if (this.currentBG)
		{
			$(this.currentBG).css('top', (scrollInfo[1]-40)+'px');
			$(this.currentBG).css('left', scrollInfo[0]+'px');
		}
		
		if (this.currentBox)
		{
			$(this.currentBox).css({top:(screenInfo[1] / 2 + scrollInfo[1]) + 'px',
									left:'50%',
									marginTop:'-' + ($(this.currentBox).height() / 2) + 'px',
									marginLeft:'-' + ($(this.currentBox).width() / 2) + 'px'	});
		}
	}
	
	this.centerBox = centerBox;
	
	
	function boxclose()
	{
		//document.body.removeChild(this.currentBG);
		//this.currentBG = undefined;
		
		document.body.removeChild(this.currentBox);
		this.currentBox = undefined;
		
		//document.body.scroll = "yes";
		//document.body.style.overflow = "auto";
		
		generalScripts.resumePlayer();
		$("#jquery_jplayer_1").jPlayer("play");
	}
	
	this.boxclose = boxclose;
	
	
	function boxhide()
	{
		$(this.currentBG).css('display', 'none');
		$(this.currentBox).css('display', 'none');
		
		//document.body.scroll = "yes";
		//document.body.style.overflow = "auto";
		
		generalScripts.resumePlayer();
	}
	
	this.boxhide = boxhide;
	
	
	
	function loadSplash()
	{
		var loadDiv = document.createElement('div');
		loadDiv.id = 'loadSplash';
		
		$(loadDiv).css('display', 'block');
		$(loadDiv).css('position', 'absolute');
		$(loadDiv).css('top', window.pageYOffset+'px');
		$(loadDiv).css('left', window.pageXOffset+'px');
		$(loadDiv).css('width', '100%');
		$(loadDiv).css('height', '100%');
		$(loadDiv).css('background-color', '#000000');
		$(loadDiv).css('z-index', this.nextZIndex); this.nextZIndex ++;
		
		document.onscroll = function()
		{
			$(loadDiv).css('top', window.pageYOffset+'px');
			$(loadDiv).css('left', window.pageXOffset+'px');
		};
		
		$(loadDiv).fadeTo('fast', 0.7);
		
		document.body.appendChild(loadDiv);
	}
	
	this.loadSplash = loadSplash;
	
	
	
	function getScroll()
	{
		var scrOfX = 0, scrOfY = 0;
		
		if (typeof(window.pageYOffset) == 'number' )
		{
			scrOfY = window.pageYOffset;	//Netscape compliant
			scrOfX = window.pageXOffset;
		}
		else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
		{
			scrOfY = document.body.scrollTop;	//DOM compliant
			scrOfX = document.body.scrollLeft;
		}
		else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
		{
			scrOfY = document.documentElement.scrollTop;	//IE6 standards compliant mode
			scrOfX = document.documentElement.scrollLeft;
		}
		
		return [scrOfX, scrOfY];
	}
	
	this.getScroll = getScroll;
	
	
	function getScreenSize()
	{
		var myWidth = 0, myHeight = 0;
		
		if( typeof( window.innerWidth ) == 'number' )
		{
			myWidth = window.innerWidth;	//Non-IE
			myHeight = window.innerHeight;
		}
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ))
		{
			myWidth = document.documentElement.clientWidth;	//IE 6+ in 'standards compliant mode'
			myHeight = document.documentElement.clientHeight;
		}
		else if( document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			myWidth = document.body.clientWidth;	//IE 4 compatible
			myHeight = document.body.clientHeight;
		}
		
		return [myWidth, myHeight];
	}
	
	this.getScreenSize = getScreenSize;
	
}

