$(document).ready(function(){
	
	var deviceBB = DetectBlackBerry( navigator.userAgent.toLowerCase() );
	if (deviceBB) {
		$('#blackberry_desktop_link').show();
	}
		
	//Begin progressive enhancements
	//$('#container').removeClass('javascript_disabled');
	
	// if ($('.show_more_table').length != 0)
	//   {
	//     var initial_display = 20;
	//     var inremental_display = 20;
	//     $('.show_more_table').each(function(){
	//       if ($(this).attr('data-show'))
	//       {
	//         initial_display = $(this).attr('data-show');
	//         inremental_display = $(this).attr('data-show');
	//       }
	//       var story_list = $(this);
	//       var button = $(this).siblings('.block-button');
	//       if (button.length != 0)
	//       {
	//         //Hide stories after init display
	//         var count = 0;
	//         var children = story_list.children('table').children('tbody').children('tr');
	//         children.each(function(){
	//           if (count >= initial_display){
	//             $(this).hide();
	//           }
	//           count++;
	//         });
	//         
	//         if (children.length <= initial_display)
	//         {
	//           //button.hide();
	//           button.children('.button, .action').hide();
	//         }
	//         
	//         //Clicking a story will display it
	//         button.click(function(){
	//           var count = 0;
	//           var hidden = 0;
	//           children.each(function(){
	//             if( ! $(this).is(':visible') ) {
	//               if (count < inremental_display){
	//                 $(this).show();
	//                 count++;
	//               }else{
	//                 hidden++;
	//               }
	//             }
	//           });
	//           
	//           if (hidden == 0){
	//             $(this).children('.button').hide();
	//           }
	//           
	//           return false;
	//         });
	//       
	//       }
	//     });
	//   }
	//   
	//   
	//   //Is there a story list on this page?
	//   if ( $('.story_list, .show_more_li').length != 0)
	//   {
	//     //Limit the story display to 3
	//     var initial_display = 4;
	//     var inremental_display = 6;
	//     $('.story_list, .show_more_li').each(function(){
	//       var story_list = $(this);
	//       if ($(this).attr('data-show'))
	//       {
	//         initial_display = $(this).attr('data-show');
	//         inremental_display = $(this).attr('data-show');
	//       }
	//       var button = $(this).siblings('.block-button');
	//       if (button.length != 0)
	//       {
	//         //Hide stories after first 3
	//         var count = 0;
	//         story_list.children('li').each(function(){
	//           if (count >= initial_display){
	//             $(this).hide();
	//           }
	//           count++;
	//         });
	//         
	//         if (story_list.children('li').length <= initial_display)
	//         {
	//           button.hide();
	//         }
	//         //Clicking a story will display it
	//         button.click(function(){
	//           var count = 0;
	//           var hidden = 0;
	//           story_list.children('li').each(function(){
	//             if( ! $(this).is(':visible') ) {
	//               if (count < inremental_display){
	//                 $(this).show();
	//                 count++;
	//               }else{
	//                 hidden++;
	//               }
	//             }
	//           });
	//           
	//           if (hidden == 0){
	//             button.hide();
	//             //$(this).children('.button, .action').hide();
	//           }
	//           
	//           return false;
	//         });
	//       
	//       }
	//     });
	//   }
	//   
	//   //If there is an article on this page?
	//   var story_detail = '.story_detail';
	//   if ( $(story_detail).length != 0)
	//   {
	//     var story_height = $(story_detail + '>.maxwidth>.content').height();
	//     //Truncate the story content
	//     var condense = $(story_detail + '>.maxwidth>.content').condense({condensedLength: 400, appendButtons: false});
	//     if ($(story_detail + '>.maxwidth>.content.the_clone').length > 0){
	//       //elipsis
	//       $(story_detail + '>.maxwidth>.content.the_clone').children('p:last').append(' ...');
	//       //If the continue reading button is clicked display the rest of the copy
	//       $(story_detail + ' .block-button').click(function(){
	//         var condense_height = $(this).siblings('.maxwidth').children('.the_clone').height();
	//         $(this).siblings('.maxwidth').children('.the_clone').remove();
	//         var jcontent = $(this).siblings('.maxwidth').children('.content');
	//         jcontent.show();
	//         $(this).hide();
	//         return false;
	//       });
	//     }else
	//     {
	//       $(story_detail + ' .block-button').hide();
	//     }
	//   }
	//   
	//   //Is there a weather group on this page?
	//   if ( $('.weather_group').length != 0)
	//   {   
	//     var weather = $('.weather_group');
	//     var count = 0;
	//     
	//     weather.children('li').each(function(){
	//       var icon = $(this).children('h2').children('a').children('.icon');
	//       var content = $(this).children('.content');
	//       var h2 = $(this).children('h2');
	//       h2.click(function(){
	//         if (content.is(':visible')) 
	//         {
	//           //console.log(icon);
	//           icon.html('+');
	//           content.hide();
	//         }
	//         else
	//         {
	//           icon.html('-');
	//           content.show(); 
	//         }
	//         return false;
	//       });
	//     });
	//     
	//   } 
});

function toggleWeather(li)
{
	var jo = $(li);
	//Do the collapse
	if (jo.hasClass('expanded') )
	{
		jo.removeClass('expanded').addClass('collapsed');
		jo.children('h2').children('a').children('.icon').html('[+]');
		jo.children('.image').hide();
	}
	//Do the expand
	else
	{
		jo.addClass('expanded').removeClass('collapsed');
		jo.children('h2').children('a').children('.icon').html('[-]');
		jo.children('.image').show();
	}

}

function setExpand(element)
{
	var jo = $(element);
	jo.removeClass('collapsed').addClass('expanded');
	jo.children('.image').show();
	jo.children('h2').children('a').children('.icon').addClass('action_hide').html('[-]');
}

function setCollapse(element)
{
	var jo = $(element);
	jo.removeClass('expanded').addClass('collapsed');
	jo.children('.image').hide();
	jo.children('h2').children('a').children('.icon').addClass('action_show').html('[+]');
}

// Detects if the current browser is a BlackBerry of some sort.
function DetectBlackBerry(target)
{
   if (target.search("blackberry") > -1)
      return true;
   else
      return false;
}
