//New corporate PSN drop down code
$(document).ready(function() {
	$.fn.LSNify({
		"iconSet": "gray",
		"contextualNav": true,
		"cap": true
	}); 
	$.dropdownJSON()
	$('#psnwrap').createNavInteraction({
		"enable":true
	})
}); 

var productCategory = "";
var wtbci=0;
$(document).ready(function(){
	$(".hp_postitproductsBox_Link").hover(function(){
		$(this).css({'cursor':'pointer'});
		$(this).find('.roundarrow').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273660931028&assetType=MMM_Image&blobAttribute=ImageFile");
		},
		function(){
			$(this).css({'cursor':'normal'});
			$(this).find('.roundarrow').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273659170959&assetType=MMM_Image&blobAttribute=ImageFile");
	});
	
	$(".solutions_callout_link a").hover(function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273660931028&assetType=MMM_Image&blobAttribute=ImageFile");
	  },
	  function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273659170959&assetType=MMM_Image&blobAttribute=ImageFile"); 
	  });

	$(".rightColLink a").hover(function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273660931028&assetType=MMM_Image&blobAttribute=ImageFile");
	  },
	  function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273659170959&assetType=MMM_Image&blobAttribute=ImageFile"); 
	  });

	$(".special_offers_link a").hover(function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273660931028&assetType=MMM_Image&blobAttribute=ImageFile");
	  },
	  function(){
	  	$(this).children('img').attr("src", "/3MContentRetrievalAPI/BlobServlet?assetId=1273659170959&assetType=MMM_Image&blobAttribute=ImageFile"); 
	  });

	
	
	$(".hp_postitproductsBox_Link").click(function(){
		location.href = $(this).attr('href');													   
   });
	
	//make links with the class lightbox open in a colorbox
	$('a.lightbox').colorbox({height:'500px', width:'700px', iframe:true});
	$('a.flowbox').colorbox({height:'300px', width:'390px', scrolling:false});
	$('a.flowboxPOW').colorbox({height:'320px', width:'470px', scrolling:false, inline:true, href:"#vidColorBox"});
 	// 300 390	 
	
	//change around the lsn
	//$("#lsnwrap").parent().hide();
	//$("#regLSNContainer").hide();
	
	/*The product catalog POW sets a variable to turn on the LSN - check for it 
	if (typeof regLSNContainerOn != 'undefined'){
		if (regLSNContainerOn == "yes"){
			if (productCategory == "Offers"){
				$("#regLSN").html('<h3><a href="http://www.post-it.com/wps/portal/3M/en_US/Post_It/Global/">Post-it&reg; Brand &gt;</a></h3><span class="regLSNSubHead">Offers</span>');
				$("#lsnwrap ul li a").filter(function(){return /Offers/.test( $(this).text())}).next('ul').clone().appendTo("#regLSN");
			}
			else {
				$("#regLSN").html('<h3><a href="http://www.post-it.com/wps/portal/3M/en_US/Post_It/Global/">Post-it&reg; Brand &gt;</a></h3><span class="regLSNSubHead">Products</span>');
				$("#lsnwrap ul li a").filter(function(){return /Products/.test( $(this).text())}).next('ul').clone().appendTo("#regLSN");
			}
			
			$("#regLSNContainer").show();
		}
	}
	*/
	/*
	var hovergsn;
	var lastgsn;
	var position;
	var subNavHovered="no";
	*/
	/*When the gsn is hovered over, clone the nav items from the lsn to display under the matching parent link
	$("#gsn li").hover(
	function(){
		hovergsn = $(this).attr('id');
		subNavHovered = "no";
		var lsnCount = 0;
		var thisgsn = $(this).text();
		lastgsn=thisgsn;
		var matchfound = "no";
		$("#subLSNContainer").stop(true, true).show();
		position = $(this).children('a').offset().left - $("#masterwrap").offset().left;
		
		$("#subLSN").html('&nbsp;');
		$("#lsnwrap ul li a").each(function(){
			var thislsn = $(this).text();
			
			if (thislsn == thisgsn){
				
				matchfound = "yes";
				var contents = $(this).parent().find('ul').text();
				if (contents == "" || contents == null || contents.length < 1){
					$("#subLSNContainer").stop(true, true).hide();
				}
				else{
					$(this).parent().find("ul:first").clone().appendTo("#subLSN");
					$("#subLSN ul").show();
					$("#subLSNContainer").show().css("left", position);
					$("#subLSN ul li ul").hide();
					$("#subLSN .dontshow").hide();
					$("#subLSN ul li").hover(
						function(){
							$(this).css('background-color', '#0AA2DE');
						},
						function(){
							$(this).css('background-color', '#014871');
						}
					);
				}
			}
			if (matchfound == "no"){
				$("#subLSNContainer").stop(true, true).hide();
			}
			
		});
   }, 

   
   
   function (){
	   if (subNavHovered == "no"){
			$("#subLSNContainer").delay(200).fadeOut();
	   }
	   //
   });
   */

	/*
	$("#subLSNContainer").hover(
	function(){
		subNavHovered = "yes";
		$("#"+hovergsn+" a").css({'background': 'url("/3MContentRetrievalAPI/BlobServlet?assetId=1273658530162&assetType=MMM_Image&blobAttribute=ImageFile") repeat scroll 0 0 #FFFFFF','height':'24px'});
		$(this).stop(true, true).fadeIn();
	},
	function(){
		$("#"+hovergsn+" a").css('background', '');
		$(this).stop(true, true).delay(200).fadeOut();
	});
	*/

