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

(function($) {
    $.fn.flagship = function(options){

		var opts = $.extend({}, $.fn.flagship.defaults, options);

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

			if( $('#flagship-flash-container').length > 0 ) {
				var flashwidth = $(window).width() - 0; 
				var flashheight =  $(window).height() - opts.footer - opts.header; 

				if( $('.flagship-flash-iframe').length <= 0 && $('#flash-content-url').length > 0 ){
					var _src = $.trim($('#flash-content-url').attr('value'));
					$('#lg_main_loader').prepend('<iframe class="flagship-flash-iframe" width="'+flashwidth+'px" height="'+flashheight+'" frameborder="0" allowtransparency="true" scrolling="auto" src="'+_src+'"></iframe>');
					$('.flagship-flash-iframe').mouseover(function(){
						if($('#left-nav-dom').css("left") != "0px"){
							$('#left-nav-dom').add('div.shutter').stop().animate({left:-205},opts.toggleTiming,opts.toggleEasing, function(){
									$('div.shutter span.close').css({backgroundPosition:"-11px center"});
							});
						}
					});
					$('.loading').remove();
				}

				$('#flagship-flash-container').css({height: flashheight + 'px', width: flashwidth + 'px'});					
			    $('#lg_main_loader').css({visibility:'visible'});
			}

			$flagship.bind('flagship:resize',function(){
				var footerLeft = 0;
				var flashwidth = $(window).width(); 
				var flashheight =  $(window).height() - opts.footer - opts.header; 
				if( $('div#left-nav-dom').css("left") == "0px" ) {
						$('.flagship-product-links').addClass('flagship-product-links-open');
						footerLeft = (flashwidth - $('.flagship-footer').width() + 230)/2;
				}else{
						$('.flagship-product-links').removeClass('flagship-product-links-open');
						footerLeft = (flashwidth - $('.flagship-footer').width() + 60)/2;
				}	
				$('.flagship-footer div.secondary').css({marginLeft:0+'px'});				
				$('.flagship-footer').css({left: footerLeft + 'px'});
				$('#lg_main_loader iframe').css({height: flashheight + 'px', width: flashwidth + 'px'});	
				$('#flagship-flash-container').css({height: flashheight + 'px', width: flashwidth + 'px'});		
				$('.container').css({marginLeft: '10px'});
			}).trigger('flagship:resize');

		});
	};

	$.fn.flagship.defaults = 
	{
		leftNavWidth: 217,
		footer: 30,
        header: 40
	};

})(jQuery);


window.onload = function()
{
	if(document.location.hostname.indexOf("lge.com") != -1)
	{
		document.domain = "lge.com";
	}

    $('#lg_main_loader').css({visibility:'hidden', height: $(window).height() - 70 + 'px'});
	$('div.flagship-footer').footer();
	$('div.flagship-footer').css({left:($(window).width() - $('.flagship-footer').width() + 45)/2+'px'});
	$('div.flagship-footer .secondary').css({marginLeft:'0px'});
	$('div.flagship-footer .secondary ul li:last').html($('div.flagship-footer .secondary ul li:last').html().replace('|',''));
	
	$('div.menu-left').leftnav({isFlagship:true});

	$('.search-results-container').search();

	// function for 3D model 
	onLoadPostInit();
}

function onLoadPostInit()
{
	if($.browser.msie && $.browser.version < 7)
	{
		$('img[src$=.png],div.support ul.contact li').not('.hr').addClass('pngfix');
		$('img.hr[src$=.png]').each(function() {this.src = this.src.replace('.png','.gif');});
		if( window.location.pathname.indexOf('/cn/') >= 0 ){$('body').addClass('cn_font_type');}
	}

	$('input[type=hidden]').css({display:'none'});
	$('div.container').css({visibility:'visible'});

	var footerLeftOpen = ($(window).width() - $('.flagship-footer').width() + 215)/2;
	var footerLeftClose= ($(window).width() - $('.flagship-footer').width() + 45)/2;

	$('#left-nav-dom').add('div.shutter').css({left:0});
	$('.flagship-footer').css({left:footerLeftOpen + 'px', marginLeft:'0px'});
	$('.flagship-product-links').css({left:160});

	setTimeout(function(){ 
		// option 2: 
		$('.flagship-footer').animate({left:footerLeftClose+'px'},1000);
		$('.flagship-product-links').animate({left:10},1000,'easeInQuad');    
		$('#left-nav-dom').add('div.shutter').stop().animate({left:-205},1000, 'easeInQuad',function() {
					$('div.shutter span.close').css({backgroundPosition:"-11px center"});
					$('.product-flagship-content').flagship();
		});
	}, 1000 ); 


	var $wtbcontainer = ($('.where-to-buy-container').length > 0) ? $('.where-to-buy-container') : $('<div class="where-to-buy-container"><span class="top"><h4>'+$('.where-to-buy-overlay h4').text()+'</h4></span></div>').appendTo('#productSpecs');
		
	$wtbcontainer.wtbcontainer().trigger('wtbcontainer:init');

	$('.where-to-buy-overlay').wtboverlay().trigger('wtbquery:init');
	
	/* 20091014 yoonsoonhyuk */
	//$('.where-to-buy-overlay #localeCode').attr('value','US');

	$('.where-to-buy-overlay').find('a[href^=#]').click(function()
	{						    
			$('.content-menu li.'+this.href.split('#')[1]).click();
			return false;
	});

	$('.flagship-header .where-to-buy').click(function(){
		var tagName = '/'+$('#tagCountry').attr('value')+'_'+$('#tagCategory').attr('value')+'_wheretobuy';
        tagLink($(this),'internal_link','Rich Media Experience Page - Where to Buy',tagName);
		$('.where-to-buy-overlay').trigger('wtbquery:open');
	});
  
	var tagName = '/'+$('#tagCountry').attr('value')+'_'+$('#tagCategory').attr('value')+'_'+$('#tagProduct').attr('value')+'_flagship';
    tagLink($(this),'internal_link','Rich Media Experience Page',tagName);

	$('.bugClass').click(function()
	{
		window.open('/common/bug/RetrieveBugList.jsp?url='+window.location.pathname,'buglist','scrollbars=yes,width=800,height=700');
	});
	
	window.onresize = function()
	{
		try
		{
			$('div.flagship-footer').trigger('footer:resize');
			$('.product-flagship-content').trigger('flagship:resize');
		}
		catch(e) {};
	}

	$('body').unbind('mousemove').mousemove(function(e)
	{
		try
		{
			$('div#left-nav-dom').trigger('leftnav:mouseapproach',[e.pageX,e.pageY]);
		} 
		catch(e) {};
	});

	try 
	{
		if(isReview){$('.product-menu .reviews').click();}
	} 
	catch(e) {};

	$('img.post-load').each(function()
	{
		this.src = $(this).attr('title');
		$(this).attr('title','');
	});
}
