
document.write('<script type="text/javascript" src="/common/js/jquery.form.js"></script>');

(function($) {

	$.fn.topic = function()
	{	
		return this.each(function()
		{
			var $topic = $(this);

			$topic.find('a').each(function()
			{
				if($topic.next('a').length != 0)
				{
					$topic.css({paddingRight:8});
				}
			});

			$topic.find('h5').each(function()
			{
				$topic.prev('h4,h5').css({marginBottom:0});
			});

			$topic.children().not('img,ul').css({marginLeft:$topic.find('img:first').width()+20});
			$topic.children('ul').css({marginLeft:$topic.find('img:first').width()+20+15});

			if($topic.parents('div.float-box').length == 0)
			{
				$topic.after('<div class="clear"></div>');
			}
		});
	};

	$.fn.gallery = function()
	{
		return this.each(function()
		{
			$gallery = $(this);

			$gallery.filter('.gallery-left').find('div:first').css({left:$gallery.find('img:first').width()+5});

			$gallery.filter('.gallery,.gallery-left').find('div:first > img').each(function()
			{
				var _image = $(this);
				
				_image.attr('galleryimage',_image.attr('title')).attr('title','').click(function()
				{
					$gallery.find('> img').attr('src',_image.attr('galleryimage'));
				});
			});

			$gallery.filter('.press-release-gallery').find('div:first > img').each(function()
			{
				var _image = $(this);
				
				_image.attr('gallerysrc',_image.attr('title').split(',')[0]);
				_image.attr('enlargesrc',_image.attr('title').split(',')[1]);
				
				_image.attr('title','').mouseover(function()
				{
					$gallery.find('> img').attr('src',_image.attr('gallerysrc')).attr('enlargesrc',_image.attr('enlargesrc'));
				});
			});

			$gallery.filter('.press-release-gallery').find('> img').attr('enlargesrc',$gallery.find('div img:first').attr('enlargesrc'));
		});
	};

	$.fn.jumpMenu = function()
	{
		return this.each(function()
		{
			$(this).change(function()
			{
				if($(this).val() != 'null')
				{
					document.location = $(this).val();
				}
			});
		});
	};

	$.fn.filterMenu = function()
	{
		return this.each(function()
		{
			var _menu = $(this);
			var _select = _menu.find('select:first');
			
			_select.css({display:'inline'});

			_select.change(function()
			{
				_menu.find('select:gt(0)').css({display:'none'});
				_menu.find('select[name='+_select.val()+']').css({display:'inline'}).val('null');
				$('.filter-attr').parent().show();
			});
			
			_menu.find('select:gt(0)').change(function()
			{
				if($(this).val() != 'null')
				{
					$('.filter-attr').parent().hide();
					$('.filter-attr:contains('+$.trim($(this).val())+')').parent().show();
				}
				else
				{
					$('.filter-attr').parent().show();
				}
			});

			_select.change();
		});
	};

	$.fn.globalOperations = function()
	{
		return this.each(function()
		{
			var _page = $(this);

			_page.parents('.about-content').find('div.flash').css({textAlign:'left'});

			_page.find('table tr td:first').css({fontWeight:'bold',fontSize:'12px'});

			_page.find('h3').each(function(i)
			{
				_page.find('select:first').append('<option value="'+i+'">'+$(this).text()+'</option>');
			});

			_page.find('select:first').change(function()
			{
				_page.find('tr').show();
				
				if($(this).val() == 'null')
				{
					_page.find('select:last').empty().append('<option value="null">Select Region / Country</option>');
					_page.find('select:last').attr('disabled','disabled');

					_page.find('div').show();
				}
				else
				{
					_page.find('div').hide();

					_page.find('select:last').empty().attr('disabled','');
					_page.find('select:last').append('<option value="null">Select Region / Country</option>');
					
					var last = "";

					_page.find('div:eq('+$(this).val()+') tr').find('td:first').each(function()
					{	
						var text = $.trim($(this).text().replace('(Head Quarter)','').replace('(Head Quarters)',''));

						if(text != last)
						{
							_page.find('select:last').append('<option value="'+text+'">'+text+'</option>');
						}
						last = text;
					});

					_page.find('div:eq('+$(this).val()+')').show();
				}
			});

			_page.find('select:last').change(function()
			{
				var value = $.trim($(this).val());

				if(value != 'null')
				{
					_page.find('tr').find('td:first').each(function()
					{
						if($.trim($(this).text().replace('(Head Quarter)','').replace('(Head Quarters)','')) != value)
						{
							$(this).parents('tr').hide();
						}
						else
						{
							$(this).parents('tr').show();
						}

					});
				}
				else
				{
					_page.find('tr').show();
				}
			});
		});
	};

	$.fn.library = function()
	{
		return this.each(function()
		{
			var _container = $(this);
			var _rows = Math.floor($(this).find('div').length/4);
			
			for(var i=0; i < _rows; i++)
			{
				var _maxHeight = 0;
				
				for(var j=0; j < 4; j++)
				{
					(_container.find('h4:eq('+((i*4)+j)+')').height() > _maxHeight) ? _maxHeight = _container.find('h4:eq('+((i*4)+j)+')').height() : null;
				}

				for(var j=0; j < 4; j++)
				{
					_container.find('h4:eq('+((i*4)+j)+')').css({height:_maxHeight});
				}
			}
		});
	};

})(jQuery);

