﻿$(document).ready(function(){

	$("#main_left div.two div.right h2").corner("top 8px");
	$("#inner_right h2").corner("tl bl 6px");
//	$("#top_nav ul ul").corner("tr 8px");
	$("#inner_right h2").corner("tl bl 6px");
	
	$("#top_banner").css('padding-top',$("#main_top").get(0).offsetHeight - 183);
	
	w = $("#top_nav").get(0).offsetWidth + 275;
	if(navigator.userAgent.indexOf("IE 6") != -1) w += 3;
	$("#main_left").css('width',w);
	$("#main_right_out").css('margin-left',-w);
	$("#main_right").css('margin-left',w+20);
	
	$('#top_search input.button').each(
		function()
		{
			$(this).mouseover(
				function()
				{
					$(this).attr('src','/images/web/button_01_a.gif');
				}
			)
			$(this).mouseout(
				function()
				{
					$(this).attr('src','/images/web/button_01.gif');
				}
			)
		}
	)

	$('#firms_top_info div.submit input.button').each(
		function()
		{
			$(this).mouseover(
				function()
				{
					$(this).css("background-image","url('/images/web/filter_button_back_a.gif')");
				}
			)
			$(this).mouseout(
				function()
				{
					$(this).css("background-image","url('/images/web/filter_button_back.gif')");
				}
			)
		}
	)

	$("input:text").each(
	function()
	{
		if(this.value!='')
		{
		$(this).attr('val',this.value);
		$(this).addClass('text');
			$(this).focus(
				function()
				{
					if(this.value == $(this).attr('val'))
					{
						this.value = '';
					}
				}
			)
			$(this).blur(
				function()
				{
					if(this.value == '')
					{
						this.value = $(this).attr('val');
					}
				}
			)
		}
	}
	)

	$('.metro').each(
		function()
		{
			$('div.selectable div.item',this).each(
				function()
				{
					$(this).mouseover(
						function()
						{
							$('.metro div.selectable div.item').removeClass('over');
							$(this).addClass('over');
						}
					)
				}
			)
		
			$(this).mouseover(
				function()
				{
					$('div.selectable',this).css('display','block');
					
				}
			)
			$(this).mouseout(
				function()
				{
					$('div.selectable',this).css('display','none');
					
				}
			)

			$('div.selectable input[@type="checkbox"]',this).each(
				function()
				{
					$(this).change(
						function()
						{
							set_text(this);
						}
					)
				}
			)
		
			$('div.selectable input[@type="checkbox"]',this).eq(0).each(
				function()
				{
					$(this).click(
						function()
						{
							selectable = this.parentNode.parentNode;
							a = $('input[@type="checkbox"]',selectable);
							if(this.checked)
							{
								for(i=0;i<a.length;i++)
								{
									if(i!=0)
									{
										a[i].checked = 'checked';
									}
								}
							}
							else
							{
								for(i=0;i<a.length;i++)
								{
									if(i!=0)
									{
										a[i].checked = '';
									}
								}
							}
						}
					)
				}
			)
		
		}
	)

  	if ((navigator.userAgent.indexOf('MSIE') != -1)) {
		$("#top_nav li").hoverClass("over");
	}

});

function set_text(node)
{
	selectable = node.parentNode.parentNode;
	text = '';
	a = $('input[@type="checkbox"]',selectable);
	for(i=0;i<a.length;i++)
	{
		if(i!=0)
		{
			if(a[i].checked)
			{
				text += $(a[i].parentNode).text();
			}
		}
	}
	$('input.a',selectable.parentNode).get(0).value = text;
}


$.fn.hoverClass = function(c) {
			return this.each(function(){
				$(this).hover( 
					function() { $(this).addClass(c); },
					function() { $(this).removeClass(c); }
				);
			});
		};
