/*********************************************/
/*********************************************/
/** COPYRIGHTED - COPYRIGHTED - COPYRIGHTED **/
/** THIS FILE IS STRICTLY COPYRIGHTED       **/
/** OWNER:                                  **/
/** David Lorenz                            **/
/** Schloßstraße 3                          **/
/** 72351 Geislingen                        **/
/** Country: GER                            **/
/**                                         **/
/** www.vaib.de                             **/
/** VAIB INTERNET TECHNOLOGIES              **/
/*********************************************/
/*********************************************/

function ExecScrollTop(){
	$('html,body').animate({
		scrollTop: 0
	},400);
}

var BASEURL			=	'http://streamdrag.com/';
var base			=	new Object();
base.voided			=	function(){}; //just voiding

base.ReqFlashV	=	8;

base.MouseX			=	0;
base.MouseY			=	0;
base.setMousePos	=	function(e){
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}else if (e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft+document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop+document.documentElement.scrollTop;
	}
	
	base.MouseX			=	posx;
	base.MouseY			=	posy;
};

document.onmousemove	=	base.setMousePos;

/** SYSTEM-LOADER **/
base.systemLoader		=	function(){
	var ul				=	$('#system_loader>ul');
	var jsChecked		=	$('<li style="display:none" class="check_checked">Checked.</li>');
	var FlashChecking	=	$('<li style="display:none" class="checkingName">checking Flash-Plugin...</li>');
	jsChecked.appendTo(ul);
	jsChecked.toggle('slow');
	FlashChecking.appendTo(ul);
	FlashChecking.slideDown('slow');
	
	
	swfobject.cbEmbedSWF('flash/test.swf', 
                       "flashtest", "2", "2", "8", null, null, null, function(){
					   	base.systemLoader_FlashSuccess();
					   }, function(){
					   	base.systemLoader_FlashFailed();
					   });
};

base.systemLoader_FlashSuccess	=	function(){
	$('#flashtest').css('display','none');
	var ul		=	$('#system_loader>ul');
	var FlashChecked	=	$('<li style="display:none" class="check_checked">Checked.</li>');
	FlashChecked.appendTo(ul);
	FlashChecked.toggle('slow');
	
	var YT_checking	=	$('<li style="display:none;" class="checkingName">'
				+'<img src="img/ajax_min_dark.gif" alt="" style="padding:2px 5px 0px 0" /><strong>loading Player...</strong>'
				+'<div class="clearer"></div></li>');
	YT_checking.appendTo(ul);
	YT_checking.slideDown('slow');
	
	window.setTimeout(function(){
		_YTPlayer.EmbedPlayerToElm();
	},300);
};

base.systemLoader_FlashFailed	=	function(){
	$('#flashtest').css('display','none');
	var ul		=	$('#system_loader>ul');
	var FlashChecked	=	$('<li style="display:none" class="check_failed">Please install Flash >= v8</li>');
	FlashChecked.appendTo(ul);
	FlashChecked.toggle('slow');
};

/* TOOLTIP:Start */
base.tooltipTimeout	=	false;
base.tooltipShow	=	function(msg,setT,setL){
	window.clearTimeout(base.tooltipTimeout);
	
	if(setT && setL && typeof(setL)=='number' && typeof(setL) == 'number'){
		setL	=	(base.MouseX-browser.getCursorLeftToSite())+setL;
		$('#toolTip').css('top',setT+'px');
		$('#toolTip').css('left',setL+'px');
	}else{
		$('#toolTip').css('top',base.MouseY+12+'px');
		$('#toolTip').css('left',base.MouseX-142+'px');
	}
	$('#toolTip>div>div').html(msg);
	$('#toolTip').fadeIn('fast');
	
	base.tooltipTimeout	=	window.setTimeout('base.tooltipClose()',800);
};

