// intense debate variables
var idcomments_acct = '';	
var idcomments_post_id = '';
var idcomments_post_url= '';

$(function(){
  var d = new Date();
  $('#header').prepend('<div id="fin_header_datetime">'+$.datepicker.formatDate('DD, MM d, yy - Seattle, WA', d)+'</div><div id="fin_header_weather_container"></div>');
  $('#fin_header_weather_container').load("/templates/forecast_home.html");
  $("#fin_headlinenews_hover #fin_topstory .fin_headlinenews_target").hover(function(){
  	$("#fin_headlinenews_hover #fin_topstory .fin_headlinenews_target .fin_cover").stop().animate({top:'0px'},{queue:false,duration:160});
  }, function() {
  	$("#fin_headlinenews_hover #fin_topstory .fin_headlinenews_target .fin_cover").stop().animate({top:'-80px'},{queue:false,duration:160});
  });
  $(".fin_thumblist .fin_headlinenews_target").hover(function(){
    $("#fin_headlinenews_hover #fin_topstory .fin_headlinenews_target").html($(this).html())
    $(".fin_thumblist .fin_headlinenews_target a").removeClass("fin_current");    
    $(this).find("a").addClass("fin_current");
  }, function() {
  });
  // $("#fin_topstory .fin_headlinenews_target").html($(".fin_thumblist .fin_headlinenews_target:first").html());

  // date for datasphere
  var d = new Date();
  d.setDate(d.getDate() - 1);
  var day = d.getDate();
  if(day < 10) day = '0'+day;
  var month = d.getMonth() + 1;
  if(month < 10) month = '0'+month;

  // Category labels
  var fin_blocks = new Array();
  fin_blocks["fin_header_weather_container"] = '1. MiniForecast';
  fin_blocks["fin_header_tv_spot"] = '1. Connect';
  fin_blocks["navbuttons"] = '2. TopNav';
  fin_blocks["subnav"] = '3. SubNav';
  fin_blocks["fin_headlinenews_hover"] = '5. Headline Carousel';
  fin_blocks["fin_headlines_container"] = '5. Top Stories';
  fin_blocks["fin_headlines_photogalleries"] = '5. Photo Galleries';
  fin_blocks["fin_headlines_pulp_promo"] = "5a. Pulp Promo";
  fin_blocks["fin_guiltypleasures"] = '6. Guilty Pleasures';
  fin_blocks["fin_local_container"] = '6. Local';
  fin_blocks["FIN_stay_connected"] = '6. Stay Connected';
  fin_blocks["KOMO_Homepage_Hyperlocal_Widget"] = '7. Community';
  fin_blocks["fin_national_container"] = '8. World';
  fin_blocks["fin_askkomo"] = '8. Ask KOMO';
  fin_blocks["fin_sports_container"] = '9. Sports';
  fin_blocks["mostpopular"] = '9. Most Popular';
  fin_blocks["fin_videocarousel"] = '10. Top Video';
  fin_blocks["fin_yourlifeyourstyle"] = '11. Your Life Your Style';
  fin_blocks["fin_commentary"] = '11. Extras';
  fin_blocks["FIN_facebook_fanbox"] = '11. Facebook Fanbox';
  fin_blocks["fin_morenews"] = '12. More News';
  fin_blocks["dsnslocaldeals"] = '13. Local Deals';
  fin_blocks["footer"] = '15. Footer';
  
  // JLND 2011-02-25: Track many types of clicks.
  $('#fin_header_weather_container, #fin_header_tv_spot, #navbuttons, #subnav, #fin_headlinenews_hover, #fin_headlines_container, #fin_headlines_photogalleries,#fin_guiltypleasures, #fin_local_container, #FIN_stay_connected, #KOMO_Homepage_Hyperlocal_Widget, #fin_national_container, #fin_askkomo, #fin_sports_container, #mostpopular, #fin_videocarousel, #fin_yourlifeyourstyle, #fin_commentary, #FIN_facebook_fanbox, #fin_morenews,#dsnslocaldeals, #footer, #fin_headlines_pulp_promo').click(function(event){ 
	var clickedlnk = $(event.target).closest('a');
	var whichitem = $(this).attr('id');
	var lnktext = '';
	if(clickedlnk.length && clickedlnk.attr('href') && clickedlnk.attr('href').length) {
	  event.preventDefault();
      if (whichitem == 'fin_header_weather_container') {
        lnktext = 'Complete Forecast' + ' | ' + clickedlnk.attr('href');
	  } else {
	    lnktext = clickedlnk.text() + ' | ' + clickedlnk.attr('href');
      }
      var eventcat = '';
	  eventcat = fin_blocks[whichitem];
	  try { pageTracker._trackEvent('FIN_Click_Link', eventcat, lnktext); } catch (e) { }
      // try { console.log('FIN_Link_Click' + ' | ' + eventcat + ' | ' + lnktext);  } catch (e) { }
      setTimeout('document.location = "' +   clickedlnk.attr('href') + '"', 100);
	} else if ($(this).attr('onclick') && $(this).attr('onclick').length) {	
	  if (whichitem == 'fin_askkomo') {
		lnktext = 'Ask KOMO box';
		eventcat = whichitem;
	  }
      // try { console.log('FIN_Link_Click' + ' | ' + eventcat + ' | ' + lnktext);  } catch (e) { }
	  try { pageTracker._trackEvent('FIN_Click_Link', eventcat, lnktext); } catch (e) { }
	}
  });
});


