
var BK = BK || {};

BK.Plugins = BK.Plugins || {};
BK.Press = BK.Press || {};

BK.Plugins.carouselVars = {
	'carouselInterval' : ''
};

BK.Plugins.mediaCarouselVars = {
	
	'itemCountArray' : [],
	'currentItemArray' : [],
	'carouselSpeed' : 200,
	'isAnimating' : false

};

BK.Plugins.threeTileCarousel = {

	init: function(){
		BK.Plugins.threeTileCarousel.setupBehaviors();
		BK.Plugins.threeTileCarousel.setupTabBorders();
	},
	
	setupTabBorders: function(){

		var findBoxes = $('.bk_threetile_slideshow');
		
		findBoxes.each(function(){
		
			var thisBox = $(this);

			//Fire if cached.
			BK.Plugins.threeTileCarousel.thumbRepeater($(this).find('img'));
			
			//Fire on load, if not cached / reloaded.
			thisBox.find('li img').load(function(){
			
				BK.Plugins.threeTileCarousel.thumbRepeater($(this));

			});
		});
	},
	
	thumbRepeater : function(which){
		
		var onloadThisBox = which.parents('.bk_threetile_slideshow');
	
		//Create offstate to load the next animation frame into.			
		onloadThisBox.prepend('<div class="offState"></div>');

		var boxWidth = onloadThisBox.width();
		var borderWidthPx = Math.ceil((285 + boxWidth) / 116);

		//This might have to fire more than once, so if it does remove other highlight objects.
		onloadThisBox.find('span.highlight').remove();

		var borderHTML = '<span class="highlight"><span class="corner"></span></span>';
		onloadThisBox.find('li a').prepend(borderHTML);
		onloadThisBox.find('li img').attr('style','').width( onloadThisBox.find('li img')[0].width );
		onloadThisBox.find('li img').attr('style','').height( onloadThisBox.find('li img')[0].height );
		onloadThisBox.find('span.highlight').css('borderWidth', borderWidthPx);
		onloadThisBox.find('span.highlight').width( onloadThisBox.find('li img')[0].width - ( borderWidthPx * 2 ) );
		onloadThisBox.find('span.highlight').height( onloadThisBox.find('li img')[0].height - ( borderWidthPx * 2 ) );

		//Highlight First By Default, if nothing else is active yet.
		if ( onloadThisBox.find('li.active').length === 0 ) {
			onloadThisBox.find('li:first').addClass('active');
			onloadThisBox.find('li:first').trigger('click', 'firstLoad');
		}
		
	},
	
	setupBehaviors: function() {
		$('.bk_threetile_slideshow li').bind('click', function(event, eventType){
			var liTarget = $(this);
			if (eventType === 'progression') {
				BK.Plugins.threeTileCarousel.addImage( liTarget, liTarget.parents('ul').children('.offState') );
				liTarget.parents('ul').find('.heroImage').fadeOut(200);
				liTarget.parents('ul').find('.offState').fadeIn(200, function(){
					$(this).parents('ul').children('.heroImage').remove();
					$(this).attr('class','heroImage');
					liTarget.parent().find('li').removeClass('active');
					liTarget.addClass('active');
					liTarget.parents('ul').prepend('<div class="offState"></div>');
				});
				
				return false;
				
			}
			if ( liTarget.attr('class').search('active') === -1 || eventType === 'firstLoad' ) {
				BK.Plugins.threeTileCarousel.addImage( liTarget, liTarget.parents('ul').children('.heroImage') );
			}			
			liTarget.parent().find('li').removeClass('active');
			liTarget.addClass('active');
			
			if (eventType !== 'progression') { $(this).parent().addClass('skipNextAnim'); }

			return false;

		});
		
		$('.bk_threetile_slideshow .heroImage a').live('click', function(){
      if ($(this).parents('ul').find('li.active a:first-child').attr('class').search('link') > -1) {
				try {
          $(this).parents('ul').find('li.active a.actual_link').click();
        } catch(e) {
        } 
			}
			else if ($(this).parents('ul').find('li.active a:first-child').attr('class').search('video') > -1) {
				if ($(this).width() > 250) {
					BK.Plugins.threeTileCarousel.addVideo($(this).parents('ul').find('li.active a'));
				} 
			}
			
			return false;
		});
		
	},
	
	addImage: function(whichTile, where){
		var imageHTML = '';
		imageHTML += '<a href="'+whichTile.find('a').attr('href')+'" title="'+whichTile.find('a').attr('title')+'" rel="'+whichTile.find('a').attr('href')+'" class="'+whichTile.find('a').attr('class')+'">';
		imageHTML += '<img src="'+whichTile.find('a img').attr('src')+'" />';
		imageHTML += '</a>';
		
        where.css('height','').html(imageHTML);

		//Add CSS Play Button if tile is a video.
		if (whichTile.parents('ul').find('li.active a').attr('class').search('video') > -1) {
			where.find('a').append('<div class="playButton"><span></span></div>');
			if (where.width() <= 250) {
				where.find('a').modalVideo();
			}
		}
	},
	
	addVideo: function(whichTile){

		whichTile.parents('ul').find('.heroImage').height( whichTile.parents('ul').find('.heroImage img').height() );
		var vidID = whichTile.parents('ul').attr('id');

        var tileVidURL = whichTile.attr('href');
        var tilePosterURL = whichTile.find('img').attr('src');
        
        var oggLink = tileVidURL.replace('flv','ogg');
        var mp4Link = tileVidURL.replace('flv','mp4');

		var imgWidth = whichTile.parents('ul').find('.heroImage img').width();
		var imgHeight = whichTile.parents('ul').find('.heroImage img').height();

		var flashEmbed = '<embed width="'+imgWidth+'" height="'+imgHeight+'" flashvars="videoType=progressive&amp;';
		flashEmbed += 'videoURL=/cms' + CulturePrefix + 'cms_out/digital_assets/video/news/breakfast_march.flv&amp;width='+imgWidth+'&amp;height='+imgHeight+'" ';
		flashEmbed += 'pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.bk.com/page_templates/cultures' + CulturePrefix + 'flash/BKVideoPlayer.swf" ';
		flashEmbed += 'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000">';
		
		var tileVidHTML = '';
        tileVidHTML += '<div class="video-js-box" style="height:100%; width:100%; float:left">';
        tileVidHTML += '<video class="video-js" width="100%" height=100%" poster="'+tilePosterURL+'" >';
        tileVidHTML += '<source src="' + mp4Link + '" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\'>';
        tileVidHTML += '<source src="' + oggLink + '" type=\'video/ogg; codecs="theora, vorbis"\'>';
        tileVidHTML += flashEmbed;
        tileVidHTML += '</video>';
        tileVidHTML += '</div>';
       
        whichTile.parents('ul').find('.heroImage').html(tileVidHTML);
        VideoJS.setup(vidID);
        whichTile.parents('ul').find('.heroImage video').addClass('initialized');
        
        if (whichTile.parents('ul').find('.heroImage video').width() < 200) { whichTile.parents('ul').find('.vjs-progress-control').hide(); }
        
        if ( BK.Plugins.threeTileCarousel.canPlayHTMLVid() ) {
	        $('video').each(function(){$(this)[0].pause();});
			whichTile.parents('ul').find('.heroImage video')[0].play();
		}
	},
	
	canPlayHTMLVid : function() {
        var elem = document.createElement('video'),
            bool = !!elem.canPlayType;
        
        if (bool){  
            bool      = new Boolean(bool);  
            bool.ogg  = elem.canPlayType('video/ogg; codecs="theora"');
            bool.h264 = elem.canPlayType('video/mp4; codecs="avc1.42E01E"');
            bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"');
        }
        return bool;
    }

};

