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

(function($) {
	
	if(typeof($isJsUnit)!="undefined") {
		if($isJsUnit == "true" && (parent.document.location + "").indexOf("testContainer") > 0) return;
	}
	$.fn.feed = function(options) 
	{
		var opts = $.extend({}, $.fn.feed.defaults, options);
		
		return this.each(function() 
		{
			var $container = $(this);
			var _url = $.trim($container.find('span:first').text());
			
			$container.append('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />');

			if(_url != null && _url != "")
			{
				$.get(_url,{},function(response)
				{
					var _xml = processXML(response);

					var $disclaimer = $container.find('div.disclaimer').remove().clone();
					/* 20090814 leadweb modify */
					var xml_review = '';

					_xml.find('review').each(function(i)
					{
						var $review = $(this);

						xml_review += '<div>';
						xml_review += '<img src="'+$review.find('source_logo_url').text()+'" alt="" class="source_logo" />'; /* //20090831 leadweb modify */
						xml_review += '<p>Review By: '+$review.find('source_name').text()+'</p>';
						xml_review += '<p>Phone Rating: '+$review.find('score').text()+'</p>';
						xml_review += '<p class="date">'+$review.find('review_date').text()+'</p>';
						xml_review += '<p class="summary">'+$review.find('summary').text()+'&nbsp;<a href="'+$review.find('review_url').text()+'" targe="_blank">Read Full Review</a></p>';
						xml_review += '</div>';

						if(i != _xml.find('review').length-1) {
							xml_review += '<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />';
						}

					});

					$container.prepend(xml_review);
					$container.append($disclaimer);
					/* //20090814 leadweb modify */

				},"text");
			}
		});
	};

	$.fn.feed.defaults = 
	{
	};

	$.fn.flashGallery = function()
	{
		return this.each(function()
		{	
			var $gallery = $(this);
			var $tracking = $gallery.find('ul.tracking');

			var _xml = '<?xml version="1.0" encoding="UTF-8"?><slideShow>';
			
			$tracking.find('li').each(function()
			{
				_xml += '<'+$.trim(this.className)+'>'+$.trim($(this).text().replace('&','').replace('"',''))+'</'+$.trim(this.className)+'>';
			});
			
			$gallery.find('ul.images img').each(function(i)
			{
				var _thumb = $('div.gallery ul.thumbnails img:eq('+i+')').attr('src');
				_xml += '<imgBlock><img>'+this.src+'</img><thumb>'+_thumb+'</thumb><caption>'+this.alt+'</caption></imgBlock>'
			});
				
			if($.fn.flash.hasFlash("9.0.0"))
			{
				$gallery.flash({src:'/common/flash/ui/product-gallery.swf',width:701,height:517,wmode:'opaque',flashvars:{dataFile:_xml+'</slideShow>'}});
			}
			else
			{
				$gallery.find('ul.images').show().find('img.product-img-large').removeClass('product-img-large');
				$gallery.find('ul.images li').css({textAlign:'center'});
			}
		});
	};

	$.fn.flash3DModel = function(){

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

			if($.fn.flash.hasFlash("9.0.124"))
			{
				$('.closeModelView').click(function(){
						$("#modelMain").get(0).closeView();											
				});

                $('.openModelView').click(function(){
					$("#modelMain").get(0).openView();
				});
				$('.container').append($('.closeModelView'));
				var localhost = 'http://'+location.host;

				var _xml = '<?xml version="1.0" encoding="UTF-8"?>'
				+ '<product3D anchorPoint="BR" sliderPositionFromBottom="100">'
				+ '<preloader file="/common/flash/ui/preloader.swf"/>'
				+ '<track file="/common/flash/ui/track.swf"/>'
				+ '<button file="/common/flash/ui/button.swf"/>';

                if( $('#sequenceLoc')){
					_xml += '<images sequence="'+$('#sequenceLoc').attr('value')+'" ';

				}
                if( $('#firstFrameLoc')){
					_xml += 'firstFrame="'+$('#firstFrameLoc').attr('value')+'" /></product3D>';

				}

				var flashvars = {};
				var params = {};
				var attributes = {};

				flashvars.configXML = escape(_xml);
				
				params.allowscriptaccess = "always";
				params.allownetworking = "all";
				params.wmode = "transparent";
				
				attributes.id = "modelMain";
				attributes.name = "modelMain";
				
				swfobject.embedSWF("/common/flash/ui/product-model.swf", "modelContent", "100%", "100%", "9.0.124", false, flashvars, params, attributes);
			}			
		});
	};

    $.fn.flagshipEntry = function(options){

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

		return this.each(function()
		{
			var $flagship = $(this);
            var flagshipUrl = $('#flagshipUrl').attr('value');
			var flashUrl = $.trim($('#flagshipFlashPath').attr('value'));

	        $('#product-flagship-entry-point').click(function(){
				    document.location = flagshipUrl;
			});
			
            if ( $('#flagshipFlashPath').length > 0  && flashUrl != '')
            {			
				var flashvars = {};
				var params = {};
				var attributes = {};

				flashvars.flagshipUrl = flagshipUrl; /* //pubmo 1.27 add */
				params.allowscriptaccess = "always";
				params.allownetworking = "all";
				params.wmode = "transparent";
				attributes.id = "product-flagship-flash-container";
				attributes.name = "product-flagship-flash-container";				
				swfobject.embedSWF(flashUrl, "product-flagship-flash-container", "100%", "100%", "9", false, flashvars, params, attributes);
			 }

		});
	};
})(jQuery);

