jQuery(document).ready(function() {
   $=jQuery;
   //extract the sidebar widgets for the tabs
   $('#sidebar_1 .sidebar_list').each(function() {
      var widgets = $(this).children();
      var widgetList = '<ul id="tabs-widget-list"></ul>';
      var titleList = '<ul>';
      var first = true;
      
      //get the titles, hide them, add widget to tabs list
      widgets.each(function() {
         
         var widgetTitle = $(this).children('h3, h2').text();
         if (widgetTitle == 'Tags' || widgetTitle == 'Recent' || widgetTitle == 'Popular' || widgetTitle == 'Comments') {
            
            if(first==true) $(this).parent().append(widgetList);
            first = false;
            
            $(this).children('h3, h2').hide();
            var listItem = '<li><a href="#'+$(this).attr('id')+'">'+widgetTitle+'</a></li>';
            titleList += listItem;
            $('#tabs-widget-list').append(this);
         } else {
            $(this).parent().append(this);
         }
      });
      titleList += '</ul>';
      
      // add the title list to the beginning of the tabs widget list
      $('#tabs-widget-list').prepend(titleList);
   });
   // apply the tabs plugin
   $('#tabs-widget-list').tabs({ event: 'mouseover' });
   
   //=====================================================
   
   // wrap the drop-shadow images in divs for the effect
   $('img.drop-shadow').each(function() {
      var theClass = $(this).attr('class');
      var theHeight = $(this).attr('height') + 22;
      var theWidth = $(this).attr('width') + 22;
      $(this).wrap('<div class="'+theClass+'" style="width:'+theWidth+'px; height:'+theHeight+'px;"></div>').removeClass();
   });
   
   //=====================================================
   
   // Lightbox
	$('a[rel*=lightbox]').lightBox(); 
   
	
   //=====================================================
	
   // MailChimp pop up
   
   
   function showMCPop() {
      $("#mc_overlay, #mc_box").show();
      $("body").css({ "overflow" : "hidden" });
      $(document).keyup(function(e) {
         
         if (e.keyCode == 27) {
            $("#mc_overlay, #mc_box").hide();
            $("body").css({ "overflow" : "auto" , "overflow-y" : "scroll" });
            createCookie("mcpop", "1", 7300);
         }
      });
      
      $("#mc_close").click(function() {
         $("#mc_overlay, #mc_box").hide();
         $("body").css({ "overflow" : "auto" , "overflow-y" : "scroll" });
         createCookie("mcpop", "1", 7300);
      });
      
   }
   
   if(!readCookie("mcpop")) {
      setTimeout(showMCPop, 15000);
   }
   
   //=====================================================
	
   // Cookie functions
   
   function createCookie(name,value,days) {
   	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
   	}
   	else var expires = "";
   	document.cookie = name+"="+value+expires+"; path=/";
   }
   
   function readCookie(name) {
   	var nameEQ = name + "=";
   	var ca = document.cookie.split(';');
   	for(var 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;
   }
	
   //=====================================================
	
//    // Fix Flash to render under MC overlay
// 	
// 	// For Internet Explorer
// 	$("object").each(function () {
//    	
//    
// 	   var hasmode = false;
// 	   
// 	   $(this).children().each(function () {
//    		if ($(this).attr("name") == "wmode") {
//       		$(this).attr("value") = "opaque";
//       		hasmode = true;
// 		   }
//    	});
//    	
//    	if(hasmode == false) {
//          var param = "<param name=\"wmode\" value=\"opaque\" />";
//          //$(this).append(param);
//    	}
//    	//$(this).clone().appendTo(this);
//    	//$(this).remove();
// 	});	
// 	
	// For Firefox Browser
	$("embed").attr("wmode",'opaque');

// 	
// 	
});