base.tooltipShowLong	=	function(msg,setT,setL){
	base.tooltipShow(msg,setT,setL);
	window.clearTimeout(base.tooltipTimeout);
	
	base.tooltipTimeout	=	window.setTimeout('base.tooltipClose()',1500);
};

base.tooltipClose	=	function(){
	$('#toolTip').fadeOut('fast');
};
/* TOOLTIP:End */

base.openWindow		=	function(url,width,height){
	if(!height){
		var height=520;
	}
	
	if(!width){
		var width=470;
	}
	addedWindow	=	window.open(url,"Streamdrag","width="+width+",height="+height+",resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=no");
};

/* ERRROR-Contenting:Start */
base.contErr	=	function(msg){
	$('#searchContents').html('<div id="errord">'+msg+'</div>');
};
/* ERRROR-Contenting:End */


var browser			=	new Object();
browser.getWidth	=	function(){
	return	document.body.offsetWidth;
};

browser.getHeight	=	function(){
	return	document.body.offsetHeight;
};

browser.getCursorLeftToSite		=	function(){
	//getCursorLeft relative to "container" (inner)
	var containerWidth		=	885;
	var currentTotalWidth	=	browser.getWidth();
	var TotalEmptySpace		=	currentTotalWidth-containerWidth;
	var relInnerSiteLeft;
	/**var bar_Minimum			=	296; 
	var bar_Maximum			=	537; **/
	/* bar_Minimum is the relInnerSiteLeft-Value that is equal to a barPosition=0% */
	/* bar_Maximum is the relInnerSiteLeft-Value that is equal to a barPosition=100% */
	
	if(TotalEmptySpace < 1){
		relInnerSiteLeft	=	base.MouseX;
	}else{
		var JustLeftedSpace	=	Math.round(TotalEmptySpace/2);
		relInnerSiteLeft	=	base.MouseX-JustLeftedSpace;
	}
	
	return relInnerSiteLeft;
};


browser.getCursorLeftToLoaderBar	=	function(innerSiteLeft){
	var relSiteLeft;
	if(innerSiteLeft){ //can be set, but has not to be set
		relSiteLeft	=	innerSiteLeft;
	}else{
		relSiteLeft	=	browser.getCursorLeftToSite();
	}
	var relBarLeft;
	var barMinLeft	=	297;
	
	relBarLeft	=	relSiteLeft-barMinLeft;
	if(navigator.appName=='Netscape'){
		relBarLeft	=	relBarLeft+2;
	}
	
	if(relBarLeft < 1){
		relBarLeft = 1;
	}else if(relBarLeft > 240){
		relBarLeft	=	240;
	}
	
	var virtualPercent	=	(relBarLeft/240)*100;
	return virtualPercent;
};










//---------------------------------------
//---------------------------------------
//handle TopBar
//---------------------------------------
//---------------------------------------
var TopBar	=	new Object();
TopBar.isState	=	'closed';

TopBar.g	=	function(){
	return $('#topbar_sizing');
};

TopBar.nToggle	=	function(){
	if(TopBar.isState=='closed'){
		TopBar.nOpen();
	}else if(TopBar.isState=='opened'){
		TopBar.nClose();
	}
};

TopBar.nOpen	=	function(){
	if(TopBar.isState=='closed'){
		TopBar.isState	=	'opening';
		TopBar.g().animate({height:'80px'},700,'swing',function(){
			TopBar.isState	=	'opened';
		});
	}
};

TopBar.bOpen	=	function(){
	if(TopBar.isState=='closed'){
		TopBar.isState	=	'opening';
		TopBar.g().animate({height:'170px'},700,'swing',function(){
			TopBar.isState	=	'opened';
		});
	}
};

TopBar.nClose	=	function(){
	if(TopBar.isState=='opened'){
		TopBar.isState	=	'closing';
		TopBar.g().animate({height:'0px'},400,'swing',function(){
			TopBar.isState	=	'closed';
		});
	}
};