var navHeightExpanded = 175;
var isMetaParsed = false;
var pageName;
var visitorSegment;
var siteSection;

$(document).ready( function() {
	// Fixes IE6 bg image flicker issue
	if($.browser.msie && $.browser.version == 6){
		document.execCommand("BackgroundImageCache",false,true);
	}
	
	// This is to fix the way IE mangles list items and bullet placement.
	$('#details li').each(function(index){
		if($.browser.msie && $.browser.version < 8){
			$(this).html('<p>' + $(this).text() + '</p>');
			$('p', this).css('marginTop', '-3px');
		}
	});
								
	// Store all of the required URLs for each specific product so that they can be accessed using the id attribute of the originating link.
	var prodInfo = {
		urls: {
			'nortonIS-buyIt':		'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=21174782&tppc=&ptype=cart&trf_id=symcom&inid=it_hho_ogniclic_nis2012_to_store',
			'nortonIS-upgrade':		
			'http://buy.norton.com/upgrades-renewals?ctry=IT&lang=IT&trf_id=symcom&inid=it_hho_ogniclic_upgrade_to_store',
			'nortonIS-tryIt':
			'http://it.norton.com/downloads/',
			'nortonIS-details':		'http://buy.norton.com/estore/mf/productDetails/productSkuCode/21174782/productShortName/norton-internet-security/sourcePageType/LandingProductFeatures/priceGroupId/1000000/slotNo/1/',
			
			'nortonAV-buyIt':		'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=21174116&tppc=&ptype=cart&trf_id=symcom&inid=it_hho_ogniclic_2012_to_store',
			'nortonAV-upgrade':		
			'http://buy.norton.com/upgrades-renewals?ctry=IT&lang=IT&trf_id=symcom&inid=it_hho_ogniclic_upgrade_to_store',
			'nortonAV-tryIt':
			'http://it.norton.com/downloads/',
			'nortonAV-details':		'http://buy.norton.com/estore/mf/productDetails/productSkuCode/21174116/productShortName/norton-antivirus/sourcePageType/LandingProductFeatures/priceGroupId/1000000/slotNo/2/',
			
			'norton360-buyIt':
			'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=21148333&ptype=cart&trf_id=symcom&inid=it_360v5_ecm_to_store',
			'norton360-upgrade':	'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=21148333&tppc=979cb3719ca22378b40a726424634bf2&ptype=pd&trf_id=symcom&inid=it_360v5_upgrade_ecm_to_store',
			'norton360-tryIt':
			'http://it.norton.com/downloads/trialsoftware/index.jsp',
			'norton360-details':	
			'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=21148333&ptype=pd&trf_id=symcom&inid=it_360v5_ecm_to_store',
			
			'nortonNOBU-buyIt':		'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=20052384&tppc=7b7c8944b5fdda38d995eeec5ca584e6&ptype=cart&trf_id=symcom&inid=it_symcom_nobu_ecm_to_store',
			'nortonNOBU-upgrade':	'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=20052384&tppc=0de68b0614dcaa7f6fa1987cc3b032ce&ptype=cart&trf_id=symcom&inid=it_symcom_nobu_ecm_to_store',
			'nortonNOBU-tryIt':
			'http://it.norton.com/downloads/trialsoftware/register.jsp?pvid=nobu2010',
			'nortonNOBU-details':	'http://buy.norton.com/ps?ctry=IT&lang=IT&selSKU=20052384&tppc=7b7c8944b5fdda38d995eeec5ca584e6&ptype=pd&trf_id=symcom&inid=it_symcom_nobu_ecm_to_store'
		},
		omTags: {
			'nortonIS-buyIt':		'IS buy-it',
			'nortonIS-upgrade':		'IS upgrade',
			'nortonIS-tryIt':		'IS try-it',
			'nortonIS-details':		'IS details',
			
			'nortonAV-buyIt':		'AV buy-it',
			'nortonAV-upgrade':		'AV upgrade',
			'nortonAV-tryIt':		'AV try-it',
			'nortonAV-details':		'AV details',
			
			'norton360-buyIt':		'360 buy-it',
			'norton360-upgrade':	'360 upgrade',
			'norton360-tryIt':		'360 try-it',
			'norton360-details':	'360 details',
			
			'nortonNOBU-buyIt':		'NOBU buy-it',
			'nortonNOBU-upgrate':	'NOBU upgrade',
			'nortonNOBU-tryIt':		'NOBU try-it',
			'nortonNOBU-details':	'NOBU details'
		}
	}; // END prodInfo
	
	function followProdLink(event){
		// If we get 'undefined' using @id as the key, then us @rel instead.
		var key = prodInfo.urls[$(this).attr('id')] !== undefined ? $(this).attr('id') : $(this).attr('rel') ;
		
		// Fire omniture tracking.
		omnitureClick(prodInfo.omTags[key]);
		
		// Go to the url for the requested item.
		// setTimeout is for IE6 compatibility, and to make sure the tracking has a chance to register.
		setTimeout(function(){
			window.location = prodInfo.urls[key];
		}, 10);
	}
	
	// Create a live handler for all .prodLink links.
	$('.prodLink').live('click', followProdLink);
	
	$("#footer-flash").hover(function() { $(this).removeClass('footer-flash-shrink').addClass('footer-flash-expand'); } );
	
	$.cookie("pagetype",$('body').attr('id'),{ path:'/' });
	
}); // END $(document).ready()

