var isIE6 = /MSIE 6/i.test(navigator.userAgent);

// This function adjusts the size of the component to the size of the module position and adjusts the max resize to the size of that module

var resize = new Array();

function changeResize(component,container){
	if (component.id) component = component.id;
	if (container.id) container = container.id;

	// Adjust the size of the component to the size of the module position
	var adjWidth = $(container).getStyle('width').toInt();
	var adjHeight = $(container).getStyle('height').toInt();
    $(container).getElements('.full-stretch').each(function(currComp){
		adjHeight -= ($(currComp.id + '-container').getStyle('height').toInt() + 2);
   });
   adjHeight += $(component+'-container').getStyle('height').toInt();

	$(component+'-container').setStyles({ 'left': 0 , 'top': 0 , 'width': adjWidth + 'px'  });

	adjustBar(component);

	resize[component] = $(component+'-container').makeResizable({

		// Limit resize to vertical only
		modifiers: {x: false, y: 'height'},
		// Sets the resize limits
		limit: {y: [yMin[component], adjHeight]},

		// The element that must be dragged to resize the component
		handle: $(component+'-handle'),

		// How many pixels you must drag the resize element before it actually begins resizing
		snap: 5, 

		onComplete: function(){

		    $(container).getElements('.full-stretch').each(function(currComp){
				changeResize(currComp.id,container);
		   });

		}

	});

}

// This maximizes all of the components
function maximizeAllComponents()
{
   $$('.module').each(function(currModule)
   {
      maximizeComponents(currModule);
   });
}

// This is will maximize the componets in the specified module
function maximizeComponents(module)
{
   if (module.id) module = module.id;
   var currModule = $(module);
   var compHeight, heightDiff;
   var compactComps = 0;

   var components = $$('#' + module + ' .full-stretch');
   var h = parseInt(currModule.getStyle('height')) - (2 * components.length);
   components.each(function(currComp){
		if(parseInt($(currComp.id + '-container').getStyle('height')) == 26)
		{
			h -= 26;
			compactComps++;
		}
   });
   h = h / (components.length - compactComps);
   heightDiff = parseInt(currModule.getStyle('height')) - (((components.length - compactComps) * (h+2)) + (26 * compactComps));
   components.each(function(currComp)
   {
     if(parseInt($(currComp.id + '-container').getStyle('height')) != 26)
      $(currComp.id + '-container').setStyle('height', h + 'px');
   });
   components.each(function(currComp)
   {
     changeResize(currComp, currModule);
   });
}

// This function allows for the dragging of the components to different module positions

var drags = new Array();

function createDrag(component){

	drags[component] = new Drag.Move(component+'-container', {

		// Sets the dragging handle of the component

		handle: $(component+'-top'),

		// Sets the amount of pixels the component must be dragged before it actually moves

		snap: 20, 

		// Sets the areas that the component can be dropped

		droppables: '.module', 

		onSnap: function(el){

			el.style.zIndex = 1;

		},

		// el is the element being dropped, droppable is the element it's being dropped in
		onDrop: function(el, droppable)
		{
			if (droppable)
			{
				var availHeight = $(droppable).getStyle('height').toInt();
			    droppable.getElements('.full-stretch').each(function(currComp){
					if(currComp.id != component)
						availHeight -= ($(currComp.id + '-container').getStyle('height').toInt() + 2);
			   });
			   var oldMod = getComponentModule(component);
				el.inject(droppable);
				el.style.zIndex = 0;
				el.style.position = "relative";
				el.style.top = 0 + "px";
				el.style.left = 0 + "px";
			   if(availHeight >= yMin[component])
			   {
					el.style.height = availHeight - 2 + 'px';
				    droppable.getElements('.full-stretch').each(function(currComp){
						changeResize(currComp.id,droppable);
				   });
				}
			   else
					maximizeComponents(droppable);
				if(oldMod)
					maximizeComponents(oldMod);
			}
			else
			{
				if(el.parentNode.id != 'wrapper')
				{
					el.style.top = 0 + "px";
					el.style.left = 0 + "px";
				}
			}
		}

	});

}



// This function creates a basic drag that doesn't need to drop into modules

