$(document).ready(function() {

// Replace %20 (Spaces) in catname with a real space

    var strNewString = $('h2.catname').text().replace(/\%20/g,' ');
    $('h2.catname').text(strNewString);

// iOS Hover Event Class Fix - http://niteodesign.com/web-design/iphone-ipad-ios-and-the-css-hover-event/
// alternate http://blog.0100.tv/2010/05/fixing-the-hover-event-on-the-ipadiphoneipod/
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
$(".nav li a").click(function(){  // Update class to point at the head of the list
});
}

// YES: http://www.script-tutorials.com/click-action-css3-dropdown-menu-with-jquery/
//http://stackoverflow.com/questions/752386/on-click-toggle-ul-on-click-elsewhere-hide-ul

	function imageresize() {
	
	var contentwidth = $('.container').width();
	$('.flex').each(function(){

	if ((contentwidth) > '480'){
	$(this).attr('src', $(this).attr('data-src'));
		}
	else
		{
	$(this).attr('src', $(this).attr('data-rel'));
		}

});
}

imageresize();//Triggers when document first loads    

	$(window).bind("resize", function(){ //Adjusts image when browser resized
	imageresize();
		});



$("#menu a").click(function(){
$("#nav ul,form.cms_form").slideToggle(400);
$(this).toggleClass("active"); return false;
});


   	$("#close_menu").click(function(){
	$("#nav ul,form.search,form.cms_form").hide('slow');
	$("#menu a").toggleClass("active"); return false;
	});
   


// Add fancy box **************//

	$("a.group").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'padding': '0', 
			'titlePosition' 		: 'inside',

		'margin': 30,
		'overlayColor': '#7caf32',
		'overlayOpacity': '0.9'
			});
			
			
// Add bar separator to categories unless there is only one and except the :last-child ******//
$('div.categories ul li').not(':last-child').append(' | ');

// Add class current to category and blogpost navigation **************//

 $(function(){
   var path = location.pathname.substring(1);
   if ( path )
     $('.widget a[href$="' + path + '"]').attr('class', 'selected');
 });


});

