var jqueryslidemenu={

animateduration: {over: 200, out: 100},

buildmenu:function(menuid){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			//alert(this.offsetWidth + " " + $('.header_nav_menu_tips').css('width'));
			this._dimensions={w:( this.offsetWidth > 1000 ? $('.header_nav_menu_tips').css('width') : this.offsetWidth ), h:this.offsetHeight, subulw: ( $subul.outerWidth() > 1000 ? $('.header_nav_menu_tips').css('width') : $subul.outerWidth() ), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					if ($targetul.queue().length<=1)
						$targetul.css({left:menuleft+"px", top:"50px", zIndex:10, width:this._dimensions.subulw+'px'}).slideDown(jqueryslidemenu.animateduration.over)
				},
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					$targetul.slideUp(jqueryslidemenu.animateduration.out)
				}
			)
		})
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	})
}
};

jqueryslidemenu.buildmenu("menu_container");

$().ready(function() {
	$('#sidebar_messages_href').click(function(){
		$('#sidebar_messages').addClass('sidebar_messages_active');
		$('#sidebar_journalism').removeClass('sidebar_journalism_active');
		
		$('#sidebar_journalism_content').css('display', 'none');
		$('#sidebar_messages_content').css('display', 'block');
	});
	
	$('#sidebar_journalism_href').click(function(){
		$('#sidebar_journalism').addClass('sidebar_journalism_active');
		$('#sidebar_messages').removeClass('sidebar_messages_active');
		
		$('#sidebar_messages_content').css('display', 'none');
		$('#sidebar_journalism_content').css('display', 'block');
	});
	
	if ( document.getElementById('login_signup') != undefined )
	{
		document.getElementById('login_signup').focus();
	}
});

function handle_keypress(e)
{
	e = e || window.event;
	var unicode=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
	if (unicode == 13) {
		document.filter_form.submit();
	}
}

function signup_set_company()
{
	if ( document.getElementById('is_invoice').checked == false )
	{
		$('#invoice_company').parent().parent().css('display', 'none');
		$('#invoice_nip').parent().parent().css('display', 'none');
		$('#invoice_street').parent().parent().css('display', 'none');
		$('#invoice_number').parent().parent().css('display', 'none');
		$('#invoice_flat').parent().parent().css('display', 'none');
		$('#invoice_postcode').parent().parent().css('display', 'none');
		$('#invoice_city').parent().parent().css('display', 'none');
		$('#name').parent().parent().css('display', 'none');
	}
	else {
		$('#invoice_company').parent().parent().css('display', 'block');
		$('#invoice_nip').parent().parent().css('display', 'block');
		$('#invoice_street').parent().parent().css('display', 'block');
		$('#invoice_number').parent().parent().css('display', 'block');
		$('#invoice_flat').parent().parent().css('display', 'block');
		$('#invoice_postcode').parent().parent().css('display', 'block');
		$('#invoice_city').parent().parent().css('display', 'block');
		$('#name').parent().parent().css('display', 'block');
	}
}

if ( typeof console != 'undefined' )
	console.log();


if ( window.CKEDITOR )
{
	(function()
	{
		var showCompatibilityMsg = function()
		{
			var env = CKEDITOR.env;

			var html = '<p><strong>Twoja przeglądarka nie jest kompatybilna CKEditor.</strong>';

			var browsers =
			{
				gecko : 'Firefox 2.0',
				ie : 'Internet Explorer 6.0',
				opera : 'Opera 9.5',
				webkit : 'Safari 3.0'
			};

			var alsoBrowsers = '';

			for ( var key in env )
			{
				if ( browsers[ key ] )
				{
					if ( env[key] )
						html += ' CKEditor jest kompatybilny z ' + browsers[ key ] + ' lub wyższym.';
					else
						alsoBrowsers += browsers[ key ] + '+, ';
				}
			}

			alsoBrowsers = alsoBrowsers.replace( /\+,([^,]+), $/, '+ i $1' );

			html += ' Jest także kompatybilny z ' + alsoBrowsers + '.';

			html += '</p><p>W niekompatybilnych przeglądarkach możesz edytować tekst w formie PLAIN.</p>';

			document.getElementById( 'alerts' ).innerHTML = html;
		};

		var onload = function()
		{
			if ( !CKEDITOR.env.isCompatible )
				showCompatibilityMsg();
		};

		if ( window.addEventListener )
			window.addEventListener( 'load', onload, false );
		else if ( window.attachEvent )
			window.attachEvent( 'onload', onload );
	})();
}