function createBasicDrag(component){

	drags[component] = new Drag(component+'-container', {

		// Sets the dragging handle of the component

		handle: $(component+'-top'),

		// Sets the amount of pixels the component must be dragged before it actually moves

		snap: 20

	});

}

var yMin = new Array();
function setComponentLimit(comp, y)
{
   if (comp.id) comp = comp.id
   yMin[comp] = y;
}

// This function is for the custom scroll bar

var scrollBar = new Array();

function createScroll(component,direction){

	if(direction != 'horizontal')

		direction = 'vertical';

	// component -scroll is the actual bar and component -knob is the handle

	scrollBar[component] = new Slider($(component+'-scroll'),$(component+'-scroll').getElement('#'+component+'-knob'),{

		mode: direction, 

		wheel: true,

		steps: 15,

		// this.step is 0 - 100 based on the position on the handle and turned to a percent by dividing by 100 and adjusts the position of scroll position of component -wrapper.

		onChange: function(){

			if(direction == 'horizontal')

				$(component+'-wrapper').scrollLeft = (this.step / 15) * ($(component+'-wrapper').scrollWidth - $(component+'-wrapper').offsetWidth);

			else

				$(component+'-wrapper').scrollTop = (this.step / 15) * ($(component+'-wrapper').scrollHeight - $(component+'-wrapper').offsetHeight);

		}

	}).set(0);

	

	// Makes the content scroll when mousewheel used on content only if it's a vertical scroll

	if(direction == 'vertical')

	{

		$(component+'-wrapper').addEvent('mousewheel', function(e){

			e.stop(); // prevent the mousewheel from scrolling the page.

			if (e.wheel < 0)

				var newStep = scrollBar[component].step + 1;

			else

				var newStep = scrollBar[component].step - 1;

			scrollBar[component].set(newStep);

			$(component+'-wrapper').scrollTop = (scrollBar[component].step / 15) * ($(component+'-wrapper').scrollHeight - $(component+'-wrapper').offsetHeight);

		});

	}

}



// This function os for creating sliders

var slider = new Array();

function createSlider(component,direction,start,numSteps){

	if(!numSteps)

		numSteps = 100;

	slider[component] = new Slider($(component+'-slider'),$(component+'-slider').getElement('#'+component+'-handle'),{

		mode: direction,

		steps: numSteps,

		wheel: true,

		// this.step is 0 - 100 based on the position on the handle and turned to a percent by dividing by 100 and adjusts the position of scroll position of component -wrapper.

		onChange: function(){

			if(!isIE6)
			{
				$(component+'-input').value = Math.round(this.step);

				if(component=='video-border')

					adjustVideoBorder();

				if(component=='video-size')

					adjustVideoSize();
			}

		},

		onComplete: function(){

			$(component+'-input').value = Math.round(this.step);

			if(component=='video-border')

				adjustVideoBorder();

			if(component=='video-size')

				adjustVideoSize();

		}

	}).set(start);

	$(component+'-input').value = start;

}



// Function to create a morph (usually used for expanding containers)

var morphs = new Array();

function createMorph(container,speed)

{

	morphs[container] = new Fx.Morph(container, {wait: false, duration: speed, transition: Fx.Transitions.Sine.linear});

}



// Function to show elements that are hidden

function showElement(elm,overlay){

	$(elm).style.visibility = "visible";

	if(overlay)

	{

		$('overlay').style.visibility = "visible";

		$('overlay-inner').style.visibility = "visible";

	}

}

// Function to hide elements that are showing

function hideElement(elm,overlay){

	$(elm).style.visibility = "hidden";

	if(overlay)

	{

		$('overlay').style.visibility = "hidden";

		$('overlay-inner').style.visibility = "hidden";

	}

}







// Function  to toggle elements between expand and compact

var toggledElm = new Array();

function toggleElement(elm,eHgt,cHgt,start,auto)

{

	if(!toggledElm[elm])

		toggledElm[elm] = start;

	if(toggledElm[elm] == 'close')

	{

		expandElement(elm,eHgt,auto);

		toggledElm[elm] = 'open';

	}

	else

	{

		compactElement(elm,cHgt,auto);

		toggledElm[elm] = 'close';

	}

}