/*Find current url -- to highlight the active gsn 
var activegsn = "null";
	if(/Home\/Solutions\//.test(window.location.href)){
		activegsn = "Solutions";
	}
	else if(/Home\/Products\//.test(window.location.href)){
		activegsn = "Products";
	}
	else if(/Home\/Connections\//.test(window.location.href)){
		activegsn = "Connections";
	}
	else if(/Home\/Offers\//.test(window.location.href)){
		activegsn = "Special Offers";
	}
	else if(/Home\/About\//.test(window.location.href)){
		activegsn = "About Post-it®";
	}
	activegsn = activegsn.slice(0, - 1); //remove the last character -- to eliminate matching problems with trademarks or copywrite symbols
	var checkgsn = "blank";
$("#gsn li a").each(function(){
	checkgsn = $(this).text();
	checkgsn = checkgsn.slice(0, - 1); //remove the last character
	if (checkgsn == activegsn){
    	$(this).addClass('activeGsn');
		
    }
});
*/


	/*Pow Tabs on Product Details Page*/
	if($(".pow_tab_content").size()>=2){
		$(".pow_tab_content").hide();
		var activeTab = $(".pow_tab_active").attr('id');
		$("#"+activeTab+"Div").show();
		
		$(".pow_tab").click(function(){
			$(".pow_tab_active").removeClass('pow_tab_active');
			$(this).addClass('pow_tab_active');
			$(".pow_tab_content").hide();
			var activeTab = $(".pow_tab_active").attr('id');
			$("#"+activeTab+"Div").show();
			return false;
		});
		 
		$(".pow_tab").hover(function(){
			if ($(this).hasClass("pow_tab_active")){
				$(this).css('top','1px');
			}
			else {
				$(this).css({'top':'1px', 'cursor':'pointer'});
			}
		},
		function(){
			if ($(this).hasClass("pow_tab_active")){
				$(this).css('top','1px');
			}
			else {
				$(this).css({'top':'2px', 'cursor':'normal'});
			}
	
		});
	}else{
	$(".pow_tab").addClass('pow_tab_active');
	}
	
