if (!window.console) { 
    window.console = {
        log: function(obj){ /* define own logging function here, or leave empty */ }
    };
}


$(document).ready(function() {  
	
/* Mobile Redirect Message */
var mobileCookie = getParameterByName(window.location.href, 'MGKsite');
var cookie = readCookie('MGKMobileCookie');
var expDate =new Date();
expDate.setDate(expDate.getDate()+1);
expDate = expDate.formatDate("D, j M Y G:i:s %U%T%C");
if(mobileCookie === "desktop") {
	document.cookie = 'MGKMobileCookie=desktop; expires=' + expDate + '; path=/';
} else {
	if (cookie === "mobile") {
		window.location.href = 'http://m.wmgk.com';
	} else if (cookie === "desktop") {
		//Do Nothing
	} else {
		if (jQuery.browser.mobile === true) {
			$("body").append("<div class=\"mobile-alert\"><div class=\"message\"><h3>MGK's Gone Mobile...</h3>Hey! You're on a mobile device. Are you sure you want to be browsing the desktop site? How about checking out the mobile version?<div class=\"user-options\"><a href=\"#\" class=\"yes\">Yes, please</a><a href=\"#\" class=\"no\">No thanks</a></div></div></div>");
			
			//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
			var popMargTop = ($('.mobile-alert .message').height() + 80) / 2;
			var popMargLeft = ($('.mobile-alert .message').width() + 80) / 2;
			
			//Apply Margin to Popup
			$('.mobile-alert .message').css({
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});
			
			var expDate =new Date();
			expDate.setDate(expDate.getDate()+14);
			expDate = expDate.formatDate("D, j M Y G:i:s %U%T%C");
			
			$(".mobile-alert .message a").live("click", function(e) {
			e.preventDefault();
			var option = $(this).attr("class");
			if (option === "no") {
				document.cookie = 'MGKMobileCookie=desktop; expires=' + expDate + '; path=/';
				$(".mobile-alert").remove();
			} else if (option === "yes") {
				document.cookie = 'MGKMobileCookie=mobile; expires=' + expDate + '; path=/';
				window.location.href = 'http://m.wmgk.com';
				return false;
			}
			});
		}
	}
}
	
	
	//MGK ON FACEBOOK LINK
	$("div.subnav_m02 ul.subnavblock_m02 li.first a[href*='facebook.com/1029wmgk']").parents("div.skin_m02").children("div.label_img_m02").children("img[src*='mgk-on-facebook-header.png']").wrap("<a href=\"http://www.facebook.com/1029wmgk\" target=\"_blank\"></a>");
	$("div.subnav_m02 ul.subnavblock_m02 li.first a[href*='facebook.com/1029wmgk']").parents("div.subnav_m02").css("display","none");
	
	
	/** Facebook "Like" Button // Twitter // Google + // AddThis **/	

	var page_name = returnDocument();
	
	if(page_name == "home.aspx" || page_name == null || page_name =="index.aspx" || page_name == "") {
			var pathName = returnPath();
			
		$('table.blogs_home_link').each(function(){
			var entryLink = $(this).find("a:last").attr("href");
			var shareHTML = makeShareButtons.init({url:entryLink});
			$(this).after(shareHTML);

		});
		
		$('a.jumperlink').not($("div.contestTeaser a.jumperlink")).each(function(){
			var entryLink = pathName + $(this).attr("href");
			var shareHTML = makeShareButtons.init({url:entryLink});
			$(this).after(shareHTML);
		});
		
		FB.XFBML.parse();

	}
	else if (page_name == "blogentry.aspx") {	
		var shareHTML = makeShareButtons.init({at:true, tw:true, gp:true});
		$('table.blog_entry td.mini').append(shareHTML);
		$.addthis('jzajac');
		$.getScript("http://platform.twitter.com/widgets.js");
		$.getScript("https://apis.google.com/js/plusone.js");
		FB.XFBML.parse();
	}
	else if (page_name == "story.aspx") {
		var shareHTML = makeShareButtons.init({at:true, tw:true, gp:true});
		$('a.jumperlink[href*="TellAFriend"]').after(shareHTML).remove();	
		$.addthis('jzajac');
		$.getScript("http://platform.twitter.com/widgets.js");
		$.getScript("https://apis.google.com/js/plusone.js");
		FB.XFBML.parse();
	}
	
	$(".share-this").each(function(){
		if($(this).hasClass("all")) {
			var shareHTML = makeShareButtons.init({at:true, tw:true, gp:true});
			$(this).html(shareHTML);
			$.addthis('jzajac');
			$.getScript("http://platform.twitter.com/widgets.js");
			$.getScript("https://apis.google.com/js/plusone.js");
			FB.XFBML.parse();
		} else {
			var shareHTML = makeShareButtons.init({});
			$(this).html(shareHTML);
			FB.XFBML.parse();
		}
	});

/* AUDIO PLAYER TOOLTIPS */
if(FlashDetect.installed){
	$(function () {
	  $('div[id*="Audio"]').each(function () {
		$(this).addClass("blog-audio-player");
		$(this).parent('div').addClass("blog-audio-container");
		var blogEntryID = ($(this).attr('id')).split('_')[1].slice(0,8);
	
		$(this).after("<div class='blog-audio-tooltip'><p>To listen, <b>click the play button</b>.</p><p>Don't see it? Listen on our <a href='http://m.wmgk.com/?entry_id="+blogEntryID+"'>mobile site</a> or <a href='http://www.wmgk.com/about/podcasts/'>get help here</a>.</p></div>");
		
		// options
		var distance = 30;
		var time = 250;
		var hideDelay = 500;
		
		if ($(this).height() > 50) {
			var init_bottom = 25;
		} else {var init_bottom = 10; }
		
		var hideDelayTimer = null;
	
		// tracker
		var beingShown = false;
		var shown = false;
		
		var trigger = $(this);
		var popup = $(trigger).siblings('.blog-audio-tooltip').css('opacity', 0);
		var popupWidth = $(trigger).width();
		
		// animate when the page loads
		setTimeout(function() {      
			beingShown = true;
			popup.css({
				  bottom: init_bottom, display: 'block' // brings the popup back in to view
				  })        
				.animate({opacity:1}).animate({left:'-=5px'}).animate({left:'+=5px'}).animate({left:'-=5px'}).animate({left:'+=5px'}).animate({left:'-=5px'}).animate({left:'+=2px'}, function () {
			  // reset the timer if we get fired again - avoids double animations
			  if (hideDelayTimer) clearTimeout(hideDelayTimer);
					  beingShown = false;
					  shown = true;
			  // store the timer so that it can be cleared in the mouseover if required
			  hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
				  bottom: '-=' + distance + 'px',
				  opacity: 0
				}, time, 'swing', function () {
				  // once the animate is complete, set the tracker variables
				  shown = false;
				  // hide the popup entirely after the effect (opacity alone doesn't do the job)
				  popup.css('display', 'none');
				});
			  }, 4000);
			});
		}, 4000);
	
		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
		  // stops the hide event if we move from the trigger to the popup element
		  if (hideDelayTimer) clearTimeout(hideDelayTimer);
	
		  // don't trigger the animation again if we're being shown, or already visible
		  if (beingShown || shown) {
			return;
		  } else {
			beingShown = true;
			// reset position of popup box
			popup.css({
			  bottom: init_bottom + 30,
			  //left: -10,
			  display: 'block' // brings the popup back in to view
			})
			// (we're using chaining on the popup) now animate it's opacity and position
			.animate({
			  bottom: '-=' + distance + 'px',
			  opacity: 1
			}, time, 'swing', function() {
			  // once the animation is complete, set the tracker variables
			  beingShown = false;
			  shown = true;
			});
		  }
		}).mouseout(function () {
		  // reset the timer if we get fired again - avoids double animations
		  if (hideDelayTimer) clearTimeout(hideDelayTimer);
		  
		  // store the timer so that it can be cleared in the mouseover if required
		  hideDelayTimer = setTimeout(function () {
			hideDelayTimer = null;
			popup.animate({
			  bottom: '-=' + distance + 'px',
			  opacity: 0
			}, time, 'swing', function () {
			  // once the animate is complete, set the tracker variables
			  shown = false;
			  // hide the popup entirely after the effect (opacity alone doesn't do the job)
			  popup.css('display', 'none');
			});
		  }, hideDelay);
		});
	  });
	});
	} else {
	$('div[id*="Audio"]').each(function () {
		$(this).addClass("blog-audio-player");
		$(this).parent('div').addClass("blog-audio-container");
		var blogEntryID = ($(this).attr('id')).split('_')[1].slice(0,8);
	
		$(this).html("<div class='blog-audio-tooltip'><p>Listen on our <a href='http://m.wmgk.com/?entry_id="+blogEntryID+"'>mobile site</a> or <a href='http://www.wmgk.com/about/podcasts/'>get help here</a>.</p></div>");
		
		var trigger = $(this);
		var popup = $(trigger).children('.blog-audio-tooltip').css('display', 'block').css('background-position', '100% 100%').css('position', 'relative').css('left', 0);
	});
}

	
	/** Random Masthead Image **/
	var mh = ["masthead-rolling-stones.png","masthead-bruce-springsteen.png","masthead-beatles.png","masthead-the-who.png","masthead-led-zeppelin.png","masthead-fleetwood-mac.png","masthead-zz-top.png","masthead-eagles.png","masthead-aerosmith.png"];
	var mhpath = "http://www.wmgk.com/Pics/Global/masthead/";
	var randomNumber = 0;
	$('img#mgk-masthead').attr('src', mhpath + mh[Math.round(Math.random()*(mh.length-1))] );
	
	
	/*ADD DESCRIPTION TO CAPTCHA
   ******************************/						   
	$("div[ id *= 'ContestHeader' ] ~ div[ id *= 'MemberAuthenticated' ]").each(function(){

		$(this).find("div#recaptcha_widget_div").each(function(){
			
			$(this).prepend("<div id=\"captcha-info-box\"><p class=\"captcha-info\">MGK @Work Network Contests & Noontime Nugget requests now require you to do the following to register.</p><p class=\"captcha-info\">Type the words or letters you see below into the space provided, then click ENTER and you'll be registered. In addition, you'll receive an accompanying message on your screen that will confirm your registration.</p></div>");
			
			$(this).after("<div id=\"captcha-info-box\"><p class=\"captcha-info captcha-small\"><b>Why are we asking you to do this?</b> It proves that you are a person and not a computer automation system trying to register multiple times.</p></div>");	
		});
	});
					
	/*TODAY/TOMORROW/NEXT WEEK ON THE DEBELLA SHOW
   ******************************/				
	$("div.multipleskinarea div[ id *= 'NormalMode'] span.largeheader span#ctl00_MainTopLeft_GenericControl17_ucf401de4b1ba9490d841fb96035156f32_ModuleTitle, span.largeheader span#jdb-teaser-title").each(function(){
					var d = new Date();
					var dayoftheweek = d.getDay();
					var timeofday = d.getHours();
					var msg = "";
					if (dayoftheweek == 0) {
								msg = "Tomorrow on the John DeBella Show"
					}
					else if (dayoftheweek>=1 && dayoftheweek<=4 && timeofday < 12) {
								msg = "Today on the John DeBella Show"
					}
					else if (dayoftheweek>=1 && dayoftheweek<=4 && timeofday >= 12) {
								msg = "Tomorrow on the John DeBella Show"
					}
					else if (dayoftheweek == 5 && timeofday < 12) {
								msg = "Today on the John DeBella Show"
					}
					else if (dayoftheweek == 5 && timeofday >= 12) {
								msg = "Next week on the John DeBella Show"
					}
					else if (dayoftheweek == 6) {
								msg = "Next week on the John DeBella Show"
					}
				$(this).html(msg);
		});
					
	
	$("div.memberStatus span.lnkLogin a").append(" - @WORK NETWORK");
	$("div.memberStatus span").css("display", "inline-block");
	$("div.memberStatus span.delimiter").remove();
	$("div.memberStatus").each(function(){
		h = -$(this).outerHeight();
		$(this).css("margin-top", h);
	});
							  
	$("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  0     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
		dropShadows:  true,	
		autoArrows:    true,
		delay:         800,
		onBeforeShow:  function(){
		var subMenuHeight = 	$(this).height();
			if(subMenuHeight >= 200) {
				$(this).addClass("tall-menu");	
			}
		}    // callback function fires just before reveal animation begins – 'this' is the ul about to open 
		});  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 