BK.Plugins.mediaCarousel = {

	init: function(){
		
		//Reset arrays, just in case we need to reinit in later applications.
		BK.Plugins.mediaCarouselVars.itemCountArray = [];
		BK.Plugins.mediaCarouselVars.currentItemArray = [];
	
		BK.Plugins.mediaCarousel.setupBehaviors();
		BK.Plugins.mediaCarousel.setupCarouselEnvironment();
	},

	setupCarouselEnvironment: function(){

		var findBoxes = $('.bk_media_carousel');
		
		var boxCount = 0;
		
		findBoxes.each(function(){
		
			//Setup JS-enabled environment.
			var thisBox = $(this);

			//Store item count in an array.
			var itemCount = thisBox.find('li').length;
			BK.Plugins.mediaCarouselVars.itemCountArray.push(itemCount);
			
			if ( itemCount > 6 ) {

				thisBox.addClass('mediaCarousel-'+boxCount);
				thisBox.wrap('<div class="bk_media_carouselObjectWrapper jsEnabled"></div>');
				thisBox.find('a.video').prepend('<span class="playButton"><span></span></span>');
				thisBox.parents('.bk_media_carousel_container').append('<div class="leftArrow">Previous</div><div class="rightArrow">Next</div>');
			
				//Set position at '1' for init.
				BK.Plugins.mediaCarouselVars.currentItemArray[boxCount] = 1;

				thisBox.parents('.bk_media_carousel_container').find('.leftArrow').bind('click',function(){
			
					var whichNo;
					var classArray = $(this).parents('.bk_media_carousel_container').find('.bk_media_carousel').attr('class').split(' ');
					for ( i = 0; i < classArray.length; i++ ) { 
						if (classArray[i].search('mediaCarousel-') !== -1) { 
							whichNo = (classArray[i].split('mediaCarousel-')[1])*1;
						} 
					}

					if( BK.Plugins.mediaCarouselVars.isAnimating === false && BK.Plugins.mediaCarouselVars.currentItemArray[whichNo] > 1 ) {
						BK.Plugins.mediaCarouselVars.isAnimating = true;
						var currentPos = $(this).parents('.bk_media_carousel_container').find('ul').css('left').split('px')[0]*1;
						$(this).parents('.bk_media_carousel_container').find('ul').animate({'left':(currentPos + 149)}, BK.Plugins.mediaCarouselVars.carouselSpeed ,function(){
							BK.Plugins.mediaCarouselVars.isAnimating = false;
						});
						BK.Plugins.mediaCarouselVars.currentItemArray[whichNo]--;
						BK.Plugins.mediaCarousel.setArrows(whichNo);
					}
				});

				thisBox.parents('.bk_media_carousel_container').find('.rightArrow').bind('click',function(){
				
			
					var whichNo;
					var classArray = $(this).parents('.bk_media_carousel_container').find('.bk_media_carousel').attr('class').split(' ');
					
					for ( i = 0; i < classArray.length; i++ ) { 
						if (classArray[i].search('mediaCarousel-') !== -1) { 
							whichNo = (classArray[i].split('mediaCarousel-')[1])*1; 
						} 
					}
				
					if( BK.Plugins.mediaCarouselVars.isAnimating === false && BK.Plugins.mediaCarouselVars.itemCountArray[whichNo] - 5 - BK.Plugins.mediaCarouselVars.currentItemArray[whichNo] >= 0 ) {
				
						BK.Plugins.mediaCarouselVars.isAnimating = true;
						var currentPos = $(this).parents('.bk_media_carousel_container').find('ul').css('left').split('px')[0]*1;
						$(this).parents('.bk_media_carousel_container').find('ul').animate({'left':(currentPos - 149)}, BK.Plugins.mediaCarouselVars.carouselSpeed ,function(){
							BK.Plugins.mediaCarouselVars.isAnimating = false;
						});
						BK.Plugins.mediaCarouselVars.currentItemArray[whichNo]++;
						BK.Plugins.mediaCarousel.setArrows(whichNo);	
					}
				});
			
				BK.Plugins.mediaCarousel.setArrows(boxCount);
				
			
			}

			thisBox.parents('.bk_media_carousel_container').show();
				
			boxCount++;
			
		});
	},
	
	setArrows : function(whichNo) {
	
		var whichSet = $('.bk_media_carousel_container')[whichNo];
		whichSet = $(whichSet);
	
		if( BK.Plugins.mediaCarouselVars.itemCountArray[whichNo] - 5 - BK.Plugins.mediaCarouselVars.currentItemArray[whichNo] === -1 ) { 
			whichSet.find('.rightArrow').addClass('rightArrowOff');
		} else { 
			whichSet.find('.rightArrow').removeClass('rightArrowOff');
		}
		
		if ( BK.Plugins.mediaCarouselVars.currentItemArray[whichNo] > 1 ) {
			whichSet.find('.leftArrow').removeClass('leftArrowOff'); 
		} else { 
			whichSet.find('.leftArrow').addClass('leftArrowOff');
		}
		
		if ( BK.Press.Vals.IE6 ) {
			whichSet.find('.rightArrow').css('position','relative').css('position','absolute');
			whichSet.find('.leftArrow').css('position','relative').css('position','absolute');
		}
		
	},
	
	setupBehaviors: function() {
		$('.bk_media_carousel li').bind('mouseover', function(event, eventType){

		});
		
		$('.bk_media_carousel li a').bind('click', function(){ return false; });
		
	}

};