// Function to expand elements

function expandElement(elm,hgt,auto){

	if(!morphs[elm])

		createMorph(elm,500);

		if(hgt=='auto' || !hgt)
	{
		var aHgt = $(elm).getStyle('height').toInt();
		$(elm).style.height = "auto";
		hgt = $(elm).offsetHeight;
		$(elm).style.height = aHgt + 'px';
		morphs[elm].start({
			'height': hgt
		});
	}
	else

	{

		morphs[elm].start({

			'height': hgt

		}).chain(function(){

			if(auto == 'auto')

				$(elm).style.height = "auto";

		});

	}

	toggledElm[elm] = 'open';

}

// Function to compact elements

function compactElement(elm,hgt,auto){

	if(auto == 'auto')

		$(elm).style.height = $(elm).offsetHeight + 'px';

	if(!morphs[elm])

		createMorph(elm,500);

	if(!hgt)

		hgt = 0;

	morphs[elm].start({

		'height': hgt

	});

	toggledElm[elm] = 'close';

}



// Function to adjust the scroll bar

function adjustBar(component){

	var controlHeight = 0;

	// Does special adjustments if it is the player component

	if(component=='player')

	{

		// Checks if the width has changed and adjusts the height to show all the options

		if(showPlayerControls)

		{

			if($('video-player-controls-container').offsetWidth < 503)

			{

				controlHeight = 310;

				$('video-player-controls-right').style.cssFloat = $('video-player-controls-right').style.styleFloat = 'left';
				$('video-player-controls-right').getElements('.video-controls-options').each(function(vidOpts){
					vidOpts.style.cssFloat = vidOpts.style.styleFloat = 'left';
				});

			}

			else

			{

				controlHeight = 187;

				$('video-player-controls-right').style.cssFloat = $('video-player-controls-right').style.styleFloat = 'right';
				$('video-player-controls-right').getElements('.video-controls-options').each(function(vidOpts){
					vidOpts.style.cssFloat = vidOpts.style.styleFloat = 'right';
				});

			}

			$('video-player-controls-container').style.height = controlHeight + 'px';

			$('video-player-controls-content').style.height = controlHeight - 43 + 'px';

		}

		if(hidePlayerTop)

		{
			if($(component+'-container').offsetHeight < 26 + controlHeight)
				controlHeight = $(component+'-container').offsetHeight - 26;

			$(component+'-wrapper').style.height = $(component+'-container').offsetHeight - 15 - controlHeight + 'px';

			// Adjust the height of the custom scroll bar

			$(component+'-scroll').style.height = $(component+'-container').offsetHeight - 26 - controlHeight + 'px';

		}

		else

		{
			if($(component+'-container').offsetHeight < 52 + controlHeight)
				controlHeight = $(component+'-container').offsetHeight - 52;

			$(component+'-wrapper').style.height = $(component+'-container').offsetHeight - 41 - controlHeight + 'px';

			// Adjust the height of the custom scroll bar

			$(component+'-scroll').style.height = $(component+'-container').offsetHeight - 52 - controlHeight + 'px';

		}

	}

	else if(component=='message')

	{

		controlHeight = $(component+'-container').getStyle('padding-top').toInt() + $(component+'-container').getStyle('padding-bottom').toInt();

		if($(component+'-top'))

			controlHeight += $(component+'-top').offsetHeight;

		if($(component+'-top-second'))

			controlHeight += $(component+'-top-second').offsetHeight;

		if($(component+'-type-container'))

			controlHeight += $(component+'-type-container').offsetHeight;

		if(toggledElm['message-send-pm-container'] && toggledElm['message-send-pm-container'] == "open")

			controlHeight += 210;

		if(toggledElm['message-colors-container'] && toggledElm['message-colors-container'] == "open")

			controlHeight += 156;

		if(toggledElm['message-advanced-container'] && toggledElm['message-advanced-container'] == "open")

		{

			controlHeight += 161;

			if(toggledElm['chat-commands'] && toggledElm['chat-commands'] == "open")

				controlHeight += 46;

		}

		if($(component+'-container').offsetHeight < 8 + controlHeight)
			controlHeight = $(component+'-container').offsetHeight - 8;

		$(component+'-wrapper').style.height = $(component+'-container').offsetHeight - controlHeight - 8 + 'px';

		$(component+'-chats').style.height = 'auto';
		if($(component+'-chats').offsetHeight < $(component+'-wrapper').getStyle('height').toInt())
			$(component+'-chats').style.height = $(component+'-wrapper').getStyle('height').toInt() + 'px';

		// Adjust the height of the custom scroll bar

		$(component+'-scroll').style.height = $(component+'-container').offsetHeight - controlHeight - 8 + 'px';

	}

	else if(component == 'archive')

	{

		controlHeight = $(component+'-container').getStyle('padding-top').toInt() + $(component+'-container').getStyle('padding-bottom').toInt();

		if(toggledElm['archive-advanced-container'] && toggledElm['archive-advanced-container'] == "open")

		{

			$('archive-advanced-container').style.height = 'auto';
			$('archive-advanced-container').style.height = $('archive-advanced-container').offsetHeight + 'px';

			if($('archive-container').offsetWidth < 268)

				controlHeight += 282;

			else if($('archive-container').offsetWidth < 354)

				controlHeight += 200;

			else if($('archive-container').offsetWidth < 388)

				controlHeight += 184;

			else

				controlHeight += 143;

		}

		if($(component+'-top'))

			controlHeight += $(component+'-top').offsetHeight;

		if($(component+'-top-second'))

			controlHeight += $(component+'-top-second').offsetHeight;

		if($(component+'-container').offsetHeight < 38 + controlHeight)
			controlHeight = $(component+'-container').offsetHeight - 38;

		$(component+'-wrapper').style.height = $(component+'-container').offsetHeight - controlHeight - 38 + 'px';

		// Adjust the height of the custom scroll bar

		$(component+'-scroll').style.height = $(component+'-container').offsetHeight - controlHeight - 19 + 'px';

		if(isIE6)
		{
			$(component+'-horizontal-scroll').style.width = $(component+'-container').offsetWidth - $(component+'-scroll').getStyle('width').toInt() - $(component+'-scroll').getStyle('margin-right').toInt() - $(component+'-horizontal-wrapper').getStyle('padding-left').toInt() - 8 + 'px';
			$(component+'-horizontal-wrapper').style.width = $(component+'-container').offsetWidth - $(component+'-scroll').getStyle('width').toInt() - $(component+'-scroll').getStyle('margin-right').toInt() - $(component+'-horizontal-wrapper').getStyle('padding-left').toInt() - 8 + 'px';
		}
		else
		{
			$(component+'-horizontal-scroll').style.width = $(component+'-container').offsetWidth - $(component+'-scroll').getStyle('width').toInt() - $(component+'-scroll').getStyle('margin-right').toInt() - $(component+'-horizontal-wrapper').getStyle('padding-left').toInt() - 4 + 'px';
			$(component+'-horizontal-wrapper').style.width = $(component+'-container').offsetWidth - $(component+'-scroll').getStyle('width').toInt() - $(component+'-scroll').getStyle('margin-right').toInt() - $(component+'-horizontal-wrapper').getStyle('padding-left').toInt() - 4 + 'px';
		}
		// Finds the ratio of the scroll area to the visible area

		if($(component+'-horizontal-wrapper').offsetWidth / $(component+'-horizontal-wrapper').scrollWidth > 1)

			var scrollRatioH = 1;

		else

			var scrollRatioH = $(component+'-horizontal-wrapper').offsetWidth / $(component+'-horizontal-wrapper').scrollWidth;

		// Adjusts the size of the handle based on the ratio

		$(component+'-horizontal-knob').style.width = scrollRatioH * $(component+'-horizontal-scroll').offsetWidth + 'px';

		// Resets the scrollbar due to size change

		if(scrollBar[component+'-horizontal'])

		{

			scrollBar[component+'-horizontal'].resetIni();

			$(component+'-horizontal-wrapper').scrollLeft = (scrollBar[component+'-horizontal'].step / 15) * ($(component+'-horizontal-wrapper').scrollWidth - $(component+'-horizontal-wrapper').offsetWidth);

		}

	}

	else

	{

		controlHeight = $(component+'-container').getStyle('padding-top').toInt() + $(component+'-container').getStyle('padding-bottom').toInt();

		if($(component+'-top'))

			controlHeight += $(component+'-top').offsetHeight;

		if($(component+'-top-second'))

			controlHeight += $(component+'-top-second').offsetHeight;

		if($(component+'-container').offsetHeight < 14 + controlHeight)
			controlHeight = $(component+'-container').offsetHeight - 14;

		$(component+'-wrapper').style.height = $(component+'-container').offsetHeight - controlHeight - 3 + 'px';

		// Adjust the height of the custom scroll bar

		$(component+'-scroll').style.height = $(component+'-container').offsetHeight - controlHeight - 14 + 'px';

	}

	// Finds the ratio of the scroll area to the visible area

	if($(component+'-wrapper').offsetHeight / $(component+'-wrapper').scrollHeight > 1)

		var scrollRatio = 1;

	else

		var scrollRatio = $(component+'-wrapper').offsetHeight / $(component+'-wrapper').scrollHeight;

	// Adjusts the size of the handle based on the ratio

	$(component+'-knob').style.height = scrollRatio * $(component+'-scroll').offsetHeight + 'px';

	// Resets the scrollbar due to size change

	if(scrollBar[component])

	{

		scrollBar[component].resetIni();

		$(component+'-wrapper').scrollTop = (scrollBar[component].step / 15) * ($(component+'-wrapper').scrollHeight - $(component+'-wrapper').offsetHeight);

	}

}