window.onload = function()
{
	onLoadPreInit();
	$('h1,div.hero h3,div.header h3').mafr();
	$('h2').each(function()
	{
		if($(this).parents('div.faqs').length == 0 && $(this).parents('div.header').length == 0 && $(this).parents('div#left-nav-dom').length == 0)
		{
			$(this).mafr();
		}
	});

	$('.about-content .header').each(function()
	{
		var $header = $(this);

		$header.parents('.about-content').css({margin:'0 auto'});
		
		$('body').css({background:'url(/us/img/about/bg-section-gradient.jpg) 0px 291px repeat-x'});

		if($header.attr('style').indexOf('investor-relations') != -1)
		{
			$('body').css({background:'url(/us/img/about/bg-section-gradient.jpg) 0px 286px repeat-x'});
		}

		if($header.attr('style').indexOf('press') != -1)
		{
			$('body').css({background:'url(/us/img/about/bg-section-gradient-press.jpg) 0px 287px repeat-x'});
		}

		if($header.attr('style').indexOf('experience-lg') != -1)
		{
			$('body').css({background:'url(/us/img/about/bg-section-gradient-experience.jpg) 0px 290px repeat-x'});
		}
	});
	
	$('.image-left,.image-right').each(function()
	{
		$(this).find('span:first').css({width:$(this).find('img:first').width()});
	});
	
	$('table').each(function()
	{
		$(this).find('tr:even').addClass('odd');
	});
	
	$('.content-list li').append('<div class="clear"></div>');

	$('.topic').topic();
	$('.gallery,.gallery-left,.press-release-gallery').gallery();
	$('.library-container').library();
	$('select.jump-menu').jumpMenu();
	$('.filter-menu').filterMenu();
	$('.global-operations').globalOperations();
	$('.button,.small-button,.app-button').button();

	$('.library-container .preview,.press-release-gallery > img,.tv-ads span.watch-video,.overlay-banner-ad,.stakeholder-engagement .detailview,.certification-procedure .detailview').overlay(); //2009-12-02 lbc modify
	$('input:text').prefill();
	$('form').form();

	$('div.content-container > .flash').embed();
	/*//overlay duplicate delete : 20100413 JinMoongi start*/
	if($('.library-container .preview,.press-release-gallery > img,.tv-ads span.watch-video,.overlay-banner-ad,.stakeholder-engagement .detailview,.certification-procedure .detailview').length == 0) {
		$('.overlay-content').overlay(); /* //overlay : 20100310 parkjeongmi add */
	}
	/*//overlay duplicate delete : 20100413 JinMoongi end*/
	
	$('.content-container').css({visibility:'visible',paddingTop:0}); /* //SMG-198 about-lg css modify : 20100608 parkjeongmi modify */
	
	/* social : 20100309 parkjeongmi add */
	$('.content-container').find('.social').each(function()
	{
		$(this).find('a').each(function()
		{
			try
			{
			  	eval("var _url='"+this.href.replace(/%27/g,"'")+"';");
				this.href = _url;
			}
			catch(e)
			{
			} 
			this.target = "_blank";
		});
	});
	/* //social : 20100309 parkjeongmi add */
	
	/* LGEINMA-13 India B2B site project. : 20100701 parkjeongmi add */
	$('.testimonial-content').each(function() 
	{
		var $testimonial = $(this);
		$testimonial.find('h5').mafr({font:'BryantProBold'});
		
		$testimonial.find('.rs-type-one').each(function()
		{
			$(this).find('.img-content div').not('.flash').each(function(idx)
			{
				((idx%2) == 0) ? $(this).addClass('float-left') : $(this).addClass('float-right');
			});
		});
		
		$testimonial.find('.rs-type-two').each(function()
		{
			$(this).find('.text-content').addClass('float-right');
			$(this).find('.img-content').addClass('float-left');
		});
		
		$testimonial.find('.flash').embed();
		
	});
	/*//LGEINMA-13 India B2B site project. : 20100701 parkjeongmi add */
	
	/* //LGEAE-123 Change the text 'Watch Video' for Radio Ads : 20100802 parkjeongmi add */
	$(".audio-preview a").audioplay();

	onLoadPostInit();
}