BK.Press.Vals = {
	
	'yearVal' : '',
	'sortVal' : '',
	'filterVal' : '',
	'IE6' : ( navigator.appVersion.indexOf("MSIE 6.") === -1 ) ? false : true,
	'IE7' : ( navigator.appVersion.indexOf("MSIE 7.") === -1 ) ? false : true,
	'iPad' : ( navigator.userAgent.search(/iPad/i) === -1 ) ? false : true,
	'supportsTouch' : ( 'createTouch' in document ),
	'downEventVar' : ( supportsTouch ? 'touchstart' : 'mousedown' ),
	'dragEventVar' : ( supportsTouch ? 'touchmove' : 'mousemove' ),
	'dropEventVar' : ( supportsTouch ? 'touchend' : 'mouseup' )
	
};

BK.Press.All = {
	
	init : function() {
		
		//Set Values of sorting Dropdowns.
		BK.Press.All.dropDownSet();
		BK.Press.All.modalVidSetup();
		BK.Press.All.ie6LeftColFix();
		
	},
	
	ie6LeftColFix : function() {
		
		if ( BK.Press.Vals.IE6 && $('#GlobalHeader').height() <= 860 ) {

		    $('#GlobalHeader, #MenuTab').css('height','auto').css('height',$(document).height());

		}
		
	},
	
	modalVidSetup : function(){
		
		$('.pr_imgVid_video a.video').modalVideo();
		
	},
	
	splitURLVars : function() {   
		var getData = [];
	    var vars = window.location.search;
	    if (vars) {
	      vars = vars.substr(1);
	      var pairs = vars.split("&");
	      for ( i = 0; i < pairs.length; i++ ) {
	        var formData = pairs[i].split("=");
	        var name = formData[0];
	        var value = formData[1];
	        getData[name] = value;
	      }
	    }
	  return getData;
	},
	
	capitalizr : function(someString) {
        var newVal = '';
        someString = someString.split(' ');
        for( c=0; c < someString.length; c++ ) {
            newVal += someString[c].substring(0,1).toUpperCase() + someString[c].substring(1,someString[c].length) + ' ';
        }
        return newVal;
	},
	
	dropDownSet : function() {
		
		var strUrl = document.location;
		var arrUrl = BK.Press.All.splitURLVars(strUrl);
		
		var unsetYear = 'Year';
		var unsetSort = 'Sort By';
		var unsetNarrow = 'Narrow Results';
		
		if ( arrUrl.year ) {
			if ( arrUrl.year.length > 0 && typeof arrUrl.year === 'string' ){ 
				BK.Press.Vals.yearVal = BK.Press.All.capitalizr(arrUrl.year); 
				$('.pr_sort_year').find('.text').html(BK.Press.Vals.yearVal); 
			} 
		} else {
			$('.pr_sort_year').find('.text').html(unsetYear); 
		}
		
		if ( arrUrl.sort ) { 
			if ( arrUrl.sort.length > 0 && typeof arrUrl.sort === 'string' ){ 
				BK.Press.Vals.sortVal = BK.Press.All.capitalizr(arrUrl.sort); 
				$('.pr_sort_sortBy').find('.text').html(BK.Press.Vals.sortVal);
			} else {
				$('.pr_sort_sortBy').find('.text').html(unsetSort); 
			}
		}
		
		if ( arrUrl.narrow ) { 
			if ( arrUrl.narrow.length > 0 && typeof arrUrl.narrow === 'string' ){ 
				BK.Press.Vals.filterVal = BK.Press.All.capitalizr(arrUrl.narrow);
				$('.pr_sort_narrowResults').find('.text').html(BK.Press.Vals.filterVal);
			} 
		} else {
			$('.pr_sort_narrowResults').find('.text').html(unsetNarrow); 
		}
	}
};

BK.Press.FrontPage = {
	
	init : function() {
		
		BK.Press.FrontPage.resizeCols();
		BK.Press.FrontPage.setupBehaviors();
		
	},
	
	resizeCols: function() {
		
		var colHeights = [];
		
		colHeights.push( $('.pr_front_leftCol').height() );
		colHeights.push( $('.pr_front_mainCol').height() );
		colHeights.push( $('.pr_front_rightCol').height() );	
		
		var colMaxHeight = Math.max.apply( Math, colHeights );
		
		$('.pr_front_mainCol').height(colMaxHeight);
	},
	
	setupBehaviors: function() {
		
		$('.pr_featuredItem .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room Home', 'link_see all', 'press releases');
		});
		
		$('#press_materials_link').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_see all', 'images_video - media contacts');
		});
		
		$('#public_archive_link').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_see all', 'images_video - public archives');
		});
		
		$('.pr_front_mainCol .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_see all', 'campaigns');
		});
		
		$('.pr_front_rightCol_top .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_learn more', 'about bk');
		});
		
		$('.pr_front_rightCol_bottom .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_see all', 'contacts');
		});
		
		$('.pr_front_rightCol_bottom .content .email a').bind('click',function(){
			BK.Press.Track.event('Press Room Home','link_email', 'email - mediainquiries@whopper.com');
		});
		
		$('.bk_threetile_slideshow .heroImage a.video img, .bk_threetile_slideshow .heroImage a.video .playButton').live('click',function(){
			BK.Press.Track.event('Press Room Home','video_play', 'video_play - ' + $(this).parent().attr('title') );
		});
		
		$('.modal_overlay.video_player .call_to_action a').live('click',function(){
			BK.Press.Track.event('Press Room Home', 'link_see all', 'more videos' );
		});
		
	}
};

