function initDailyShuffle() {
      $("#daily-story-shuffle .content dl dd").jCarouselLite({
        btnNext: "div#daily-story-shuffle .controls .next a",
        btnPrev: "div#daily-story-shuffle .controls .prev a",
        circular: true,
         visible: 4,
         scroll: 4,
         speed: 1200,
          easing: "easeinout"

        });
}
    function initLoginWidget () {
            $('#user-login .controls a').bind("click", function() { $('#user-login .content').slideToggle(100); return false; });
    }

function initTabbedModule(container_id) {
	var tabContainers = $('#' + container_id + ' div.tabs > div');
	tabContainers.hide().filter('#article-popular-news').show();
	
	$('#' + container_id + ' .tabNavControls ul li a').click(function () {
                tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('#' + container_id + ' .tabNavControls ul li a').removeClass('active');
		$(this).addClass('active');
		return false;
	}).filter('#article-popular-news').click();
}

function clearSearchFormFocus(){
  $('input#edit-search-theme-form-keys').val("Search SPIN.com");
  $('input#edit-search-theme-form-keys').focus(function () {
         $(this).val("");
    });
  $('input#edit-search-theme-form-keys').blur(function () {
         $(this).val("Search SPIN.com");
    });
}


function popup(winURL) {
  window.open(winURL,"popup","width=900,height=500, scrollbars=yes"); 
}



$(document).ready(function(){
	$('.sharing-tools .twitter .tweet, .sharing-tools .addthis_toolbox a').bind('click', function() {
  	  popup(this.getAttribute("href"));
          return false; 
       });
        $('.sharing-tools .facebook a').bind('click', function() {
          toggleFbCount(this);
          popup(this.getAttribute("href"));
          return false;
       });
});


function toggleFbCount(el){
   var facebookCount = $(el).children("strong");
   var state = facebookCount.css("visibility");
   if (state == "hidden"){
     facebookCount.css("visibility","visible").text("1"); // if the count is hidden that means it is at zero. so we go ahead and show it and adjust the count to 1
   } 
}

function setCookie(c_name,value,expiredays){
        var exdate = new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";path=/;expires="+exdate.toUTCString());
}

function getCookie(c_name){
        if (document.cookie.length>0) {
          c_start = document.cookie.indexOf(c_name + "=");
          if (c_start!=-1) {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);

            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
          }
        }
        return "";
}


