// expander script runs in conjunction with jquery

$(document).ready(function() {

  // simple example, using all default options
	 
 
	// News ticker animation
	var current = -1;
	var elems = new Array();
	var elems_i = 0;
	$('.items').each(function() {
		elems[elems_i++] = $(this);
	});
	var num_elems = elems_i - 1;
	var animate_out = function() {
		elems[current].animate({ top: '-200px' }, 'slow', 'linear', animate_in);
	}
	var animate_out_delay = function() {
		setTimeout(animate_out, 5000);
	}
	var animate_in = function() {
		current = current < num_elems ? current + 1 : 0;
		elems[current].css('top', '150px').animate({ top: '0px' }, 'slow', 'linear', animate_out_delay);
	}
	animate_in();
	
	// Survey loading script
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
		
		
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
		
		// For Ie6
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$('#top').hide();
		}
		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  (winH/2-$(id).height()/2)-100);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	
	
	// Expander activation stuff
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			$('#top').show();
		}
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			$('#top').show();
		}
	});			
  
  // override some default options
  $('div.expandable p').expander({
    slicePoint:       500,  // default is 100
	expandSpeed: 	1000,
	expandEffect:     'fadeIn',
    expandText:         'read more ...', // default is 'read more...'
    collapseTimer:    15000, // re-collapses after 5 seconds; default is 0, so no re-collapsing
    userCollapseText: '[ hide ]'  // default is '[collapse expanded text]'
  });
  
  
  // Coda panels scripts
 $('#coda-slider-1').codaSlider({
        autoSlide: true,
        autoSlideInterval: 8000,
        autoSlideStopWhenClicked: true,
		dynamicArrows: false,
		dynamicTabs: false
    });

});
