//

$(function() {
	// General Slides
	$('.slides')
	.before('<div id="pager">')
	.cycle({
		fx: 'fade', 
   		pager:  '#pager', 
	    pause:   1 
	});
	
	//NyroModal
	$('.nyroModal').nyroModal();
	
	// color table
	$('tr:even td').css('background', '#eeeeee');
	
	// Remove Default values for class dft-val
	$('.dft-val').focus( function() {
		if (this.value == this.defaultValue) {
			this.value = '';
			$(this).removeClass('gray');
		}
	});
	$('.dft-val').blur( function() {
		if (this.value == '') {
			this.value = this.defaultValue;
			$(this).addClass('gray');
		}
	});
	
	// Ajax for block-tabs
	$('.block-tabs .header a').click(function() {
		$('.block-tabs .header a').removeClass('active');
		$(this).addClass('active');
		// run ajax
		$.get($(this).attr('href'), function(data) {
			$('.block-tabs .content').html(data);
		});
		return false;
	});
	
	// Ajax for block-mtabs
	$('.block-mtabs .header a').click(function() {
		$('.block-mtabs .header a').removeClass('active');
		$(this).addClass('active');
		// run ajax
		$.get($(this).attr('href'), function(data) {
			$('.block-mtabs .content').html(data);
		});		
		return false;
	});
	
	// Attend Information
	$('.attend a').click(function() {
		$(this).closest('.article').find('.attend-full').removeClass('hide');
		return false;
	});
	$('.attend-full a.close').click(function() {
		$(this).closest('.attend-full').addClass('hide');
		return false;
	});
	
	// Accordian For Sidebar
	$('#navigation').accordion({
		alwaysOpen: false,
		autoheight: false,
		header: '.header',
		clearStyle: true
	});
			
	// Nav 
	var displaySub = $('#nav .menu .current').has('ul').length ? true : false;
	if (displaySub == true) {
		$('#nav').css('height', '53px');
		$('.nav-no-sub').append('<ul><li></li></ul>');
	}

	if ($('#nav .menu li').hasClass('current')) {
		$('#nav .menu >ul > li').mouseover(function() {
			if ( $(this).hasClass('current') == false ) {
				$('.menu .current').addClass('no-back');
			}
		}).mouseout(function() { 
			$('.menu .current').removeClass('no-back');
		});
	}

	// Offset Sub Nav
	if (!$('#nav-media').hasClass('current')) {
		$('#nav-media li:first-child').css('margin-left', '408px');
	}
	if (!$('#nav-sport-of-3-gun').hasClass('current')) {
		$('#nav-sport-of-3-gun li:first-child').css('margin-left', '190px');
	}	
	if (!$('#nav-3gn-the-series').hasClass('current')) {
		$('#nav-3gn-the-series li:first-child').css('margin-left', '55px');
	}
	
	
})

// Flash Ad
function expand(pid) {
	$('#' + pid).css('height', '200px');
};
			
// Called when the ad is done closing
function closed(pid) {
	$('#' + pid).css('height', '50px');
};
			
// Called when the user clicks 'close'
function close(pid) {
				
};

// Create div containers for items
function addRow(mcls, item, cols) {
    if (mcls == null || mcls == '') mcls= '.articles';
    if (item == null || item == '') item = '.article';
    if (cols == null || cols == '') cols = 3;
	var divs = $(mcls+ " " + item);
	for(var i = 0; i < divs.length; i+=cols) {
		divs.slice(i, i+cols).wrapAll("<div class='row'></div>");
	}
}