// Functions to convert RGB to Hex and Hex to RGB

function RGBtoHex(RGB) {

	var rgbColor = RGB.replace("rgb(","").replace(")","").split(", ");

	return "#"+toHex(rgbColor[0])+toHex(rgbColor[1])+toHex(rgbColor[2]);

}

function toHex(N) {

	if (N==null) return "00";

	N=parseInt(N); if (N==0 || isNaN(N)) return "00";

	N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);

	return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);

}

function HextoRGB(hex){

	hex = hex.replace("#","");
	
	if(hex.length == 3)
	{
	var rColor = parseInt((hex).substring(0,1) +""+(hex).substring(0,1),16);

	var gColor = parseInt((hex).substring(1,2) +""+(hex).substring(1,2),16);

	var bColor = parseInt((hex).substring(2,3) +""+(hex).substring(2,3),16);
	}
	else
	{
	var rColor = parseInt((hex).substring(0,2),16);

	var gColor = parseInt((hex).substring(2,4),16);

	var bColor = parseInt((hex).substring(4,6),16);
	}
	return "rgb("+ rColor +", "+ gColor +", "+ bColor +")";

}



// Function to change colors and return as hex (negative darkens and positive lightens). Change is value from -255 to 255

function colorChange(color,change){

	if(color.match("#"))

		color = HextoRGB(color);

	rgbColor = color.replace("rgb(","").replace(")","").split(", ");

	for(x=0;x<3;x++)

	{

		rgbColor[x] = parseInt(rgbColor[x]) + change;

		if(rgbColor[x] > 255)

			rgbColor[x] = 255;

		if(rgbColor[x] < 0)

			rgbColor[x] = 0;

	}

	return RGBtoHex("rgb("+ rgbColor[0] +", "+ rgbColor[1] +", "+ rgbColor[2] +")");

}