/*This controls the carousel on the homepage*/	
	$("#hp_rotatingBanners_controls").click(function(){
		userHasInteracted = "yes";
	});
	$(".pos1").click(function(){
		curbanner = 1;
		rotatebanners(curbanner);
	});
	$(".pos2").click(function(){
		curbanner = 2;
		rotatebanners(curbanner);
	});
	$(".pos3").click(function(){
		curbanner = 3;
		rotatebanners(curbanner);
	});
	$(".pos1").css('background-image','url("/3MContentRetrievalAPI/BlobServlet?assetId=1273660760831&assetType=MMM_Image&blobAttribute=ImageFile")');
	
	autoRotatebanners();
	
	//Fixes intermitent problem on product details page with h1 appearing incorrectly behind items.
	$('gs_h1').css('min-height', '28px');
	
}); //End of document ready function


var curbanner = 1;
var userHasInteracted = "no";
function autoRotatebanners(){
	curbanner++;
	if(curbanner > $('.hp_rotateLink').size() ){curbanner = 1};
	setTimeout(function(){ 
		if(userHasInteracted == "no"){
			rotatebanners(curbanner);
			autoRotatebanners(); 
		}
	}, 4000);
}
function rotatebanners(curbanner){	
	$(".hp_rotateLink").css('background-image','url("/3MContentRetrievalAPI/BlobServlet?assetId=1273660760838&assetType=MMM_Image&blobAttribute=ImageFile")');
	$('#hp_rotatingBanners div').animate({
		 left: (curbanner-1)*251*-1+'px'
	  }, 3000, function() {
		 $(".pos"+curbanner).css('background-image','url("/3MContentRetrievalAPI/BlobServlet?assetId=1273660760831&assetType=MMM_Image&blobAttribute=ImageFile")');
		
	  });
}

function closeSubLSNContainer(){
	$("#subLSNContainer").hide();
	$("#subLSN").html('&nbsp;');
}

function POW_ge_equalHeight(group) {
    var tallest = 0;
	var drows = 0;
    group.each(function() {
		drows++;
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });

  jQuery.each(jQuery.browser, function(i) {
   if($.browser.msie){
      group.height(tallest);
   }else{
      group.height(tallest+10);
   }
 });
	
	//also adjust the background to fit the new size
	$('#contentwrap').height(parseInt(tallest*(Math.ceil(drows)/4)+550));
}
function POW_be_equalHeight(group) {
    var tallest = 0;
	var drows = 0;
    group.each(function() {
		drows++;
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    
	
	
  jQuery.each(jQuery.browser, function(i) {
   if($.browser.msie){
      group.height(tallest);
   }else{
      group.height(tallest+10);
   }
 });
	
	
	
	//also adjust the background to fit the new size
	$('#contentwrap').height(parseInt(tallest*(Math.ceil(drows)/3)+550));
}
function getQStr(key, default_) {
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}	
// DOCUMENT READY
$(document).ready(function() {
 /* Metrics Tagging */
 $("#ctyfoot0 a").click(function(){dcsMultiTrack('WT.cg_n','WTB_ROLLUP','WT.cg_s','WTB_GLOBAL_FOOTER','DCS.dcsuri',window.location.pathname+'WTB_GLOBAL_FOOTER','WT.dl','99')});
 // DOCUMENT READY
 
 /* Pintrest Pop-Up Code */
	(function (w, d, load) {
		var script, 
		first = d.getElementsByTagName('SCRIPT')[0],  
		n = load.length, 
		i = 0,
		go = function () {
		for (i = 0; i < n; i = i + 1) {
			script = d.createElement('SCRIPT');
			script.type = 'text/javascript';
			script.async = true;
			script.src = load[i];
			first.parentNode.insertBefore(script, first);
		}
		}
		if (w.attachEvent) {
		w.attachEvent('onload', go);
		} else {
		w.addEventListener('load', go, false);
		}
		}(window, document, 
		['//assets.pinterest.com/js/pinit.js']
	));    

});
// DOCUMENT READY


$(document).ready(function(){
	ideaExchangeImageBehave();
});

function ideaExchangeImageBehave() {
	$(".feat, .feat-lst").hover(
	  function () {
		$(this).find("img.light").hide();
		$(this).find("img.dark").show();
	  }, 
	  function () {
		$(this).find("img.light").show();
		$(this).find("img.dark").hide();
	  }
	);	

}
