// JavaScript Document
var current_div = '.cycler-display-first';

$(document).ready(function() {
  $('.cycler-display-first').load('panel1.cfm', null, function() {
    start_cycler();
  });
});

function start_cycler() {
    $('.hmbanner-pics').cycle({ 
            fx: 'scrollHorz',
             speed:  'slow',
			timeout: 0,
			next:    '#next', 
			prev:    '#prev'
    });

    $('.slideshow').cycle({
        fx:     'fade',
        speed:  'slow',
          timeout: 0,
        pager:  '.hmbanner-pics',
	 		  before:   onBefore,
				after:		onAfter,
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
        return '.hmbanner-pics a:eq(' + (idx) + ') img';
        }
    });
}

function onBefore() {
	var video = '';
	for(var i = 0; i < 15; i++) {
		video = document.getElementById('youtubevideo'+i);
    if (video) {
			if (video.pauseVideo) {
	      video.pauseVideo();
			}
    }
	}
	return true;
}

function onAfter() {
	var content = $(this).find('embed,object');
	if (content.length > 0) {
		if (content.hasClass('youtubevideo')) {
			videoStart(content.attr('id'));
		}
	}
}

function videoStart(id) {
	var video = '';
	video = document.getElementById(id);
	if (video) {
		if (video.pauseVideo) {
			video.playVideo();
			return true;
		}
	}
	return false;
}