// Function to adjust lightness of text with mouseover

function lightenText(className,change){

	$$('.'+className).each(function(lighten){

		lighten.addEvent('mouseenter',function(){

			lighten.style.color = colorChange(lighten.getStyle('color'),change);

		});

		lighten.addEvent('mouseleave',function(){

			lighten.style.color = colorChange(lighten.getStyle('color'),-change);

		});

	});

}



// Functioin creates the tool tips for any element with the class Tips. content of tip is taken from the 'rel' attribute

function createTips(tipClass){

	var toolTips = new Tips('.'+tipClass, {

		offsets: {'x': 16, 'y': -26},

		showDelay: 500,

		hideDelay: 500

	});

	$$('.'+tipClass).each(function(tipClick){

		tipClick.addEvent('click',function(){

			$$('.tip').each(function(tip){

				tip.parentNode.style.visibility = "hidden";

			});

		});

	});

}



// Trim Functions

function trim(stringToTrim) {

	return stringToTrim.replace(/^\s+|\s+$/g,"");

}

function ltrim(stringToTrim) {

	return stringToTrim.replace(/^\s+/,"");

}

function rtrim(stringToTrim) {

	return stringToTrim.replace(/\s+$/,"");

}

// Hide/show components
var compOpened = new Array();
function hideComponent(component){
	if(compOpened[component] == "show")
	{
		compOpened[component] = $(component+'-container').parentNode.id;
		$(component+'-container').inject('hidden-components');
		$('toolbar-'+component).style.color = '#FFFFFF';
		$('toolbar-'+component).style.background = '#4d4d4d';
		if(compOpened[component] != "wrapper")
			maximizeComponents(compOpened[component]);
	}
	else
	{
		if(compOpened[component] == "wrapper")
		{
			$(component+'-container').style.position = 'absolute';
			$(component+'-container').style.top = '50px';
			$(component+'-container').style.left = '50px';
		}
		$(component+'-container').inject(compOpened[component]);
		if(compOpened[component] != "wrapper")
			maximizeComponents(compOpened[component]);
		compOpened[component] = "show";
		$('toolbar-'+component).style.color = '#4d4d4d';
		$('toolbar-'+component).style.background = '#1a1a1a';
	}
}