//REMOVE "..." from Contest Descriptions
$("span[ id *='ContestDescription'] ").each(function(){
													  //$(this).css("border","10px solid black");
	if ($(this).html() == "-...") 
		$(this).remove();
});
   
 
  
      
   $("div#wpvi-sponsor").html("<a href='http://banners.andomedia.com/openx_gm/www/delivery/ck.php?oaparams=2__bannerid=10443__zoneid=0__log=no__cb=638456afd6__maxdest=	 http://abclocal.go.com/wpvi/channel?section=news/entertainment&id=7098104' target='_blank'><img src='http://banners.andomedia.com/openx_gm/www/delivery/avw.php?campaignid=1783&bannerid=10443' border='0' alt='' /></a>");
   
      $("div#bottom_ad").html("<iframe id='a4eaa1ea' name='a4eaa1ea' src='http://banners.andomedia.com/openx_gm/www/delivery/afr.php?n=a4eaa1ea&amp;zoneid=336&amp;cb=INSERT_RANDOM_NUMBER_HERE' framespacing='0' frameborder='no' scrolling='no' width='468' height='60'><a href='http://banners.andomedia.com/openx_gm/www/delivery/ck.php?n=a03e2d3a&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://banners.andomedia.com/openx_gm/www/delivery/avw.php?zoneid=336&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a03e2d3a' border='0' alt='' /></a></iframe><script type='text/javascript' src='http://banners.andomedia.com/openx_gm/www/delivery/ag.php'></script>");
   
   
   
	/**POP-UP WINDOWS **/
	/*AV PLAYER*/ $(".av-popup").popup({width: 675, height: 320});
	/*Listen Live HD1*/ $(".stream-popup-lc").popup({width: 680,height: 511});
	/*Listen Live HD2*/ $(".stream-popup-lc-hd2").popup({width: 680,height: 380});
	/*Listen Live STW*/ $(".stream-popup-stw, a[target='stream']").popup({width: 742,height: 388,resizeable: false,scrollbars: false,titlebar:false,status:false,toolbar:false,menubar:false});	
	/** RSS **/ $(".rss-email-popup").popup({width: 675,height: 550});
	


   
   // ALLOWS YOU TO SELECT ALL EXTERNAL LINKS WITH $('a:external')					
	$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/) && !obj.href.match(/^http\:\/\/www\./) && !obj.href.match(/^http\:\/\/beta\./) && (obj.hostname != location.hostname) && !obj.href.match(/^javascript\:/);
	};
		
	//FORCES ALL EXTERNAL LINKS TO OPEN IN NEW WINDOW
	$('a:external').attr("target","_blank");


   /*AT WORK NETWORK - CURRENT CONTESTS
   ******************************/
   if ( $("table[ id *= 'ctl00_MainTopLeft_GenericControl7_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").length > 0 ) {
		$("table[ id *= 'gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").remove();
		$("table[ id *= 'gvContestList' ] tr td p br").remove();
	}
   if ( $("table[ id *= 'ctl00_MainTopLeft_GenericControl5_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").length > 0 ) {
		$("table[ id *= 'gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").remove();
		$("table[ id *= 'gvContestList' ] tr td p br").remove();
	}
	if ( $("table[ id *= 'ctl00_MainTopLeft_GenericControl6_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").length > 0 ) {
		$("table[ id *= 'gvContestList' ] tr td p span[ id *= 'lblContestDescription' ]").remove();
		$("table[ id *= 'gvContestList' ] tr td p br").remove();
	}

