//var slideshow = new Array();

$(document).ready(function(){
	
	$('#sponsor_slideshow').cycle({
		fx: 'fade',
		random: true,
		timeout: 6000,
		speed: 500
	});
	
	
	
	$('#slideshow_images').cycle({
		fx: 'fade',
		timeout: 0,
		speed: 500,
		startingSlide: 0
	});
	
	$('#trig_0').click(function() { 
   		$('#slideshow_images').cycle(0); 
    	return false; 
	});
	
	$('#trig_1').click(function() { 
   		$('#slideshow_images').cycle(1); 
    	return false; 
	});
	
	$('#trig_2').click(function() { 
   		$('#slideshow_images').cycle(2); 
    	return false; 
	});
	
	$('#trig_3').click(function() { 
   		$('#slideshow_images').cycle(3); 
    	return false; 
	});
	
	$('#trig_4').click(function() { 
   		$('#slideshow_images').cycle(4); 
    	return false; 
	});
	
	
	
	/*
	i=0;
	$('#slideshow_text h2').each(function(){
		//slideshow[slideshow.length] = $(this).text();
		$(this).attr('rel', i);
		i++;
	}).click(function(e){
		e.preventDefault();
		console.log($(this).attr('rel'));
		//$('#slideshow_images').cycle(parseInt($(this).attr('rel')));
		
		$('#slideshow_images').cycle(2);
		return false;
	});
	*/

	// accordion_nav
	//$('.trigger:last').addClass('last');
	
	$('.indicator_text').hide();
	$('.trigger:first').parent().addClass('active');
	$('.trigger:first').next().show();
	
	$('.indicator_wrapper').append('<div class="slide_arrow"></div>');
	
	$('.trigger').click(function(){
	    if( $(this).next().is(':hidden') ) {
	    	$('.trigger').next().slideUp();
	    	$('.trigger').parent().removeClass('active');
	    	$(this).next().slideDown();
	    	$(this).parent().toggleClass('active');
	    }
	    return false;
	});
	
	
	// submits search form and newsletter sign up
	$('#search_form a.submit_button').click(function(e){
    	e.preventDefault();
    	$("#search_form").submit(); 
  	});
	
	$('#newsletter_signup a.submit_button').click(function(e){
    	e.preventDefault();
    	$("#newsletter_signup").submit(); 
  	});
	
	
	// tweet 
	$(function(){
      $("#twitter_feed").tweet({
        username: "ATCICnews",
        count: 2,
        template: "{text}{time}",
        loading_text: "loading tweets..."
      });
    });

	
	//Search form
	$('input#akeywords').each(function(){
				$(this).data('value', $(this).attr('value'));
		});
		
		$('input#akeywords').focus(function(){
			if ($(this).attr('value') == $(this).data('value')){
				$(this).attr('value', '');
				$(this).css('color', '#454443');
			}
		});
		
		$('input#akeywords').blur(function(){
			if ($(this).attr('value') == ''){
				$(this).attr('value', $(this).data('value'));
				$(this).css('color', '#94897f');
			}
		});


	//removes divider from the last element of the nav
	$('#nav ul.nav1>li:last-child').css({
	    'background-image': 'none',
	    'margin-right' : 0
	});
	    	
	    
	//removes the subnav if it isn't present
	if ($("#subnav ul li.on").children("ul").length == 0) {
	    $("#subnav_area").remove();
	}
	
	//changes the page width on pages w/o a subnav area
	if ($("#subnav_area").children().size() == 0) {					
	    $("#main_content").css({
			"width": "auto",
	    	"padding-left": "20px",
	    	"padding-right": "20px",
	    	"float": "none"
	    });
	}
	
});

