// HERO IMAGE
jQuery(function($){
	$('#hero').cycle({ 
		fx:     'scrollHorz', 
		prev:   '.previousArrow', 
		next:   '.nextArrow',
		speed:    300,
		timeout: 6000,
		pause: 1
	});

    // PAUSE/RESUME ON VIDEO CLICK
	$('#hero').hover(function(){
		$(this).cycle('pause');
	});

  // FADE GRAYSCALE BUCKETS
	$(".buckets").hover(function() { //On hover...
	var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

	//Set a background image(thumbOver) on the <a> tag - Set position to bottom
	$(this).find(".bucketImage").css({
		'background' : 'url(' + thumbOver + ') no-repeat center bottom'
	});

	//Animate the image to 0 opacity (fade it out)
	$(this).find("span").stop().fadeTo('fast', 0 , function() {
		$(this).hide() //Hide the image after fade
	});

	} , function() { //on hover out...
	//Fade the image to full opacity 
	$(this).find("span").stop().fadeTo('fast', 1).show();
	});

    // FADING SOCIAL MEDIA ICONS
	$(".socialIcons").hover(function() { //On hover...
	var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

	//Set a background image(thumbOver) on the <a> tag - Set position to bottom
	$(this).find(".icon").css({
		'background' : 'url(' + thumbOver + ') no-repeat center bottom'
	});

	//Animate the image to 0 opacity (fade it out)
	$(this).find("span").stop().fadeTo('slow', 0 , function() {
		$(this).hide() //Hide the image after fade
	});

	} , function() { //on hover out...
	//Fade the image to full opacity 
    $(this).find("span").stop().fadeTo('slow', 1).show();
	});

    // SEARCH BAR AUTOFILL
	$('#txtSearch').autofill({
    value: 'Search',
    defaultTextColor: '#000',
    activeTextColor: '#000'
	});

   $('#subscribe').autofill({
    value: 'Enter your e-mail address',
    defaultTextColor: '#000',
    activeTextColor: '#000'
	}); 

   $('#dealer_zip_code').autofill({
    value: 'Enter City, State or ZIP Code',
    defaultTextColor: '#999',
    activeTextColor: '#444'
	}); 

  $('.dealer-search').autofill({
    value: 'Enter City, State or ZIP Code',
    defaultTextColor: '#999',
    activeTextColor: '#444'
	});

  $('.sb').click(function(){
    $('form.browse-all-dealers').toggleClass('hide');
  });

  //FANCY BOX
  $(".zoomVid").click(function() {
  $.fancybox({
    'overlayOpacity' : 0.7,
    'overlayColor' : '#000',
    'overlayShow' : 'true',
    'padding' : 0,
    'autoScale': false,
    'transitionIn': 'fade',
    'transitionOut': 'fade',
    'title' : this.title,
    'width'	: 560,
    'height': 340,
    'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
    'type': 'swf',
    'swf': {
       'wmode'						: 'transparent',
       'allowfullscreen'  : 'false'
    }

  });
      return false;
  });

    //fix for IE that did not like a return false //line 104
    $('.zoomVid').click(function(){
        $.fancybox({
           'callbackOnClose'   : function(){
                $('#fancy_content').empty();
            } 
        });
    });
});

function showTTabContent(id){
	$('.tabContent').hide();
	$('#' + id + '_tabContent').show();
}

function currentCContentBold(id) {
	$('.trainLink').removeClass('activeModel');
}

//FADE IN / OUT BETWEEN SHOW/HIDE --> ERRORS IN IE7
$(document).ready(function(){
    $('#modelInfo ul li.modelLink').click(function(){
        var schedule = $(this).attr('id');

        if (schedule == 'schedule'){
            $('.sidebar').fadeOut(300);
            $('#one_tabContent').fadeOut(300);
            $('#schedule_tabContent').fadeIn(300);
        } 
        else 
        {
            $('.sidebar').fadeIn(300);
            $('#one_tabContent').fadeIn(300);
            $('#schedule_tabContent').fadeOut(300);
        }
    });
});