/*** support ***/
(function($) {
	$('div.product-header .product-menu').find('li').each(function() {
		var _checkClick = false;
		/* LGEAE-180  Content to push on specific spots : 20100806 jinmoongi modify*/
		var $support = $('div.product-content > div.support');
		$(this).click(function() {
			$('#supportTab').attr('height',$support.attr('iframeheight'));
			/*//LGEAE-180  Content to push on specific spots : 20100806 jinmoongi modify*/
			var _liClass = $(this).attr('class');
			switch(_liClass) {
			
				case 'support' :
					
					if($('#supportTab').attr('src') == undefined) {
						
						
					}else {
							var loc = document.getElementById('localeCd').value;
							var loc_f = loc.toLowerCase();
							
							$('#supportTab').attr('src', "/"+loc_f+"/common/product/support.jsp?localeCd="+document.getElementById('localeCd').value+"&productId="+document.getElementById('productId').value+"&uri="+document.getElementById("uri").value);
					}
					
					_checkClick = true;
					
					break;
			}
		});
	});

})(jQuery);

window.onload = function()
{
	onLoadPreInit();
	// function for 3D model 
	
	$('div.product-header').header();

	/*** overview ***/
	$('div.product-content div.overview').find('> h3:first').mafr({font:'BryantProLight'});
	$('div.product-content div.overview .learn').addClass("overlay-learning-center").overlay();

	($('div.product-content div.overview').height() < 495) ? $('div.product-content div.overview').css({height:495}) : null;

	/*** features ***/
	$('div.product-content div.features dl:first').features();
	$('div.product-content div.features div.gui-accordian').accordian();

	/* 20090817 leadweb add : features-logo link */
	$('div.product-content div.features').find('.features-logo-img').each(function(n) {
		if($(this).attr('linkurl') != undefined && $(this).attr('linkurl').length > 0) {
			var _target = "";
			$(this).css({cursor:'pointer'});
			($(this).attr('linktarget') == 'blank') ? _target = '_blank' : _target = '_self';
			$(this).wrap('<a href="'+$(this).attr('linkurl')+'" target="'+_target+'" style="display:inline;"></a>');
		}
	});
	/* //20090817 leadweb add : features-logo link */
	/*** gallery ***/
	$('div.gallery').flashGallery();

	/*** specifications ***/
	var $specpdf = $('div.specifications > ul > li.pdf:first').parents('ul:first');

	if($specpdf.prev().length == 0)
	{
		$('div.specifications .preview').parent('p').before($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />'));
		$specpdf.filter('ul.pdf').css({width:'100%',position:'relative',top:-8,right:18});
	}
	else
	{
		$specpdf.before($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />'));
		$specpdf.css({position:'absolute',left:'12px',width:'400px',paddingTop:'10px'}).find('li.pdf').css({position:'relative',right:''});
		$specpdf.next('p').css({marginTop:0,paddingTop:'10px'});
	}

	$('div.product-content div.specifications ul:first li').each(function()
	{
		($(this).find('a').length > 1) ? $(this).find('a:first').after("&nbsp;|&nbsp;") : null;
	});
	
	$('div.product-content div.specifications').addClass('gui-accordian').accordian();

	
	/*** accessories ***/
	$('div.accessories').find('> *').not('ul').wrapAll('<div class="left"></div>');
	$('div.accessories').find('div.left > h3:first').before($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="clear:both;display:block;width:485px;margin:0;float:none;" />'));
	$('div.accessories').find('dl').each(function() {$(this).css({height:$(this).find('dt').length*16});});
	$('div.accessories').find('dt:odd,dd:odd').addClass('stripe');
	$('div.accessories').find('> ul:first').addClass("documents");
	$('div.accessories').find('ul.documents ul:first li:first').not('.pdf').css({margin:"-10px 0 15px 0"});
	$('div.accessories').find('ul h4').css({fontSize:'16px'}).mafr({font:'BryantProMedium'});
	$('div.accessories').find('> ul:last li:first').after($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;width:150px;margin:0 0 15px 15px;" />'));
	$('div.accessories').find('li li').each(function() {($(this).find('a').length > 1) ? $(this).find('a:first').after("&nbsp;|&nbsp;") : null;});
	$('div.accessories').append('<div class="clear"></div>');
	
	if($('#supportTab').attr('src') == undefined) {
		/*** support ***/
		$('div.product-content div.support h2, div.product-content div.support > div.left h3').mafr({font:'BryantProMedium'});
		$('div.product-content div.support ul h3').css({fontSize:'16px'}).mafr({font:'BryantProMedium'});
		$('div.support').find('> ul:last').addClass("documents");
		$('div.support').find('> ul:first').addClass("contact");
		$('div.support').find('> *').not('ul.documents').wrapAll('<div class="left"></div>');
		$('div.support').find('div.left > h3:first').before($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;width:435px;margin-bottom:15px;" />'));
		$('div.support').find('li li').each(function() {($(this).find('a').length > 1) ? $(this).find('a:first').after("&nbsp;|&nbsp;") : null;});
		$('div.support').find('ul.documents ul:first li:first').not('.pdf').css({margin:"-10px 0 15px 0"});
		$('div.support').find('ul.documents > li:last').css({marginBottom:0}).end().find('ul.documents > li:last > ul:last').css({paddingBottom:0}).end().find('ul.documents > li:last > ul:last > li:last').css({marginBottom:0});
		$('div.support').find('ul.contact li:lt(2)').after('<img src="/common/img/bg-support-hr.jpg" alt="" />');
		$('div.support').append('<div class="clear"></div>');
		
	}
	
	/*** reviews ***/
	$('div.expert-reviews').feed();
	/* 20090903 leadweb modify */
	$('div.expert-reviews.fulltext-type .summary').each(function() {
		if($(this).height() > $(this).parent().height()) {
			$(this).parent().css({height:parseInt($(this).height())});
		}
	});
	/*//20090903 leadweb modify */

	$('div.expert-reviews.fulltext-type').find('.close_wrap').css({display:'none'});
	$('div.expert-reviews.fulltext-type .fulltext-review').each(function(){
		var _review = $(this);
		if(!_review.hasClass('open')){
			_review.data('height', _review.height());
			_review.css('height',0);
			_review.find('.close').click(function(){
				_review.animate({height:0},700,"easeOutCubic", function(){
					$('html,body').animate({scrollTop:_review.prev().prev().offset().top},500,"linear"); 
				});
				_review.next('img').remove();
				_review.prev().prev().find('.open_wrap').show();
				_review.prev().prev().find('.close_wrap').hide();
			});
		}
	});

	$('div.expert-reviews .fulltext-review').each(function(){
		var _review = $(this);
		_review.find('.print').click(function(){
			window.open($(this).attr('href'));
			return false;
		});
	});

	$('div.expert-reviews.fulltext-type .summary a.open').click(function(){

		if($(this).attr('linktarget') == 'blank'){
			window.open($(this).attr('href'));
		}else{
			var _review = $(this).parent().parent().parent().next().next();
			if(parseInt(_review.height()) == 0){
				var goalHeight = _review.data('height');
				_review.animate({height:goalHeight},700,"easeInCubic");
				if($.browser.msie && $.browser.version < 7) _review.after('<img src="/common/img/bg-hr.gif" class="hr" alt="" style="display:block;" />'); 
				else _review.after('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />'); 
				$(this).parent().parent().find('.open_wrap').hide();
				$(this).parent().parent().find('.close_wrap').show();
			}
		}
		return false;
	});

	$('div.expert-reviews.fulltext-type .summary a.close').click(function(){
		var _review = $(this).parent().parent().parent().next().next();
		_review.find('.close').trigger('click');
		return false;
	});

	$('div.expert-reviews.fulltext-type').find('img.hr:last').remove();

	$('.fulltext-review .review-content .img, .fulltext-review .review-content .img-left').hover(
		function(){$(this).find('a').show();},
		function(){$(this).find('a').hide();}
	);

	$('.fulltext-review .review-content .img a, .fulltext-review .review-content .img-left a').click(function(){
		showImageViewer($(this).attr('href'));
		return false;
	});

	/* 20090915 leadweb modify */
	$('div.expert-reviews img.source_logo').each(function(){
		resizeImg($(this), 163, 160);
	});
	/* //20090915 leadweb modify */
	/*** mobile ***/
	$('div.mobile-accessories > ul:first').after($('<img src="/common/img/bg-hr.png" class="hr" alt="" style="display:block;" />'));
	$('div.resources').find('ul.documents li').each(function() {($(this).find('a').length > 1) ? $(this).find('a:first').after("&nbsp;|&nbsp;") : null;});
	$('div.resources h3,div.resources .right h4,div.resources .right h5').mafr({font:'BryantProMedium'});
	$('div.fun-stuff h3').mafr({font:'BryantProMedium'});

	$('.tooltip').tooltip();
	$('.button').button();
	$('.wallpaper-preview,.video-preview').overlay();
	$('#modelContent').flash3DModel();
	$('#product-flagship-entry-point').flagshipEntry();
	
	$('ul.icon-list').each(function()
	{
		var _ul = $(this);
		var _div = $(this).parent('div');
		//2010.03.11 JP feature error
		//var _height = [0,0,0];
		var _height = [0,0,0,0];
		//2010.03.11 JP feature error
		_div.css({display:'block',left:-2000});
		
		_ul.find('li').each(function(i)
		{
			var _li = $(this);

			if(_li.attr('style') != undefined && _li.attr('style').toLowerCase().indexOf('background') != -1)
			{
				_li.css({width:165,padding:'0 10px 0 35px',margin:'0 0 4px 0',backgroundPosition:'center left'});
				_height[Math.floor(i/3)] = 30;
			}
		});
		
		_ul.find('li').each(function(i)
		{
			_height[Math.floor(i/3)] = Math.max(_height[Math.floor(i/3)],$(this).height());
		});
		
		_ul.find('li').each(function(i)
		{
			$(this).css({height:_height[Math.floor(i/3)]});
		});
		
		_div.css({display:'none',left:0});
	});

	if($('.product-menu li.'+document.location.hash.replace('#','')).length != 0)
	{
		$('.product-menu li.'+document.location.hash.replace('#','')).click();
	}
	else
	{	
		var _goto = null;

		$('.product-menu li').each(function()
		{
			if(document.location.href.indexOf('#'+$(this).attr('class')+'?') != -1)
			{
				_goto = $(this).attr('class');
			}
		});
		
		(_goto != null) ? $('.product-menu li.'+_goto).click() : $('.product-menu li:eq(1)').click();
	}

	$('.overlay-3d-tour,.overlay-product-video,.overlay-interactive-demo').overlay();

	$('div.additional-products').rotator();
	
	$('#fun-stuff-frame').css({visibility:'visible'});
	$('div.product-content > div').not('.product-header').css({visibility:'visible'});
	$('div.product-content').compare().trigger('compare:initItem');

	/* 20090915 leadweb modify */
	$('ul.awards-banner img').each(function(){
			resizeImg($(this), 62, 62);
	});
	/* //20090915 leadweb modify */

	/* where to buy */
	whereToBuyCategoryCheck();
	$('.where-to-buy-category :checkbox').click(whereToBuyCategoryCheck);

	$('.buy-online').click(function() {
		$('.where-to-buy-container').css({display:'block'});
		$('.where-to-buy-container h4').text('Buy Online');
		$('.where-to-buy-online-content').css({width:'652px',height:'443px',display:'block'});
		$('.buy-online-frame').insertAfter('.where-to-buy-container .toggle');
		$('.buy-online-frame').css({width:'642px',height:'433px'}).attr('scrolling','auto');
		$('.where-to-buy-container .toggle').css({visibility:'hidden'});
		$('body > .buy-online-frame').remove();

		$('.where-to-buy-container .top .close').click(function(){
			$('.buy-online-frame').remove();
			$('.where-to-buy-container h4').text('Where to Buy');
		});
	});

	/* 20091120 pjm add */
	$('.reviews ul.sub-nav .video-reviews').click(function() {
		if($('#expoFrm').attr('src') == undefined || $('#expoFrm').attr('src').length == 0){
		  $('#expoFrm').attr('src', $('#expoFrm').attr('src-file'));
	    }
	});
	/* //20091120 pjm add */
	
	onLoadPostInit();
}

// function for 3D Model toggleSize call back function. 
function toggleSize()
{	
		if( $('#modelbase').hasClass('larger')) {
			$('.product-header').animate({opacity:1}, 100, function(){
				$('.additional-products').animate({opacity:1}, 100).css({visibility:'visible'});
				$('.closeModelView').css({visibility:'hidden'});
				$('.openModelView').css({visibility:'visible'});
				$('.overview').children().not('#modelstage').fadeIn("slow").css({visibility:"visible"});
				$('#modelbase').toggleClass('larger');
			}).css({visibility:'visible'});
		}else{
			$('.product-header').animate({opacity: 0.3}, 100, function(){
				$(this).css({visibility:'hidden'});
				$('.additional-products').animate({opacity: 0.3}, 100).css({visibility:'hidden'});
				$('.overview').children().not('#modelstage').fadeOut().css({visibility:"hidden"});
				$('.openModelView').css({visibility:'hidden'});
				$('.closeModelView').css({visibility:'visible'});
				$('#modelbase').toggleClass('larger');
			});
		}
}

function showImageViewer(path){
	$('.image-viewer').remove();
	var top = $(document).scrollTop()-150;
	$('div.expert-reviews').append('<div class="image-viewer" style="top:'+top+'px">				<h4>Image View</h4>				<div class="close"><a href="#" onclick="$(this).parents(\'.image-viewer\').remove();return false;">CLOSE</a></div>				<div class="image-content">					<img src="'+path+'" alt="" class="img-origin" />				</div>			</div>');
	resizeImg($('div.image-viewer img.img-origin'), 600, 320); /* //20090915 leadweb add */
}

/* 20090915 leadweb add */
function resizeImg(img, defaultW, defaultH) {
	var _width = img.width();
	var _height = img.height();

	if( _width > defaultW ) {
		img.width(defaultW);
		img.height(defaultH);
	}
	if(_height > defaultH) {
		img.height(defaultH);
	} 
}

/* //20090915 leadweb add */
// where to buy check category
function whereToBuyCategoryCheck(){
	$('.results-list ul li').hide();
	$('.online-store-result ul li').hide();

	if($('.where-to-buy-category input:checked').length){
		var show_item_count = 0;
		var show_online_item_count = 0;
		$('.where-to-buy-category input:checked').each(function(){
			var categoryName = $(this).attr('value').toLowerCase();
			$('.results-list ul li input[type=hidden]').each(function(){
				var itemCategoryArr = $(this).attr('value').split(',');
				for(var i=0;i<itemCategoryArr.length;i++){
					if(jQuery.trim(itemCategoryArr[i]).toLowerCase() == categoryName){
						$(this).parent().show();
					}
				}
			});

			$('.online-store-result ul li input[type=hidden]').each(function(){
				var itemCategoryArr = $(this).attr('value').split(',');
				for(var i=0;i<itemCategoryArr.length;i++){
					if(jQuery.trim(itemCategoryArr[i]).toLowerCase() == categoryName){
						$(this).parent().show();
					}
				}
			});
		});

		$('.results-list ul li').each(function(){
			if($(this).css('display') != 'none') show_item_count++;
		});
		$('.results-count').text(show_item_count);

		$('.online-store-result ul li').each(function(){
			if($(this).css('display') != 'none') show_online_item_count++;
		});
		$('.online-store-results-count').text(show_online_item_count);
	}else{
		$('.results-list ul li').show();
		$('.results-count').text($('.results-list ul li').length);

		$('.online-store-result ul li').show();
		$('.online-store-results-count').text($('..online-store-result ul li').length);
	}
}