//Remove NON-AT-WORK-NETWORK CONTESTS FROM AT-WORK NETWORK PAGE

$("table[ id *= 'ctl00_MainTopLeft_GenericControl5_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ], table[ id *= 'ctl00_MainTopLeft_GenericControl6_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ], table[ id *= 'ctl00_MainTopLeft_GenericControl7_uc26917ad25fcf4077b7fd32925a8e9d82_gvContestList' ]").each(function(){
	$(this).find("h3 span:contains('[ON-AIR]')").each(function(){
		$(this).parents("tr:eq(0)").remove();			
	});
	$(this).find("tr").removeClass("tralt trdef");
	$(this).find("tr:even").addClass("trdef");
	$(this).find("tr:odd").addClass("tralt");
																																																																														});
	
   /*AT WORK NETWORK - HOME PAGE BANNER
   ******************************/
   if ($("ul#at-work-network-fp").length > 0) {
	   $("ul#at-work-network-fp").bind( "click", function() {
			window.location="http://www.wmgk.com/extras/";					   
		});
   }
   
   /*Daily Prize Info
   ******************************/
$("div#daily-prize-info a#daily-claim-link, div#daily-prize-info a#daily-about-link").bind("click", function() {	
			var buttonSelector = $(this).attr("id");
			if ( buttonSelector == "daily-claim-link" ) {
				var prizeInfoDisplay = $("div#daily-prize-claim").css("display");
				var prizeInfoSelector = "div#daily-prize-claim";
				prizeDisplay (prizeInfoSelector, prizeInfoDisplay);		
			} else if ( buttonSelector == "daily-about-link" ) {
				var prizeInfoDisplay = $("div#daily-prize-about").css("display");
				var prizeInfoSelector = "div#daily-prize-about";
				prizeDisplay (prizeInfoSelector, prizeInfoDisplay);
			}
		});

   
   /*Add Links to Music News RSS Consumer
   ******************************/
	if ( $("div.rssconsumer div.title a[ id *= 'repFeedItemsTitleOnly' ]").length > 0 ) {
	}
   
 
   
   //Remove LOGIN/REGISTER form from On-Air Contest posts
	if ( $("span.header span:contains('[ON-AIR]')").length > 0 ) {
		$("span.header span:contains('[ON-AIR]')").each(function() {
		$("div[ id *= 'UnivLoginVerify_pnlLogin' ], div.hdiv11, div[id*='MemberAuthenticated']").remove();
		});
	} else if ( $("span.header span:contains('[ONLINE*]')").length > 0 ) {
		$("span.header span:contains('[ONLINE*]')").each(function() {
		$("div[ id *= 'UnivLoginVerify_pnlLogin' ], div.hdiv11, div[id*='MemberAuthenticated']").remove();
		});
	}
	
	// GOOGLE ANALYTICS TRACKING FOR PHOTO GALLERIES AND AV PLAYERS

	