function showTabContent(id){
	$('.tabContent').hide();
	$('#' + id + '_tabContent').show();
	$('#modelInfo ul li').removeClass('activeModel');
	$(this).toggleClass('activeModel');
}

function currentContentBold(id) {
	$('.modelLink').removeClass('activeModel');
	$('#' + id).addClass('activeModel');
}

// Tabs  FIREARMS LANDING PAGE
$(document).ready(function(){
	$('.tabContent').hide();
	$('#one_tabContent').show();
	$('#modelTabs ul li#one').addClass('activeTab');
	$('.tabLink').hover(function(){
		var id = $(this).attr('id');
		$('.tabContent').hide();
		$('#' + id + '_tabContent').show();
		$('#modelTabs ul li').removeClass('activeTab');
		$(this).toggleClass('activeTab');
	});

//TABS FOR INDIVIDUAL MODELS 
	$('.tabContent').hide();
	$('#one_tabContent').show();
	$('#modelInfo ul li#one').addClass('activeModel');
	$('.modelLink').click(function(){
		var id = $(this).attr('id');
		$('.tabContent').hide();
		$('#' + id + '_tabContent').show();
		$('#modelInfo ul li').removeClass('activeModel');
		$(this).toggleClass('activeModel');
	});
	$('.modelLink').hover(function(){
		$(this).css({'color' : '#fff'});
		}, function(){
		$(this).css({'color' : '#999'});
	});
});

//INTERNATIONAL AJAX INFO
$(document).ready(function(){

    $('#country').change(RepCountry);

    function RepCountry(){
        var sel = $('#country option:selected');
        var value = "";
        if (sel.val() != 0){
            value = sel.val(); 
        }
        var sel2 = $('p#content_' + value + '').html();
        $('#rep').html(sel2);
    }
});

//FOR TRAINING PAGES (REMOVES activeModel class)
$(document).ready(function(){
	$('.tabContent').hide();
	$('#one_tabContent').show();
	$('#modelInfo ul li#one').addClass('activeModel');
	$('.trainLink').click(function(){
		var id = $(this).attr('id');
		$('.tabContent').hide();
		$('#' + id + '_tabContent').show();
		$('#trainingInfo ul li').removeClass('activeTraining');
		$(this).toggleClass('activeTraining');
	});
	$('.trainLink').hover(function(){
		$(this).css({'color' : '#333'});
		}, function(){
		$(this).css({'color' : '#999'});
	});
});

//wtf is this code
$(document).ready(function(){
	$('.moreNews').hide();
	$('.newsBlock a.moreLink').click(function(){
		$(this).toggle();
		var id = $(this).attr('id');
		$('#' + id + '_moreNews').show();
	});

	$('.moreVids').css({'display' : 'none'});
	$('a.lessLink').css({'display' : 'none'});
	$('a.moreLink').click(function(){
		$('.moreVids').css({'display' : 'block'});
        $(this).css({'display' : 'none'});
        $('a.lessLink').css({'display' : 'block'});
        $('a.lessLink').click(function(){
            $(this).css({'display' : 'none'});
            $('.moreVids').css({'display' : 'none'});
            $('a.moreLink').css({'display' : 'block'});
        });
	});

	$('.moreFloats').css({'display' : 'none'});
	$('a.lessLink2').css({'display' : 'none'});
	$('a.moreLink2').click(function(){
		$('.moreFloats').css({'display' : 'block'});
        $(this).css({'display' : 'none'});
        $('a.lessLink2').css({'display' : 'block'});
        $('a.lessLink2').click(function(){
            $(this).css({'display' : 'none'});
            $('.moreFloats').css({'display' : 'none'});
            $('a.moreLink2').css({'display' : 'block'});
        });
	});
});