BK.Press.PressPage = {
	
	//PressPageVars
	'currentPage' : 1,
	'numberOfArticles' : '',
	'numberOfPages' : '',
	'itemsPerPage' : 4,	
	
	init : function() {
		
		BK.Press.PressPage.numberOfArticles = $('.pr_prs_item').length;
		BK.Press.PressPage.numberOfPages = Math.ceil( BK.Press.PressPage.numberOfArticles / 4 );
		BK.Press.PressPage.setupPages();
		BK.Press.PressPage.setupBehaviors();
		BK.Press.PressPage.showPage(1);
				
	},
	
	setupPages : function () {
		
		$('ul.pr_pagination').html('');
		
		var pageList = $('ul.pr_pagination');
		var theClass = '';

		if (BK.Press.PressPage.numberOfPages <= 25){
			for ( i = 1; i <= BK.Press.PressPage.numberOfPages; i++){
				theClass = 'pageNo';
				if ( i === BK.Press.PressPage.currentPage ) { theClass += ' active'; }
				pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
			}
		} else {
			if ( BK.Press.PressPage.currentPage <= 10 ){
				for ( i = 1; i <= 20; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.PressPage.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
				pageList.append('<span class="dots">...</span><li class="pageNo"><a href="#">'+BK.Press.PressPage.numberOfPages+'</a></li>');			
			} else if ( BK.Press.PressPage.currentPage >= BK.Press.PressPage.numberOfPages - 9 ){
				pageList.append('<li class="pageNo"><a href="#">1</a></li><span class="dots">...</span>');
				for ( i = BK.Press.PressPage.numberOfPages - 16; i <= BK.Press.PressPage.numberOfPages; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.PressPage.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
			} else {
				pageList.append('<li class="pageNo"><a href="#">1</a></li><span class="dots">...</span>');
				for ( i = BK.Press.PressPage.currentPage*1 - 7; i <= BK.Press.PressPage.currentPage*1 + 7; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.PressPage.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
				pageList.append('<span class="dots">...</span><li class="pageNo"><a href="#">'+BK.Press.PressPage.numberOfPages+'</a></li>');
			}
		}
	},

	setupBehaviors : function() {
		
		$('ul.pr_pagination .pageNo a').live('click', function(){
			
			var whichPage = $(this).html();
			BK.Press.PressPage.showPage(whichPage);
			$(this).parents('.pr_pagination').find('.pageNo').attr('class', 'pageNo');
			$(this).parents('.pageNo').addClass('active');
			return false;
			
		});
		
		$('.pr_prsDetail_print a').bind('click', function(){
			window.print();
			return false;
		});
		
		$('select').change(function(){
			var newVal = BK.Press.All.capitalizr($(this).val());
			$(this).parent().find('.text').html(newVal);
		});
		
		$('.searchHit').bind('click',function(){
			$(this).parent('form')[0].submit();
		});
		
		$('.pr_prs_item .moreLink a, .pr_featuredItem .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room - Press Releases','link_read more', 'read more-' + $(this).parent().parent().find('h4,h5 a').text() );
		});

	},
	
	showPage : function(whichPage) {

		$('.pr_featuredItem').show();
		$('.pr_prs_item').hide();
		
		if ($('.pr_prs_item').length === 0) { 
			$('.pr_featuredItem').hide(); 
			$('.pr_cNews_noResults').show(); 
		} else {
			$('.pr_featuredItem').show();
			$('.pr_cNews_regItem').hide();
		}
		
		
		var groupHeight = 0;
		var nA = BK.Press.PressPage.numberOfArticles;
		var nP = BK.Press.PressPage.numberOfPages;
		var iPP = BK.Press.PressPage.itemsPerPage;
		
		for ( i = 1; i <= ((whichPage === nP && nA%iPP > 0) ? nA%iPP : iPP); i++ ){
			var thisItem = $('.itemNo-' + (((whichPage-1)*4)+i));
			thisItem.show();
			groupHeight += thisItem.height();
			if ( typeof thisItem.css('marginTop') !== 'undefined' && typeof thisItem.css('paddingBottom') !== 'undefined' ) {
				groupHeight += thisItem.css('marginTop').split('px')[0]*1;
				groupHeight += thisItem.css('paddingBottom').split('px')[0]*1;
			}
			groupHeight += 4;
		}
		
		BK.Press.PressPage.currentPage = whichPage * 1;
		BK.Press.PressPage.setupPages();
		$('.pr_prs_dynamicItemWrap').stop().animate({height:groupHeight},450);
		
		if ( BK.Press.Vals.IE6 ) {
			
			$('.pr_prs_featuredHeader h3').height('auto').height('13px');
		    $('#GlobalHeader, #MenuTab').css('height','auto').css('height',$(document).height());
						
		}
		
	}
	
};

BK.Press.Search = {
	
	'currentYear' : '',
	'currentSort' : '',
	'currentNarrow' : '',
	
	init : function() {

		BK.Press.Search.currentYear = $('.pr_sort_year select').val();
		BK.Press.Search.currentSort = $('.pr_sort_sortBy select').val();
		BK.Press.Search.currentNarrow = $('.pr_sort_narrowResults select').val();

		if ( BK.Press.Search.currentYear === 'all' ) { BK.Press.Search.currentYear = ''; }		
		if ( BK.Press.Search.currentNarrow === 'all' ) { BK.Press.Search.currentNarrow = ''; }
		
		BK.Press.Search.setupBehaviors();
		
	},
	
	setupBehaviors : function() {
		
		$('.pr_sort_year select').change(function(){
			var newVal = $(this).val();
			if ( newVal === 'all' ) { newVal = ''; }
			BK.Press.Search.currentYear = newVal;
			BK.Press.Search.redirect();
		});
		$('.pr_sort_sortBy select').change(function(){
			var newVal = $(this).val();
			if ( newVal === 'all' ) { newVal = ''; }
			BK.Press.Search.currentSort = newVal;
			BK.Press.Search.redirect();
		});
		$('.pr_sort_narrowResults select').change(function(){
			var newVal = $(this).val();
			if ( newVal === 'all' ) { newVal = ''; }
			BK.Press.Search.currentNarrow = newVal;
			BK.Press.Search.redirect();
		});
		
	},
	
	redirect : function() {
		window.location = 'http://' + window.location.hostname + window.location.pathname + '?' + 'year='+BK.Press.Search.currentYear+'&sort='+BK.Press.Search.currentSort+'&narrow='+BK.Press.Search.currentNarrow;
	}
	
};

BK.Press.cNews = {

	//Pagination Vars
	'currentPage' : 1,
	'numberOfArticles' : '',
	'numberOfPages' : '',
	'itemsPerPage' : 4,	
	'whichSection' : '',

	init : function(section) {
		
		BK.Press.cNews.whichSection = section;
		
		BK.Press.cNews.numberOfArticles = $('.pr_cNews_regItem').length;
		BK.Press.cNews.numberOfPages = Math.ceil( BK.Press.cNews.numberOfArticles / 4 );
		BK.Press.cNews.setupPages();
		BK.Press.cNews.setupBehaviors();
		BK.Press.cNews.showPage(1);
				
	},
	
	setupPages : function () {
		
		$('ul.pr_pagination').html('');
		
		var pageList = $('ul.pr_pagination');
		var theClass = '';

		if (BK.Press.cNews.numberOfPages <= 25){
			for ( i = 1; i <= BK.Press.cNews.numberOfPages; i++){
				theClass = 'pageNo';
				if ( i === BK.Press.cNews.currentPage ) { theClass += ' active'; }
				pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
			}
		} else {
			theClass = '';
			if ( BK.Press.cNews.currentPage <= 10 ){
				for ( i = 1; i <= 20; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.cNews.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
				pageList.append('<span class="dots">...</span><li class="pageNo"><a href="#">'+BK.Press.PressPage.numberOfPages+'</a></li>');			
			} else if ( BK.Press.cNews.currentPage >= BK.Press.cNews.numberOfPages - 9 ){
				pageList.append('<li class="pageNo"><a href="#">1</a></li><span class="dots">...</span>');
				for ( i = BK.Press.cNews.numberOfPages - 16; i <= BK.Press.cNews.numberOfPages; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.cNews.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
			} else {
				pageList.append('<li class="pageNo"><a href="#">1</a></li><span class="dots">...</span>');
				for ( i = BK.Press.cNews.currentPage*1 - 7; i <= BK.Press.cNews.currentPage*1 + 7; i++){
					theClass = 'pageNo';
					if ( i === BK.Press.cNews.currentPage ) { theClass += ' active'; }
					pageList.append('<li class="'+theClass+'"><a href="#">'+i+'</a></li>');			
				}
				pageList.append('<span class="dots">...</span><li class="pageNo"><a href="#">'+BK.Press.cNews.numberOfPages+'</a></li>');
			}
		}
	},
	
	setupBehaviors : function() {
		
		$('ul.pr_pagination .pageNo a').live('click', function(){
			
			var whichPage = $(this).html();
			BK.Press.cNews.showPage(whichPage);
			$(this).parents('.pr_pagination').find('.pageNo').attr('class', 'pageNo');
			$(this).parents('.pageNo').addClass('active');
			return false;
			
		});
	
		$('select').change(function(){
			var newVal = BK.Press.All.capitalizr($(this).val());
			$(this).parent().find('.text').html(newVal);
		});
		
		//Create Modal Video Events
		$('.slideshow_item a.embed').modalVideo();
		
		$('.searchHit').bind('click',function(){
			$(this).parent('form')[0].submit();
		});
		
		$('.pr_featuredItem .moreLink a, .pr_cNews_regItem .moreLink a').bind('click',function(){
			BK.Press.Track.event('Press Room - Campaign News','link_read more', 'read more-' + $(this).parents('div.content').find('h4').text() );
		});
		
		$('.slideshow_item a').bind('click',function(){
			if ( $(this).attr('href') !== '#' ) {			
				BK.Press.Track.event('Press Room - Campaign News','link_image', 'image-' + $(this).attr('title') );
			}
		});
		
		$('.modal_overlay.video_player .call_to_action a').live('click',function(){
			BK.Press.Track.event('Press Room - Campaign News', 'open_image', 'image-' + $(this).parents('.modal_overlay_content').find('h4').text() );
		});
		
	},
	
	showPage : function(whichPage) {
		
		if ( BK.Press.cNews.whichSection === 'listing' ) {
		
			if ( !BK.Press.Vals.IE6 && !BK.Press.Vals.IE7 && BK.Press.cNews.numberOfPages > 0 ) {	
				$('.pr_templateContainer').css('height', $('.pr_templateContainer').height());
			}
			
			if ($('.pr_cNews_regItem').length === 0) { 
				$('.pr_featuredItem').hide(); 
				$('.pr_cNews_noResults').show(); 
			} else {
				$('.pr_featuredItem').show();
				$('.pr_cNews_regItem').hide();
			}

	
			var groupHeight = 0;
			var nA = BK.Press.cNews.numberOfArticles;
			var nP = BK.Press.cNews.numberOfPages;
			var iPP = BK.Press.cNews.itemsPerPage;
		
			for ( i = 1; i <= ((whichPage === nP && nA%iPP > 0) ? nA%iPP : iPP); i++ ){
				var thisItem = $('.itemNo-' + (((whichPage-1)*4)+i));
				thisItem.show();
				groupHeight += thisItem.height();
			  if ( typeof thisItem.css('marginTop') !== 'undefined' ) {
					groupHeight += thisItem.css('marginTop').split('px')[0]*1;
				}
			}
		
			groupHeight += $('.pr_featuredItem').height();
			groupHeight += 110;
		
			BK.Press.cNews.currentPage = whichPage;
			BK.Press.cNews.setupPages();
			
			if ( BK.Press.Vals.IE6 ) {
				
				$('.pr_cNews_featuredHeader h3').height('auto').height('13px');
				$('.leftArrow, .rightArrow').css('position','relative').css('position','absolute');
				
			}
			
			if ( !BK.Press.Vals.IE6 && !BK.Press.Vals.IE7 && BK.Press.cNews.numberOfPages > 0 ) {
				$('.pr_templateContainer').stop().animate({height:groupHeight},450, function(){ 
					$(this).css('height','');
				});
			}
			
		}
	}
};

BK.Press.mediaContacts = {
	
	init : function(){
		
		BK.Press.mediaContacts.setupBehaviors();
	
	},
	
	setupBehaviors : function() {
		
		$('.pr_mContacts_content a').each(function(){
			if ( $(this).attr('href').search('mailto') !== -1 ) {
				$(this).bind('click',function(){
					BK.Press.Track.event('Press Room - Media Contacts', 'email', $(this).attr('href').split('mailto:')[1] );
				});
			} else {
			}
		});
		
	}
};

BK.Press.publicArchive = {
	
	vars : {
		
		clickedExternalURL : ''
		
	},
	
	init : function(){
		
		BK.Press.publicArchive.setupBehaviors();
	
	},
	
	setupBehaviors : function() {

		$('.pr_imgVid_video a.video').bind('click',function(){
			BK.Press.Track.event('Press Room - Public Archive','video_play', $(this).attr('title') );
		})
		
		$('.pr_imgVid_video a[target="_blank"]').bind('click',function(){
			BK.Press.publicArchive.vars.clickedExternalURL = $(this).attr('href');
		});
			
		$('.modal_overlay li.cancel').live('mousedown',function(){
			BK.Press.Track.event(CulturePrefix + 'file_link','leave_confirmation', 'confirmation_cancel_' + BK.Press.publicArchive.vars.clickedExternalURL );
		});
	
		$('.modal_overlay li.continue').live('mousedown',function(){
			BK.Press.Track.event(CulturePrefix + 'file_link','leave_confirmation', 'confirmation_continue_' + BK.Press.publicArchive.vars.clickedExternalURL );
		});
	
	}
};

BK.Press.imgVid = {

    init: function () {

        BK.Press.imgVid.revealForms();
        BK.Press.imgVid.logoSetup();
        BK.Press.imgVid.setupBehaviors();

    },

    revealForms: function () {

        $('#pr_imgVid_signupPrompt, #pr_imgVid_login_content').show();

    },

    setupBehaviors: function () {

        $('#pr_imgVid_forgotPw').click(function () {
            BK.Press.imgVid.passwordModal();
        });

        $('#pr_imgVid_pwField').bind('focus', function () {
            $(this).val('');
            $(this).unbind('focus');
        });

        $('.pr_modal #pr_imgVid_cancelButton, #pr_blackout').live(BK.Press.Vals.downEventVar, function (e) {

            e.preventDefault();

            if ($(this).attr('class') === 'pr_signupSuccess') {
                location.reload();
            } else {
                $('#pr_blackout, .pr_modal').remove();
            }
        });

        $('select').change(function () {
            var newVal = BK.Press.All.capitalizr($(this).val());
            $(this).parent().find('.text').html(newVal);
        });

        $('#pr_imgVid_signupPrompt a').live('click', function () {
            $('#pr_imgVid_login_content').hide();
            $('#pr_imgVid_signup_content').show();
            $('#pr_imgVid_login_error').hide();
            $('#pr_imgVid_signupPrompt').hide();
            $('#pr_imgVid_loginPrompt').show();
        });

        $('#pr_imgVid_signup_content #pr_imgVid_cancelButton, #pr_imgVid_loginPrompt a').live('click', function () {
            $('#pr_imgVid_login_content').show();
            $('#pr_imgVid_signup_content').hide();
            $('#pr_imgVid_login_error').hide();
            $('#pr_imgVid_signupPrompt').show();
            $('#pr_imgVid_loginPrompt').hide();
        });

        $('#pr_imgVid_signup_content form').live('submit', function () {
            BK.Press.imgVid.signupCall();
            return false;
        });

        $('#pr_imgVid_signup_content #pr_imgVid_signupButton').live('click', function () {
            BK.Press.imgVid.signupCall();
        });

        $('#pr_imgVid_signup_content input').live('keypress', function (event) {
            if (event.which == "13") {
                event.preventDefault();
                BK.Press.imgVid.signupCall();
            }
        });

        $('#pr_imgVid_login_content form').bind('submit', function (e) {
            BK.Press.imgVid.loginCall();
            e.preventDefault();
        });

        $('#pr_imgVid_login_content #pr_imgVid_loginButton').bind('click', function () {
            BK.Press.imgVid.loginCall();
        });

        $('#pr_imgVid_login_content input').live('keypress', function (event) {
            if (event.which == "13") {
                event.preventDefault();
                BK.Press.imgVid.loginCall();
            }
        });

        $('.pr_imgVid_userLogout').bind('click', function () {
            window.location = 'http://' + window.location.hostname + CulturePrefix + 'company-info/press/press-materials.html';
        });

        $('.pr_modal_password form').live('submit', function () {
            BK.Press.imgVid.forgotPWCall();
            return false;
        });

        $('.pr_modal_password input').live('keypress', function (event) {
            if (event.which == "13") {
                event.preventDefault();
                BK.Press.imgVid.forgotPWCall();
            }
        });

        $('.pr_modal_password .pr_imgVid_submitButton').live('click', function () {
            BK.Press.imgVid.forgotPWCall();
        });

        // Tracking Assignments.

        $('.pr_imgVid_product').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-images', 'view_images-' + $(this).find('.pr_imgVid_productDescript h4').text());
        });

        $('.pr_imgVid_prodD_dlLink a, .pr_imgVid_prodD_downloadGallery a').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-images', 'download_images-' + $(this).parents('.pr_imgVid_contentContainer').find('h3').text());
        });

        $('.pr_imgVid_prodD_cta a').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-images', 'build-' + $(this).parents('.pr_imgVid_contentContainer').find('h3').text());
        });

        $('.pr_imgVid_logoWrapper .dlLinks a').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-logos', 'download_logo-' + $(this).parents('.pr_imgVid_logo').find('.pr_imgVid_logoFooter .size').text());
        });

        $('.pr_imgVid_video a.video').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-videos', 'video_play-' + $(this).attr('title'));
        });

        $('.pr_imgVid_video_dlLink a').bind('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-videos', 'video_download-' + $(this).parents('.pr_imgVid_videoWrapper').find('h4').text());
        });

        $('.modal_overlay_content .call_to_action a').live('click', function () {
            BK.Press.Track.event(window.location.pathname, 'press_materials-videos', 'video_download-' + $(this).parents('.modal_overlay_content').find('h4').text());
        });

        if (BK.Press.imgVid.readCookie("loginSuccess") == "true") {
            BK.Press.Track.event("Press Room - Login", "login", "login_successful");
            BK.Press.imgVid.eraseCookie("loginSuccess");
        }
    },

    logoSetup: function () {

        $('.pr_imgVid_logoWrap').each(function () {
            var logoOffset = $(this).height() - $(this).find('img').height();
            logoOffset /= 2;
            $(this).find('img').css('paddingTop', logoOffset);
        });

        if (BK.Press.Vals.IE6) {
            $('.pr_imgVid_logoWrap img').css('visibility', '');
        }

    },

    IE6ModalOverride: function () {

        if (BK.Press.Vals.IE6) {

            var overrideHeight = $(document).height();

            if ($(window).height() > overrideHeight) {
                overrideHeight = $(window).height();
            }

            $('#pr_blackout').height(overrideHeight);

        }

    },

    passwordModal: function () {

        var modalHTML = '';
        modalHTML += '<div id="pr_blackout"></div>';
        modalHTML += '<div class="pr_modal pr_modal_password ThreePxRounded">';
        modalHTML += '<h4>Forgot Password</h4>';
        modalHTML += '<div class="pr_imgVid_pw_error">Invalid Email Address. Please Try Again!</div>';
        modalHTML += '<div class="pr_modalCopy">Your password has been sent to your email address.</div>';
        modalHTML += '<form accept-charset="utf-8" method="get" action="#">';
        modalHTML += '<input type="text" class="pr_imgVid_inputField" value="Enter Email Address" name="email">';
        modalHTML += '<input type="submit" id="" value="Login" style="display: none;">';
        modalHTML += '<a id="pr_imgVid_cancelButton">Cancel</a>';
        modalHTML += '<a class="pr_imgVid_submitButton">Submit</a>';
        modalHTML += '</form>';
        modalHTML += '</div>';

        $('body').append(modalHTML);

        BK.Press.imgVid.IE6ModalOverride();

        $('.pr_modal_password input').bind('focus', function () {
            $(this).val('');
        });

    },

    forgotPWCall: function () {

        var pwEmail = $('.pr_modal_password .pr_imgVid_inputField').val();

        if (pwEmail.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) !== -1) {

            var post_url = "/web_services/campaign_services.aspx";
            var post_data = {};
            post_data.functionName = "prSetForgotPassword";
            post_data.username = pwEmail;
            post_data.format = "xml";

            $.ajax({
                type: 'POST',
                url: post_url,
                data: post_data,
                async: false,
                dataType: 'xml',
                success: function (xml) {

                    var responseJSON = $.xml2json(xml);

                    if (responseJSON.status === 'FAILURE') {

                        if (responseJSON.reason === 'user not approved') {
                            $('.pr_imgVid_pw_error').html('User Not Yet Approved.').show();
                        }

                        if (responseJSON.reason === 'Error Occurred' || responseJSON.reason === 'user not found') {
                            $('.pr_imgVid_pw_error').html('User Not Found. Please Try Again!').show();
                        }

                    } else {

                        $('.pr_modal_password .pr_modalCopy').show();
                        $('.pr_imgVid_pw_error').hide();
                        $('.pr_modal_password form').hide();

                    }
                }
            });

        } else {
            $('.pr_imgVid_pw_error').html('Invalid Email Address. Please Try Again!').show();
        }
    },

    loginCall: function () {

        var signinEmail = $('#pr_imgVid_login_content .pr_imgVid_emailField').val();
        var signinPw = $('#pr_imgVid_login_content #pr_imgVid_pwField').val();

        if (signinEmail.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) !== -1) {

            var post_url = "/web_services/campaign_services.aspx";
            var post_data = {};
            post_data.functionName = "prUserLogin";
            post_data.username = signinEmail;
            post_data.password = signinPw;
            post_data.format = "xml";
            //this is session management
            post_data.sn = "LoggedIn"; //session name
            post_data.sv = "true"; // session value

            $.ajax({
                type: 'POST',
                url: post_url,
                data: post_data,
                async: false,
                dataType: 'xml',
                success: function (xml) {

                    var responseJSON = $.xml2json(xml);

                    if (responseJSON.status === 'FAILURE') {

                        if (responseJSON.reason === 'Wrong Password') { $('#pr_imgVid_login_error').html('Incorrect Password. Please Try Again!').show(); }

                    } else {
                        BK.Press.imgVid.createCookie("loginSuccess", "true", 1);
                        //BK.Press.Track.event("Press Room - Login", "login", "login_successful");
                        window.location = 'http://' + window.location.hostname + CulturePrefix + 'company-info/press/press-materials/products.html';
                    }
                }
            });
        } else {
            $('#pr_imgVid_login_error').html('Invalid Email Address. Please Try Again!').show();
        }
    },

    signupCall: function () {

        if ($('.tocCheckBox input')[0].checked === true) {

            var userFirstName = $('#pr_imgVid_signup_content .pr_imgVid_fnameField').val();
            var userLastName = $('#pr_imgVid_signup_content .pr_imgVid_lnameField').val();
            var userJobTitle = $('#pr_imgVid_signup_content .pr_imgVid_titleField').val();
            var userPublication = $('#pr_imgVid_signup_content .pr_imgVid_pubField').val();
            var userPhoneNumber = $('#pr_imgVid_signup_content .pr_imgVid_phoneField').val();
            var userEmail = $('#pr_imgVid_signup_content .pr_imgVid_emailField').val();

            if (userEmail.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].value.search(/[^ ]$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].value.search(/[^ ]$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].value.search(/[^ ]$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].value.search(/[^ ]$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].value.search(/[^ ]$/) !== -1 &&
					$('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].value !== $('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].defaultValue &&
					$('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].value !== $('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].defaultValue &&
					$('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].value !== $('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].defaultValue &&
					$('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].value !== $('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].defaultValue &&
					$('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].value !== $('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].defaultValue) {

                var post_url = "/web_services/campaign_services.aspx";
                var post_data = {};
                post_data.functionName = "prUserSignUp";
                post_data.username = userEmail;
                post_data.first_name = userFirstName;
                post_data.last_name = userLastName;
                post_data.job_title = userJobTitle;
                post_data.publication = userPublication;
                post_data.phone_number = userPhoneNumber;
                post_data.format = "xml";

                $.ajax({
                    type: 'POST',
                    url: post_url,
                    data: post_data,
                    async: false,
                    dataType: 'xml',
                    success: function (xml) {

                        var responseJSON = $.xml2json(xml);

                        if (responseJSON.status === 'FAILURE') {

                            if (responseJSON.reason === 'user already signed up') { $('#pr_imgVid_signup_error').html('User Already Registered.').show(); }

                        } else {

                            BK.Press.imgVid.signupModal();

                        }
                    }
                });
            } else {

                var errorMessage = '';

                if (userEmail.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) === -1) {
                    errorMessage += '<div>Invalid Email Address. Please Try Again!</div>';
                }

                if ($('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].value.search(/[^ ]$/) === -1 ||
						$('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].value.search(/[^ ]$/) === -1 ||
						$('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].value.search(/[^ ]$/) === -1 ||
						$('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].value.search(/[^ ]$/) === -1 ||
						$('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].value.search(/[^ ]$/) === -1 ||
						$('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].value === $('#pr_imgVid_signup_content .pr_imgVid_fnameField')[0].defaultValue ||
						$('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].value === $('#pr_imgVid_signup_content .pr_imgVid_lnameField')[0].defaultValue ||
						$('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].value === $('#pr_imgVid_signup_content .pr_imgVid_titleField')[0].defaultValue ||
						$('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].value === $('#pr_imgVid_signup_content .pr_imgVid_pubField')[0].defaultValue ||
						$('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].value === $('#pr_imgVid_signup_content .pr_imgVid_phoneField')[0].defaultValue) {

                    errorMessage = '<div>All Fields Required. Please Try Again!</div>';

                }

                $('#pr_imgVid_signup_error').html(errorMessage).show();
            }
        } else {
            $('#pr_imgVid_signup_error').html('You Must Agree to the Terms and Conditions.').show();
        }

    },

    signupModal: function () {

        var modalHTML = '';
        modalHTML += '<div id="pr_blackout" class="pr_signupSuccess"></div>';
        modalHTML += '<div class="pr_modal pr_modal_signup ThreePxRounded">';
        modalHTML += '<h4>Sign Up</h4>';
        modalHTML += '<div class="pr_modalCopy">Once your email address has been approved you will receive an email with your password.</div>';
        modalHTML += '</div>';

        $('body').append(modalHTML);

        BK.Press.imgVid.IE6ModalOverride();

    },

    createCookie: function (name, value, days) {
        var expires = '';
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toGMTString();
        }
        else {
            expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
    },

    readCookie: function (name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
            if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); }
        }
        return null;
    },

    eraseCookie: function (name) {
        BK.Press.imgVid.createCookie(name, "", -1);
    }
};

BK.Press.Track = {

    event: function (sectionLocation, eventType, eventDetail) {
        try {
            pageTracker._trackEvent(sectionLocation, eventType, eventDetail);
        }
        catch (e) { }
    },

    pageLoad: function () {
        try {
            pageTracker._trackPageview();
        }
        catch (e) { }
    },

    mediaLogin: function () {

        try {
            pageTracker._setCustomVar(1, 'Media Reporter Logged in Once upon a time', 'Yes', 1);
        } catch (e) { };
        try {
            pageTracker._setCustomVar(3, 'Media Reporter Currently Logged In', 'Yes', 5);
        } catch (e) { };

    }
};



$(document).ready(function(){
	
	BK.Press.All.init();
	BK.Plugins.mediaCarousel.init();
	BK.Plugins.threeTileCarousel.init();
	BK.Press.Search.init();

	if ( window.location.pathname.search('/press/index.html') > -1 ) { BK.Press.FrontPage.init(); }
	if ( window.location.pathname.search('bk-press') > -1 ) { BK.Press.PressPage.init(); }
	if ( window.location.pathname.search('press-release') > -1 ) { BK.Press.PressPage.init(); }
	if ( window.location.pathname.search('campaign-news') > -1 ) { BK.Press.cNews.init('listing'); }
	if ( window.location.pathname.search('campaign-detail') > -1 ) { BK.Press.cNews.init('details'); }
	if ( window.location.pathname.search('contact-us') > -1 ) { BK.Press.mediaContacts.init(); }
	if ( window.location.pathname.search('public-archive') > -1 ) { BK.Press.publicArchive.init(); }
	if ( window.location.pathname.search('press-materials') > -1 ) { BK.Press.imgVid.init(); }
	
});