if(pageTracker != null && typeof(pageTracker) != 'undefined') {
	
	$("div[ id *= 'AVPlayerFlash' ] > *").bind("click", function() {
		trackThis("AV Player", this);
	});
	
	$("div[ id *= 'Images_' ] > *").bind("click", function() {
		trackThis("Photo Gallery", this);
	});
	
	$("div[ id *= 'Audio_' ] > *").one("click", function() {
		trackThis("Audio Embed", this);	
	});
	
	$("a[href *='.mp3']").bind("click", function() {
		pageTracker._trackEvent('MP3 Download', $(this).context.hostname, $(this).attr('href'));
	});
	
	$('a:external').bind("click", function() {
		 pageTracker._trackEvent('Outbound Traffic', $(this).context.hostname, $(this).attr('href'));
	});
	
}
	//TEMPORARY WARNING ABOUT PASSWORD
	
	$("div [id *= 'UnivLoginVerify_lblLoginText']").after("<div class=\"temporary-warning\"><p>Our new improved website requires @Work Network Members to have: an email address AND A PASSWORD. <b>It's really easy to get your password</b>.</p><p>Once you get it, you'll be able to get all of the <b>inside info</b>, Members only <b>contest registration</b> and more that @Work Network Members enjoy. </p><ol><li>Enter your email address in the field above. In the password field, enter \"WMGK\", and click \"Login\".</li><li>You'll get an error saying this password is incorrect. Don't worry! Click \"Send Reminder\" and we'll give you the real one.</li><li>Once you've checked your email and you've got your new password, come back here and log in with it.</li></ol></p><p>If you've got any problems, please don't hesitate to drop <a href=\"mailto:webmaster@wmgk.com?Subject=Trouble logging in to the new WMGK.com!\">tech support</a> an email, or click below to chat with live tech support.</p></div>");
		
	
	$("td[ id *= 'tdMemberLogin01' ]").before("<a name=\"member-instructions\"></a><br /><br />");
	
	// ALERT VIP MEMBERS TO FIND THEIR PASSWORD
	$('.button_memberlogin, .btnWrap').after("<span id=\"vip-help\" class=\"btnWrap\"><input type=\"submit\" class=\"notAMember btnGo\" tabindex=\"4\" value=\"Already a member, but no password? Help!\"></span><div class=\"friendly-warning\"><p>Our new improved website requires @Work Network Members to have: an email address AND A PASSWORD. <b>It's really easy to get your password</b>.</p><p>Once you get it, you'll be able to get all of the <b>inside info</b>, Members only <b>contest registration</b> and more that @Work Network Members enjoy. </p><ol><li>Enter your email address in the field above. In the password field, enter \"WMGK\", and click \"Login\".</li><li>You'll get an error saying this password is incorrect. Don't worry! Click \"Send Reminder\" and we'll give you the real one.</li><li>Once you've checked your email and you've got your new password, come back here and log in with it.</li></ol></p><p>If you've got any problems, please don't hesitate to drop <a href=\"mailto:webmaster@wmgk.com?Subject=Trouble logging in to the new WMGK.com!\">tech support</a> an email, or click below to chat with live tech support.</p></div>");
	
	$('#vip-help, .vip-help').bind("click", function() {
		var warningDisplay = $("div.friendly-warning").css("display");
				if (warningDisplay == "none") {
					$("div.friendly-warning").slideDown("slow");
					location.href = "#member-instructions";
				}
				else {
					$("div.friendly-warning").slideUp("slow");
				}		
			return false;
		});
   
 });