$(window).load(function(){
	// This fixes an issue where the topnav would slide under the flash videos in Firefox 2.
	// Setting the position causes the elements to recalculate in a manner that makes them work correctly.
	// It has to be in window.load because it doesn't work anywhere else.
	// Unfortunately, this causes the menu to blink once, but it seems to be the only way to get it working.
	if ($.browser.mozilla && parseFloat($.browser.version.substr(0, 3)) < 1.9) {
		$('#topnav').css({ position: 'absolute' });
		$('#footer-flash').css({ top: -7 });
		$('#norton-products-compare #compareTableHeading').css({ position: 'absolute' });
	}
});

initPreloader = function(mylocation) {
  if (!($.cookie("isPreloaded"))) {
  		window.location.href = "/preloader.html?redirect="+ escape(mylocation);
	}
}

expandHeader = function() {
	$('#flashnav').css({ height: navHeightExpanded });
}

shrinkHeader = function() {
	$('#flashnav').css({ height: '' });
}

expandFooter = function() {
      $("#footer-flash").removeClass('footer-flash-shrink').addClass('footer-flash-expand');
}

shrinkFooter = function() {
      $("#footer-flash").removeClass('footer-flash-expand').addClass('footer-flash-shrink');
}

getSection = function() {
	var mycookie = $.cookie("pagetype").split("-");
	var sendCookie = mycookie[0]+"-"+mycookie[1];
	return sendCookie;
}

getFirstLoad = function() {
	return $.cookie("firstLoad");
}

setFirstLoad = function() {
	$.cookie("firstLoad","false",{ path:'/' });
}

getSpinBoxes = function() {
	return $.cookie("spinBoxes");
}

setSpinBoxes = function() {
	$.cookie("spinBoxes","false",{ path:'/' });
}

carouselReset = function(carousel, item, idx, state) {
  if(idx == 10) {
    $('.jcarousel-next-horizontal').css({backgroundPosition: '0 -30px'});
  }
  else {
    $('.jcarousel-next-horizontal').css({backgroundPosition: '0 0'});
  }
};

laptopToggle = function(value) {
	var selected = "#flash-"+value;
	if($(selected).hasClass('flashselect')) return;

	$('div#laptop')
		.hide()
		.removeClass('flashselect');

	$(selected)
		.show()
		.addClass('flashselect');
}

laptopSWF = function(value) {
    var so2 = new SWFObject("/assets/swf/laptop.swf","flashlaptop","540","516","#ff0000",true);
    so2.addParam("scale","noscale");
    so2.addParam("wmode","transparent");
    
	if(value == "spam") {
		so2.addVariable("flvFile", "/assets/flv/spam.flv");
	}
	else if(value == "spyware") {
        so2.addVariable("flvFile", "/assets/flv/spyware.flv");
    }
	else if(value == "phishing") {
        so2.addVariable("flvFile", "/assets/flv/phishinglaptop.flv");
    }
	else {
        so2.addVariable("flvFile", "/assets/flv/malware.flv");
	}
	so2.write("flash-laptop");
}

getPageMeta = function() {
	if(!isMetaParsed)
		parseMeta();
	
	return pageName;
}

getSiteSection = function() {
	if(!isMetaParsed)
		parseMeta();
	
	return siteSection;
}

getVisitorSegment = function() {
	if(!isMetaParsed)
		parseMeta();
	
	return visitorSegment;
}

parseMeta = function() {
	var metas = document.getElementsByTagName('meta');
	var n;
	var c;
	
	for(i = 0; i < metas.length; i++){
		n = metas[i].name;
		c = metas[i].content;
		
		if(n == 'om.page_name'){
			pageName = c;
		}
		else if(n == 'om.visitor_segment'){
			visitorSegment = c;
		}
		else if(n == 'om.site_section'){
			siteSection = c;
		}
	}
}

