/* ========================================================================= */
/* BE SURE TO COMMENT CODE/IDENTIFY PER PLUGIN CALL                          */
/* ========================================================================= */
window.onload = function() {

	$('.archive-list li:nth-child(4n)').css('margin-right', '0');
	$('#nav > li:first-child').remove();
	$('#nav > li:first-child a').css('border-left', 'none');
	$('#nav > li:last-child a').css('border-right', 'none');
	$('#nav li:last-child').addClass('bttm');
	
	$('.post-list > li:first-child').css('border-top', 'none');
	$('.banner-bttm ul li:last-child').css('border-right', 'none');
	
	$('.team-list:nth-child(2n)').addClass('tl-alternate');
	
	$('.content-main blockquote:last-child').css('border-bottom', 'none');
	
	//Cycle Banner
	if(($('.banner-img .bi-slide').length)>1){
		var transition = $.browser.msie && $.browser.version == 8 ? 'none' : 'fade';
		$('.banner-img').cycle({
	        fx:     transition,
	        speed:  800,
	        timeout: 6000,
	        pager:  '.banner-bttm ul',
	        pagerAnchorBuilder: function(idx, slide) {
	            // return sel string for existing anchor
	            return '.banner-bttm ul li:eq(' + (idx) + ') a';
	        }
	    });
    }
    
    
   
    //Tabs 
    $('.newsroom').tabs({
    	"show" : function(){
    		$('.tcb-slider').cycle('destroy');
    		$('.tcn-slider').cycle('destroy');
    		
    		//Newsroom Cycle
		    $('.tcb-slider').cycle({
		    	fx:     'none',
		        speed:  0,
		        timeout: 0,
		        activePagerClass: 'selected',
		        pager:  '.nav-blog'
		    });
		    
		    $('.tcn-slider').cycle({
		    	fx:     'none',
		        speed:  0,
		        timeout: 0,
		        activePagerClass: 'selected',
		        pager:  '.nav-news'
		    });
		    
		    return false;
    	}
    });
    
    
    
    // Calculator math
    $('#submit').click(function(e){
        e.preventDefault();
        var cost = $("#cost").val();
        var miles = $("#miles").val().replace(",","");
        var newcar = $("#newcar").val();
        var current = $("#current").val();
        var total = ((miles/current) - (miles/newcar)) * (cost/12);
        var totalyear = ((miles/current) - (miles/newcar)) * cost;
        total = Math.round(total);
        totalyear = Math.round(totalyear);
        if(total > 0){
            $('.calc-solution #monthly').text(total);
        } else {
            $('.calc-solution #monthly').text('Error');
        }
        if(totalyear > 0){
            $('.calc-solution #yearly').text(totalyear);
            $('.calc-solution #yearly2').text((totalyear * 2));
            $('.calc-solution #yearly3').text((totalyear * 3));
            $('.calc-solution #yearly4').text((totalyear * 4));
        } else {
            $('.calc-solution #yearly').text('Error');
            $('.calc-solution #yearly2').text('Error');
            $('.calc-solution #yearly3').text('Error');
            $('.calc-solution #yearly4').text('Error');
        }
	});
	
	$('a[rel="cb-team"]').colorbox();

	$('a[rel="cb-video"]').colorbox({
		iframe: true,
		width: '620px',
		height: '480px'
	});
	
	//$(".cb-iframe").colorbox({iframe:true, width:"80%", height:"80%", opacity: 0.7});
		
	// Video Slider 
	if(($('div.slide').length)>1){
		$('.video-slider .arrows').css('display', 'block');
		$('.video-slide').cycle({
	    	fx: 'fade',
	        speed: 1,
	        timeout: 0,
	        prev: '.video-slider .prev',
	        next: '.video-slider .next',
			before: function(){
		        $(this).parent().find('div.current').removeClass('current');
		           
		    },
			after: function(curr, next, opts){
				$(this).addClass('current');
			
				/*
				var index = opts.currSlide;
				$('.video-slider .prev')[index == 0 ? 'hide' : 'show']();
				$('.video-slider .next')[index == opts.slideCount - 1 ? 'hide' : 'show'](); 
				*/
			} 
		});
	}

	$('.links-list li a').hover(function(e){
		if(e.type == "mouseenter") {
			$(this).children('img').animate({
				opacity: .8
			}, 350, function() {
			    // Animation complete.
			});	
		}
		if(e.type == "mouseleave") {
			$(this).children('img').animate({
				opacity: 1
			}, 150, function() {
			    // Animation complete.
			});	
		}
	});
	
	
	
}