window.addEvent('domready', function(){

	// Rounds corners

	// Nifty("div.rounded","transparent");

	// Nifty("div.rounded-top","transparent top");

	

	lightenText('lighten',32);

	lightenText('xlighten',64);

	createTips('Tips');

});

// Expanding & Collapsing a Component
// Relies on the component structure already in place
// Uses a div id="[component]-expand-collapse"
var stopExpand = false;
function expandCollapseComponent(element)
{
  if(!stopExpand && $(element + '-container').parentNode.id != "wrapper")
  {
   stopExpand = true;
   if (element.id) element = element.id;
   var component = $(element + '-container');
   var handle = $(element + '-handle');

   // Expand and collapse to:
   var lower = 26;
   
   // This is the expand height
   var upper = parseInt(getComponentModule(element).getStyle('height')) + 26;
   getComponentModule(element).getElements('.full-stretch').each(function(currComp){
     upper -= $(currComp.id + '-container').offsetHeight;
   });

   // Check the position of the expand-collapse toggle
   if (parseInt(component.getStyle('height')) == lower && upper != lower)
   {
      expandElement(element + '-container',upper,false);
      // Set the style of the arrow
      $(element + '-expand-collapse').set(
      {
         'styles':
         {
            'background-image': 'url("images/collapseGroup.gif")',
            'width': '12px',
            'height': '6px',
            'margin-left': '8px',
		'margin-right': '0px',
		'margin-top': '12px'
         }
      });

      // Display the component handle
      handle.setStyle('display', 'block');
   }
   else
   {
      compactElement(element + '-container',lower,false);
      // Set the style of the arrow
      $(element + '-expand-collapse').set(
      {
         'styles':
         {
            'background-image': 'url("images/expandGroup.gif")',
            'width': '6px',
            'height': '12px',
            'margin-left': '10px',
		'margin-right': '4px',
		'margin-top': '9px'
         }
      });

      // Hide the component handle
      handle.setStyle('display', 'none');
   }
	(function() {
		adjustBar(element); 
		stopExpand = false;
	}).delay(1000);
  }
}

// Gets the number of components existing in the specified module
function getNumComponents(module)
{
   if (module.id) module = module.id;
   return $$('#' + module + ' .full-stretch').length;
}

// Gets the module housing the component
function getComponentModule(component)
{
   if (component.id) component = component.id;
   var thisModule;
   $$('.module').each(function(currModule)
   {
      $$('#' + currModule.id + ' .full-stretch').each(function(currComp)
      {
         // If we found our match, stop everything and return our current module
         if (currComp.id == component)
         {
            thisModule = currModule;
         }
      });
   });
   return thisModule;
}

