if(typeof console != 'object'){
	console = {log:function(str){}};
}
$(function(){
	/*initialize the accordion menu for quick links.*/
	$('ul#quickLinks').accordion({
		header: '.head',
		alwaysOpen: false,
		active: false,
		autoHeight: false
	});

	$('ul#quickLinks ul').accordion({
		header: '.head2',
		alwaysOpen: false,
		active: false,
		autoHeight: false
	});
	
	$('#spotlightWrap').cycle({ 
    	timeout: 4000,
    	next: '#spotNext', 
    	prev: '#spotPrev', 
    	fx: 'fade'
	});
	
	$('#headlineContent').cycle({ 
    	timeout: 9000,
    	fx: 'fade',
    	next: '#next', 
    	prev: '#prev',
    	before: onBefore,
    	after: onAfter,
    	fit: 0,
    	containerResize: 0
	});
		
		
	function onBefore(curr, next, opts, fwd) { 
    	$('#nextUp').html('<p>loading...</p>');
    	//alert(this.alt); 
	} 
	function onAfter(curr, next, opts, fwd) { 
		//store all the children in the slides variable
    	var $slides = $(this).parent().children();
    	//store the index of the current slide in the index variable
    	var index = $slides.index(this);
    	//create nextslide
    	var $nextSlide;
    	
    	if (fwd && index == (opts.slideCount - 1)) { 
    	        $nextSlide = $slides.eq(0);
    	} else if (fwd) {
    	        $nextSlide = $slides.eq(index+1);
    	} else if (!fwd && index == 0) {
    	        $nextSlide = $slides.eq(opts.slideCount-1);
    	} else if (opts.slideCount == 0) {
    	        $nextSlide = $slides.eq(opts.slideCount-1);
    	        
    	} else {
    	        $nextSlide = $slides.eq(index-1);
		}
    	$('#nextUp').html('<p>UP NEXT: ' + $nextSlide.children().children('h1').html() +'</p>'); 
    	$('#currentSlide').html((index+1) + ' of ' + opts.slideCount)
		if(screen.height<620 && screen.width < 820){
			$(".slideInner").css("width","auto");
		}
    	
	}

	
	//toggles the play and pause.
	
	 $('#pauseBtn').toggle(function() {

		$('#headlineContent').cycle('pause');
		$(this).attr({ src: "images/pause_inactive.gif"});

		}, function() {

		$('#headlineContent').cycle('resume', true);
		$(this).attr({ src: "images/pause_slide.gif"});


	});
	
	screenHeight = 620;
	screenWidth = 820;
	if(screen.height<screenHeight && screen.width < screenWidth){
		document.getElementById("headlineContent").style.height="450px";
		$(".slideInner").css("width","auto");
	}
	
});


function resizeImg(image){
	screenHeight = 620;
	screenWidth = 820;
	
	newWidth  = 180;
	newHeight = 250;
	
	if(screen.height < screenHeight && screen.width < screenWidth){
		if (image == undefined || image == null) return false;
		if ( (image.width > image.height) && (image.width>newWidth) ){
			newHeight = (newWidth * image.height / image.width);
			image.height = newHeight;
			image.width = newWidth;
		}
		if ( (image.height > image.width) && (image.height>newHeight) ){
			newWidth = (newHeight * image.width / image.height);
			image.height = newHeight;
			image.width = newWidth;
		}
	}
}