function popup(url,name) 
{
	return window.open(url,name,'width=600,height=400,location=no,toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no');
}
function popupmedia(url,name)
{
	return window.open(url,name,'width=330,height=430,location=no,toolbar=no,directories=no,menubar=no,resizable=no,scrollbars=no,status=no');
}
function loadSth()
{
	$('contentBar').innerHTML='';
	$('contentBar').className='';
	$('loadingBar').style.display='block';
}
function unloadSth(message,type)
{
	$('contentBar').innerHTML=message;
	$('contentBar').className=type;
	$('loadingBar').style.display='none';
}
// ---------------------------------------------------

function showFlash()
{
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}
//------------------------------------

var timer1;
var timer2;
var timerLogin1;
var actualMenu='';
var defaultMenu='';
var _subMenu='';
var _newColor='';
var colorMenu;
var fixedPanel=false;
$(document).ready(function() 
{	
	$('#secundaryMenu').css('background-color',colorMenu);
	defaultMenu=String($('#listMainMenu li.selected').attr('id')).substr(4);
	$('#secundaryMenu').hover(function(){clearTimeout(timer1);}, function(){preparePanel();});
	$('#listMainMenu a').hover(function(){}, function(){preparePanel();});
	
	$('#cartLayer').mousedown(function(){$(this).addClass('clickCartButton');});
	$('#userPanel').mousedown(function(){$(this).addClass('clickUserButton');clearTimeout(timerLogin1);$('#loginPanel').show();fixedPanel=true;});
	$('#cartLayer').mouseup(function(){if($(this).hasClass('clickCartButton')){$(this).removeClass('clickCartButton');}});
	$('#userPanel').mouseup(function(){if($(this).hasClass('clickUserButton') && !fixedPanel){$(this).removeClass('clickUserButton');}});
	$('#cartLayer').mouseenter(function(){$(this).removeClass('clickCartButton');$(this).removeClass('clickUserButton');$(this).addClass('hoverButtons');});
	$('#userPanel').mouseenter(function(){if(!fixedPanel){$(this).removeClass('clickCartButton');$(this).removeClass('clickUserButton');$(this).addClass('hoverButtons');}clearTimeout(timerLogin1);if(!fixedPanel){$('#loginPanel').fadeIn();}});
	$('#loginPanel').hover(function(){clearTimeout(timerLogin1);}, function(){if(!fixedPanel){timerLogin1=setTimeout('closeLogin()',200);}});
	$('#cartLayer').mouseleave(function(){$(this).removeClass('hoverButtons');$(this).removeClass('clickCartButton');});
	$('#userPanel').mouseleave(function(){if(!fixedPanel){$(this).removeClass('hoverButtons');$(this).removeClass('clickUserButton');}if(!fixedPanel){timerLogin1=setTimeout('closeLogin()',200);}});
	
	$('body').click(function(e) {
        if (e.target.id == 'userPanel' || $(e.target).parents('#userPanel').size()) { 
            // Inside
        } else { 
           fixedPanel=false;
		   timerLogin1=setTimeout('closeLogin()',200);
		   $('#userPanel').removeClass('hoverButtons');$('#userPanel').removeClass('clickUserButton');
        }
    });
	
});
function rgb2hex(rgb) {
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

function hex(x) {
	return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}
function showSubmenu(submenu,newColor)
{
	if(actualMenu!='')
		$('#'+actualMenu).hide();
	else
		$('#'+defaultMenu).hide();
	_subMenu=submenu;
	_newColor=newColor;
	clearTimeout(timer1);
	clearTimeout(timer2);
	timer2=setTimeout('finallyShow()',200);
}
function finallyShow()
{
	$('#'+_subMenu).show();
	$('#secundaryMenu').animate({ backgroundColor: _newColor}, 200);
	actualMenu=_subMenu;
}
function preparePanel()
{
	timer1=setTimeout('closePanel()',1000);
}
function closeLogin()
{
	clearTimeout(timerLogin1);
	$('#loginPanel').fadeOut('50');
}
function closePanel()
{
	clearTimeout(timer1);
	if(actualMenu!=defaultMenu)
	{	
		if(actualMenu!='')
			$('#'+actualMenu).hide();
		$('#secundaryMenu').animate({ backgroundColor: colorMenu}, 200);
		$('#'+defaultMenu).show();
	}
	actualMenu='';
}