window.addEvent('domready', function()
{
   $('group-expand-collapse').addEvent('click', function()
   {
      expandCollapseComponent('group');
   });

   $('message-expand-collapse').addEvent('click', function()
   {
      expandCollapseComponent('message');
   });

   $('archive-expand-collapse').addEvent('click', function()
   {
      expandCollapseComponent('archive');
   });

   var components = $$('.full-stretch');
   // Get the height we need to set for all the modules (--2 because of the border-bottom)
   var h = parseInt($$('#wrapper .module')[0].getStyle('height')) - 2;

   components.each(function(currComp)
   {
      $(currComp.id + '-container').setStyle('height', h);
   });

   preloader();
});



function createNewElm(typeArg,classArg,idArg,textArg,srcArg)
{
	var thisElm = document.createElement(typeArg);
	if(classArg)
		thisElm.className = classArg;
	if(idArg)
		thisElm.id = idArg;
	if(srcArg)
		thisElm.src = srcArg;
	if(textArg)
		thisElm.innerHTML = textArg;
	return thisElm;
}

window.addEvent('load', function(){
	$('wrapper').style.visibility = "visible";
	$('loadScreen').style.display = "none";
	if(document.body.offsetWidth < 1100)
	{
		$('wrapper').style.width = 750 + 'px';
		$('leftmod').style.width = 185 + 'px';
		$('centermod').style.width = 340 + 'px';
		$('rightmod').style.width = 210 + 'px';
		$('toolbar-container').style.width = 741 + 'px';
		changeResize('group','leftmod');
		changeResize('player','centermod');
		changeResize('message','rightmod');
	}
 });
 
function preloader() 
{
     // create object
     var imageObj = new Image();

     // set image list
     var images = new Array("images/player_corner.png","images/player_corner_hover.png","images/video_corner.png","images/video_corner_hover.png","images/tip_top.gif","images/tip_bottom.gif","images/tip_middle.gif","images/tip_point.gif","images/video_corner_small.png","images/video_corner_small_hover.png","images/player_slider_bg.png","images/player_slider_handle_hover.png","images/player_slider_handle_hover.png","images/camera_slider_bg.png","images/camera_slider_handle.png","images/camera_change_bg.png","images/camera_change_bg_over.png","images/mic_settings_bg.png","images/mic_settings_bg_over.png","images/camera_slider_bg.png","images/camera_slider_handle.png","images/camera_slider_bg.png","images/go_back.png","images/go_back_hover.png","images/cam_settings.png","images/cam_settings_hover.png","images/add_group.png","images/add_group_hover.png","images/remove_group.png","images/remove_group_hover.png","images/bullet_blue.png","images/bullet_gray.png","images/bullet_blue_selected.png","images/bullet_gray_selected.png","images/join_group.png","images/join_group_hover.png","images/join_group_blue.png","images/join_group_blue_hover.png","images/chat.png","images/chat_hover.png","images/add.png","images/add_hover.png","images/remove.png","images/remove_hover.png","images/controls.png","images/controls_hover.png","images/list_expanded.png","images/profile.png","images/profile_hover.png","images/group_switch.png","images/group_switch_hover.png","images/invites.png","images/invites_hover.png","images/camera_change_bg.png","images/camera_change_bg_over.png","images/mic_settings_bg.png","images/mic_settings_bg_over.png","images/camera_slider_bg.png","images/camera_slider_handle.png","images/camera_slider_bg.png","images/pm.png","images/pm_hover.png","images/change_colors.png","images/change_colors_hover.png","images/message_controls.png","images/message_controls_hover.png","images/play_video.png","images/play_video_hover.png","images/stop_video.png","images/stop_video_hover.png","images/stats.png","images/stats_hover.png","images/stats_hover.png","images/remove_video.png","images/remove_video_hover.png","images/message_controls.png","images/message_controls_hover.png","images/gray_dot.gif","images/toolbar_slider.png","images/toolbar_handle.png","images/collapseGroup.gif");

     // start preloading
     for(i=0; i<images.length; i++)
          imageObj.src=images[i];
}