function country(index)
{
	$('.region').hide();
	$('.region:eq('+(index-1)+')').show();
}

function Identity(index)
{
}

/* award slide */
var msie_browser = (document.all) ? true : false;
var old_m = "1";
var m = "1";

function product(m) 
{
	if(old_m != m) 
	{
		document.getElementById("product" + m).style.display = "block";
	}

	if(old_m != "")
	{
		document.getElementById("product" + old_m).style.display = "none";
	}

	if(old_m = m)
	{
		document.getElementById("product" + m).style.display = "block";
	} 
	else 
	{
		old_m = m;
	}
}

function Goto(index)
{
	if(index > 0 && index < 11)
	{
		window.open("http://www.lg.com/about/design/portfolio2008.jsp?pr="+index,"lgdesignportfolio","width=750,height=520,history=no,resizable=no,status=no,scrollbars=no,menubar=no");
	}
}

$(function(){
	/* 20091127 lbc add */
	$('.award-year select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});

	$('.prints-ads-year select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});

	$('.tv-ads-year select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});

	$('.global-sports-list select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});

	$('.history-year select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});

	$('.design-award-year select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});
	$('.serch-site select').dropdown().change(function(){
		if($(this).val() != 'null') location.href = $(this).val();
	});
	$('.mobile-phonesPop select').dropdown().change(function(){
		for (i=0;i <= 5 ;i++ ) {
			$('#region'+i).find('ul').addClass('off');
		}
		$('#country-' + $(this).val()).removeClass('off');
	});

	$('#job-search-site select').dropdown();
	/* 20091127 lbc add */
	
	/* 20091022 leadweb add */
	$('.tab-menu-content').find('a.tab').each(function(){
		if(document.location.hash){
			if($(this).attr('href') == document.location.hash){
				$(this).parent('li').addClass('on');
				$($(this).attr('href')).show();
			}else{
				$(this).parent('li').removeClass('on');
				$($(this).attr('href')).css({display:'none'});
			}
		}else{
			if($(this).parent('li').hasClass('on')) $($(this).attr('href')).show();
			else $($(this).attr('href')).css({display:'none'});

			if(!$('.tab-menu-content').find('li.on').length){
				$('.tab-menu-content').find('a.tab:eq(0)').parent('li').addClass('on');
				$($('.tab-menu-content').find('a.tab:eq(0)').attr('href')).show();
			}
		}
		
		$(this).click(function(){
			if($(this).attr('href').indexOf('#') == 0){
				$($('.tab-menu-content').find('li.on a.tab').attr('href')).hide();
				$('.tab-menu-content').find('li.on').removeClass('on');
				$($(this).attr('href')).show();
				$(this).parent('li').addClass('on');
				return false;
			}
		});
	});
	/*//20091022 leadweb add */
});

